From 1da3149e2f7f8246b3670c22aa3bfa17e9bc2fee Mon Sep 17 00:00:00 2001 From: Wojtek Date: Fri, 16 Oct 2026 21:31:59 +0200 Subject: [PATCH] Preserve randomized question order in test results --- README.md | 2 +- .../sql/updates/mysql/1.43.23.sql | 1 + com_testquestions.xml | 2 +- .../src/View/Set/HtmlView.php | 20 +++++++++++++++++++ .../com_testquestions/tmpl/set/default.php | 3 +++ 5 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 administrator/components/com_testquestions/sql/updates/mysql/1.43.23.sql diff --git a/README.md b/README.md index f75c8ad..f8b1bfa 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.22). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.23). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.43.23.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.23.sql new file mode 100644 index 0000000..69a8745 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.23.sql @@ -0,0 +1 @@ +-- Wydanie 1.43.23: zachowano w wyniku kolejność pytań z wylosowanego testu. diff --git a/com_testquestions.xml b/com_testquestions.xml index 9a441e5..a0ca1f7 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.22 + 1.43.23 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions diff --git a/components/com_testquestions/src/View/Set/HtmlView.php b/components/com_testquestions/src/View/Set/HtmlView.php index 1fd5c40..7a516b6 100644 --- a/components/com_testquestions/src/View/Set/HtmlView.php +++ b/components/com_testquestions/src/View/Set/HtmlView.php @@ -25,6 +25,26 @@ class HtmlView extends BaseHtmlView $this->items = $this->get('Items'); $this->sets = $this->get('Sets'); $input = Factory::getApplication()->getInput(); + if ($input->getCmd('task') === 'check' && $input->getMethod() === 'POST' && $this->items) { + $submittedQuestionOrder = array_map('intval', (array) $input->post->get('question_order', [], 'array')); + $expectedQuestionIds = array_map(static function ($item) { + return (int) $item->id; + }, $this->items); + $sortedSubmittedOrder = $submittedQuestionOrder; + $sortedExpectedIds = $expectedQuestionIds; + sort($sortedSubmittedOrder); + sort($sortedExpectedIds); + + if ($sortedSubmittedOrder === $sortedExpectedIds) { + $itemsById = []; + foreach ($this->items as $item) { + $itemsById[(int) $item->id] = $item; + } + $this->items = array_values(array_map(static function ($questionId) use ($itemsById) { + return $itemsById[$questionId]; + }, $submittedQuestionOrder)); + } + } $this->started = $input->getMethod() === 'POST' && $input->post->getString('participant_name', '') !== '' && $input->post->getInt('set_id', 0) > 0; diff --git a/components/com_testquestions/tmpl/set/default.php b/components/com_testquestions/tmpl/set/default.php index 5fb7395..dc20f9d 100644 --- a/components/com_testquestions/tmpl/set/default.php +++ b/components/com_testquestions/tmpl/set/default.php @@ -84,6 +84,9 @@ $resolveImageUrl = static function ($path) { items) : ?>
+ results) : ?> + items as $item) : ?> + items as $number => $item) : ?> results && !empty($this->results['items'][$item->id]['answer_order'])