Fix set question saving and add previews

This commit is contained in:
Wojtek
2026-10-15 16:39:00 +02:00
parent 36e79f442e
commit d09360e587
6 changed files with 21 additions and 4 deletions
+1 -1
View File
@@ -23,6 +23,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.9.1). W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.9.2).
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
@@ -56,3 +56,4 @@ COM_TESTQUESTIONS_SET_SEARCH="Szukaj zestawów..."
COM_TESTQUESTIONS_SET_CATEGORY_FILTER="Filtruj pytania według kategorii" COM_TESTQUESTIONS_SET_CATEGORY_FILTER="Filtruj pytania według kategorii"
COM_TESTQUESTIONS_SET_ALL_CATEGORIES="Wszystkie kategorie" COM_TESTQUESTIONS_SET_ALL_CATEGORIES="Wszystkie kategorie"
COM_TESTQUESTIONS_UNCATEGORIZED="Bez kategorii" COM_TESTQUESTIONS_UNCATEGORIZED="Bez kategorii"
COM_TESTQUESTIONS_SET_SHOW_DETAILS="Pokaż pytanie i odpowiedzi"
@@ -0,0 +1 @@
-- No database changes required for version 1.9.2.
@@ -50,7 +50,7 @@ class SetModel extends AdminModel
return $db->setQuery( return $db->setQuery(
$db->getQuery(true) $db->getQuery(true)
->select(['q.id', 'q.question', 'q.category_id', 'c.title AS category_title']) ->select(['q.id', 'q.question', 'q.question_type', 'q.answer_a', 'q.answer_b', 'q.answer_c', 'q.answer_d', 'q.answer_open', 'q.correct_answer', 'q.category_id', 'c.title AS category_title'])
->from($db->quoteName('#__testquestions_questions', 'q')) ->from($db->quoteName('#__testquestions_questions', 'q'))
->leftJoin($db->quoteName('#__testquestions_categories', 'c') . ' ON c.id = q.category_id') ->leftJoin($db->quoteName('#__testquestions_categories', 'c') . ' ON c.id = q.category_id')
->order('c.title ASC, q.ordering ASC, q.id ASC') ->order('c.title ASC, q.ordering ASC, q.id ASC')
@@ -71,7 +71,8 @@ class SetModel extends AdminModel
public function save($data) public function save($data)
{ {
$questionIds = array_values(array_unique(array_filter(array_map('intval', (array) ($data['question_ids'] ?? []))))); $formData = Factory::getApplication()->getInput()->post->get('jform', [], 'array');
$questionIds = array_values(array_unique(array_filter(array_map('intval', (array) ($formData['question_ids'] ?? $data['question_ids'] ?? [])))));
unset($data['question_ids']); unset($data['question_ids']);
if (!parent::save($data)) { if (!parent::save($data)) {
@@ -31,6 +31,20 @@ HTMLHelper::_('behavior.formvalidator');
<span class="badge bg-secondary"><?php echo $this->escape($question->category_title ?: \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_UNCATEGORIZED')); ?></span> <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))); ?> <?php echo $this->escape(trim(strip_tags($question->question))); ?>
</label> </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">
<div class="mb-2"><?php echo $question->question; ?></div>
<?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><strong>A:</strong> <?php echo $question->answer_a; ?><?php echo (int) $question->correct_answer === 1 ? ' ✓' : ''; ?></div>
<div><strong>B:</strong> <?php echo $question->answer_b; ?><?php echo (int) $question->correct_answer === 2 ? ' ✓' : ''; ?></div>
<div><strong>C:</strong> <?php echo $question->answer_c; ?><?php echo (int) $question->correct_answer === 3 ? ' ✓' : ''; ?></div>
<div><strong>D:</strong> <?php echo $question->answer_d; ?><?php echo (int) $question->correct_answer === 4 ? ' ✓' : ''; ?></div>
<?php endif; ?>
</div>
</details>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</div> </div>
+1 -1
View File
@@ -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.9.1</version> <version>1.9.2</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>