[pLog-svn] r1518 - in plog/trunk: class/action/admin class/dao
templates/admin
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Tue Mar 15 21:11:15 GMT 2005
Author: oscar
Date: 2005-03-15 21:11:15 +0000 (Tue, 15 Mar 2005)
New Revision: 1518
Modified:
plog/trunk/class/action/admin/admindeletearticlecategoryaction.class.php
plog/trunk/class/dao/articlecategories.class.php
plog/trunk/class/dao/articlecategory.class.php
plog/trunk/templates/admin/editarticlecategories.template
Log:
fixed issue 343 (I think) I had to redo the method ArticleCategories::getNumArticles() and now it probably is not as optimal as before but this will have to do... haven't got too much time or energy left to improve things.
Modified: plog/trunk/class/action/admin/admindeletearticlecategoryaction.class.php
===================================================================
--- plog/trunk/class/action/admin/admindeletearticlecategoryaction.class.php 2005-03-15 20:43:37 UTC (rev 1517)
+++ plog/trunk/class/action/admin/admindeletearticlecategoryaction.class.php 2005-03-15 21:11:15 UTC (rev 1518)
@@ -58,7 +58,8 @@
$category = $categories->getCategory( $categoryId, $this->_blogInfo->getId());
if( $category ) {
// get how many articles it has
- $numArticles = $categories->getNumArticlesCategory( $categoryId );
+ //$numArticles = $categories->getNumArticlesCategory( $categoryId );
+ $numArticles = $category->getNumArticles( POST_STATUS_ALL );
// fire the pre-event
$this->notifyEvent( EVENT_PRE_CATEGORY_DELETE, Array( "category" => &$category ));
Modified: plog/trunk/class/dao/articlecategories.class.php
===================================================================
--- plog/trunk/class/dao/articlecategories.class.php 2005-03-15 20:43:37 UTC (rev 1517)
+++ plog/trunk/class/dao/articlecategories.class.php 2005-03-15 21:11:15 UTC (rev 1518)
@@ -321,19 +321,22 @@
function getNumArticlesCategory( $categoryId, $status = POST_STATUS_PUBLISHED )
{
$prefix = $this->getPrefix();
- if( empty($this->totalArticles)) {
- $query1 = "SELECT l.category_id, COUNT(*) AS 'count' FROM
- {$prefix}article_categories_link AS l, {$prefix}articles AS a
- WHERE l.article_id = a.id
- AND a.status = $status
- GROUP BY(l.category_id)";
- $this->totalArticles = $this->_db->GetAssoc( $query1 );
- }
+ $query1 = "SELECT COUNT(*) AS 'count' FROM
+ {$prefix}article_categories_link AS l, {$prefix}articles AS a
+ WHERE l.article_id = a.id AND l.category_id = '".Db::qstr($categoryId)."'";
+ if( $status != POST_STATUS_ALL )
+ $query1 .= " AND a.status = '".Db::qstr($status)."'";
- $totalArticles = $this->totalArticles[$categoryId];
- if( $totalArticles == "" ) $totalArticles = 0;
-
- return $totalArticles;
+ $result = $this->Execute( $query1 );
+
+ if( !$result )
+ return 0;
+
+ $row = $result->FetchRow();
+ $total = $row["count"];
+ if( $total == "" ) $total = 0;
+
+ return( $total );
}
/**
Modified: plog/trunk/class/dao/articlecategory.class.php
===================================================================
--- plog/trunk/class/dao/articlecategory.class.php 2005-03-15 20:43:37 UTC (rev 1517)
+++ plog/trunk/class/dao/articlecategory.class.php 2005-03-15 21:11:15 UTC (rev 1518)
@@ -142,14 +142,35 @@
/**
* Returns how many articles have been categorized under this category.
*
+ * @param status A valid post status
* @return An integer value
*/
- function getNumArticles()
+ function getNumArticles( $status = POST_STATUS_PUBLISHED )
{
- return $this->_numArticles;
+ $origStatus = $status;
+ if( $status == POST_STATUS_ALL )
+ $status = 0;
+
+ if( !is_array( $this->_numArticles[$status] ) || $this->_numArticles[$status] == null ) {
+ $categories = new ArticleCategories();
+ $this->_numArticles[$status] = $categories->getNumArticlesCategory( $this->getId(), $origStatus );
+ }
+
+ return( $this->_numArticles[$status] );
}
/**
+ * shorthand method for getting the total number of articles in the category, regardless of the
+ * status
+ *
+ * @return the total number of posts
+ */
+ function getNumAllArticles()
+ {
+ return( $this->getNumArticles( POST_STATUS_ALL ));
+ }
+
+ /**
* returns the articles categorized here
*
* @param an array of Article obejcts
@@ -159,11 +180,11 @@
if( !is_array( $this->_articles[$status] ) || $this->_articles[$status] == null ) {
$articles = new Articles();
// you've got to love these huge method calls...
- $this->_articles = $articles->getBlogArticles( $this->getBlogId(),
- -1,
- -1,
- $this->getId(),
- $status );
+ $this->_articles[$status] = $articles->getBlogArticles( $this->getBlogId(),
+ -1,
+ -1,
+ $this->getId(),
+ $status );
}
return( $this->_articles[$status] );
Modified: plog/trunk/templates/admin/editarticlecategories.template
===================================================================
--- plog/trunk/templates/admin/editarticlecategories.template 2005-03-15 20:43:37 UTC (rev 1517)
+++ plog/trunk/templates/admin/editarticlecategories.template 2005-03-15 21:11:15 UTC (rev 1518)
@@ -25,7 +25,7 @@
<a href="admin.php?op=editArticleCategory&categoryId={$category->getId()}">{$category->getName()}</a>
</td>
{if $category->getNumArticles() > 0}
- <td><a href="admin.php?op=editPosts&showCategory={$category->getId()}&showStatus=0">({$category->getNumArticles()})</a></td>
+ <td><a href="admin.php?op=editPosts&showCategory={$category->getId()}&showStatus=0">({$category->getNumAllArticles()})</a></td>
{else}
<td>(0)</td>
{/if}
More information about the pLog-svn
mailing list