[pLog-svn] r1027 - in plog/trunk/class: dao view

oscar at devel.plogworld.net oscar at devel.plogworld.net
Wed Feb 9 23:19:14 GMT 2005


Author: oscar
Date: 2005-02-09 23:19:14 +0000 (Wed, 09 Feb 2005)
New Revision: 1027

Modified:
   plog/trunk/class/dao/article.class.php
   plog/trunk/class/dao/articles.class.php
   plog/trunk/class/view/viewarticleview.class.php
Log:
fixed issue 226 (http://bugs.plogworld.net/view.php?id=226) as reported by user 'pest', regarding problems with getBlogPrevArticle and getBlogNextArticle when used with time offsets. The aforementioned methods have been modified to remove the time offset of the article when checking for the previous and next posts in time. Also the signature of the method has changed a bit, since now it does not take an article id and a blog id as parameters but only an Article object.

Also the objects 'prevpost' and 'nexpost' have been removed from the default template context in postandcomments.template and now it is possible to get a reference to the next and previous posts in any context where we have an Article object via Article::getPrevArticle() and Article::getNextArticle() The data is loaded as needed so in fact this should improve performance a bit if we don't want to know anything about the next and previous article...

I have also modified the wiki to reflect these changes (http://wiki.plogworld.net/index.php/PLog_1.0/Porting_templates_to_pLog_1.0#.7B.24nextpost.7D_and_.7B.24prevpost.7D)

Modified: plog/trunk/class/dao/article.class.php
===================================================================
--- plog/trunk/class/dao/article.class.php	2005-02-09 18:39:00 UTC (rev 1026)
+++ plog/trunk/class/dao/article.class.php	2005-02-09 23:19:14 UTC (rev 1027)
@@ -48,6 +48,8 @@
 		var $_fields;
 		var $_trackbacks;
 		var $_slug;
+		var $_nextArticle;
+		var $_prevArticle;
 
         /**
          * Constructor.
@@ -760,6 +762,39 @@
 		{
 			return( $this->_timestamp->getDay());
 		}
-
+		
+		/**
+		 * returns the previous article in time
+		 *
+		 * @return an Article object representing the previous article, in time, in the database
+		 */
+		function getPrevArticle()
+		{
+			if( !isset($this->_prevArticle )) {
+				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+				
+				$articles = new Articles();
+				$this->_prevArticle = $articles->getBlogPrevArticle( $this );
+			}
+			
+			return( $this->_prevArticle );
+		}
+		
+		/**
+		 * returns the next article in time
+		 *
+		 * @return an Article object representing the next article, in time, in the database
+		 */
+		function getNextArticle()
+		{
+			if( !isset($this->_nextArticle )) {
+				include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+				
+				$articles = new Articles();
+				$this->_nextArticle = $articles->getBlogNextArticle( $this );
+			}
+			
+			return( $this->_nextArticle );
+		}		
 	}
 ?>

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2005-02-09 18:39:00 UTC (rev 1026)
+++ plog/trunk/class/dao/articles.class.php	2005-02-09 23:19:14 UTC (rev 1027)
@@ -178,62 +178,44 @@
         /**
          * Returns the article that goes after the one we give as the parameter.
          *
-         * @param articleId The Article identifier.
-         * @param blogId The blog to which the article belongs.
-         * @return An Article object with the next article or false if there was no article.
+         * @param article An article object         
+		 * @return An Article object with the next article or false if there was no article.
          */
-        function getBlogNextArticle( $articleId, $blogId )
+        function getBlogNextArticle( $article )
         {
-            // fetch the article
-            $article = $this->getBlogArticle( $articleId, $blogId );
-            if( !$article )
-                return false;
+			// we need to keep the timestamp in mind
+			$date = $article->getDateObject();
+			$articleCorrectedDate = Timestamp::getDateWithOffset( $article->getDate(), -($article->getTimeOffset()));
+			$blogId = $article->getBlog();
 
             // gets the article that is just next in time
             $query = "SELECT * FROM ".$this->getPrefix()."articles 
-			                  WHERE date > '".$article->getDate()."' AND 
-							        status = 1 AND blog_id = '".Db::qstr($blogId)."' ORDER BY date ASC LIMIT 1;";
-            $result = $this->Execute( $query );
-            if( !$result )
-                return false;
-            if( $result->RecordCount() == 0 )
-                return false;
-
-            // get the information from the article
-            $row = $result->FetchRow();
-
-            return $this->_fillArticleInformation( $row );
+			                  WHERE date > '".$articleCorrectedDate."' AND status = '".Db::qstr(POST_STATUS_PUBLISHED)."' 
+							        AND blog_id = '".Db::qstr($blogId)."' ORDER BY date ASC LIMIT 1;";
+			
+			return( $this->_getBlogArticleFromQuery( $query, false ));
         }
 
         /**
          * Returns the article that goes before the one we give as the parameter.
          *
-         * @param articleId The Article identifier.
-         * @param blogId The blog to which the article belongs.
-         * @return An Article object with the next article or false if there was no article.
+         * @param article An article object
+         * @return An Article object with the previous article or false if there was no article.
          */
-        function getBlogPrevArticle( $articleId, $blogId )
+        function getBlogPrevArticle( $article )
         {
-            // fetch the article
-            $article = $this->getBlogArticle( $articleId, $blogId );
-            if( !$article )
-                return false;               
-
-            // gets the article that is just next in time
+			// we need to keep the timestamp in mind
+			$date = $article->getDateObject();
+			$articleCorrectedDate = Timestamp::getDateWithOffset( $article->getDate(), -($article->getTimeOffset()));
+			$blogId = $article->getBlog();			
+		
+            // gets the article that is just previous in time
             $query = "SELECT * FROM ".$this->getPrefix()."articles 
-			                   WHERE date < '".$article->getDate()."' AND status = 1 AND 
-							         blog_id = '".Db::qstr($blogId)."' ORDER BY date DESC LIMIT 1;";
-            $result = $this->Execute( $query );
-            if( !$result )
-                return false;
-            if( $result->RecordCount() == 0 )
-                return false;
-
-            // get the information from the article
-            $row = $result->FetchRow();
-
-            return  $this->_fillArticleInformation( $row );
-        }
+			                   WHERE date < '".$articleCorrectedDate."' AND status = ".POST_STATUS_PUBLISHED." 
+									 AND blog_id = '".Db::qstr($blogId)."' ORDER BY date DESC LIMIT 1;";
+									 
+			return( $this->_getBlogArticleFromQuery( $query, false ));
+		}
 		
 		/**
 		 * a shortcut for getBlogArticles in case we're only interested in searching all the items

Modified: plog/trunk/class/view/viewarticleview.class.php
===================================================================
--- plog/trunk/class/view/viewarticleview.class.php	2005-02-09 18:39:00 UTC (rev 1026)
+++ plog/trunk/class/view/viewarticleview.class.php	2005-02-09 23:19:14 UTC (rev 1027)
@@ -49,9 +49,7 @@
 			
 			// get the next and previous articles, based on the article we're going to show
 			$article = $this->getValue( 'post' );
-            $nextArticle = $this->articles->getBlogNextArticle( $article->getId(), $this->_blogInfo->getId());
-            $prevArticle = $this->articles->getBlogPrevArticle( $article->getId(), $this->_blogInfo->getId());
-            
+			
             // notify of certain events
 			$postText = $article->getIntroText();
 			$postExtendedText = $article->getExtendedText();
@@ -64,10 +62,7 @@
 			
 			// once ready, put the article back to the context of the view
 			$this->setValue( 'post', $article );			
-			
             $this->setValue( 'comments', $article->getComments());
-            $this->setValue( 'nextpost', $nextArticle );
-            $this->setValue( 'prevpost', $prevArticle );
             $this->setValue( 'user', $article->getUser());
             $this->setValue( 'trackbacks', $article->getTrackbacks());
             




More information about the pLog-svn mailing list