gayb
1. com_zoo\controllers\default.php
заменил
$item_count = $this->category->id == 0 ? $this->app->table->item->getItemCountFromCategory($this->application->id, $category_id, true) : $this->category->itemCount();
на
$item_count = $this->app->table->item->getItemCountFromCategory($this->application->id, $category_id, true);
Чтоб каждый раз пересчитывал количество строк.
2. administrator\components\com_zoo\tables\default.php
заменить 2 функции
public function getByCategory($application_id, $category_id, $published = false, $user = null, $orderby = "", $offset = 0, $limit = 0) {
// get database
$db = $this->database;
// get dates
$date = $this->app->date->create();
$now = $db->Quote($date->toMySQL());
$null = $db->Quote($db->getNullDate());
// get item ordering
$orderby = $this->_getItemOrder($orderby);
if (isset($_POST['search']))
$_SESSION['search'] = JString::strtolower($_POST['search']);
if (isset($_SESSION['searchby'])) {
if ($_SESSION['searchby'] != $category_id) {
unset($_SESSION['search']);
unset($_SESSION['searchby']);
}
} else
$_SESSION['searchby'] = $category_id;
if (isset($_SESSION['search'])) {
$search = " AND LOWER(a.name) LIKE ".$db->Quote('%'.$_SESSION['search'].'%');
} else
$search = "";
$query = "SELECT a.*"
." FROM ".$this->name." AS a"
." LEFT JOIN ".ZOO_TABLE_CATEGORY_ITEM." AS b ON a.id = b.item_id"
.(isset($orderby['join'])? $orderby['join']: "")
." WHERE a.application_id = ".(int) $application_id
.$search
." AND b.category_id ".(is_array($category_id)? " IN (".implode(",", $category_id).")" : " = ".(int) $category_id)
." AND ".$this->app->user->getDBAccessString($user)
.($published == true ? " AND a.state = 1"
." AND (a.publish_up = ".$null." OR a.publish_up <= ".$now.")"
." AND (a.publish_down = ".$null." OR a.publish_down >= ".$now.")": "")
." GROUP BY a.id"
." ORDER BY a.priority DESC".(isset($orderby['query'])? ", ".$orderby['query'] : "")
.(($limit ? " LIMIT ".(int)$offset.",".(int)$limit : ""));
return $this->_queryObjectList($query);
}
public function getItemCountFromCategory($application_id, $category_id, $published = false, $user = null){
// get database
$db = $this->database;
// get dates
$date = $this->app->date->create();
$now = $db->Quote($date->toMySQL());
$null = $db->Quote($db->getNullDate());
if (isset($_SESSION['search']))
$search = " AND LOWER(a.name) LIKE ".$db->Quote('%'.$_SESSION['search'].'%');
else
$search = "";
$query = "SELECT a.*"
." FROM ".$this->name." AS a"
." LEFT JOIN ".ZOO_TABLE_CATEGORY_ITEM." AS b ON a.id = b.item_id"
." WHERE a.application_id = ".(int) $application_id
.$search
." AND b.category_id ".(is_array($category_id)? " IN (".implode(",", $category_id).")" : " = ".(int) $category_id)
." AND ".$this->app->user->getDBAccessString($user)
.($published == true ? " AND a.state = 1"
." AND (a.publish_up = ".$null." OR a.publish_up <= ".$now.")"
." AND (a.publish_down = ".$null." OR a.publish_down >= ".$now.")": "")
." GROUP BY a.id";
$db->query($query);
return $db->getNumRows();
}
3. и в шаблоне templates\default\category.php
добавил форму
<form id="name-filter" action="<?php echo (substr(JFactory::getURI()->toString(), -1)%10 ? '1' : JFactory::getURI()->toString()); ?>" method="post" name="searchForm" accept-charset="utf-8">
<input type="text" name="search" id="zoo-search" value="<?php if (isset($_SESSION['search'])) echo $_SESSION['search'];?>" />
<button onclick="this.form.submit();"><?php echo JText::_('Search'); ?></button>
<button onclick="document.getElementById('zoo-search').value='';this.form.submit();"><?php echo JText::_('Reset'); ?></button>
</form>
ЗЫ: В Joomle есть функции работы с сессиями, позволяющие сделать код более красивый, но тогда я об этом еще не знал. И переменная сессии "search" очень просто названа, может с кем нибудь пересечься.