ADD search and filtering to the component

This commit is contained in:
2023-10-26 12:58:58 +02:00
parent d5263e7405
commit e69f2af6b0
5 changed files with 97 additions and 5 deletions

View File

@ -11,7 +11,8 @@
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table;
// use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
\defined('_JEXEC') or die;
@ -67,6 +68,12 @@ class PartsModel extends ListModel
->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {
$like = $db->quote('%' . $search . '%');
$query->where($db->quoteName('d.component_name') . ' LIKE ' . $like);
}
// Filter by published state
$published = (string) $this->getState('filter.published');
if (is_numeric($published)) {
@ -74,7 +81,8 @@ class PartsModel extends ListModel
$query->where($db->quoteName('d.state') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') {
$query->where($db->quoteName('d.state') . ' IN (0, 1)');
//$query->where($db->quoteName('d.state') . ' IN (0, 1)');
$query->whereIn($db->quoteName('d.state'), [0, 1]);
}
return $query;

View File

@ -30,6 +30,10 @@ class HtmlView extends BaseHtmlView
$this->items = $this->get('Items');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// set the toolbar
$this->addToolbar();