[pLog-svn] r4066 - plog/branches/lifetype-1.1.1/class/summary/dao

oscar at devel.lifetype.net oscar at devel.lifetype.net
Thu Sep 28 21:17:57 GMT 2006


Author: oscar
Date: 2006-09-28 21:17:57 +0000 (Thu, 28 Sep 2006)
New Revision: 4066

Modified:
   plog/branches/lifetype-1.1.1/class/summary/dao/summarystats.class.php
Log:
several fixes related to issue 1072


Modified: plog/branches/lifetype-1.1.1/class/summary/dao/summarystats.class.php
===================================================================
--- plog/branches/lifetype-1.1.1/class/summary/dao/summarystats.class.php	2006-09-28 20:46:22 UTC (rev 4065)
+++ plog/branches/lifetype-1.1.1/class/summary/dao/summarystats.class.php	2006-09-28 21:17:57 UTC (rev 4066)
@@ -226,7 +226,7 @@
 
 			$prefix = $this->getPrefix();
 
-			$query = "SELECT a.*
+			$query = "SELECT a.id AS id, a.blog_id AS blog_id
 					  FROM {$prefix}articles a, 
 					       {$prefix}blogs b
 					  WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now."
@@ -242,9 +242,15 @@
 			$query .= " ORDER BY a.date DESC";
 
             if( $maxPosts <= 0 )
-            	$maxPosts = $this->_summaryPageShowMax;            	
-            $query .= " LIMIT 0,".$maxPosts;
+            	$maxPosts = $this->_summaryPageShowMax;
 
+		// the multiplier here isn't a very elegant solution but what we're trying to avoid
+		// here is a situation where if the limit is '10', then a blog posting 10 articles in one
+		// go would use all these 10 'slots' in the result set. Then when the list of posts is 
+		// post-processed, there would only be one article left... which is definitely not
+		// what we'd like
+            $query .= " LIMIT 0,".$maxPosts * 15;
+
             $result = $this->Execute( $query );
 
             if( !$result )
@@ -259,7 +265,7 @@
                 if (!in_array($row["blog_id"], $blogs))
                 {
                     $blogs[] = $row["blog_id"];
-                    array_push( $posts, $articles->mapRow($row) );
+                    array_push( $posts, $articles->getArticle($row["id"]) );
                     $i++;
                 }
             }
@@ -269,7 +275,7 @@
             return $posts;
         }
 
-        function getRecentPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, 
+        function getPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, 
         										 $page = -1, 
         										 $itemsPerPage = SUMMARY_DEFAULT_ITEMS_PER_PAGE )
         {
@@ -300,7 +306,9 @@
             $posts = Array();
 			$articles = new Articles();
             while( $row = $result->FetchRow() ) {
-                array_push( $posts, $articles->getArticle($row["id"]) );
+		// if we call Articles::getArticle() we'll be using the cached data
+		// if it was already there, instead of mapping the whole row here
+                array_push( $posts, $articles->getArticle( $row["id"] ));
             }
 
             $result->Close();
@@ -308,17 +316,15 @@
             return $posts;
         }
 
-        function getNumRecentPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES )
+        function getNumPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES )
         {
             include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
 			$prefix = $this->getPrefix();
 
-			$query = "SELECT COUNT(*)
-					  FROM {$prefix}articles a, 
-					       {$prefix}blogs b
-					  WHERE a.date <= ".$this->_now."
-					        AND a.blog_id = b.id
+
+			$query =" a.date <= ".$this->_now."
+					       AND a.blog_id = b.id
 					        AND b.status = ".BLOG_STATUS_ACTIVE."
 					        AND a.status = ".POST_STATUS_PUBLISHED."
 							AND b.show_in_summary = '1'
@@ -327,19 +333,12 @@
 			if($globaArticleCategoryId != ALL_GLOBAL_ARTICLE_CATEGORIES)
 				$query .= " AND a.global_category_id = '".Db::qstr($globaArticleCategoryId)."'";				
 
-			$query .= " GROUP BY a.blog_id ORDER BY a.date DESC";
-            $result = $this->Execute( $query );
-            
-            if( !$result )
-                return 0;
-
-	        $count = $result->RowCount();
-
-            $result->Close();
-
-            return $count;
+            return( $this->getNumItems( "{$prefix}articles a, {$prefix}blogs b", $query, "a.id" ));
         }
 
+		/**
+		 * @private
+		 */
 		function getNow() 
 		{
 			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
@@ -350,6 +349,9 @@
 			return $now;
 		}
 
+		/** 
+		 * @private
+		 */
 		function getStartTime( $duration ) 
 		{
 			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );



More information about the pLog-svn mailing list