[pLog-svn] r3613 - plog/trunk/class/summary/dao

mark at devel.lifetype.net mark at devel.lifetype.net
Sun Jun 18 17:56:16 GMT 2006


Author: mark
Date: 2006-06-18 17:56:15 +0000 (Sun, 18 Jun 2006)
New Revision: 3613

Modified:
   plog/trunk/class/summary/dao/summarystats.class.php
   plog/trunk/class/summary/dao/summarystatsconstants.class.php
Log:
Refactoring SummaryStats. Now, we can specify the duration through constant SUMMARY_DEFAULT_TIME_FENCE . The default is 7 days.

Modified: plog/trunk/class/summary/dao/summarystats.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystats.class.php	2006-06-18 17:20:40 UTC (rev 3612)
+++ plog/trunk/class/summary/dao/summarystats.class.php	2006-06-18 17:56:15 UTC (rev 3613)
@@ -21,32 +21,17 @@
     {
         
         var $_now;
-        var $_sevenDaysAgo;
+        var $_startTime;
         var $_summaryPageShowMax;
 
         function SummaryStats()
         {
             // initialize ADOdb
-			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
             $this->Model();
+
+            $this->_now = $this->getNow();
+            $this->_startTime = $this->getStartTime();
             
-            // calculate the date limits
-            $t = new Timestamp();
-                //$this->_now = $t->getTimestamp(); 
-            $this->_now = $t->getYear().$t->getMonth();
-			if( $t->getDay() < 10 )
-				$this->_now .= "0";
-			$this->_now .= $t->getDay();
-			$this->_now .= "235959";
-            // 7 days ago
-            $t->subtractSeconds( 7 * 24 * 60 * 60 );
-            //$this->_sevenDaysAgo = $t->getTimestamp();
-			$this->_sevenDaysAgo = $t->getYear().$t->getMonth();
-			if( $t->getDay() < 10 )
-				$this->_sevenDaysAgo .= "0";
-			$this->_sevenDaysAgo .= $t->getDay();
-			$this->_sevenDaysAgo .= "000000";
-            
             // get the summary_page_show_max from config
             $config =& Config::getConfig();
             $this->_summaryPageShowMax = $config->getValue( "summary_page_show_max", SUMMARY_DEFAULT_PAGE_SHOW_MAX );
@@ -73,7 +58,7 @@
 					  WHERE a.blog_id = b.id
 					        AND a.status = ".POST_STATUS_PUBLISHED."
 							AND b.status = ".BLOG_STATUS_ACTIVE."
-                                                        AND a.date >= ".$this->_sevenDaysAgo."
+                            AND a.date >= ".$this->_startTime."
 							AND a.date <= ".$this->_now."
 							AND a.in_summary_page = '1'
 							AND a.num_nonspam_comments > 0
@@ -118,7 +103,7 @@
                  WHERE a.status = ".POST_STATUS_PUBLISHED."
                  AND a.blog_id = b.id 
 				 AND b.status = ".BLOG_STATUS_ACTIVE."
-                 AND a.date <= ".$this->_now." AND a.date > ".$this->_sevenDaysAgo."
+                 AND a.date <= ".$this->_now." AND a.date > ".$this->_startTime."
 				 AND in_summary_page = '1'
 				 AND b.show_in_summary = '1'
 				 ORDER BY a.num_reads DESC";
@@ -160,7 +145,7 @@
 			          FROM ".$this->getPrefix()."blogs 
 					  WHERE status = ".BLOG_STATUS_ACTIVE." 
 					  AND show_in_summary = '1'
-					  AND create_date > ".$this->_sevenDaysAgo."
+					  AND create_date > ".$this->_startTime."
 					  ORDER BY create_date DESC";
 
             if( $maxBlogs > 0 )
@@ -204,7 +189,7 @@
                       FROM {$prefix}articles AS a
                       INNER JOIN {$prefix}blogs AS b 
                       ON b.id = a.blog_id AND b.status = ".BLOG_STATUS_ACTIVE."
-                      WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now." 
+                      WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now." 
 					  AND in_summary_page = '1' 
 					  AND b.show_in_summary = '1'
 					  GROUP BY a.id
@@ -245,7 +230,6 @@
          */
         function getRecentArticles( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, $maxPosts = 0 )
         {
-            include_once( PLOG_CLASS_PATH . "class/data/timestamp.class.php" );
             include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
 			$prefix = $this->getPrefix();
@@ -253,7 +237,7 @@
 			$query = "SELECT a.*
 					  FROM {$prefix}articles a, 
 					       {$prefix}blogs b
-					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					  WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now."
 					        AND a.blog_id = b.id
 					        AND b.status = ".BLOG_STATUS_ACTIVE."
 					        AND a.status = ".POST_STATUS_PUBLISHED."
@@ -304,7 +288,6 @@
         										 $page = -1, 
         										 $itemsPerPage = SUMMARY_DEFAULT_ITEMS_PER_PAGE )
         {
-            include_once( PLOG_CLASS_PATH . "class/data/timestamp.class.php" );
             include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
 			$prefix = $this->getPrefix();
@@ -312,7 +295,7 @@
 			$query = "SELECT a.id as id, MAX(a.date) as date
 					  FROM {$prefix}articles a, 
 					       {$prefix}blogs b
-					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					  WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now."
 					        AND a.blog_id = b.id
 					        AND b.status = ".BLOG_STATUS_ACTIVE."
 					        AND a.status = ".POST_STATUS_PUBLISHED."
@@ -342,7 +325,6 @@
 
         function getNumRecentPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES )
         {
-            include_once( PLOG_CLASS_PATH . "class/data/timestamp.class.php" );
             include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
 
 			$prefix = $this->getPrefix();
@@ -350,7 +332,7 @@
 			$query = "SELECT a.*
 					  FROM {$prefix}articles a, 
 					       {$prefix}blogs b
-					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					  WHERE a.date >= ".$this->_startTime." AND a.date <= ".$this->_now."
 					        AND a.blog_id = b.id
 					        AND b.status = ".BLOG_STATUS_ACTIVE."
 					        AND a.status = ".POST_STATUS_PUBLISHED."
@@ -371,6 +353,34 @@
             $result->Close();
 
             return $count;
-        }          
+        }
+
+		function getNow() {
+			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+
+            $time = new Timestamp();
+            $now = $time->getYear().$time->getMonth();
+			if( $time->getDay() < 10 )
+				$now .= "0";
+			$now .= $time->getDay();
+			$now .= "235959";
+
+			return $now;
+		}
+
+		function getStartTime() {
+			include_once( PLOG_CLASS_PATH.'class/data/timestamp.class.php' );
+
+            $time = new Timestamp();
+            $time->subtractSeconds( SUMMARY_DEFAULT_TIME_FENCE * 24 * 60 * 60 );
+			$startTime = $time->getYear().$time->getMonth();
+			if( $time->getDay() < 10 )
+				$startTime .= "0";
+			$startTime .= $time->getDay();
+			$startTime .= "000000";
+
+			return $startTime;
+		}
+                
     }
 ?>
\ No newline at end of file

Modified: plog/trunk/class/summary/dao/summarystatsconstants.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystatsconstants.class.php	2006-06-18 17:20:40 UTC (rev 3612)
+++ plog/trunk/class/summary/dao/summarystatsconstants.class.php	2006-06-18 17:56:15 UTC (rev 3613)
@@ -5,4 +5,9 @@
 	define( "SUMMARY_DEFAULT_ITEMS_PER_PAGE", 25 );
 	define( "SUMMARY_DEFAULT_PAGE_SHOW_MAX", 15 );
 	define( "ALL_GLOBAL_ARTICLE_CATEGORIES", 0 );
+	
+	/**
+	 *
+	 */
+	define( "SUMMARY_DEFAULT_TIME_FENCE", 7 );
 ?>
\ No newline at end of file



More information about the pLog-svn mailing list