[pLog-svn] r2464 - in plog/trunk/class: cache dao
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Tue Sep 13 19:35:53 GMT 2005
Author: oscar
Date: 2005-09-13 19:35:52 +0000 (Tue, 13 Sep 2005)
New Revision: 2464
Modified:
plog/trunk/class/cache/cachemanager.class.php
plog/trunk/class/dao/articlecategories.class.php
plog/trunk/class/dao/articles.class.php
plog/trunk/class/dao/blogcategories.class.php
plog/trunk/class/dao/blogs.class.php
plog/trunk/class/dao/commentscommon.class.php
plog/trunk/class/dao/globalarticlecategories.class.php
plog/trunk/class/dao/model.class.php
plog/trunk/class/dao/mylinks.class.php
plog/trunk/class/dao/mylinkscategories.class.php
Log:
added support for sorting the items
Modified: plog/trunk/class/cache/cachemanager.class.php
===================================================================
--- plog/trunk/class/cache/cachemanager.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/cache/cachemanager.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -10,8 +10,6 @@
define( "CACHE_USERALBUMS", "useralbums" );
define( "CACHE_USERINFO", "userinfo" );
define( "CACHE_USERIDBYNAME", "userinfo_idbyname" );
- define( "CACHE_BLOGINFOS", "bloginfo" );
- define( "CACHE_BLOGIDBYNAME", "bloginfo_idbyname" );
define( "CACHE_TRACKBACKS", "trackbacks" );
define( "CACHE_NUMTRACKBACKS", "trackbacks_size" );
define( "CACHE_CONFIGDBSTORAGE", "config_db_storage" );
Modified: plog/trunk/class/dao/articlecategories.class.php
===================================================================
--- plog/trunk/class/dao/articlecategories.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/articlecategories.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -115,6 +115,7 @@
CACHE_ARTICLE_CATEGORIES_BLOG,
Array( CACHE_ARTICLE_CATEGORIES => "getId",
CACHE_ARTICLE_CATEGORIES_BYNAME => "getMangledName" ),
+ Array(),
$page,
$itemsPerPage );
Modified: plog/trunk/class/dao/articles.class.php
===================================================================
--- plog/trunk/class/dao/articles.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/articles.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -52,7 +52,8 @@
$blogArticles = $this->getMany( "blog_id",
$blogId,
CACHE_ARTICLES_BYBLOG,
- Array( CACHE_ARTICLES => "getId" ));
+ Array( CACHE_ARTICLES => "getId" ),
+ Array( "date" => "DESC" ));
return( $blogArticles );
}
@@ -802,6 +803,7 @@
*/
function updateArticleCustomFields( $artId, $blogId, $fields )
{
+ include_once( PLOG_CLASS_PATH."class/dao/customfields/customfieldsvalues.class.php" );
$customFields = new CustomFieldsValues();
// first remove the values
Modified: plog/trunk/class/dao/blogcategories.class.php
===================================================================
--- plog/trunk/class/dao/blogcategories.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/blogcategories.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -92,6 +92,7 @@
{
$categories = $this->getAll( "all", CACHE_BLOGCATEGORIES_ALL,
Array( CACHE_BLOGCATEGORIES => "getId" ),
+ Array( "name" => "ASC" ),
$page,
$itemsPerPage );
Modified: plog/trunk/class/dao/blogs.class.php
===================================================================
--- plog/trunk/class/dao/blogs.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/blogs.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -2,6 +2,9 @@
require_once( PLOG_CLASS_PATH . 'class/dao/model.class.php' );
require_once( PLOG_CLASS_PATH . 'class/dao/blogstatus.class.php' );
+
+ define( "CACHE_BLOGINFOS", "bloginfo" );
+ define( "CACHE_BLOGIDBYNAME", "bloginfo_idbyname" );
/**
* \ingroup DAO
Modified: plog/trunk/class/dao/commentscommon.class.php
===================================================================
--- plog/trunk/class/dao/commentscommon.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/commentscommon.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -105,20 +105,19 @@
$page = -1,
$itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
+ if( $order == COMMENT_ORDER_NEWEST_FIRST )
+ $order = Array( "date" => "DESC" );
+ else
+ $order = Array( "date" => "ASC" );
+
$comments = $this->getMany( "article_id",
$artid,
CACHE_ARTICLE_COMMENTS_BYARTICLE,
Array( CACHE_ARTICLE_COMMENTS => "getId" ),
+ $order,
$page,
- $ItemsPerPage );
+ $itemsPerPage );
- /**
- * :TODO:
- * - filter by status!!!
- * - filter by type!!!
- * - use the $order parameter!!!
- */
-
$result = Array();
if( $comments ) {
// load the post to get the blog in order to get the time difference
@@ -129,17 +128,38 @@
$timeDiff = $blogSettings->getValue( "time_offset" );
include_once( PLOG_CLASS_PATH."class/data/timestamp.class.php" );
foreach( $comments as $comment ) {
- $date = Timestamp::getDateWithOffset( $comment->getDate(), $timeDiff );
- $comment->setDate( $date );
- $result[] = $comment;
+ if( $this->check( $comment, $type, $status )) {
+ $date = Timestamp::getDateWithOffset( $comment->getDate(), $timeDiff );
+ $comment->setDate( $date );
+ $result[] = $comment;
+ }
}
}
else
- $result = Array();
+ $result = Array();
return( $result );
}
+ /**
+ * @param comment
+ * @param type
+ * @param status
+ * @private
+ */
+ function check( $comment, $type, $status )
+ {
+ if( $status != COMMENT_TYPE_ANY )
+ if( $comment->getType() != $type )
+ return false;
+
+ if( $status != COMMENT_STATUS_ALL )
+ if( $comment->getStatus() != $status )
+ return false;
+
+ return( true );
+ }
+
/**
* Returns the total number of comments for a post
*
@@ -149,18 +169,35 @@
*/
function getNumPostComments( $artId, $status = COMMENT_STATUS_ALL, $type = COMMENT_TYPE_ANY )
{
- // create the table name
- $prefix = $this->getPrefix();
- $table = "{$prefix}articles_comments";
- // and the condition if any...
- $cond = "article_id = '".Db::qstr($artId)."'";
- if( $status != COMMENT_STATUS_ALL )
- $cond .= " AND status = '".Db::qstr($status)."'";
- if( $type != COMMENT_TYPE_ANY )
- $query .= " AND type = '".Db::qstr($type)."'";
-
- // get the number of items and return it to the caller
- return( $this->getNumItems( $table, $cond ));
+ include_once( PLOG_CLASS_PATH."class/dao/articles.class.php" );
+ $numComments = 0;
+ $articles = new Articles();
+ $article = $articles->getArticle( $artId );
+
+ if( $type == COMMENT_TYPE_COMMENT ) {
+ if( $status == COMMENT_STATUS_ALL && $article ) {
+ $numComments = $article->getTotalComments();
+ }
+ elseif( $status == COMMENT_STATUS_ACTIVE && $article ) {
+ $numComments = $article->getNumComments();
+ }
+ else {
+ $numComments = $this->getPostComments( $artId, COMMENT_ORDER_NEWEST_FIRST, $status, $type );
+ }
+ }
+ else {
+ if( $status == COMMENT_STATUS_ALL && $article ) {
+ $numComments = $article->getTotalComments();
+ }
+ elseif( $status == COMMENT_STATUS_ACTIVE && $article ) {
+ $numComments = $article->getNumComments();
+ }
+ else {
+ $numComments = $this->getPostComments( $artId, COMMENT_ORDER_NEWEST_FIRST, $status, $type );
+ }
+ }
+
+ return( $numComments );
}
/**
Modified: plog/trunk/class/dao/globalarticlecategories.class.php
===================================================================
--- plog/trunk/class/dao/globalarticlecategories.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/globalarticlecategories.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -97,6 +97,7 @@
{
$categories = $this->getAll( "all", CACHE_GLOBALCATEGORIES_ALL,
Array( CACHE_GLOBALCATEGORIES => "getId" ),
+ Array( "name" => "ASC" ),
$page,
$itemsPerPage );
Modified: plog/trunk/class/dao/model.class.php
===================================================================
--- plog/trunk/class/dao/model.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/model.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -223,12 +223,12 @@
return( $where );
}
- function getAll( $key, $cacheId, $itemCaches = null, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ function getAll( $key, $cacheId, $itemCaches = null, $sorting = Array(), $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
- return( $this->getMany( $key, null, $cacheId, $itemCaches, $page, $itemsPerPage ));
+ return( $this->getMany( $key, null, $cacheId, $itemCaches, $sorting, $page, $itemsPerPage ));
}
- function getMany( $key, $value, $cacheId, $itemCaches = null, $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
+ function getMany( $key, $value, $cacheId, $itemCaches = null, $sorting = Array(), $page = -1, $itemsPerPage = DEFAULT_ITEMS_PER_PAGE )
{
$dbObjects = $this->_cache->getData( $value, $cacheId );
if( !$dbObjects ) {
@@ -236,6 +236,14 @@
$query = "SELECT * FROM ".$this->table;
if( $value )
$query .= " WHERE {$key} = '".Db::qstr($value)."'";
+ if( count( $sorting ) > 0 ) {
+ // check the sorting...
+ $orderBy = " ORDER BY ";
+ foreach( $sorting as $field => $dir ) {
+ $orderBy .= "$field $dir";
+ }
+ $query .= $orderBy;
+ }
$this->log->debug("query = $query");
$result = $this->Execute( $query );
Modified: plog/trunk/class/dao/mylinks.class.php
===================================================================
--- plog/trunk/class/dao/mylinks.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/mylinks.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -36,6 +36,7 @@
$blogId,
CACHE_MYLINKS_ALL,
Array( CACHE_MYLINKS => "getId" ),
+ Array( "date" => "DESC" ),
$page,
$itemsPerPage );
@@ -181,9 +182,13 @@
function mapRow( $row )
{
- $blogLink = new MyLink( $row["name"], $row["description"],
- $row["url"], $row["blog_id"], $row["category_id"],
- $row["date"], $row["rss_feed"],
+ $blogLink = new MyLink( $row["name"],
+ $row["description"],
+ $row["url"],
+ $row["blog_id"],
+ $row["category_id"],
+ $row["date"],
+ $row["rss_feed"],
unserialize($row["properties"]),
$row["id"] );
Modified: plog/trunk/class/dao/mylinkscategories.class.php
===================================================================
--- plog/trunk/class/dao/mylinkscategories.class.php 2005-09-11 17:11:01 UTC (rev 2463)
+++ plog/trunk/class/dao/mylinkscategories.class.php 2005-09-13 19:35:52 UTC (rev 2464)
@@ -50,29 +50,24 @@
* :TODO:
* Implement sorting here!!!
*/
- /*if( $order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER ) {
- $query .= " ORDER BY c.name ASC";
- }
- elseif( $order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER ) {
- $query .= " ORDER BY c.name DESC";
- }
- elseif( $order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST ) {
- $query .= " ORDER BY num_links DESC";
- }
- elseif( $order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST ) {
- $query .= " ORDER BY num_links ASC";
- }
- elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST ) {
- $query .= " ORDER BY c.last_modification ASC";
- }
- elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST ) {
- $query .= " ORDER BY c.last_modification ASC";
- }*/
+ if( $order == MYLINKS_CATEGORIES_ALPHABETICAL_ORDER )
+ $order = Array( "name" => "ASC" );
+ elseif( $order == MYLINKS_CATEGORIES_REVERSE_ALPHABETICAL_ORDER )
+ $order = Array( "name" => "DESC" );
+ elseif( $order == MYLINKS_CATEGORIES_MOST_LINKS_FIRST )
+ $order = Array( "num_links" => "DESC" );
+ elseif( $order == MYLINKS_CATEGORIES_LESS_LINKS_FIRST )
+ $order = Array( "num_links" => "ASC" );
+ elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_FIRST )
+ $order = Array( "last_modification" => "ASC" );
+ elseif( $order == MYLINKS_CATEGORIES_LAST_UPDATED_LAST )
+ $order = Array( "last_modification" => "ASC" );
$blogCategories = $this->getMany( "blog_id",
$blogId,
CACHE_MYLINKCATEGORIES_ALL,
Array( CACHE_MYLINKCATEGORIES => "getId" ),
+ $order,
$page,
$itemsPerPage );
More information about the pLog-svn
mailing list