[pLog-svn] r3219 - in plog/trunk: class/summary/action class/summary/dao class/summary/view templates/summary

mark at devel.lifetype.net mark at devel.lifetype.net
Mon Apr 10 14:24:23 GMT 2006


Author: mark
Date: 2006-04-10 14:24:22 +0000 (Mon, 10 Apr 2006)
New Revision: 3219

Added:
   plog/trunk/class/summary/action/postlistaction.class.php
   plog/trunk/class/summary/view/summarypostlistview.class.php
   plog/trunk/templates/summary/postslist.template
Modified:
   plog/trunk/class/summary/dao/summarystats.class.php
Log:
Now, postList working.

So, we can see the posts list in different global article category very easily through summary page.

The different between BlogList and PostList is I  extend summarystats for PostList instead of extend articles. :(

Becasue after checking all the related scripts. I think extend SummaryStats is easier and clear then extend Articles..

Added: plog/trunk/class/summary/action/postlistaction.class.php
===================================================================
--- plog/trunk/class/summary/action/postlistaction.class.php	2006-04-10 08:55:48 UTC (rev 3218)
+++ plog/trunk/class/summary/action/postlistaction.class.php	2006-04-10 14:24:22 UTC (rev 3219)
@@ -0,0 +1,49 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/summary/action/summaryaction.class.php" );
+    include_once( PLOG_CLASS_PATH."class/summary/view/summarypostlistview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/data/validator/integervalidator.class.php" );       
+
+	/**
+	 * shows a list with all the blogs, pager included
+	 */
+     class PostListAction extends SummaryAction
+     {
+        function PostListAction( $actionInfo, $request )
+        {
+            $this->SummaryAction( $actionInfo, $request );
+        }
+
+        /**
+         * Loads the posts and shows them.
+         */
+        function perform()
+        {
+            // get the blogCategoryId from request
+			$globalArticleCategoryId = $this->_request->getValue( "globalArticleCategoryId" );
+			$val = new IntegerValidator();
+			if( !$val->validate( $globalArticleCategoryId ))
+				$globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;
+
+            // this is a bit hackish but it works...
+            $page = View::getCurrentPageFromRequest();
+            
+            // create the view
+			$this->_view = new SummaryPostListView( Array( "summary" => "PostList", 
+													"globalArticleCategoryId" => $globalArticleCategoryId,
+			                                        "page" => $page, 
+			                                        "locale" => $this->_locale->getLocaleCode() ));
+			
+			if( $this->_view->isCached()) {
+				// nothing to do, the view is cached
+				return true;
+			}
+
+			$this->_view->setValue( "globalArticleCategoryId", $globalArticleCategoryId );
+			
+			$this->setCommonData();
+			
+			return true;
+        }
+     }	 
+?>
\ No newline at end of file

Modified: plog/trunk/class/summary/dao/summarystats.class.php
===================================================================
--- plog/trunk/class/summary/dao/summarystats.class.php	2006-04-10 08:55:48 UTC (rev 3218)
+++ plog/trunk/class/summary/dao/summarystats.class.php	2006-04-10 14:24:22 UTC (rev 3219)
@@ -9,6 +9,8 @@
 	 * maximum number of items that will be shown per page in the summary
 	 */
 	define( "SUMMARY_DEFAULT_ITEMS_PER_PAGE", 15 );
+	
+	define( "ALL_GLOBAL_ARTICLE_CATEGORIES", 0 );
 
     /**
      * This class implements a few methods that can be used to obtain the list of most recent blogs, posts, commets,
@@ -261,5 +263,83 @@
 
             return $posts;
         }
+
+        function getRecentPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, 
+        										 $ignoreTopic = "", 
+        										 $ignoreText = "", 
+        										 $page = -1, 
+        										 $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+        {
+            include_once( PLOG_CLASS_PATH . "class/data/timestamp.class.php" );
+            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+            $t      = new Timestamp();
+            $date   = $t->getTimestamp();
+			$prefix = $this->getPrefix();
+
+			$query = "SELECT a.*
+					  FROM {$prefix}articles a, 
+					       {$prefix}blogs b
+					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					        AND a.blog_id = b.id
+					        AND b.status = ".BLOG_STATUS_ACTIVE."
+					        AND a.status = ".POST_STATUS_PUBLISHED."
+							AND a.in_summary_page = '1'";
+
+			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, $page, $itemsPerPage );
+            
+            if( !$result )
+                return Array();
+
+            $posts = Array();
+			$articles = new Articles();
+            while( $row = $result->FetchRow() ) {
+                array_push( $posts, $articles->mapRow($row) );
+            }
+
+            $result->Close();            
+
+            return $posts;
+        }
+
+        function getNumRecentPostsByGlobalCategory( $globaArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES, 
+        											$ignoreTopic = "", 
+        											$ignoreText = "" )
+        {
+            include_once( PLOG_CLASS_PATH . "class/data/timestamp.class.php" );
+            include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+
+            $t      = new Timestamp();
+            $date   = $t->getTimestamp();
+			$prefix = $this->getPrefix();
+
+			$query = "SELECT a.*
+					  FROM {$prefix}articles a, 
+					       {$prefix}blogs b
+					  WHERE a.date >= ".$this->_sevenDaysAgo." AND a.date <= ".$this->_now."
+					        AND a.blog_id = b.id
+					        AND b.status = ".BLOG_STATUS_ACTIVE."
+					        AND a.status = ".POST_STATUS_PUBLISHED."
+							AND a.in_summary_page = '1'";
+
+			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;
+        }          
     }
 ?>
\ No newline at end of file

Added: plog/trunk/class/summary/view/summarypostlistview.class.php
===================================================================
--- plog/trunk/class/summary/view/summarypostlistview.class.php	2006-04-10 08:55:48 UTC (rev 3218)
+++ plog/trunk/class/summary/view/summarypostlistview.class.php	2006-04-10 14:24:22 UTC (rev 3219)
@@ -0,0 +1,73 @@
+<?php
+
+	include_once( PLOG_CLASS_PATH."class/summary/view/summarycachedview.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+    include_once( PLOG_CLASS_PATH."class/dao/globalarticlecategories.class.php" ); 
+    include_once( PLOG_CLASS_PATH."class/data/pager/pager.class.php" );
+    include_once( PLOG_CLASS_PATH."class/config/config.class.php" );
+	include_once( PLOG_CLASS_PATH."class/summary/dao/summarystats.class.php" );
+	
+	/**
+	 * shows a paged list of blogs
+	 */
+	class SummaryPostListView extends SummaryCachedView
+	{
+		var $_numArticles;
+		var $_numArticlesPerPage;
+	
+		function SummaryPostListView( $data = Array())
+		{
+			// get the page
+			$this->_page = $this->getCurrentPageFromRequest();
+			
+			$this->SummaryCachedView( "postslist", $data );
+			
+            $config =& Config::getConfig();
+			$this->_numArticlesPerPage = 25;
+		}
+		
+		function render()
+		{
+			// do nothing if the contents of our view are cached
+			if( $this->isCached()) {
+				parent::render();
+				return true;
+			}
+            // get all blog category
+            $categories = new GlobalArticleCategories();
+            $globalArticleCategories = $categories->getGlobalArticleCategories();
+            
+			// get current globalArticleCategoryId
+			$globalArticleCategoryId = $this->_params->getValue( "globalArticleCategoryId" );
+			$currentGlobalArticleCategory = $categories->getGlobalArticleCategory( $globalArticleCategoryId );
+
+			if( empty($currentGlobalArticleCategory) )
+				$globalArticleCategoryId = ALL_GLOBAL_ARTICLE_CATEGORIES;			
+
+			// get the data itself
+			$stats = new SummaryStats();						
+            $posts = $stats->getRecentPostsByGlobalCategory( $globalArticleCategoryId, "", "", $this->_page, $this->_numArticlesPerPage );
+            $numPosts = $stats->getNumRecentPostsByGlobalCategory( $globalArticleCategoryId, "", "" );
+			
+            if( !$posts ) {
+                // if there was an error, show the error view
+				$posts = Array();
+            }
+			
+			// calculate the links to the different pages
+			$pager = new Pager( "?op=PostList&amp;page=",
+			                    $this->_page, 
+								$numPosts, 
+								$this->_numArticlesPerPage );
+
+			$this->setValue( "recentPosts", $posts );
+			$this->setValue( "numRecentPosts", $numPosts );
+			$this->setValue( "pager", $pager );
+			$this->setValue( "globalArticleCategories", $globalArticleCategories );
+			$this->setValue( "currentGlobalArticleCategory", $currentGlobalArticleCategory); 
+		
+			// let the parent view do its job
+			parent::render();
+		}
+	}
+?>
\ No newline at end of file

Added: plog/trunk/templates/summary/postslist.template
===================================================================
--- plog/trunk/templates/summary/postslist.template	2006-04-10 08:55:48 UTC (rev 3218)
+++ plog/trunk/templates/summary/postslist.template	2006-04-10 14:24:22 UTC (rev 3219)
@@ -0,0 +1,20 @@
+{include file="summary/header.template" section=$locale->tr("blogs")}
+<div id="onecolumn">
+    <div id="intro">
+	{foreach from=$globalArticleCategories item=globalArticleCategory}
+		<a href="?op=PostList&amp;globalArticleCategoryId={$globalArticleCategory->getId()}">{$globalArticleCategory->getName()}</a>
+	{/foreach}
+    </div>
+    {if empty($currentGlobalArticleCategory)}
+    	<h4>{$locale->tr("all")}</h4>
+    {else}
+    	<h4>{$currentGlobalArticleCategory->getName()} ({$numRecentPosts})</h4>
+    {/if}
+	{foreach from=$recentPosts item=post}
+	 {include file="summary/post.template"}
+	{/foreach}
+	<div class="pager">
+	  {include file="summary/pager.template" style=links}
+	</div>  
+</div>
+{include file="summary/footer.template"}



More information about the pLog-svn mailing list