From e762b207bb918392b296c24ab268a8a4201f7ea2 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Thu, 15 Oct 2026 17:11:06 +0200 Subject: [PATCH] Add subject filter to question sets --- README.md | 2 +- .../language/en-GB/com_testquestions.ini | 1 + .../sql/updates/mysql/1.10.6.sql | 1 + .../com_testquestions/src/Model/SetsModel.php | 18 ++++++++++++++++++ .../src/View/Sets/HtmlView.php | 2 ++ .../com_testquestions/tmpl/sets/default.php | 12 ++++++++++-- com_testquestions.xml | 2 +- 7 files changed, 34 insertions(+), 4 deletions(-) create mode 100644 administrator/components/com_testquestions/sql/updates/mysql/1.10.6.sql diff --git a/README.md b/README.md index fc59253..7433d16 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych. ## Instalacja -W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.10.5). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.10.6). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini index c0c3084..f09a693 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -63,3 +63,4 @@ COM_TESTQUESTIONS_SUBJECT_TITLE="Nazwa przedmiotu" COM_TESTQUESTIONS_NEW_SUBJECT="Nowy przedmiot" COM_TESTQUESTIONS_EDIT_SUBJECT="Edytuj przedmiot" COM_TESTQUESTIONS_SELECT_SUBJECT="-- wybierz przedmiot --" +COM_TESTQUESTIONS_FILTER_SUBJECT="Wszystkie przedmioty" diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.10.6.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.10.6.sql new file mode 100644 index 0000000..0081ba5 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.10.6.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.10.6. diff --git a/administrator/components/com_testquestions/src/Model/SetsModel.php b/administrator/components/com_testquestions/src/Model/SetsModel.php index 2afa656..a324496 100644 --- a/administrator/components/com_testquestions/src/Model/SetsModel.php +++ b/administrator/components/com_testquestions/src/Model/SetsModel.php @@ -14,6 +14,7 @@ class SetsModel extends ListModel parent::populateState($ordering, $direction); $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.published', $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '', 'string')); + $this->setState('filter.subject_id', $this->getUserStateFromRequest($this->context . '.filter.subject_id', 'filter_subject_id', '', 'int')); } protected function getListQuery() @@ -36,6 +37,23 @@ class SetsModel extends ListModel $query->where('s.published = ' . (int) $published); } + if ((int) $this->getState('filter.subject_id') > 0) { + $query->where('s.subject_id = ' . (int) $this->getState('filter.subject_id')); + } + return $query->order('s.ordering ASC, s.title ASC'); } + + public function getSubjects() + { + $db = Factory::getContainer()->get('DatabaseDriver'); + + return $db->setQuery( + $db->getQuery(true) + ->select(['id', 'title']) + ->from($db->quoteName('#__testquestions_subjects')) + ->where($db->quoteName('published') . ' = 1') + ->order($db->quoteName('title') . ' ASC') + )->loadObjectList(); + } } diff --git a/administrator/components/com_testquestions/src/View/Sets/HtmlView.php b/administrator/components/com_testquestions/src/View/Sets/HtmlView.php index ac8c40c..dbc42fd 100644 --- a/administrator/components/com_testquestions/src/View/Sets/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Sets/HtmlView.php @@ -14,12 +14,14 @@ class HtmlView extends BaseHtmlView protected $items; protected $pagination; protected $state; + protected $subjects; public function display($tpl = null) { $this->items = $this->get('Items'); $this->pagination = $this->get('Pagination'); $this->state = $this->get('State'); + $this->subjects = $this->get('Subjects'); if (count($errors = $this->get('Errors'))) { throw new \RuntimeException(implode("\n", $errors)); diff --git a/administrator/components/com_testquestions/tmpl/sets/default.php b/administrator/components/com_testquestions/tmpl/sets/default.php index c256718..da884bb 100644 --- a/administrator/components/com_testquestions/tmpl/sets/default.php +++ b/administrator/components/com_testquestions/tmpl/sets/default.php @@ -9,16 +9,24 @@ HTMLHelper::_('behavior.multiselect'); ?>
-
+
-
+
+
+ +
diff --git a/com_testquestions.xml b/com_testquestions.xml index fa814c3..d4a1389 100644 --- a/com_testquestions.xml +++ b/com_testquestions.xml @@ -4,7 +4,7 @@ 2026-10-14 Komponent GNU General Public License version 2 or later - 1.10.5 + 1.10.6 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions