From e69f2af6b0480d76cc767bc443c16637746dfebf Mon Sep 17 00:00:00 2001 From: Thomas Kuschel Date: Thu, 26 Oct 2023 12:58:58 +0200 Subject: [PATCH] ADD search and filtering to the component --- admin/forms/filter_parts.xml | 78 +++++++++++++++++++++++++++++++ admin/src/Model/PartsModel.php | 12 ++++- admin/src/View/Parts/HtmlView.php | 4 ++ admin/tmpl/parts/default.php | 4 +- depot.xml | 4 +- 5 files changed, 97 insertions(+), 5 deletions(-) create mode 100644 admin/forms/filter_parts.xml diff --git a/admin/forms/filter_parts.xml b/admin/forms/filter_parts.xml new file mode 100644 index 0000000..7a8b4bf --- /dev/null +++ b/admin/forms/filter_parts.xml @@ -0,0 +1,78 @@ + +
+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
diff --git a/admin/src/Model/PartsModel.php b/admin/src/Model/PartsModel.php index d943fe1..2368fba 100644 --- a/admin/src/Model/PartsModel.php +++ b/admin/src/Model/PartsModel.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; @@ -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; diff --git a/admin/src/View/Parts/HtmlView.php b/admin/src/View/Parts/HtmlView.php index 43610f3..2a2d532 100644 --- a/admin/src/View/Parts/HtmlView.php +++ b/admin/src/View/Parts/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/parts/default.php b/admin/tmpl/parts/default.php index 841a11a..b26f825 100644 --- a/admin/tmpl/parts/default.php +++ b/admin/tmpl/parts/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)): ?>
- diff --git a/depot.xml b/depot.xml index 1e55132..7a60e7c 100644 --- a/depot.xml +++ b/depot.xml @@ -2,12 +2,12 @@ Depot KW4NZ - 2023-10-15 + 2023-10-24 (C) KW4NZ Thomas Kuschel GPL v2 +; see LICENSE.md thomas@kuschel.at https://kuschel.at - 0.9.3 + 0.9.4 COM_DEPOT_XML_DESCRIPTION KW4NZ\Component\Depot