From 301f322017618306b186e353e77380d45962ebb3 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Thu, 15 Oct 2026 21:39:34 +0200 Subject: [PATCH] Show percentages for original and corrected points --- README.md | 2 +- .../com_testquestions/sql/install.mysql.utf8mb4.sql | 1 + .../com_testquestions/sql/updates/mysql/1.29.0.sql | 6 ++++++ .../components/com_testquestions/tmpl/results/default.php | 5 ++++- com_testquestions.xml | 2 +- components/com_testquestions/src/Model/SetModel.php | 3 +++ components/com_testquestions/src/View/Set/HtmlView.php | 3 +++ 7 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 administrator/components/com_testquestions/sql/updates/mysql/1.29.0.sql diff --git a/README.md b/README.md index ef9ff54..7a0cea3 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.28.2). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.29.0). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql index 93122fc..2e29b11 100644 --- a/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql +++ b/administrator/components/com_testquestions/sql/install.mysql.utf8mb4.sql @@ -84,6 +84,7 @@ 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_total` int unsigned NOT NULL DEFAULT 0, `points_before` int unsigned NOT NULL DEFAULT 0, `points_after` int unsigned NOT NULL DEFAULT 0, `answers` longtext NULL, diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.29.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.29.0.sql new file mode 100644 index 0000000..eb56dbc --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.29.0.sql @@ -0,0 +1,6 @@ +ALTER TABLE `#__testquestions_results` + ADD COLUMN `points_total` int unsigned NOT NULL DEFAULT 0 AFTER `percentage`; + +UPDATE `#__testquestions_results` +SET `points_total` = `total_count` +WHERE `points_total` = 0; diff --git a/administrator/components/com_testquestions/tmpl/results/default.php b/administrator/components/com_testquestions/tmpl/results/default.php index dc3f52f..c9fc5c4 100644 --- a/administrator/components/com_testquestions/tmpl/results/default.php +++ b/administrator/components/com_testquestions/tmpl/results/default.php @@ -25,7 +25,10 @@ use Joomla\CMS\Router\Route; escape($item->participant_name); ?> escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?> - points_before; ?> / points_after; ?> + points_total ?: (int) $item->total_count; ?> + points_before / $pointsTotal) * 100, 2) : 0; ?> + points_after / $pointsTotal) * 100, 2) : 0; ?> + 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 7e637d1..1d103c6 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.28.2 + 1.29.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 652e6b0..76305dc 100644 --- a/components/com_testquestions/src/Model/SetModel.php +++ b/components/com_testquestions/src/Model/SetModel.php @@ -82,7 +82,9 @@ class SetModel extends BaseDatabaseModel } $pointsBefore = 0; + $pointsTotal = 0; foreach (($result['items'] ?? []) as $item) { + $pointsTotal += (int) ($item['points'] ?? 0); if (!empty($item['correct'])) { $pointsBefore += (int) ($item['points'] ?? 0); } @@ -97,6 +99,7 @@ class SetModel extends BaseDatabaseModel 'correct_count' => (int) ($result['correct'] ?? 0), 'total_count' => (int) ($result['total'] ?? 0), 'percentage' => (float) ($result['percentage'] ?? 0), + 'points_total' => $pointsTotal, 'points_before' => $pointsBefore, 'points_after' => $pointsBefore, 'answers' => json_encode($result['items'] ?? [], JSON_UNESCAPED_UNICODE), diff --git a/components/com_testquestions/src/View/Set/HtmlView.php b/components/com_testquestions/src/View/Set/HtmlView.php index b9aaf18..7aa058d 100644 --- a/components/com_testquestions/src/View/Set/HtmlView.php +++ b/components/com_testquestions/src/View/Set/HtmlView.php @@ -85,6 +85,9 @@ class HtmlView extends BaseHtmlView 'items' => $results, 'correct' => $correct, 'total' => count($items), + 'points_total' => array_sum(array_map(static function ($item) { + return (int) ($item->points ?? 0); + }, $items)), 'percentage' => count($items) ? round(($correct / count($items)) * 100, 2) : 0, ]; }