From c9076d4a22e646c06bd0c664dbab8a9a1fe87fa7 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Fri, 16 Oct 2026 20:48:32 +0200 Subject: [PATCH] Add read-only preview for question sets --- README.md | 2 +- .../language/en-GB/com_testquestions.ini | 1 + .../sql/updates/mysql/1.43.16.sql | 1 + .../src/Model/PreviewModel.php | 33 ++++++++++++++++++- .../src/View/Preview/HtmlView.php | 11 ++++++- .../src/View/Set/HtmlView.php | 7 ++++ .../tmpl/preview/default.php | 13 ++++++-- .../com_testquestions/tmpl/set/edit.php | 9 +++-- .../com_testquestions/tmpl/sets/default.php | 7 +++- com_testquestions.xml | 2 +- 10 files changed, 77 insertions(+), 9 deletions(-) create mode 100644 administrator/components/com_testquestions/sql/updates/mysql/1.43.16.sql diff --git a/README.md b/README.md index 641fcca..6b8f076 100644 --- a/README.md +++ b/README.md @@ -30,6 +30,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.43.15). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.16). 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 5832e5f..58c83ed 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -87,6 +87,7 @@ COM_TESTQUESTIONS_PREVIEW_READONLY="Tryb podglądu — odpowiedzi są nieaktywne COM_TESTQUESTIONS_PREVIEW_EMPTY="Nie znaleziono pytań do wyświetlenia." COM_TESTQUESTIONS_PREVIEW_SELECT_QUESTIONS="Zaznacz pytania, które chcesz podejrzeć." COM_TESTQUESTIONS_PREVIEW_BACK="Wróć do listy pytań" +COM_TESTQUESTIONS_PREVIEW_SET="Podgląd zestawu" COM_TESTQUESTIONS_AI_SETTINGS_MENU="Konfiguracja AI" COM_TESTQUESTIONS_AI_SETTINGS_SAVED="Ustawienia AI zapisano." COM_TESTQUESTIONS_AI_SAVE_FAILED="Nie udało się zapisać ustawień AI." diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.43.16.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.16.sql new file mode 100644 index 0000000..b90c159 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.16.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.43.16. diff --git a/administrator/components/com_testquestions/src/Model/PreviewModel.php b/administrator/components/com_testquestions/src/Model/PreviewModel.php index f8137dd..fdae8ec 100644 --- a/administrator/components/com_testquestions/src/Model/PreviewModel.php +++ b/administrator/components/com_testquestions/src/Model/PreviewModel.php @@ -9,16 +9,47 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel; class PreviewModel extends BaseDatabaseModel { + public function getSet() + { + $setId = Factory::getApplication()->getInput()->getInt('set_id'); + if ($setId < 1) { + return null; + } + + $db = Factory::getContainer()->get('DatabaseDriver'); + + return $db->setQuery( + $db->getQuery(true) + ->select(['id', 'title', 'test_content', 'image']) + ->from($db->quoteName('#__testquestions_sets')) + ->where($db->quoteName('id') . ' = ' . $setId) + )->loadObject(); + } + public function getItems(): array { $input = Factory::getApplication()->getInput(); + $setId = $input->getInt('set_id'); + $db = Factory::getContainer()->get('DatabaseDriver'); + + if ($setId > 0) { + return $db->setQuery( + $db->getQuery(true) + ->select(['q.id', 'q.question_type', 'q.question', 'q.answer_a', 'q.answer_b', 'q.answer_c', 'q.answer_d', 'q.answer_open', 'q.correct_answer', 'q.image']) + ->from($db->quoteName('#__testquestions_set_questions', 'sq')) + ->innerJoin($db->quoteName('#__testquestions_questions', 'q') . ' ON q.id = sq.question_id') + ->where('sq.set_id = ' . $setId) + ->where('q.published = 1') + ->order('sq.ordering ASC, q.id ASC') + )->loadObjectList(); + } + $ids = array_values(array_unique(array_filter(array_map('intval', explode(',', $input->getString('ids', '')))))); if (!$ids) { return []; } - $db = Factory::getContainer()->get('DatabaseDriver'); $rows = $db->setQuery( $db->getQuery(true) ->select(['id', 'question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer', 'image']) diff --git a/administrator/components/com_testquestions/src/View/Preview/HtmlView.php b/administrator/components/com_testquestions/src/View/Preview/HtmlView.php index 9bdaefd..3669ba1 100644 --- a/administrator/components/com_testquestions/src/View/Preview/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Preview/HtmlView.php @@ -7,11 +7,13 @@ defined('_JEXEC') or die; use Joomla\CMS\Factory; use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView; +use Joomla\CMS\Router\Route; use Joomla\CMS\Toolbar\ToolbarHelper; class HtmlView extends BaseHtmlView { protected $items = []; + protected $set; public function display($tpl = null) { @@ -21,12 +23,19 @@ class HtmlView extends BaseHtmlView } $this->items = $this->get('Items'); + $this->set = $this->get('Set'); $this->getDocument()->getWebAssetManager()->registerAndUseStyle( 'com_testquestions.exam', 'media/com_testquestions/egzamin.css' ); ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_PREVIEW_TITLE')); - ToolbarHelper::link('index.php?option=com_testquestions&view=questions', 'COM_TESTQUESTIONS', 'arrow-left'); + ToolbarHelper::link( + $this->set + ? Route::_('index.php?option=com_testquestions&task=set.edit&id=' . (int) $this->set->id) + : Route::_('index.php?option=com_testquestions&view=questions'), + $this->set ? 'COM_TESTQUESTIONS_EDIT_SET' : 'COM_TESTQUESTIONS', + 'arrow-left' + ); return parent::display($tpl); } diff --git a/administrator/components/com_testquestions/src/View/Set/HtmlView.php b/administrator/components/com_testquestions/src/View/Set/HtmlView.php index a1b02bc..d482bbd 100644 --- a/administrator/components/com_testquestions/src/View/Set/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Set/HtmlView.php @@ -47,6 +47,13 @@ class HtmlView extends BaseHtmlView protected function addToolbar() { ToolbarHelper::title($this->item->id ? Text::_('COM_TESTQUESTIONS_EDIT_SET') : Text::_('COM_TESTQUESTIONS_NEW_SET')); + if (!empty($this->item->id) && ((string) $this->item->set_type !== 'multi' || $this->isVariant)) { + ToolbarHelper::link( + 'index.php?option=com_testquestions&view=preview&set_id=' . (int) $this->item->id, + 'COM_TESTQUESTIONS_PREVIEW_SET', + 'eye' + ); + } ToolbarHelper::custom('set.save', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE', false); ToolbarHelper::custom('set.saveandclose', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE_AND_CLOSE', false); ToolbarHelper::cancel('set.cancel', 'JTOOLBAR_CANCEL'); diff --git a/administrator/components/com_testquestions/tmpl/preview/default.php b/administrator/components/com_testquestions/tmpl/preview/default.php index bcac317..82552f3 100644 --- a/administrator/components/com_testquestions/tmpl/preview/default.php +++ b/administrator/components/com_testquestions/tmpl/preview/default.php @@ -17,6 +17,15 @@ $resolveImageUrl = static function ($path) { ?>

+ set) : ?> +
+

set->title, ENT_QUOTES, 'UTF-8'); ?>

+ set->image) : ?> +
+ + set->test_content) : ?>
set->test_content; ?>
+
+ items) : ?>
@@ -54,7 +63,7 @@ $resolveImageUrl = static function ($path) { - - + + set ? \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_EDIT_SET') : \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_PREVIEW_BACK'); ?>
diff --git a/administrator/components/com_testquestions/tmpl/set/edit.php b/administrator/components/com_testquestions/tmpl/set/edit.php index 25c76ce..c604d08 100644 --- a/administrator/components/com_testquestions/tmpl/set/edit.php +++ b/administrator/components/com_testquestions/tmpl/set/edit.php @@ -40,8 +40,13 @@ HTMLHelper::_('behavior.formvalidator'); diff --git a/administrator/components/com_testquestions/tmpl/sets/default.php b/administrator/components/com_testquestions/tmpl/sets/default.php index a437b9a..2fbe4f1 100644 --- a/administrator/components/com_testquestions/tmpl/sets/default.php +++ b/administrator/components/com_testquestions/tmpl/sets/default.php @@ -54,7 +54,12 @@ HTMLHelper::_('behavior.multiselect'); items as $i => $item) : ?> id); ?> - parent_id > 0 ? '↳ ' : ''; ?>escape($item->title); ?>parent_id > 0 && $item->parent_title) : ?> (escape($item->parent_title); ?>) + + parent_id > 0 ? '↳ ' : ''; ?>escape($item->title); ?>parent_id > 0 && $item->parent_title) : ?> (escape($item->parent_title); ?>) + set_type === 'ordinary') : ?> + + + escape($item->set_type === 'multi' ? \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TYPE_MULTI') : ($item->set_type === 'variant' ? \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TYPE_VARIANT') : \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TYPE_ORDINARY'))); ?> escape($item->subject_title ?: '—'); ?> question_count; ?> diff --git a/com_testquestions.xml b/com_testquestions.xml index d74ffc7..b0910fa 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.43.15 + 1.43.16 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions