[pLog-svn] r2494 - in plog/trunk/class: action dao

oscar at devel.plogworld.net oscar at devel.plogworld.net
Mon Sep 19 07:06:23 GMT 2005


Author: oscar
Date: 2005-09-19 07:06:22 +0000 (Mon, 19 Sep 2005)
New Revision: 2494

Modified:
   plog/trunk/class/action/blogaction.class.php
   plog/trunk/class/action/defaultaction.class.php
   plog/trunk/class/action/viewarticleaction.class.php
   plog/trunk/class/dao/articles.class.php
Log:
added the beginnings of paging for the front blog page


Modified: plog/trunk/class/action/blogaction.class.php
===================================================================
--- plog/trunk/class/action/blogaction.class.php	2005-09-19 07:05:30 UTC (rev 2493)
+++ plog/trunk/class/action/blogaction.class.php	2005-09-19 07:06:22 UTC (rev 2494)
@@ -90,6 +90,9 @@
 			// update the referrers, if needed
 			$this->_updateReferrer();
 			
+			// get the "page" parameter from the request
+			$this->_page = $this->_getPage();
+			
 			$this->articles = new Articles();	
         }
 		
@@ -268,5 +271,21 @@
 			
 			return true;
 		}
+		    
+	    /**
+	     * @private
+	     */
+	    function _getPage()
+	    {
+	            include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php");    	
+				// get the value from the request
+				$page = HttpVars::getRequestValue( "page" );
+				// but first of all, validate it
+				$val = new IntegerValidator();
+				if( !$val->validate( $page ))
+					$page = 0;	
+
+				return $page;	    
+	    }		
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/action/defaultaction.class.php
===================================================================
--- plog/trunk/class/action/defaultaction.class.php	2005-09-19 07:05:30 UTC (rev 2493)
+++ plog/trunk/class/action/defaultaction.class.php	2005-09-19 07:06:22 UTC (rev 2494)
@@ -60,11 +60,12 @@
             // prepare the view
         	$this->_view = new DefaultView( $this->_blogInfo,
 			                                Array( "categoryId" => $this->_categoryId,
-							       "blogId" => $this->_blogInfo->getId(),
-							       "categoryName" => $this->_categoryName,
-							   "date" => $this->_date,
-							   "userName" => $this->_userName,
-							   "userId" => $this->_userId ));
+							                        "blogId" => $this->_blogInfo->getId(),
+							                        "categoryName" => $this->_categoryName,
+							                        "date" => $this->_date,
+							                        "userName" => $this->_userName,
+							                        "userId" => $this->_userId,
+							                        "page" => $this->_page ));
 														  
 			// check if everything's cached because if it is, then we don't have to
 			// do any work... it's already been done before and we should "safely" assume
@@ -75,6 +76,7 @@
 
             require_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
             require_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+            require_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
 
             // if we got a category name instead of a category id, then we
             // should first look up this category in the database and see if
@@ -146,9 +148,6 @@
             // export the owner. The owner information should get from blogInfo directly
             $this->_view->setValue( "owner", $this->_blogInfo->getOwnerInfo() );
 			
-            $t = new Timestamp();
-            $todayTimestamp = $t->getTimestamp();
-			
             // amount of posts that we have to show, but keeping in mind that when browsing a
             // category or specific date, we should show *all* of them
             if( $this->_date > 0 || $this->_categoryId > 0 ) {
@@ -169,15 +168,33 @@
 			
 			if( ($blogSettings->getValue( 'show_future_posts_in_calendar')) && ( $this->_date > -1 )) {
 				// if posts in the future are to be shown, we shouldn't set a maximum date
-				$blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
-								$this->_postAmount, $this->_categoryId,
-								POST_STATUS_PUBLISHED, $this->_userId );			
+				$todayTimestamp = 0;
 			}
-			else {
-				$blogArticles = $this->articles->getBlogArticles( $blogId, $this->_date,
-								$this->_postAmount, $this->_categoryId,
-								POST_STATUS_PUBLISHED, $this->_userId, $todayTimestamp );
-			}			
+			else {			
+            	$t = new Timestamp();
+            	$todayTimestamp = $t->getTimestamp();
+       		}		
+       		
+       		// get the articles...
+			$blogArticles = $this->articles->getBlogArticles( 
+			                        $blogId, 
+			                        $this->_date,
+							        $this->_postAmount, 
+							        $this->_categoryId,
+							        POST_STATUS_PUBLISHED, 
+							        $this->_userId, 
+							        $todayTimestamp,
+							        "",
+							        $this->_page );							        
+			// and the total number based on the conditions given
+			$numArticles = $this->articles->getNumBlogArticles( 
+			                        $blogId, 
+			                        $this->_date,
+							        $this->_postAmount, 
+							        $this->_categoryId,
+							        POST_STATUS_PUBLISHED, 
+							        $this->_userId, 
+							        $todayTimestamp );
 
             // if we couldn't fetch the articles, send an error and quit
             if( count($blogArticles) == 0 ) {
@@ -213,7 +230,16 @@
 				}
 				
     	        $this->_view->setValue( 'posts', $articles );
-            }
+    	        
+    	        // build the pager and pass it to the view
+    	        
+    	        $pager = new Pager( "page=".$this->_page,    // url to the next page
+    	                            $this->_page,            // current page
+    	                            $numArticles,            // total number of articles
+    	                            $this->_postAmount );
+    	        
+    	        $this->_view->setValue( 'pager', $pager );
+            }           
 
             $this->setCommonData();
             // save the information about the session for later

Modified: plog/trunk/class/action/viewarticleaction.class.php
===================================================================
--- plog/trunk/class/action/viewarticleaction.class.php	2005-09-19 07:05:30 UTC (rev 2493)
+++ plog/trunk/class/action/viewarticleaction.class.php	2005-09-19 07:06:22 UTC (rev 2494)
@@ -1,12 +1,6 @@
 <?php
 
 	include_once( PLOG_CLASS_PATH."class/action/blogaction.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
-	include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
-    include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );
-    include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );
-	include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
 
     /**
      * \ingroup Action
@@ -73,7 +67,10 @@
 		 * @private
 		 * updates the article referrers given an id
 		 */
-        function _updateArticleReferrersById($articleId){
+        function _updateArticleReferrersById($articleId)
+        {
+    		include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );	        
+	        
             if ( array_key_exists( 'HTTP_REFERER', $_SERVER ) )
             {
                 $referrers = new Referers();
@@ -85,7 +82,10 @@
 		 * @private
 		 * updates the article referrers, given a slug
 		 */
-		function _updateArticleReferrersByTitle($slug){
+		function _updateArticleReferrersByTitle($slug)
+		{
+    		include_once( PLOG_CLASS_PATH."class/dao/referers.class.php" );			
+			
 			$id = $this->articles->getArticleIdFromName($slug);
 			// if the article isn't found, we will save a referrer to
 		    // the main page, since $id will be 0.
@@ -112,6 +112,8 @@
 		 */		        
         function _getArticleCorrectedDatePeriod()
         {
+			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );		        
+	        
             $blogSettings = $this->_blogInfo->getSettings();
             $serverTimeOffset = $blogSettings->getValue( "time_offset" );
             
@@ -152,7 +154,10 @@
 
         function perform()
         {
+      
 	        include_once( PLOG_CLASS_PATH."class/view/viewarticleview.class.php" );
+    		include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );	   
+    		     
 
         	$this->_view = new ViewArticleView( $this->_blogInfo, 
                                                    Array( "articleId" => $this->_articleId,
@@ -161,7 +166,7 @@
                                                           "categoryName" => $this->_categoryName,
                                                           "userId" => $this->_userId,
                                                           "userName" => $this->_userName,
-                                                          "date" => $this->_date ));
+                                                          "date" => $this->_date ));                                                                    		                                                      
 														  
 			if( $this->_view->isCached()) {
 				if( $this->_config->getValue( 'update_cached_article_reads', false )) {
@@ -177,6 +182,12 @@
 				
 				return true;
 			}
+			
+
+			include_once( PLOG_CLASS_PATH."class/dao/articlecategories.class.php" );
+    		include_once( PLOG_CLASS_PATH."class/dao/users.class.php" );
+    		include_once( PLOG_CLASS_PATH."class/data/textfilter.class.php" );      
+			include_once( PLOG_CLASS_PATH.'class/data/pager/pager.class.php' );	 			
 														  
 			// ---
 			// if we got a category name or a user name instead of a category

Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php	2005-09-19 07:05:30 UTC (rev 2493)
+++ plog/trunk/class/dao/articles.class.php	2005-09-19 07:06:22 UTC (rev 2494)
@@ -47,13 +47,15 @@
          * @param blogId Identifier of the blog which articles we want to fetch
          * @return true
          */
-        function getArticles( $blogId )
+        function getArticles( $blogId, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
         {
         	$blogArticles = $this->getMany( "blog_id",
         	                                $blogId,
         	                                CACHE_ARTICLES_BYBLOG,
         	                                Array( CACHE_ARTICLES => "getId" ),
-        	                                Array( "date" => "DESC" ));
+        	                                Array( "date" => "DESC" ),
+        	                                $page,
+        	                                $itemsPerPage );
 			return( $blogArticles );
         }
 
@@ -343,16 +345,16 @@
          */
 
         function getBlogArticles( $blogId, 
-                                  $date        = -1, 
-                                  $amount      = -1, 
-                                  $categoryId  = 0, 
-                                  $status      = POST_STATUS_PUBLISHED, 
-                                  $userId      = 0, 
-                                  $maxDate     = 0, 
-                                  $searchTerms = "", 
-                                  $page        = -1 )
+                                  $date         = -1, 
+                                  $amount       = -1, 
+                                  $categoryId   = 0, 
+                                  $status       = POST_STATUS_PUBLISHED, 
+                                  $userId       = 0, 
+                                  $maxDate      = 0, 
+                                  $searchTerms  = "", 
+                                  $page         = -1 )
         {
-        	$articles = $this->getArticles( $blogId );  
+        	$articles = $this->getArticles( $blogId, $page, $amount );  
         	
         	if( !$articles )
         		$articles = Array();      	




More information about the pLog-svn mailing list