[pLog-svn] r1892 - in plog/trunk: class/dao class/view/admin
templates/admin
oscar at devel.plogworld.net
oscar at devel.plogworld.net
Wed Apr 20 21:54:32 GMT 2005
Author: oscar
Date: 2005-04-20 21:54:32 +0000 (Wed, 20 Apr 2005)
New Revision: 1892
Modified:
plog/trunk/class/dao/articlecategories.class.php
plog/trunk/class/view/admin/adminarticlecategorieslistview.class.php
plog/trunk/templates/admin/editarticlecategories.template
Log:
search feature for article categories
Modified: plog/trunk/class/dao/articlecategories.class.php
===================================================================
--- plog/trunk/class/dao/articlecategories.class.php 2005-04-20 21:29:33 UTC (rev 1891)
+++ plog/trunk/class/dao/articlecategories.class.php 2005-04-20 21:54:32 UTC (rev 1892)
@@ -151,11 +151,12 @@
* <li>BLOG_CATEGORIES_MOST_ARTICLES_FIRST</li>
*</ul>
* The default value is BLOG_CATEGORIES_DEFAULT_ORDER
+ * @param searchTerms
* @param page
* @param itemsPerPage
* @return An array containing all the categories from a given blog.
*/
- function getBlogCategories( $blogId, $onlyInMainPage = false, $order = BLOG_CATEGORIES_DEFAULT_ORDER, $page = -1, $itemsPerPage = 15 )
+ function getBlogCategories( $blogId, $onlyInMainPage = false, $order = BLOG_CATEGORIES_DEFAULT_ORDER, $searchTerms = "", $page = -1, $itemsPerPage = 15 )
{
// this part of the query is the same in all the cases
$prefix = $this->getPrefix();
@@ -164,13 +165,17 @@
c.parent_id AS parent_id, c.properties AS properties,
c.mangled_name AS mangled_name, IF(a.id IS NULL, 0, COUNT(*)) AS num_articles, a.date AS last_update
FROM {$prefix}articles_categories c LEFT JOIN {$prefix}article_categories_link l
- ON c.id=l.category_id LEFT JOIN {$prefix}articles a ON a.id = l.article_id
- WHERE c.blog_id = '".Db::qstr($blogId)."'";
+ ON c.id=l.category_id LEFT JOIN {$prefix}articles a ON a.id = l.article_id";
if( $onlyInMainPage )
- $query .= " AND c.in_main_page = 1 ";
+ $whereMainPage .= "c.in_main_page = 1 ";
+ if( $searchTerms )
+ $whereSearch = $this->buildSearchCondition( $searchTerms );
+ $whereBlogId = "c.blog_id = '".Db::qstr($blogId)."'";
+
+ $where = $this->buildWhereCondition( Array( $whereMainPage, $whereSearch, $whereBlogId ));
- $query .= " GROUP BY c.id ";
+ $query .= " $where GROUP BY c.id ";
// and now we simply have to change select the correct way of ordering things
if( $order == BLOG_CATEGORIES_OLDEST_FIRST ) {
@@ -196,9 +201,20 @@
}
/**
+ * @see Model::buildSearchCondition
+ */
+ function buildSearchCondition( $searchTerms )
+ {
+ $searchTerms = trim($searchTerms);
+ $searchCond = "(description LIKE '%".Db::qstr($searchTerms)."%' OR name LIKE '%".Db::qstr($searchTerms)."%')";
+
+ return( $searchCond );
+ }
+
+ /**
* @see getBlogCategories
*/
- function getBlogCategoriesAdmin( $blogId, $onlyInMainPage = false, $order = BLOG_CATEGORIES_DEFAULT_ORDER, $page = -1, $itemsPerPage = 15 )
+ function getBlogCategoriesAdmin( $blogId, $onlyInMainPage = false, $order = BLOG_CATEGORIES_DEFAULT_ORDER, $searchTerms = "", $page = -1, $itemsPerPage = 15 )
{
// this part of the query is the same in all the cases
$prefix = $this->getPrefix();
@@ -207,13 +223,17 @@
c.parent_id AS parent_id, c.properties AS properties, c.description AS description,
c.mangled_name AS mangled_name, IF(a.id IS NULL, 0, COUNT(*)) AS num_articles, a.date AS last_update
FROM {$prefix}articles_categories c LEFT JOIN {$prefix}article_categories_link l
- ON c.id=l.category_id LEFT JOIN {$prefix}articles a ON a.id = l.article_id
- WHERE c.blog_id = $blogId";
+ ON c.id=l.category_id LEFT JOIN {$prefix}articles a ON a.id = l.article_id";
- if( $onlyInMainPage )
- $query .= " AND c.in_main_page = 1 ";
-
- $query .= " GROUP BY c.id ";
+ if( $onlyInMainPage )
+ $whereMainPage .= "c.in_main_page = 1 ";
+ if( $searchTerms )
+ $whereSearch = $this->buildSearchCondition( $searchTerms );
+ $whereBlogId = "c.blog_id = '".Db::qstr($blogId)."'";
+
+ $where = $this->buildWhereCondition( Array( $whereMainPage, $whereSearch, $whereBlogId ));
+
+ $query .= " $where GROUP BY c.id ";
// and now we simply have to change select the correct way of ordering things
if( $order == BLOG_CATEGORIES_OLDEST_FIRST ) {
@@ -319,6 +339,7 @@
* @param categoryId The identifier of that category.
* @param status The status that posts of that category should have. If none specified,
* POST_STATUS_PUBLISHED will be used.
+ * @param searchTerms
* @return The number of articles, or 0 if none.
*/
function getNumArticlesCategory( $categoryId, $status = POST_STATUS_PUBLISHED )
@@ -327,19 +348,19 @@
$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)."'";
+ if( $status != POST_STATUS_ALL )
+ $query1 .= " AND a.status = '".Db::qstr($status)."'";
- $result = $this->Execute( $query1 );
+ $result = $this->Execute( $query1 );
+
+ if( !$result )
+ return 0;
- if( !$result )
- return 0;
-
- $row = $result->FetchRow();
- $total = $row["count"];
- if( $total == "" ) $total = 0;
-
- return( $total );
+ $row = $result->FetchRow();
+ $total = $row["count"];
+ if( $total == "" ) $total = 0;
+
+ return( $total );
}
/**
@@ -502,18 +523,23 @@
*
* @param blogId
* @param includeHidden
+ * @param searchTerms
* @return an integer
*/
- function getBlogNumCategories( $blogId, $includeHidden = false )
+ function getBlogNumCategories( $blogId, $includeHidden = false, $searchTerms = "" )
{
// table name
$prefix = $this->getPrefix();
$table = "{$prefix}articles_categories";
// conditions
- $cond = "blog_id = '".Db::qstr($blogId)."'";
+ $cond1 = "blog_id = '".Db::qstr($blogId)."'";
if( $includeHidden )
- $cond .= " AND in_main_page = 1";
+ $cond2 = "in_main_page = 1";
+ if( $searchTerms != "" )
+ $cond3 = $this->buildSearchCondition( $searchTerms );
+
+ $cond = " ".$this->buildWhereCondition( Array( $cond1, $cond2, $cond3 ), false );
// return the total number
$total = $this->getNumItems( $table, $cond );
Modified: plog/trunk/class/view/admin/adminarticlecategorieslistview.class.php
===================================================================
--- plog/trunk/class/view/admin/adminarticlecategorieslistview.class.php 2005-04-20 21:29:33 UTC (rev 1891)
+++ plog/trunk/class/view/admin/adminarticlecategorieslistview.class.php 2005-04-20 21:54:32 UTC (rev 1892)
@@ -13,6 +13,7 @@
class AdminArticleCategoriesListView extends AdminTemplatedView
{
var $_page;
+ var $_searchTerms;
/**
* Constructor. If nothing else, it also has to call the constructor of the parent
@@ -34,13 +35,15 @@
$categoriesOrder = $blogSettings->getValue( "categories_order" );
// get the page too
- $this->_page = $this->getCurrentPageFromRequest();
+ $this->_page = $this->getCurrentPageFromRequest();
+ $this->_searchTerms = HttpVars::getRequestValue( "searchTerms" );
// retrieve the categories in an paged fashion
- $totalCategories = $categories->getBlogNumCategories( $this->_blogInfo->getId(), true );
+ $totalCategories = $categories->getBlogNumCategories( $this->_blogInfo->getId(), true, $this->_searchTerms );
$blogCategories = $categories->getBlogCategoriesAdmin( $this->_blogInfo->getId(),
false,
$categoriesOrder,
+ $this->_searchTerms,
$this->_page,
DEFAULT_ITEMS_PER_PAGE );
if( !$blogCategories ) {
@@ -52,11 +55,12 @@
$this->setValue( "categories", $blogCategories );
// the pager that will be used
- $pager = new Pager( "?op=editArticleCategories&page=",
+ $pager = new Pager( "?op=editArticleCategories&searchTerms=".$this->_searchTerms."&page=",
$this->_page,
$totalCategories,
DEFAULT_ITEMS_PER_PAGE );
$this->setValue( "pager", $pager );
+ $this->setValue( "searchTerms", $this->_searchTerms );
parent::render();
}
Modified: plog/trunk/templates/admin/editarticlecategories.template
===================================================================
--- plog/trunk/templates/admin/editarticlecategories.template 2005-04-20 21:29:33 UTC (rev 1891)
+++ plog/trunk/templates/admin/editarticlecategories.template 2005-04-20 21:54:32 UTC (rev 1892)
@@ -1,6 +1,30 @@
{include file="$admintemplatepath/header.template"}
{include file="$admintemplatepath/navigation.template" showOpt=editArticleCategories title=$locale->tr("editArticleCategories")}
+ <div id="list_nav_bar">
+ <div id="list_nav_select">
+
+<form id="viewArticleCategories" action="admin.php" method="post">
+ <fieldset>
+ <legend>{$locale->tr("show_by")}</legend>
+
+ <div class="list_nav_option">
+ <label for="search">{$locale->tr("search_terms")}</label>
+ <br />
+ <input type="text" name="searchTerms" value="{$searchTerms}" size="15" id="search" />
+ </div>
+
+ <div class="list_nav_option">
+ <br />
+ <input type="hidden" name="op" value="editArticleCategories">
+ <input type="submit" name="Show" value="{$locale->tr("show")}">
+ </div>
+ </fieldset>
+ </form>
+ </div>
+ <br style="clear:both">
+ </div>
+
<form id="deleteCategories" action="admin.php" method="post"
<div id="list">
{include file="$admintemplatepath/successmessage.template"}
More information about the pLog-svn
mailing list