diff --git a/README.md b/README.md index 0da6356..9a56251 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.19.1). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.20.0). 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 20d4bda..d7c0227 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -70,6 +70,9 @@ COM_TESTQUESTIONS_RESULT_SCORE="Wynik" COM_TESTQUESTIONS_RESULT_DATE="Data zakończenia" COM_TESTQUESTIONS_RESULT_ANSWERS="Odpowiedzi" COM_TESTQUESTIONS_RESULT_EXECUTION_TIME="Czas wykonania" +COM_TESTQUESTIONS_RESULT_AWARDED_POINTS="Uznane punkty" +COM_TESTQUESTIONS_RESULT_COMMENT="Komentarz" +COM_TESTQUESTIONS_RESULT_SAVED="Dane wyniku zostały zapisane." COM_TESTQUESTIONS_RESULTS_SEARCH="Szukaj po użytkowniku lub zestawie..." COM_TESTQUESTIONS_YOUR_ANSWER="Twoja odpowiedź" COM_TESTQUESTIONS_SELECTED_ANSWER="Zaznaczona odpowiedź" diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.20.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.20.0.sql new file mode 100644 index 0000000..c038339 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.20.0.sql @@ -0,0 +1 @@ +-- Per-question awarded points and comments are stored in the existing answers JSON column. diff --git a/administrator/components/com_testquestions/src/Controller/ResultController.php b/administrator/components/com_testquestions/src/Controller/ResultController.php new file mode 100644 index 0000000..8dbae16 --- /dev/null +++ b/administrator/components/com_testquestions/src/Controller/ResultController.php @@ -0,0 +1,36 @@ +getInput(); + $id = $input->post->getInt('id'); + $points = (array) $input->post->get('awarded_points', [], 'array'); + $comments = (array) $input->post->get('comments', [], 'array'); + $model = $this->getModel('Result'); + + if (!$model->saveAssessment($id, $points, $comments)) { + throw new \RuntimeException(Text::_('COM_TESTQUESTIONS_RESULT_NOT_FOUND')); + } + + $this->setRedirect( + Route::_('index.php?option=com_testquestions&view=result&id=' . $id, false), + Text::_('COM_TESTQUESTIONS_RESULT_SAVED') + ); + } +} diff --git a/administrator/components/com_testquestions/src/Model/ResultModel.php b/administrator/components/com_testquestions/src/Model/ResultModel.php index 613fc84..0be425b 100644 --- a/administrator/components/com_testquestions/src/Model/ResultModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultModel.php @@ -33,7 +33,7 @@ class ResultModel extends BaseDatabaseModel if ($ids) { $item->questions = $db->setQuery( $db->getQuery(true) - ->select(['id', 'question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer']) + ->select(['id', 'question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer', 'points']) ->from($db->quoteName('#__testquestions_questions')) ->where('id IN (' . implode(',', $ids) . ')') )->loadObjectList('id'); @@ -41,4 +41,28 @@ class ResultModel extends BaseDatabaseModel return $item; } + + public function saveAssessment(int $id, array $awardedPoints, array $comments): bool + { + $item = $this->getItem($id); + + if (!$item) { + return false; + } + + foreach ($item->answers as $questionId => &$answer) { + $key = (string) $questionId; + $answer['awarded_points'] = max(0, (int) ($awardedPoints[$key] ?? 0)); + $answer['comment'] = trim((string) ($comments[$key] ?? '')); + } + unset($answer); + + $db = Factory::getContainer()->get('DatabaseDriver'); + $row = (object) [ + 'id' => $id, + 'answers' => json_encode($item->answers, JSON_UNESCAPED_UNICODE), + ]; + + return (bool) $db->updateObject('#__testquestions_results', $row, 'id'); + } } diff --git a/administrator/components/com_testquestions/tmpl/result/default.php b/administrator/components/com_testquestions/tmpl/result/default.php index 3b08416..269ffe5 100644 --- a/administrator/components/com_testquestions/tmpl/result/default.php +++ b/administrator/components/com_testquestions/tmpl/result/default.php @@ -1,4 +1,6 @@ + +
item->extra_time > 0 ? ' style="background-color: #fff3cd;"' : ''; ?>> @@ -12,6 +14,7 @@
item->execution_time / 60); ?>:item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?>
+

item->answers as $questionId => $answer) : ?> item->questions[(int) $questionId] ?? null; if (!$question) continue; ?> @@ -25,6 +28,21 @@
: correct_answer); ?>
+
+
+ + +
+
+ + +
+
+ + + + +
diff --git a/com_testquestions.xml b/com_testquestions.xml index 842f708..d5624d5 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.19.1 + 1.20.0 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions