-
+ $answerField) : ?>
+ correct_answer === $answerIndex + 1; ?>
+
- + + + +
diff --git a/README.md b/README.md index c366ee5..641fcca 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.14). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.15). 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 3927458..5832e5f 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -81,6 +81,12 @@ COM_TESTQUESTIONS_AI_USAGE_INPUT="Tokeny wejściowe" COM_TESTQUESTIONS_AI_USAGE_OUTPUT="Tokeny wyjściowe" COM_TESTQUESTIONS_AI_USAGE_TOTAL="Razem tokenów" COM_TESTQUESTIONS_AI_USAGE_COST="Koszt zapisany" +COM_TESTQUESTIONS_PREVIEW_SELECTED="Podgląd zaznaczonych" +COM_TESTQUESTIONS_PREVIEW_TITLE="Podgląd pytań testowych" +COM_TESTQUESTIONS_PREVIEW_READONLY="Tryb podglądu — odpowiedzi są nieaktywne, test nie ma limitu czasu ani przycisku zakończenia." +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_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.15.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.15.sql new file mode 100644 index 0000000..628dc3d --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.15.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.43.15. diff --git a/administrator/components/com_testquestions/src/Controller/QuestionsController.php b/administrator/components/com_testquestions/src/Controller/QuestionsController.php index d1be671..404a7ce 100644 --- a/administrator/components/com_testquestions/src/Controller/QuestionsController.php +++ b/administrator/components/com_testquestions/src/Controller/QuestionsController.php @@ -4,7 +4,11 @@ namespace Komponent\Component\Testquestions\Administrator\Controller; defined('_JEXEC') or die; +use Joomla\CMS\Factory; +use Joomla\CMS\Language\Text; use Joomla\CMS\MVC\Controller\AdminController; +use Joomla\CMS\Router\Route; +use Joomla\CMS\Session\Session; class QuestionsController extends AdminController { @@ -14,4 +18,28 @@ class QuestionsController extends AdminController { return parent::getModel($name, $prefix, $config); } + + public function preview(): void + { + if (!Session::checkToken()) { + throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403); + } + + $user = Factory::getApplication()->getIdentity(); + if (!$user->authorise('core.edit', 'com_testquestions') && !$user->authorise('core.manage', 'com_testquestions')) { + throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403); + } + + $ids = array_values(array_unique(array_filter(array_map('intval', (array) $this->input->post->get('cid', [], 'array'))))); + if (!$ids) { + $this->setRedirect( + Route::_('index.php?option=com_testquestions&view=questions', false), + Text::_('COM_TESTQUESTIONS_PREVIEW_SELECT_QUESTIONS'), + 'warning' + ); + return; + } + + $this->setRedirect(Route::_('index.php?option=com_testquestions&view=preview&ids=' . implode(',', $ids), false)); + } } diff --git a/administrator/components/com_testquestions/src/Model/PreviewModel.php b/administrator/components/com_testquestions/src/Model/PreviewModel.php new file mode 100644 index 0000000..f8137dd --- /dev/null +++ b/administrator/components/com_testquestions/src/Model/PreviewModel.php @@ -0,0 +1,38 @@ +getInput(); + $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']) + ->from($db->quoteName('#__testquestions_questions')) + ->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')') + )->loadObjectList('id'); + + $items = []; + foreach ($ids as $id) { + if (isset($rows[$id])) { + $items[] = $rows[$id]; + } + } + + return $items; + } +} diff --git a/administrator/components/com_testquestions/src/View/Preview/HtmlView.php b/administrator/components/com_testquestions/src/View/Preview/HtmlView.php new file mode 100644 index 0000000..9bdaefd --- /dev/null +++ b/administrator/components/com_testquestions/src/View/Preview/HtmlView.php @@ -0,0 +1,33 @@ +getIdentity(); + if (!$user->authorise('core.edit', 'com_testquestions') && !$user->authorise('core.manage', 'com_testquestions')) { + throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403); + } + + $this->items = $this->get('Items'); + $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'); + + return parent::display($tpl); + } +} diff --git a/administrator/components/com_testquestions/src/View/Questions/HtmlView.php b/administrator/components/com_testquestions/src/View/Questions/HtmlView.php index 6a7f5bc..76dba85 100644 --- a/administrator/components/com_testquestions/src/View/Questions/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Questions/HtmlView.php @@ -41,6 +41,7 @@ class HtmlView extends BaseHtmlView } if ($user->authorise('core.edit', 'com_testquestions')) { ToolbarHelper::editList('question.edit', 'JTOOLBAR_EDIT'); + ToolbarHelper::custom('questions.preview', 'eye', 'eye', 'COM_TESTQUESTIONS_PREVIEW_SELECTED', true); } if ($user->authorise('core.delete', 'com_testquestions')) { ToolbarHelper::deleteList('', 'questions.delete', 'JTOOLBAR_DELETE'); diff --git a/administrator/components/com_testquestions/tmpl/preview/default.php b/administrator/components/com_testquestions/tmpl/preview/default.php new file mode 100644 index 0000000..bcac317 --- /dev/null +++ b/administrator/components/com_testquestions/tmpl/preview/default.php @@ -0,0 +1,60 @@ + +