Use question times when test duration is unset
This commit is contained in:
@@ -77,7 +77,7 @@ class SetModel extends BaseDatabaseModel
|
||||
}
|
||||
|
||||
$query = $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.points', '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', 'q.time_limit'])
|
||||
->from($db->quoteName('#__testquestions_set_questions', 'sq'))
|
||||
->innerJoin($db->quoteName('#__testquestions_questions', 'q') . ' ON q.id = sq.question_id')
|
||||
->where('sq.set_id = ' . $setId)
|
||||
|
||||
@@ -5,6 +5,8 @@ defined('_JEXEC') or die;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Uri\Uri;
|
||||
|
||||
$testDurationSeconds = 0;
|
||||
|
||||
$resolveImageUrl = static function ($path) {
|
||||
$path = trim((string) $path);
|
||||
|
||||
@@ -50,16 +52,26 @@ $resolveImageUrl = static function ($path) {
|
||||
<?php elseif (!$this->set) : ?>
|
||||
<div class="alert alert-info"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_NOT_FOUND'); ?></div>
|
||||
<?php else : ?>
|
||||
<?php
|
||||
$extraTime = Factory::getApplication()->getInput()->post->getInt('extra_time', 0);
|
||||
$baseDurationSeconds = (int) $this->set->duration > 0
|
||||
? (int) $this->set->duration * 60
|
||||
: array_sum(array_map(static function ($item) {
|
||||
return max(0, (int) ($item->time_limit ?? 0));
|
||||
}, $this->items));
|
||||
$testDurationSeconds = $baseDurationSeconds + ($extraTime * 60);
|
||||
$durationMinutes = intdiv($testDurationSeconds, 60);
|
||||
$durationRemainder = $testDurationSeconds % 60;
|
||||
?>
|
||||
<header class="test-set-header">
|
||||
<?php if ($this->set->subject_title) : ?><div class="text-muted"><?php echo htmlspecialchars($this->set->subject_title, ENT_QUOTES, 'UTF-8'); ?></div><?php endif; ?>
|
||||
<h1><?php echo htmlspecialchars($this->set->title, ENT_QUOTES, 'UTF-8'); ?></h1>
|
||||
<?php $extraTime = Factory::getApplication()->getInput()->post->getInt('extra_time', 0); ?>
|
||||
<?php if ((int) $this->set->duration > 0) : ?><div class="small text-muted"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_DURATION'); ?>: <?php echo (int) $this->set->duration + $extraTime; ?> min</div><?php endif; ?>
|
||||
<?php if ($testDurationSeconds > 0) : ?><div class="small text-muted"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_DURATION'); ?>: <?php echo $durationMinutes; ?> min<?php if ($durationRemainder > 0) : ?> <?php echo $durationRemainder; ?> s<?php endif; ?></div><?php endif; ?>
|
||||
<?php if ($this->set->image) : ?><div class="foto_pyt"><img src="<?php echo htmlspecialchars($resolveImageUrl($this->set->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy"></div><?php endif; ?>
|
||||
<?php if ($this->set->test_content) : ?><div class="test-set-content"><?php echo $this->set->test_content; ?></div><?php endif; ?>
|
||||
</header>
|
||||
<?php if (!$this->results && ((int) $this->set->duration + $extraTime) > 0) : ?>
|
||||
<div class="timer-container mb-4" id="test-timer-container" data-duration="<?php echo ((int) $this->set->duration + $extraTime) * 60; ?>" aria-live="polite">
|
||||
<?php if (!$this->results && $testDurationSeconds > 0) : ?>
|
||||
<div class="timer-container mb-4" id="test-timer-container" data-duration="<?php echo $testDurationSeconds; ?>" aria-live="polite">
|
||||
<svg width="120" height="120" viewBox="0 0 120 120" aria-hidden="true">
|
||||
<circle cx="60" cy="60" r="54" fill="none" stroke="#dfe3e7" stroke-width="8"></circle>
|
||||
<circle id="test-timer-ring" class="progress-ring__circle" cx="60" cy="60" r="54" fill="none" stroke="#4a86cf" stroke-width="8" stroke-linecap="round"></circle>
|
||||
@@ -118,7 +130,7 @@ $resolveImageUrl = static function ($path) {
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php if ($this->started && !$this->results && ((int) $this->set->duration + $extraTime) > 0) : ?>
|
||||
<?php if ($this->started && !$this->results && $testDurationSeconds > 0) : ?>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const container = document.getElementById('test-timer-container');
|
||||
|
||||
Reference in New Issue
Block a user