diff --git a/README.md b/README.md index 834a925..6648b59 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.9.4). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.10.0). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/forms/set.xml b/administrator/components/com_testquestions/forms/set.xml index 86c558d..2297e59 100644 --- a/administrator/components/com_testquestions/forms/set.xml +++ b/administrator/components/com_testquestions/forms/set.xml @@ -3,6 +3,9 @@
+ + + diff --git a/administrator/components/com_testquestions/forms/subject.xml b/administrator/components/com_testquestions/forms/subject.xml new file mode 100644 index 0000000..cd858de --- /dev/null +++ b/administrator/components/com_testquestions/forms/subject.xml @@ -0,0 +1,11 @@ + +
+
+ + + + + + +
+
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 5377d99..c0c3084 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -57,3 +57,9 @@ COM_TESTQUESTIONS_SET_CATEGORY_FILTER="Filtruj pytania według kategorii" COM_TESTQUESTIONS_SET_ALL_CATEGORIES="Wszystkie kategorie" COM_TESTQUESTIONS_UNCATEGORIZED="Bez kategorii" COM_TESTQUESTIONS_SET_SHOW_DETAILS="Pokaż odpowiedzi" +COM_TESTQUESTIONS_SUBJECTS="Przedmioty" +COM_TESTQUESTIONS_SUBJECT="Przedmiot" +COM_TESTQUESTIONS_SUBJECT_TITLE="Nazwa przedmiotu" +COM_TESTQUESTIONS_NEW_SUBJECT="Nowy przedmiot" +COM_TESTQUESTIONS_EDIT_SUBJECT="Edytuj przedmiot" +COM_TESTQUESTIONS_SELECT_SUBJECT="-- wybierz przedmiot --" diff --git a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql index 74b9617..5728d6e 100644 --- a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql +++ b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql @@ -40,6 +40,7 @@ VALUES (1, 'Bez kategorii', 1, 0); CREATE TABLE IF NOT EXISTS `#__testquestions_sets` ( `id` int unsigned NOT NULL AUTO_INCREMENT, + `subject_id` int unsigned NOT NULL DEFAULT 0, `title` varchar(255) NOT NULL, `description` text NULL, `published` tinyint NOT NULL DEFAULT 1, @@ -53,6 +54,15 @@ CREATE TABLE IF NOT EXISTS `#__testquestions_sets` ( KEY `idx_ordering` (`ordering`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; +CREATE TABLE IF NOT EXISTS `#__testquestions_subjects` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(150) NOT NULL, + `published` tinyint NOT NULL DEFAULT 1, + `ordering` int NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `idx_title` (`title`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + CREATE TABLE IF NOT EXISTS `#__testquestions_set_questions` ( `set_id` int unsigned NOT NULL, `question_id` int unsigned NOT NULL, diff --git a/administrator/components/com_testquestions/sql/uninstall.mysql.utf8mb4.sql b/administrator/components/com_testquestions/sql/uninstall.mysql.utf8mb4.sql index 010f238..b555188 100644 --- a/administrator/components/com_testquestions/sql/uninstall.mysql.utf8mb4.sql +++ b/administrator/components/com_testquestions/sql/uninstall.mysql.utf8mb4.sql @@ -1,3 +1,4 @@ DROP TABLE IF EXISTS `#__testquestions_set_questions`; DROP TABLE IF EXISTS `#__testquestions_sets`; +DROP TABLE IF EXISTS `#__testquestions_subjects`; DROP TABLE IF EXISTS `#__testquestions_questions`; diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.10.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.10.0.sql new file mode 100644 index 0000000..99dd598 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.10.0.sql @@ -0,0 +1,11 @@ +CREATE TABLE IF NOT EXISTS `#__testquestions_subjects` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(150) NOT NULL, + `published` tinyint NOT NULL DEFAULT 1, + `ordering` int NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `idx_title` (`title`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + +ALTER TABLE `#__testquestions_sets` + ADD COLUMN `subject_id` int unsigned NOT NULL DEFAULT 0 AFTER `id`; diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.9.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.9.0.sql index e5c7348..a89489c 100644 --- a/administrator/components/com_testquestions/sql/updates/mysql/1.9.0.sql +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.9.0.sql @@ -1,5 +1,6 @@ CREATE TABLE IF NOT EXISTS `#__testquestions_sets` ( `id` int unsigned NOT NULL AUTO_INCREMENT, + `subject_id` int unsigned NOT NULL DEFAULT 0, `title` varchar(255) NOT NULL, `description` text NULL, `published` tinyint NOT NULL DEFAULT 1, @@ -13,6 +14,15 @@ CREATE TABLE IF NOT EXISTS `#__testquestions_sets` ( KEY `idx_ordering` (`ordering`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; +CREATE TABLE IF NOT EXISTS `#__testquestions_subjects` ( + `id` int unsigned NOT NULL AUTO_INCREMENT, + `title` varchar(150) NOT NULL, + `published` tinyint NOT NULL DEFAULT 1, + `ordering` int NOT NULL DEFAULT 0, + PRIMARY KEY (`id`), + UNIQUE KEY `idx_title` (`title`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 DEFAULT COLLATE=utf8mb4_unicode_ci; + CREATE TABLE IF NOT EXISTS `#__testquestions_set_questions` ( `set_id` int unsigned NOT NULL, `question_id` int unsigned NOT NULL, diff --git a/administrator/components/com_testquestions/src/Controller/SubjectController.php b/administrator/components/com_testquestions/src/Controller/SubjectController.php new file mode 100644 index 0000000..a911a92 --- /dev/null +++ b/administrator/components/com_testquestions/src/Controller/SubjectController.php @@ -0,0 +1,20 @@ +setRedirect('index.php?option=com_testquestions&view=subjects'); + + return true; + } +} diff --git a/administrator/components/com_testquestions/src/Controller/SubjectsController.php b/administrator/components/com_testquestions/src/Controller/SubjectsController.php new file mode 100644 index 0000000..c5d34d9 --- /dev/null +++ b/administrator/components/com_testquestions/src/Controller/SubjectsController.php @@ -0,0 +1,17 @@ + true]) + { + return parent::getModel($name, $prefix, $config); + } +} diff --git a/administrator/components/com_testquestions/src/Model/SetsModel.php b/administrator/components/com_testquestions/src/Model/SetsModel.php index d294181..2afa656 100644 --- a/administrator/components/com_testquestions/src/Model/SetsModel.php +++ b/administrator/components/com_testquestions/src/Model/SetsModel.php @@ -20,8 +20,9 @@ class SetsModel extends ListModel { $db = Factory::getContainer()->get('DatabaseDriver'); $query = $db->getQuery(true) - ->select(['s.*', 'COUNT(sq.question_id) AS question_count']) + ->select(['s.*', 'sub.title AS subject_title', 'COUNT(sq.question_id) AS question_count']) ->from($db->quoteName('#__testquestions_sets', 's')) + ->leftJoin($db->quoteName('#__testquestions_subjects', 'sub') . ' ON sub.id = s.subject_id') ->leftJoin($db->quoteName('#__testquestions_set_questions', 'sq') . ' ON sq.set_id = s.id') ->group('s.id'); diff --git a/administrator/components/com_testquestions/src/Model/SubjectModel.php b/administrator/components/com_testquestions/src/Model/SubjectModel.php new file mode 100644 index 0000000..208c937 --- /dev/null +++ b/administrator/components/com_testquestions/src/Model/SubjectModel.php @@ -0,0 +1,26 @@ +getMVCFactory()->createTable($name, $prefix, $config); + } + + public function getForm($data = [], $loadData = true) + { + return $this->loadForm('com_testquestions.subject', 'subject', ['control' => 'jform', 'load_data' => $loadData]); + } + + protected function loadFormData() + { + return Factory::getApplication()->getUserState('com_testquestions.edit.subject.data', []) ?: $this->getItem(); + } +} diff --git a/administrator/components/com_testquestions/src/Model/SubjectsModel.php b/administrator/components/com_testquestions/src/Model/SubjectsModel.php new file mode 100644 index 0000000..c282126 --- /dev/null +++ b/administrator/components/com_testquestions/src/Model/SubjectsModel.php @@ -0,0 +1,21 @@ +get('DatabaseDriver'); + + return $db->getQuery(true) + ->select('*') + ->from($db->quoteName('#__testquestions_subjects')) + ->order($db->quoteName('ordering') . ' ASC, ' . $db->quoteName('title') . ' ASC'); + } +} diff --git a/administrator/components/com_testquestions/src/Table/SubjectTable.php b/administrator/components/com_testquestions/src/Table/SubjectTable.php new file mode 100644 index 0000000..102fe41 --- /dev/null +++ b/administrator/components/com_testquestions/src/Table/SubjectTable.php @@ -0,0 +1,23 @@ +title = trim((string) $this->title); + + return $this->title !== '' && parent::check($updateNulls); + } +} diff --git a/administrator/components/com_testquestions/src/View/Sets/HtmlView.php b/administrator/components/com_testquestions/src/View/Sets/HtmlView.php index 44e924e..ac8c40c 100644 --- a/administrator/components/com_testquestions/src/View/Sets/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Sets/HtmlView.php @@ -50,5 +50,10 @@ class HtmlView extends BaseHtmlView 'COM_TESTQUESTIONS_QUESTIONS', 'list' ); + ToolbarHelper::link( + 'index.php?option=com_testquestions&view=subjects', + 'COM_TESTQUESTIONS_SUBJECTS', + 'list' + ); } } diff --git a/administrator/components/com_testquestions/src/View/Subject/HtmlView.php b/administrator/components/com_testquestions/src/View/Subject/HtmlView.php new file mode 100644 index 0000000..09fa224 --- /dev/null +++ b/administrator/components/com_testquestions/src/View/Subject/HtmlView.php @@ -0,0 +1,26 @@ +form = $this->get('Form'); + $this->item = $this->get('Item'); + ToolbarHelper::title($this->item->id ? Text::_('COM_TESTQUESTIONS_EDIT_SUBJECT') : Text::_('COM_TESTQUESTIONS_NEW_SUBJECT')); + ToolbarHelper::save('subject.save', 'JTOOLBAR_SAVE'); + ToolbarHelper::cancel('subject.cancel', 'JTOOLBAR_CANCEL'); + + return parent::display($tpl); + } +} diff --git a/administrator/components/com_testquestions/src/View/Subjects/HtmlView.php b/administrator/components/com_testquestions/src/View/Subjects/HtmlView.php new file mode 100644 index 0000000..b10d659 --- /dev/null +++ b/administrator/components/com_testquestions/src/View/Subjects/HtmlView.php @@ -0,0 +1,27 @@ +items = $this->get('Items'); + ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_SUBJECTS')); + ToolbarHelper::addNew('subject.add', 'JTOOLBAR_NEW'); + ToolbarHelper::editList('subject.edit', 'JTOOLBAR_EDIT'); + ToolbarHelper::deleteList('', 'subjects.delete', 'JTOOLBAR_DELETE'); + ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back'); + + return parent::display($tpl); + } +} diff --git a/administrator/components/com_testquestions/tmpl/sets/default.php b/administrator/components/com_testquestions/tmpl/sets/default.php index 904191b..c256718 100644 --- a/administrator/components/com_testquestions/tmpl/sets/default.php +++ b/administrator/components/com_testquestions/tmpl/sets/default.php @@ -30,6 +30,7 @@ HTMLHelper::_('behavior.multiselect'); + @@ -40,6 +41,7 @@ HTMLHelper::_('behavior.multiselect'); id); ?> escape($item->title); ?> + escape($item->subject_title ?: '—'); ?> question_count; ?> published, $i, 'sets.', true, 'cb'); ?> id; ?> diff --git a/administrator/components/com_testquestions/tmpl/subject/edit.php b/administrator/components/com_testquestions/tmpl/subject/edit.php new file mode 100644 index 0000000..ddb3812 --- /dev/null +++ b/administrator/components/com_testquestions/tmpl/subject/edit.php @@ -0,0 +1,8 @@ + +
+ form->renderField('title'); ?> + form->renderField('published'); ?> + form->renderField('id'); ?> + + +
diff --git a/administrator/components/com_testquestions/tmpl/subjects/default.php b/administrator/components/com_testquestions/tmpl/subjects/default.php new file mode 100644 index 0000000..b1884d9 --- /dev/null +++ b/administrator/components/com_testquestions/tmpl/subjects/default.php @@ -0,0 +1,24 @@ + +
+ + + + + + + + + items as $i => $item) : ?> + + + + + + + + +
id); ?>title, ENT_QUOTES, 'UTF-8'); ?>published ? Joomla\CMS\Language\Text::_('JPUBLISHED') : Joomla\CMS\Language\Text::_('JUNPUBLISHED'); ?>id; ?>
+ + + +
diff --git a/com_testquestions.xml b/com_testquestions.xml index 4046251..453ac89 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.9.4 + 1.10.0 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions