[pLog-svn] r2118 - plog/branches/plog-1.1-ben/class/dao
ork at devel.plogworld.net
ork at devel.plogworld.net
Tue May 31 00:19:27 GMT 2005
Author: ork
Date: 2005-05-31 00:19:27 +0000 (Tue, 31 May 2005)
New Revision: 2118
Added:
plog/branches/plog-1.1-ben/class/dao/blogarticles.class.php
Log:
introducing another cache-only object. this object will store all article ids of a blog and will return the article ids when asked for. :-)
there're several functions to select the right article ids. its best to take a look at Articles::getBlogArticles() to understand the way this cache is working.
this is a work in progress, while this might not produce any error right now, please do not use this in an productive environment. there _are_ bugs in this version :-)
Added: plog/branches/plog-1.1-ben/class/dao/blogarticles.class.php
===================================================================
--- plog/branches/plog-1.1-ben/class/dao/blogarticles.class.php 2005-05-30 21:37:37 UTC (rev 2117)
+++ plog/branches/plog-1.1-ben/class/dao/blogarticles.class.php 2005-05-31 00:19:27 UTC (rev 2118)
@@ -0,0 +1,130 @@
+<?php
+ require_once( PLOG_CLASS_PATH."class/object/object.class.php" );
+
+ /**
+ * \ingroup DAO
+ *
+ * Cache Object to cache all article ids of a blog, this information will not be stored
+ * in the db but only in the disk-cache.
+ */
+ class BlogArticles extends Object {
+
+ var $_blogId;
+ var $_articles = array();
+ var $_articlesByCategory = array();
+ var $_articlesByDate = array();
+ var $_articlesByStatus = array();
+ var $_articleStatus = array();
+ var $_articleDate = array();
+
+ /**
+ * Constructor
+ *
+ * The constructor expects an array of sql rows instead of articles,
+ * because to build a complete article we need to fetch to many information.
+ * This class will only return ids, so we don't need full article objects,
+ * please use Articles::getArticle() to fetch an article.
+ *
+ * @param blogId The blogId of the links to fetch
+ * @blogArticlesSqlRows array containing sql row objects of articles
+ */
+ function BlogArticles( $blogId, $blogArticlesSqlRows )
+ {
+ $this->_blogId = $blogId;
+
+ foreach( $blogArticlesSqlRows as $articleSqlRow ) {
+ $articleId = $articleSqlRow['id'];
+ $categoryId = $articleSqlRow['category_id'];
+ $date = $articleSqlRow['date'];
+ $status = $articleSqlRow['status'];
+
+ $this->_articles[] = $articleId;
+ $this->_articlesByCategory[$categoryId][] = $articleId;
+ $this->_articlesByDate[$date][] = $articleId;
+ $this->_articlesByStatus[$status][] = $articleId;
+ $this->_articleStatus[$articleId] = $status;
+ $this->_articleDate[$articleId] = $date;
+ }
+ }
+
+ /**
+ * Get the BlogId for the article ids stored in this object
+ */
+ function getBlogId()
+ {
+ return $this->_blogId;
+ }
+
+ /**
+ * Get all article ids for current blog
+ */
+ function getArticleIds()
+ {
+ return $this->_articles;
+ }
+
+ function getArticleIdsByCategory( $categoryId, $articleIds = null )
+ {
+ if( !array_key_exists($categoryId, $this->_articlesByCategory) )
+ return array();
+
+ if( $articleIds == null )
+ return $this->_articlesByCategory[$categoryId];
+
+ $returnIds = array_intersect( $articleIds, $this->_articlesByCategory[$categoryId] );
+
+ return $returnIds;
+ }
+
+ function getArticleIdsByStatus( $status, $articleIds = null )
+ {
+ require_once( PLOG_CLASS_PATH . 'class/dao/articlestatus.class.php' );
+
+ if( $articleIds == null )
+ $articleIds = $this->getArticleIds();
+
+ if( $status == POST_STATUS_ALL )
+ return $articleIds;
+
+ if( !array_key_exists($status, $this->_articlesByStatus) )
+ return array();
+
+ $returnIds = array_intersect( $articleIds, $this->_articlesByStatus[$status] );
+
+ return $returnIds;
+ }
+
+ function getArticleIdsByDate( $date, $articleIds = null )
+ {
+ if( $articleIds == null )
+ $articleIds = $this->getArticleIds();
+
+ $matchingArticleIds = array();
+ foreach( array_keys($this->_articlesByDate) as $articleDate ) {
+ if( preg_match('/^'.$date.'/', $articleDate) ) {
+ $matchingArticleIds = array_merge( $matchingArticleIds,
+ $this->_articlesByDate[$articleDate] );
+ }
+ }
+
+ $returnIds = array_intersect( $articleIds, $matchingArticleIds );
+
+ return $returnIds;
+ }
+
+ function getArticleIdsBefore( $date, $articleIds = null )
+ {
+ if( $articleIds == null )
+ $articleIds = $this->getArticleIds();
+
+ $matchingArticleIds = array();
+
+ foreach( $articleIds as $articleId ) {
+ if( $date > $this->_articleDate[$articleId] )
+ $matchingArticleIds[] = $articleId;
+ }
+
+ return $matchingArticleIds;
+ }
+ }
+?>
More information about the pLog-svn
mailing list