Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
032ffeb9da | ||
|
|
8e62165a1a | ||
|
|
1c1720e1e1 | ||
|
|
1da3149e2f | ||
|
|
ba9e236e83 |
@@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych.
|
|||||||
|
|
||||||
## Instalacja
|
## Instalacja
|
||||||
|
|
||||||
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.21).
|
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.26).
|
||||||
|
|
||||||
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||||
|
|||||||
@@ -139,6 +139,8 @@ COM_TESTQUESTIONS_RESULTS_TEST_NAME="Nazwa testu"
|
|||||||
COM_TESTQUESTIONS_RESULTS_ALL_TESTS="Wszystkie zestawy"
|
COM_TESTQUESTIONS_RESULTS_ALL_TESTS="Wszystkie zestawy"
|
||||||
COM_TESTQUESTIONS_RESULTS_DATE_FROM="Data od"
|
COM_TESTQUESTIONS_RESULTS_DATE_FROM="Data od"
|
||||||
COM_TESTQUESTIONS_RESULTS_DATE_TO="Data do"
|
COM_TESTQUESTIONS_RESULTS_DATE_TO="Data do"
|
||||||
|
COM_TESTQUESTIONS_RESULTS_DELETED="Usunięto %s zapisanych testów."
|
||||||
|
COM_TESTQUESTIONS_RESULTS_DELETE_NONE="Zaznacz testy, które chcesz usunąć."
|
||||||
COM_TESTQUESTIONS_YOUR_ANSWER="Twoja odpowiedź"
|
COM_TESTQUESTIONS_YOUR_ANSWER="Twoja odpowiedź"
|
||||||
COM_TESTQUESTIONS_SELECTED_ANSWER="Zaznaczona odpowiedź"
|
COM_TESTQUESTIONS_SELECTED_ANSWER="Zaznaczona odpowiedź"
|
||||||
COM_TESTQUESTIONS_ANSWER_CORRECT="Poprawna odpowiedź"
|
COM_TESTQUESTIONS_ANSWER_CORRECT="Poprawna odpowiedź"
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Wydanie 1.43.22: kolejność odpowiedzi zamkniętych jest losowana i zapisywana dla podejścia.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Wydanie 1.43.23: zachowano w wyniku kolejność pytań z wylosowanego testu.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Wydanie 1.43.24: ukryto ocenę AI i korektę punktów dla pustych odpowiedzi.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Wydanie 1.43.25: kolor oceny AI odzwierciedla poziom uznanych punktów.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Wydanie 1.43.26: dodano zbiorcze usuwanie zapisanych testów.
|
||||||
@@ -0,0 +1,54 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
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 ResultsController extends AdminController
|
||||||
|
{
|
||||||
|
public function delete()
|
||||||
|
{
|
||||||
|
if (!Session::checkToken()) {
|
||||||
|
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||||
|
}
|
||||||
|
|
||||||
|
$user = Factory::getApplication()->getIdentity();
|
||||||
|
if (!$user->authorise('core.delete', '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')
|
||||||
|
), static function ($id) {
|
||||||
|
return $id > 0;
|
||||||
|
})));
|
||||||
|
|
||||||
|
if (!$ids) {
|
||||||
|
$this->setRedirect(
|
||||||
|
Route::_('index.php?option=com_testquestions&view=results', false),
|
||||||
|
Text::_('COM_TESTQUESTIONS_RESULTS_DELETE_NONE'),
|
||||||
|
'warning'
|
||||||
|
);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||||
|
$db->setQuery(
|
||||||
|
$db->getQuery(true)
|
||||||
|
->delete($db->quoteName('#__testquestions_results'))
|
||||||
|
->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')')
|
||||||
|
)->execute();
|
||||||
|
|
||||||
|
$this->setRedirect(
|
||||||
|
Route::_('index.php?option=com_testquestions&view=results', false),
|
||||||
|
Text::sprintf('COM_TESTQUESTIONS_RESULTS_DELETED', $db->getAffectedRows())
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -202,7 +202,7 @@ class ResultModel extends BaseDatabaseModel
|
|||||||
$questionIds = [];
|
$questionIds = [];
|
||||||
foreach ($item->answers as $questionId => $answer) {
|
foreach ($item->answers as $questionId => $answer) {
|
||||||
$question = $item->questions[(int) $questionId] ?? null;
|
$question = $item->questions[(int) $questionId] ?? null;
|
||||||
if ($question && $question->question_type === 'open' && empty($answer['correct'])) {
|
if ($question && $question->question_type === 'open' && empty($answer['correct']) && trim((string) ($answer['selected'] ?? '')) !== '') {
|
||||||
$questionIds[] = (int) $questionId;
|
$questionIds[] = (int) $questionId;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ use Joomla\CMS\HTML\HTMLHelper;
|
|||||||
use Joomla\CMS\Language\Text;
|
use Joomla\CMS\Language\Text;
|
||||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||||
|
use Joomla\CMS\Factory;
|
||||||
|
|
||||||
class HtmlView extends BaseHtmlView
|
class HtmlView extends BaseHtmlView
|
||||||
{
|
{
|
||||||
@@ -25,6 +26,9 @@ class HtmlView extends BaseHtmlView
|
|||||||
$this->sets = $this->get('Sets');
|
$this->sets = $this->get('Sets');
|
||||||
$this->aiUsageTotals = $this->get('AiUsageTotals');
|
$this->aiUsageTotals = $this->get('AiUsageTotals');
|
||||||
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS'));
|
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS'));
|
||||||
|
if (Factory::getApplication()->getIdentity()->authorise('core.delete', 'com_testquestions')) {
|
||||||
|
ToolbarHelper::deleteList('', 'results.delete', 'JTOOLBAR_DELETE');
|
||||||
|
}
|
||||||
ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back');
|
ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back');
|
||||||
|
|
||||||
return parent::display($tpl);
|
return parent::display($tpl);
|
||||||
|
|||||||
@@ -41,7 +41,7 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<?php $pendingAiCount = 0; ?>
|
<?php $pendingAiCount = 0; ?>
|
||||||
<?php foreach ($this->item->answers as $questionId => $answer) : ?>
|
<?php foreach ($this->item->answers as $questionId => $answer) : ?>
|
||||||
<?php $candidate = $this->item->questions[(int) $questionId] ?? null; ?>
|
<?php $candidate = $this->item->questions[(int) $questionId] ?? null; ?>
|
||||||
<?php if ($candidate && $candidate->question_type === 'open' && empty($answer['correct'])) { $pendingAiCount++; } ?>
|
<?php if ($candidate && $candidate->question_type === 'open' && empty($answer['correct']) && trim((string) ($answer['selected'] ?? '')) !== '') { $pendingAiCount++; } ?>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
<?php if ($pendingAiCount > 0) : ?>
|
<?php if ($pendingAiCount > 0) : ?>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
@@ -72,6 +72,7 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<h2><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_ANSWERS'); ?></h2>
|
<h2><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_ANSWERS'); ?></h2>
|
||||||
<?php foreach ($this->item->answers as $questionId => $answer) : ?>
|
<?php foreach ($this->item->answers as $questionId => $answer) : ?>
|
||||||
<?php $question = $this->item->questions[(int) $questionId] ?? null; if (!$question) continue; ?>
|
<?php $question = $this->item->questions[(int) $questionId] ?? null; if (!$question) continue; ?>
|
||||||
|
<?php $hasResponse = trim((string) ($answer['selected'] ?? '')) !== ''; ?>
|
||||||
<article class="mb-4 border rounded p-3">
|
<article class="mb-4 border rounded p-3">
|
||||||
<div class="mb-2"><?php echo $question->question; ?></div>
|
<div class="mb-2"><?php echo $question->question; ?></div>
|
||||||
<?php if (!empty($question->image)) : ?><div class="mb-3"><img src="<?php echo htmlspecialchars($resolveImageUrl($question->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy" style="max-width: 100%; height: auto;"></div><?php endif; ?>
|
<?php if (!empty($question->image)) : ?><div class="mb-3"><img src="<?php echo htmlspecialchars($resolveImageUrl($question->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy" style="max-width: 100%; height: auto;"></div><?php endif; ?>
|
||||||
@@ -83,7 +84,7 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="mt-2 <?php echo !empty($answer['correct']) ? 'text-success' : 'text-danger'; ?>"><?php echo !empty($answer['correct']) ? '✓ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_CORRECT') : '✗ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_INCORRECT'); ?></div>
|
<div class="mt-2 <?php echo !empty($answer['correct']) ? 'text-success' : 'text-danger'; ?>"><?php echo !empty($answer['correct']) ? '✓ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_CORRECT') : '✗ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_INCORRECT'); ?></div>
|
||||||
<?php if (empty($answer['correct'])) : ?>
|
<?php if (empty($answer['correct'])) : ?>
|
||||||
<?php if ($question->question_type === 'open') : ?>
|
<?php if ($question->question_type === 'open' && $hasResponse) : ?>
|
||||||
<div class="mt-3">
|
<div class="mt-3">
|
||||||
<button type="submit" name="ai_question_id" value="<?php echo (int) $questionId; ?>" onclick="this.form.task.value='result.ai';" formaction="<?php echo Route::_('index.php?option=com_testquestions&task=result.ai&id=' . (int) $this->item->id); ?>" class="btn btn-outline-primary">
|
<button type="submit" name="ai_question_id" value="<?php echo (int) $questionId; ?>" onclick="this.form.task.value='result.ai';" formaction="<?php echo Route::_('index.php?option=com_testquestions&task=result.ai&id=' . (int) $this->item->id); ?>" class="btn btn-outline-primary">
|
||||||
<?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_EVALUATE'); ?>
|
<?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_EVALUATE'); ?>
|
||||||
@@ -101,10 +102,15 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php if (!empty($answer['ai_feedback'])) : ?>
|
<?php if (!empty($answer['ai_feedback'])) : ?>
|
||||||
<div class="alert alert-info mt-3"><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_RESULT'); ?>:</strong><br><?php echo nl2br(htmlspecialchars((string) $answer['ai_feedback'], ENT_QUOTES, 'UTF-8')); ?></div>
|
<?php
|
||||||
|
$aiPoints = (int) ($answer['awarded_points'] ?? 0);
|
||||||
|
$maxPoints = (int) ($question->points ?? 0);
|
||||||
|
$aiAlertClass = $aiPoints <= 0 ? 'alert-danger' : ($aiPoints >= $maxPoints ? 'alert-success' : 'alert-info');
|
||||||
|
?>
|
||||||
|
<div class="alert <?php echo $aiAlertClass; ?> mt-3"><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_RESULT'); ?>:</strong><br><?php echo nl2br(htmlspecialchars((string) $answer['ai_feedback'], ENT_QUOTES, 'UTF-8')); ?></div>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ($question->question_type === 'open') : ?>
|
<?php if ($question->question_type === 'open' && $hasResponse) : ?>
|
||||||
<div class="row mt-3">
|
<div class="row mt-3">
|
||||||
<div class="col-md-3">
|
<div class="col-md-3">
|
||||||
<label for="awarded-points-<?php echo (int) $questionId; ?>" class="form-label"><?php echo \Joomla\CMS\Language\Text::sprintf('COM_TESTQUESTIONS_RESULT_AWARDED_POINTS', (int) ($question->points ?? 0)); ?></label>
|
<label for="awarded-points-<?php echo (int) $questionId; ?>" class="form-label"><?php echo \Joomla\CMS\Language\Text::sprintf('COM_TESTQUESTIONS_RESULT_AWARDED_POINTS', (int) ($question->points ?? 0)); ?></label>
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ defined('_JEXEC') or die;
|
|||||||
|
|
||||||
use Joomla\CMS\HTML\HTMLHelper;
|
use Joomla\CMS\HTML\HTMLHelper;
|
||||||
use Joomla\CMS\Router\Route;
|
use Joomla\CMS\Router\Route;
|
||||||
|
HTMLHelper::_('behavior.multiselect');
|
||||||
?>
|
?>
|
||||||
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=results'); ?>" method="post" name="adminForm" id="adminForm">
|
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=results'); ?>" method="post" name="adminForm" id="adminForm">
|
||||||
<div class="row mb-3">
|
<div class="row mb-3">
|
||||||
@@ -53,6 +54,7 @@ use Joomla\CMS\Router\Route;
|
|||||||
</div>
|
</div>
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead><tr>
|
<thead><tr>
|
||||||
|
<th class="w-1"><?php echo HTMLHelper::_('grid.checkall'); ?></th>
|
||||||
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_PARTICIPANT'); ?></th>
|
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_PARTICIPANT'); ?></th>
|
||||||
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TITLE'); ?></th>
|
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TITLE'); ?></th>
|
||||||
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></th>
|
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></th>
|
||||||
@@ -62,8 +64,9 @@ use Joomla\CMS\Router\Route;
|
|||||||
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_AI_TOKENS'); ?></th>
|
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_AI_TOKENS'); ?></th>
|
||||||
</tr></thead>
|
</tr></thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<?php foreach ($this->items as $item) : ?>
|
<?php foreach ($this->items as $i => $item) : ?>
|
||||||
<tr class="<?php echo (int) $item->extra_time > 0 ? 'table-warning' : ''; ?>">
|
<tr class="<?php echo (int) $item->extra_time > 0 ? 'table-warning' : ''; ?>">
|
||||||
|
<td><?php echo HTMLHelper::_('grid.id', $i, $item->id); ?></td>
|
||||||
<th><a href="<?php echo Route::_('index.php?option=com_testquestions&view=result&id=' . (int) $item->id); ?>"><?php echo $this->escape($item->participant_name); ?></a></th>
|
<th><a href="<?php echo Route::_('index.php?option=com_testquestions&view=result&id=' . (int) $item->id); ?>"><?php echo $this->escape($item->participant_name); ?></a></th>
|
||||||
<td><?php echo $this->escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?></td>
|
<td><?php echo $this->escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?></td>
|
||||||
<?php $pointsTotal = (int) $item->points_total ?: (int) $item->total_count; ?>
|
<?php $pointsTotal = (int) $item->points_total ?: (int) $item->total_count; ?>
|
||||||
@@ -96,6 +99,7 @@ use Joomla\CMS\Router\Route;
|
|||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
<?php echo $this->pagination->getListFooter(); ?>
|
<?php echo $this->pagination->getListFooter(); ?>
|
||||||
|
<input type="hidden" name="boxchecked" value="0">
|
||||||
<input type="hidden" name="task" value="">
|
<input type="hidden" name="task" value="">
|
||||||
<?php echo HTMLHelper::_('form.token'); ?>
|
<?php echo HTMLHelper::_('form.token'); ?>
|
||||||
</form>
|
</form>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
<creationDate>2026-10-14</creationDate>
|
<creationDate>2026-10-14</creationDate>
|
||||||
<author>Komponent</author>
|
<author>Komponent</author>
|
||||||
<license>GNU General Public License version 2 or later</license>
|
<license>GNU General Public License version 2 or later</license>
|
||||||
<version>1.43.21</version>
|
<version>1.43.26</version>
|
||||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||||
<element>com_testquestions</element>
|
<element>com_testquestions</element>
|
||||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||||
|
|||||||
@@ -25,6 +25,26 @@ class HtmlView extends BaseHtmlView
|
|||||||
$this->items = $this->get('Items');
|
$this->items = $this->get('Items');
|
||||||
$this->sets = $this->get('Sets');
|
$this->sets = $this->get('Sets');
|
||||||
$input = Factory::getApplication()->getInput();
|
$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'
|
$this->started = $input->getMethod() === 'POST'
|
||||||
&& $input->post->getString('participant_name', '') !== ''
|
&& $input->post->getString('participant_name', '') !== ''
|
||||||
&& $input->post->getInt('set_id', 0) > 0;
|
&& $input->post->getInt('set_id', 0) > 0;
|
||||||
@@ -51,6 +71,7 @@ class HtmlView extends BaseHtmlView
|
|||||||
}
|
}
|
||||||
|
|
||||||
$answers = (array) $input->post->get('answers', [], 'array');
|
$answers = (array) $input->post->get('answers', [], 'array');
|
||||||
|
$submittedAnswerOrder = (array) $input->post->get('answer_order', [], 'array');
|
||||||
$results = [];
|
$results = [];
|
||||||
$correct = 0;
|
$correct = 0;
|
||||||
|
|
||||||
@@ -70,6 +91,14 @@ class HtmlView extends BaseHtmlView
|
|||||||
$isCorrect = (string) $item->correct_answer === $selected;
|
$isCorrect = (string) $item->correct_answer === $selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$answerOrder = array_map('intval', explode(',', (string) ($submittedAnswerOrder[$item->id] ?? '')));
|
||||||
|
sort($answerOrder);
|
||||||
|
if ($item->question_type !== 'closed' || $answerOrder !== [1, 2, 3, 4]) {
|
||||||
|
$answerOrder = [1, 2, 3, 4];
|
||||||
|
} else {
|
||||||
|
$answerOrder = array_map('intval', explode(',', (string) $submittedAnswerOrder[$item->id]));
|
||||||
|
}
|
||||||
|
|
||||||
if ($isCorrect) {
|
if ($isCorrect) {
|
||||||
$correct++;
|
$correct++;
|
||||||
}
|
}
|
||||||
@@ -78,6 +107,7 @@ class HtmlView extends BaseHtmlView
|
|||||||
'selected' => $selected,
|
'selected' => $selected,
|
||||||
'correct' => $isCorrect,
|
'correct' => $isCorrect,
|
||||||
'points' => (int) ($item->points ?? 0),
|
'points' => (int) ($item->points ?? 0),
|
||||||
|
'answer_order' => $answerOrder,
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -84,7 +84,18 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<?php if ($this->items) : ?>
|
<?php if ($this->items) : ?>
|
||||||
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8'); ?>" method="post" id="test-form">
|
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI'], ENT_QUOTES, 'UTF-8'); ?>" method="post" id="test-form">
|
||||||
|
<?php if (!$this->results) : ?>
|
||||||
|
<?php foreach ($this->items as $item) : ?><input type="hidden" name="question_order[]" value="<?php echo (int) $item->id; ?>"><?php endforeach; ?>
|
||||||
|
<?php endif; ?>
|
||||||
<?php foreach ($this->items as $number => $item) : ?>
|
<?php foreach ($this->items as $number => $item) : ?>
|
||||||
|
<?php
|
||||||
|
$answerOrder = $this->results && !empty($this->results['items'][$item->id]['answer_order'])
|
||||||
|
? $this->results['items'][$item->id]['answer_order']
|
||||||
|
: [1, 2, 3, 4];
|
||||||
|
if (!$this->results && $item->question_type === 'closed') {
|
||||||
|
shuffle($answerOrder);
|
||||||
|
}
|
||||||
|
?>
|
||||||
<article class="testquestion mb-4">
|
<article class="testquestion mb-4">
|
||||||
<div class="pyt"><div class="question-header"><span class="question-number"><?php echo ($number + 1) . '.'; ?></span><div class="question-text"><?php echo $item->question; ?></div></div></div>
|
<div class="pyt"><div class="question-header"><span class="question-number"><?php echo ($number + 1) . '.'; ?></span><div class="question-text"><?php echo $item->question; ?></div></div></div>
|
||||||
<?php if ($item->image) : ?><div class="foto_pyt"><img src="<?php echo htmlspecialchars($resolveImageUrl($item->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy"></div><?php endif; ?>
|
<?php if ($item->image) : ?><div class="foto_pyt"><img src="<?php echo htmlspecialchars($resolveImageUrl($item->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy"></div><?php endif; ?>
|
||||||
@@ -99,12 +110,14 @@ $resolveImageUrl = static function ($path) {
|
|||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</div>
|
</div>
|
||||||
<?php else : ?>
|
<?php else : ?>
|
||||||
|
<?php if (!$this->results) : ?><input type="hidden" name="answer_order[<?php echo (int) $item->id; ?>]" value="<?php echo htmlspecialchars(implode(',', $answerOrder), ENT_QUOTES, 'UTF-8'); ?>"><?php endif; ?>
|
||||||
<ol type="A" class="answer-list">
|
<ol type="A" class="answer-list">
|
||||||
<?php foreach (['answer_a', 'answer_b', 'answer_c', 'answer_d'] as $answerIndex => $answerField) : ?>
|
<?php foreach ($answerOrder as $displayIndex => $optionValue) : ?>
|
||||||
<?php $isSelected = $this->results && $this->results['items'][$item->id]['selected'] === (string) ($answerIndex + 1); ?>
|
<?php $answerField = 'answer_' . chr(96 + (int) $optionValue); ?>
|
||||||
<?php $isCorrectAnswer = $this->results && (string) $item->correct_answer === (string) ($answerIndex + 1); ?>
|
<?php $isSelected = $this->results && $this->results['items'][$item->id]['selected'] === (string) $optionValue; ?>
|
||||||
|
<?php $isCorrectAnswer = $this->results && (string) $item->correct_answer === (string) $optionValue; ?>
|
||||||
<li class="<?php echo $isSelected && $this->results['items'][$item->id]['correct'] ? 'odpup' : ($isSelected ? 'odpu' : ($isCorrectAnswer ? 'odpp' : 'odp')); ?>">
|
<li class="<?php echo $isSelected && $this->results['items'][$item->id]['correct'] ? 'odpup' : ($isSelected ? 'odpu' : ($isCorrectAnswer ? 'odpp' : 'odp')); ?>">
|
||||||
<label><input type="radio" name="answers[<?php echo (int) $item->id; ?>]" value="<?php echo $answerIndex + 1; ?>" <?php echo $isSelected ? 'checked' : ''; ?>><strong><?php echo chr(65 + $answerIndex); ?>.</strong> <span class="answer-text"><?php echo $item->$answerField; ?></span></label>
|
<label><input type="radio" name="answers[<?php echo (int) $item->id; ?>]" value="<?php echo (int) $optionValue; ?>" <?php echo $isSelected ? 'checked' : ''; ?>><strong><?php echo chr(65 + $displayIndex); ?>.</strong> <span class="answer-text"><?php echo $item->$answerField; ?></span></label>
|
||||||
</li>
|
</li>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</ol>
|
</ol>
|
||||||
|
|||||||
Reference in New Issue
Block a user