From 1df6c6dfc399e9a508677328c767606c73d97fd8 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Thu, 15 Oct 2026 21:11:30 +0200 Subject: [PATCH] Track corrected result points --- README.md | 2 +- .../language/en-GB/com_testquestions.ini | 1 + .../com_testquestions/sql/install.mysql.utf8mb4.sql | 2 ++ .../com_testquestions/sql/updates/mysql/1.21.0.sql | 8 ++++++++ .../com_testquestions/src/Model/ResultModel.php | 6 ++++++ .../com_testquestions/tmpl/results/default.php | 4 ++-- com_testquestions.xml | 2 +- components/com_testquestions/src/Model/SetModel.php | 11 ++++++++++- .../com_testquestions/src/View/Set/HtmlView.php | 6 +++++- 9 files changed, 36 insertions(+), 6 deletions(-) create mode 100644 administrator/components/com_testquestions/sql/updates/mysql/1.21.0.sql diff --git a/README.md b/README.md index 9a56251..dd6f8c5 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.20.0). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.21.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 d7c0227..c5e2eb1 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -67,6 +67,7 @@ COM_TESTQUESTIONS_RESULT_PREVIEW="Podgląd zapisanego testu" COM_TESTQUESTIONS_RESULT_NOT_FOUND="Nie znaleziono zapisanego testu." COM_TESTQUESTIONS_RESULT_PARTICIPANT="Użytkownik" COM_TESTQUESTIONS_RESULT_SCORE="Wynik" +COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER="Punkty przed / po korekcie" COM_TESTQUESTIONS_RESULT_DATE="Data zakończenia" COM_TESTQUESTIONS_RESULT_ANSWERS="Odpowiedzi" COM_TESTQUESTIONS_RESULT_EXECUTION_TIME="Czas wykonania" diff --git a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql index cc6e9ec..93122fc 100644 --- a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql +++ b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql @@ -84,6 +84,8 @@ CREATE TABLE IF NOT EXISTS `#__testquestions_results` ( `correct_count` smallint unsigned NOT NULL DEFAULT 0, `total_count` smallint unsigned NOT NULL DEFAULT 0, `percentage` decimal(5,2) NOT NULL DEFAULT 0.00, + `points_before` int unsigned NOT NULL DEFAULT 0, + `points_after` int unsigned NOT NULL DEFAULT 0, `answers` longtext NULL, `created` datetime NOT NULL, `created_by` int unsigned NOT NULL DEFAULT 0, diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.21.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.21.0.sql new file mode 100644 index 0000000..dc271f6 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.21.0.sql @@ -0,0 +1,8 @@ +ALTER TABLE `#__testquestions_results` + ADD COLUMN `points_before` int unsigned NOT NULL DEFAULT 0 AFTER `percentage`, + ADD COLUMN `points_after` int unsigned NOT NULL DEFAULT 0 AFTER `points_before`; + +UPDATE `#__testquestions_results` +SET `points_before` = `correct_count`, + `points_after` = `correct_count` +WHERE `points_before` = 0 AND `points_after` = 0; diff --git a/administrator/components/com_testquestions/src/Model/ResultModel.php b/administrator/components/com_testquestions/src/Model/ResultModel.php index 0be425b..f3bd044 100644 --- a/administrator/components/com_testquestions/src/Model/ResultModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultModel.php @@ -57,10 +57,16 @@ class ResultModel extends BaseDatabaseModel } unset($answer); + $pointsAfter = 0; + foreach ($item->answers as $answer) { + $pointsAfter += (int) ($answer['awarded_points'] ?? 0); + } + $db = Factory::getContainer()->get('DatabaseDriver'); $row = (object) [ 'id' => $id, 'answers' => json_encode($item->answers, JSON_UNESCAPED_UNICODE), + 'points_after' => $pointsAfter, ]; return (bool) $db->updateObject('#__testquestions_results', $row, 'id'); diff --git a/administrator/components/com_testquestions/tmpl/results/default.php b/administrator/components/com_testquestions/tmpl/results/default.php index 6544e0b..dc3f52f 100644 --- a/administrator/components/com_testquestions/tmpl/results/default.php +++ b/administrator/components/com_testquestions/tmpl/results/default.php @@ -16,7 +16,7 @@ use Joomla\CMS\Router\Route; - + @@ -25,7 +25,7 @@ use Joomla\CMS\Router\Route; escape($item->participant_name); ?> escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?> - correct_count; ?> / total_count; ?> (percentage, ENT_QUOTES, 'UTF-8'); ?>%) + points_before; ?> / points_after; ?> execution_time / 60); ?>:execution_time % 60), 2, '0', STR_PAD_LEFT); ?> created, 'Y-m-d H:i'); ?> diff --git a/com_testquestions.xml b/com_testquestions.xml index d5624d5..7ad7d3a 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.20.0 + 1.21.0 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions diff --git a/components/com_testquestions/src/Model/SetModel.php b/components/com_testquestions/src/Model/SetModel.php index cc034af..652e6b0 100644 --- a/components/com_testquestions/src/Model/SetModel.php +++ b/components/com_testquestions/src/Model/SetModel.php @@ -48,7 +48,7 @@ class SetModel extends BaseDatabaseModel 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']) + ->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.points', '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) @@ -81,6 +81,13 @@ class SetModel extends BaseDatabaseModel return false; } + $pointsBefore = 0; + foreach (($result['items'] ?? []) as $item) { + if (!empty($item['correct'])) { + $pointsBefore += (int) ($item['points'] ?? 0); + } + } + $row = (object) [ 'set_id' => $setId, 'participant_name' => trim($participantName), @@ -90,6 +97,8 @@ class SetModel extends BaseDatabaseModel 'correct_count' => (int) ($result['correct'] ?? 0), 'total_count' => (int) ($result['total'] ?? 0), 'percentage' => (float) ($result['percentage'] ?? 0), + 'points_before' => $pointsBefore, + 'points_after' => $pointsBefore, 'answers' => json_encode($result['items'] ?? [], JSON_UNESCAPED_UNICODE), 'created' => Factory::getDate()->toSql(), 'created_by' => $user ? (int) $user->id : 0, diff --git a/components/com_testquestions/src/View/Set/HtmlView.php b/components/com_testquestions/src/View/Set/HtmlView.php index 215a30a..b9aaf18 100644 --- a/components/com_testquestions/src/View/Set/HtmlView.php +++ b/components/com_testquestions/src/View/Set/HtmlView.php @@ -74,7 +74,11 @@ class HtmlView extends BaseHtmlView $correct++; } - $results[$item->id] = ['selected' => $selected, 'correct' => $isCorrect]; + $results[$item->id] = [ + 'selected' => $selected, + 'correct' => $isCorrect, + 'points' => (int) ($item->points ?? 0), + ]; } return [