149 lines
11 KiB
PHP
149 lines
11 KiB
PHP
<?php
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\HTML\HTMLHelper;
|
|
use Joomla\CMS\Router\Route;
|
|
|
|
HTMLHelper::_('behavior.formvalidator');
|
|
?>
|
|
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=set&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="adminForm" class="form-validate">
|
|
<fieldset class="adminform">
|
|
<?php echo $this->form->renderField('parent_id'); ?>
|
|
<?php if ((int) $this->item->parent_id > 0) : ?>
|
|
<div class="alert alert-info"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_PARENT'); ?>: <?php echo $this->escape($this->item->parent_title ?? ''); ?></div>
|
|
<input type="hidden" name="jform[set_type]" value="variant">
|
|
<?php else : ?>
|
|
<?php echo $this->form->renderField('set_type'); ?>
|
|
<?php endif; ?>
|
|
<?php echo $this->form->renderField('title'); ?>
|
|
<?php echo $this->form->renderField('subject_id'); ?>
|
|
<?php echo $this->form->renderField('duration'); ?>
|
|
<output id="set-duration-value" class="form-text mb-3"></output>
|
|
<?php echo $this->form->renderField('test_content'); ?>
|
|
<?php echo $this->form->renderField('image'); ?>
|
|
<?php echo $this->form->renderField('description'); ?>
|
|
<?php echo $this->form->renderField('published'); ?>
|
|
<?php if ((int) $this->item->id > 0 && (string) $this->item->set_type === 'multi') : ?>
|
|
<fieldset class="mb-3">
|
|
<legend><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_VARIANTS'); ?></legend>
|
|
<?php if ($this->variants) : ?>
|
|
<ul class="list-group mb-3">
|
|
<?php foreach ($this->variants as $variant) : ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<a href="<?php echo Route::_('index.php?option=com_testquestions&task=set.edit&id=' . (int) $variant->id); ?>"><?php echo $this->escape($variant->title); ?></a>
|
|
<span class="badge <?php echo (int) $variant->published ? 'bg-success' : 'bg-secondary'; ?>"><?php echo (int) $variant->published ? \Joomla\CMS\Language\Text::_('JPUBLISHED') : \Joomla\CMS\Language\Text::_('JUNPUBLISHED'); ?></span>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
<?php else : ?>
|
|
<p><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_NO_VARIANTS'); ?></p>
|
|
<?php endif; ?>
|
|
<a class="btn btn-secondary" href="<?php echo Route::_('index.php?option=com_testquestions&task=set.addvariant&parent_id=' . (int) $this->item->id); ?>">
|
|
<?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_ADD_VARIANT'); ?>
|
|
</a>
|
|
</fieldset>
|
|
<?php endif; ?>
|
|
<fieldset class="mb-3">
|
|
<legend><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_SELECTED_QUESTIONS'); ?></legend>
|
|
<div id="set-selected-question-list" class="border rounded p-3">
|
|
<?php foreach ($this->questions as $question) : ?>
|
|
<?php if (!in_array((int) $question->id, array_map('intval', (array) $this->item->question_ids), true)) continue; ?>
|
|
<div class="form-check set-question-row">
|
|
<input class="form-check-input" type="checkbox" name="jform[question_ids][]" value="<?php echo (int) $question->id; ?>" id="set-question-<?php echo (int) $question->id; ?>" checked>
|
|
<label class="form-check-label" for="set-question-<?php echo (int) $question->id; ?>">
|
|
<span class="badge bg-secondary"><?php echo $this->escape($question->category_title ?: \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_UNCATEGORIZED')); ?></span>
|
|
<?php echo $this->escape(trim(strip_tags($question->question))); ?>
|
|
</label>
|
|
<details class="ms-4 mt-1 mb-2">
|
|
<summary><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_SHOW_DETAILS'); ?></summary>
|
|
<div class="mt-2 p-2 bg-light border rounded">
|
|
<?php if ($question->question_type === 'open') : ?>
|
|
<div><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_FIELD_OPEN_PATTERN'); ?>:</strong> <?php echo $this->escape($question->answer_open); ?></div>
|
|
<?php else : ?>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">A:</strong><span><?php echo $question->answer_a; ?></span><?php if ((int) $question->correct_answer === 1) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">B:</strong><span><?php echo $question->answer_b; ?></span><?php if ((int) $question->correct_answer === 2) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">C:</strong><span><?php echo $question->answer_c; ?></span><?php if ((int) $question->correct_answer === 3) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">D:</strong><span><?php echo $question->answer_d; ?></span><?php if ((int) $question->correct_answer === 4) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</details>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</fieldset>
|
|
<fieldset class="mb-3">
|
|
<legend><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_AVAILABLE_QUESTIONS'); ?></legend>
|
|
<div class="mb-3">
|
|
<label for="set-question-category" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_CATEGORY_FILTER'); ?></label>
|
|
<select id="set-question-category" class="form-select">
|
|
<option value=""><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_ALL_CATEGORIES'); ?></option>
|
|
<?php foreach ($this->categories as $category) : ?>
|
|
<option value="<?php echo (int) $category->id; ?>"><?php echo $this->escape($category->title); ?></option>
|
|
<?php endforeach; ?>
|
|
</select>
|
|
</div>
|
|
<div id="set-available-question-list" class="border rounded p-3">
|
|
<?php foreach ($this->questions as $question) : ?>
|
|
<?php if (in_array((int) $question->id, array_map('intval', (array) $this->item->question_ids), true)) continue; ?>
|
|
<div class="form-check set-available-question-row" data-category="<?php echo (int) $question->category_id; ?>">
|
|
<input class="form-check-input" type="checkbox" name="jform[question_ids][]" value="<?php echo (int) $question->id; ?>" id="set-question-<?php echo (int) $question->id; ?>">
|
|
<label class="form-check-label" for="set-question-<?php echo (int) $question->id; ?>">
|
|
<span class="badge bg-secondary"><?php echo $this->escape($question->category_title ?: \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_UNCATEGORIZED')); ?></span>
|
|
<?php echo $this->escape(trim(strip_tags($question->question))); ?>
|
|
</label>
|
|
<details class="ms-4 mt-1 mb-2">
|
|
<summary><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_SHOW_DETAILS'); ?></summary>
|
|
<div class="mt-2 p-2 bg-light border rounded">
|
|
<?php if ($question->question_type === 'open') : ?>
|
|
<div><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_FIELD_OPEN_PATTERN'); ?>:</strong> <?php echo $this->escape($question->answer_open); ?></div>
|
|
<?php else : ?>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">A:</strong><span><?php echo $question->answer_a; ?></span><?php if ((int) $question->correct_answer === 1) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">B:</strong><span><?php echo $question->answer_b; ?></span><?php if ((int) $question->correct_answer === 2) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">C:</strong><span><?php echo $question->answer_c; ?></span><?php if ((int) $question->correct_answer === 3) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<div class="d-flex gap-2 align-items-start"><strong class="flex-shrink-0">D:</strong><span><?php echo $question->answer_d; ?></span><?php if ((int) $question->correct_answer === 4) : ?><span class="text-success flex-shrink-0">✓</span><?php endif; ?></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</details>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
</div>
|
|
</fieldset>
|
|
</fieldset>
|
|
<input type="hidden" name="task" value="">
|
|
<?php echo HTMLHelper::_('form.token'); ?>
|
|
</form>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const filter = document.getElementById('set-question-category');
|
|
const rows = document.querySelectorAll('.set-available-question-row');
|
|
|
|
if (!filter) {
|
|
return;
|
|
}
|
|
|
|
filter.addEventListener('change', function () {
|
|
rows.forEach(function (row) {
|
|
row.classList.toggle('d-none', filter.value !== '' && row.dataset.category !== filter.value);
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function () {
|
|
const duration = document.getElementById('jform_duration');
|
|
const output = document.getElementById('set-duration-value');
|
|
|
|
if (!duration || !output) {
|
|
return;
|
|
}
|
|
|
|
const updateDuration = function () {
|
|
output.textContent = duration.value + ' min';
|
|
};
|
|
|
|
duration.addEventListener('input', updateDuration);
|
|
updateDuration();
|
|
});
|
|
</script>
|