From add4b362ac84e53d887a5e62248303596d7238e6 Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Thu, 26 Oct 2023 16:42:11 +0200 Subject: [PATCH] ADD filter/search to manufacturers and stocks --- admin/forms/filter_manufacturers.xml | 49 +++++++++++++++++++++++ admin/forms/filter_stocks.xml | 49 +++++++++++++++++++++++ admin/src/Model/ManufacturersModel.php | 11 ++++- admin/src/Model/StocksModel.php | 10 ++++- admin/src/View/Manufacturers/HtmlView.php | 4 ++ admin/src/View/Stocks/HtmlView.php | 4 ++ admin/tmpl/manufacturers/default.php | 4 +- admin/tmpl/stocks/default.php | 3 ++ depot.xml | 2 +- 9 files changed, 132 insertions(+), 4 deletions(-) create mode 100644 admin/forms/filter_manufacturers.xml create mode 100644 admin/forms/filter_stocks.xml diff --git a/admin/forms/filter_manufacturers.xml b/admin/forms/filter_manufacturers.xml new file mode 100644 index 0000000..c661ebf --- /dev/null +++ b/admin/forms/filter_manufacturers.xml @@ -0,0 +1,49 @@ + +
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/admin/forms/filter_stocks.xml b/admin/forms/filter_stocks.xml new file mode 100644 index 0000000..2af75ca --- /dev/null +++ b/admin/forms/filter_stocks.xml @@ -0,0 +1,49 @@ + +
+ + + + + + + + + + + + + + + + + + + + +
diff --git a/admin/src/Model/ManufacturersModel.php b/admin/src/Model/ManufacturersModel.php index 7808fa2..2f3ad3c 100644 --- a/admin/src/Model/ManufacturersModel.php +++ b/admin/src/Model/ManufacturersModel.php @@ -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; @@ -60,6 +61,14 @@ class ManufacturersModel extends ListModel ->from($db->quoteName('#__depot_manufacturer', 'm')) ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('m.checked_out')); + // filter: like / search + $search = $this->getState('filter.search'); + if (!empty($search)) { + $like = $db->quote('%' . $search . '%'); + $query->where('(' . $db->quoteName('m.name_long') . ' LIKE ' . $like . ' OR ' . + $db->quoteName('m.name_short') . ' LIKE ' . $like . ')'); + } + // Filter by published state $published = (string) $this->getState('filter.published'); if (is_numeric($published)) { diff --git a/admin/src/Model/StocksModel.php b/admin/src/Model/StocksModel.php index 7896d13..bd00148 100644 --- a/admin/src/Model/StocksModel.php +++ b/admin/src/Model/StocksModel.php @@ -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; @@ -58,6 +59,13 @@ class StocksModel extends ListModel ) ->from($db->quoteName('#__depot_stock', 's')) ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('s.checked_out')); + // filter: like / search + $search = $this->getState('filter.search'); + if (!empty($search)) { + $like = $db->quote('%' . $search . '%'); + $query->where('(' . $db->quoteName('s.name') . ' LIKE ' . $like . ' OR ' . + $db->quoteName('s.description') . ' LIKE ' . $like . ')'); + } // Filter by published state $published = (string) $this->getState('filter.published'); diff --git a/admin/src/View/Manufacturers/HtmlView.php b/admin/src/View/Manufacturers/HtmlView.php index cc9342d..9f5919a 100644 --- a/admin/src/View/Manufacturers/HtmlView.php +++ b/admin/src/View/Manufacturers/HtmlView.php @@ -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(); diff --git a/admin/src/View/Stocks/HtmlView.php b/admin/src/View/Stocks/HtmlView.php index 9a3c9c6..b30b6eb 100644 --- a/admin/src/View/Stocks/HtmlView.php +++ b/admin/src/View/Stocks/HtmlView.php @@ -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(); diff --git a/admin/tmpl/manufacturers/default.php b/admin/tmpl/manufacturers/default.php index 18756d1..2ddd482 100644 --- a/admin/tmpl/manufacturers/default.php +++ b/admin/tmpl/manufacturers/default.php @@ -11,11 +11,14 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Router\Route; +use Joomla\CMS\Layout\LayoutHelper; ?>
+ $this]); ?> + items)): ?>