Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7f4f86080a | ||
|
|
9e940c5710 | ||
|
|
62befb825e | ||
|
|
804c8f5467 | ||
|
|
53dd9658e8 | ||
|
|
5e12e8838d | ||
|
|
96e8a4a0f5 | ||
|
|
3ee0b22d75 |
@@ -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.37.3).
|
||||
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.3).
|
||||
|
||||
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<config>
|
||||
<fields name="params">
|
||||
<fieldset name="basic" label="COM_TESTQUESTIONS_AI_SETTINGS">
|
||||
<field name="ai_provider" type="list" label="COM_TESTQUESTIONS_AI_PROVIDER">
|
||||
<option value="openai">OpenAI</option>
|
||||
<option value="grok">Grok</option>
|
||||
</field>
|
||||
<field name="ai_api_key" type="password" label="COM_TESTQUESTIONS_AI_API_KEY" filter="raw" autocomplete="off" />
|
||||
</fieldset>
|
||||
</fields>
|
||||
</config>
|
||||
@@ -58,8 +58,18 @@ COM_TESTQUESTIONS_SET_ADD_VARIANT="Dodaj wariant"
|
||||
COM_TESTQUESTIONS_SET_PARENT="Zestaw nadrzędny"
|
||||
COM_TESTQUESTIONS_SET_NO_VARIANTS="Brak wariantów"
|
||||
COM_TESTQUESTIONS_SET_MULTI_QUESTIONS_INFO="Pytania są dodawane w poszczególnych wariantach zestawu."
|
||||
COM_TESTQUESTIONS_SET_REORDER_INFO="Przeciągnij pytania, aby zmienić ich kolejność."
|
||||
COM_TESTQUESTIONS_SET_SAVE="Zapisz"
|
||||
COM_TESTQUESTIONS_SET_SAVE_AND_CLOSE="Zapisz i zamknij"
|
||||
COM_TESTQUESTIONS_SET_VARIANT_DURATION_INFO="Czas testu jest pobierany z zestawu nadrzędnego."
|
||||
COM_TESTQUESTIONS_AI_SETTINGS="Ustawienia AI"
|
||||
COM_TESTQUESTIONS_AI_PROVIDER="Dostawca AI"
|
||||
COM_TESTQUESTIONS_AI_API_KEY="Klucz API"
|
||||
COM_TESTQUESTIONS_AI_SETTINGS_MENU="Konfiguracja AI"
|
||||
COM_TESTQUESTIONS_AI_EVALUATE="AI"
|
||||
COM_TESTQUESTIONS_AI_RESULT="Ocena AI"
|
||||
COM_TESTQUESTIONS_AI_NOT_CONFIGURED="Skonfiguruj dostawcę i klucz API w ustawieniach komponentu."
|
||||
COM_TESTQUESTIONS_AI_ERROR="Nie udało się uzyskać odpowiedzi AI: %s"
|
||||
COM_TESTQUESTIONS_SET_DESCRIPTION="Opis zestawu"
|
||||
COM_TESTQUESTIONS_SET_QUESTIONS="Pytania w zestawie"
|
||||
COM_TESTQUESTIONS_SET_QUESTION_COUNT="Liczba pytań"
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.38.0.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.39.0.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.40.0.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.41.0.
|
||||
@@ -0,0 +1 @@
|
||||
-- AI feedback is stored in the existing answers JSON column.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.1.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.2.
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.3.
|
||||
@@ -32,6 +32,34 @@ class ResultController extends BaseController
|
||||
);
|
||||
}
|
||||
|
||||
public function ai(): void
|
||||
{
|
||||
if (!Session::checkToken()) {
|
||||
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
}
|
||||
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$id = $input->post->getInt('id');
|
||||
$questionId = $input->post->getInt('ai_question_id');
|
||||
$message = Text::_('COM_TESTQUESTIONS_AI_RESULT');
|
||||
$type = 'message';
|
||||
|
||||
try {
|
||||
$this->getModel('Result')->evaluateWithAi($id, $questionId);
|
||||
} catch (\Throwable $error) {
|
||||
$message = $error->getMessage() === 'AI_NOT_CONFIGURED'
|
||||
? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED')
|
||||
: Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $error->getMessage());
|
||||
$type = 'error';
|
||||
}
|
||||
|
||||
$this->setRedirect(
|
||||
Route::_('index.php?option=com_testquestions&view=result&id=' . $id, false),
|
||||
$message,
|
||||
$type
|
||||
);
|
||||
}
|
||||
|
||||
private function saveAssessment(): void
|
||||
{
|
||||
if (!Session::checkToken()) {
|
||||
|
||||
@@ -6,6 +6,8 @@ defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
use Joomla\CMS\Component\ComponentHelper;
|
||||
use Komponent\Component\Testquestions\Administrator\Service\AiService;
|
||||
|
||||
class ResultModel extends BaseDatabaseModel
|
||||
{
|
||||
@@ -72,4 +74,71 @@ class ResultModel extends BaseDatabaseModel
|
||||
|
||||
return (bool) $db->updateObject('#__testquestions_results', $row, 'id');
|
||||
}
|
||||
|
||||
public function evaluateWithAi(int $id, int $questionId): string
|
||||
{
|
||||
$item = $this->getItem($id);
|
||||
|
||||
if (!$item) {
|
||||
throw new \RuntimeException('Nie znaleziono zapisanego testu.');
|
||||
}
|
||||
|
||||
$answer = $item->answers[$questionId] ?? null;
|
||||
$question = $item->questions[$questionId] ?? null;
|
||||
|
||||
if (!$item || !$answer || !$question || $question->question_type !== 'open' || !empty($answer['correct'])) {
|
||||
throw new \RuntimeException('Nieprawidłowe pytanie do oceny AI.');
|
||||
}
|
||||
|
||||
$params = ComponentHelper::getParams('com_testquestions');
|
||||
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
||||
$apiKey = trim((string) $params->get('ai_api_key', ''));
|
||||
|
||||
// Odczytaj zapisane parametry bezpośrednio z bazy. Dzięki temu nie użyjemy
|
||||
// nieaktualnej wartości z pamięci ComponentHelper, a maska pola hasła
|
||||
// (np. ********) nie zostanie potraktowana jako prawdziwy klucz.
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$storedParams = (string) $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select($db->quoteName('params'))
|
||||
->from($db->quoteName('#__extensions'))
|
||||
->where($db->quoteName('type') . ' = ' . $db->quote('component'))
|
||||
->where($db->quoteName('element') . ' = ' . $db->quote('com_testquestions'))
|
||||
)->loadResult();
|
||||
$storedParams = json_decode($storedParams, true);
|
||||
|
||||
if (is_array($storedParams)) {
|
||||
$storedProvider = trim((string) ($storedParams['ai_provider'] ?? ''));
|
||||
$storedApiKey = trim((string) ($storedParams['ai_api_key'] ?? ''));
|
||||
|
||||
if ($storedProvider !== '') {
|
||||
$provider = $storedProvider;
|
||||
}
|
||||
|
||||
if ($storedApiKey !== '' && !preg_match('/^\*+$/', $storedApiKey)) {
|
||||
$apiKey = $storedApiKey;
|
||||
}
|
||||
}
|
||||
|
||||
$feedback = (new AiService())->evaluate(
|
||||
$provider,
|
||||
$apiKey,
|
||||
strip_tags((string) $question->question),
|
||||
(string) ($answer['selected'] ?? ''),
|
||||
(string) $question->answer_open
|
||||
);
|
||||
$item->answers[$questionId]['ai_feedback'] = $feedback;
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$row = (object) [
|
||||
'id' => $id,
|
||||
'answers' => json_encode($item->answers, JSON_UNESCAPED_UNICODE),
|
||||
];
|
||||
|
||||
if (!$db->updateObject('#__testquestions_results', $row, 'id')) {
|
||||
throw new \RuntimeException('Nie udało się zapisać oceny AI.');
|
||||
}
|
||||
|
||||
return $feedback;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,10 @@ class SetModel extends AdminModel
|
||||
|
||||
if ($parentId > 0) {
|
||||
$data['set_type'] = 'variant';
|
||||
$parent = $this->getItem($parentId);
|
||||
if ($parent) {
|
||||
$data['duration'] = (int) $parent->duration;
|
||||
}
|
||||
} elseif (!in_array(($data['set_type'] ?? 'ordinary'), ['ordinary', 'multi'], true)) {
|
||||
$data['set_type'] = 'ordinary';
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace Komponent\Component\Testquestions\Administrator\Service;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Http\HttpFactory;
|
||||
|
||||
class AiService
|
||||
{
|
||||
public function evaluate(string $provider, string $apiKey, string $question, string $answer, string $pattern): string
|
||||
{
|
||||
$provider = strtolower(trim($provider));
|
||||
$config = $provider === 'grok'
|
||||
? ['url' => 'https://api.x.ai/v1/responses', 'model' => 'grok-4.7']
|
||||
: ['url' => 'https://api.openai.com/v1/responses', 'model' => 'gpt-4.1-mini'];
|
||||
|
||||
if (!in_array($provider, ['openai', 'grok'], true) || trim($apiKey) === '') {
|
||||
throw new \RuntimeException('AI_NOT_CONFIGURED');
|
||||
}
|
||||
|
||||
$input = "Oceń odpowiedź ucznia na pytanie otwarte.\n\n"
|
||||
. "Pytanie:\n" . $question . "\n\n"
|
||||
. "Wzorzec odpowiedzi:\n" . $pattern . "\n\n"
|
||||
. "Odpowiedź ucznia:\n" . ($answer !== '' ? $answer : 'Brak odpowiedzi') . "\n\n"
|
||||
. "Napisz po polsku krótką ocenę: czy odpowiedź może zostać uznana za poprawną, jakie elementy są poprawne lub błędne oraz czy warto przyznać punkty. Nie zmieniaj wzorca odpowiedzi.";
|
||||
|
||||
$payload = json_encode([
|
||||
'model' => $config['model'],
|
||||
'input' => $input,
|
||||
'temperature' => 0.1,
|
||||
], JSON_UNESCAPED_UNICODE);
|
||||
|
||||
$response = HttpFactory::getHttp()->post(
|
||||
$config['url'],
|
||||
$payload,
|
||||
[
|
||||
'Authorization' => 'Bearer ' . trim($apiKey),
|
||||
'Content-Type' => 'application/json',
|
||||
],
|
||||
60
|
||||
);
|
||||
$body = json_decode((string) $response->body, true);
|
||||
|
||||
if ((int) $response->code < 200 || (int) $response->code >= 300) {
|
||||
throw new \RuntimeException((string) ($body['error']['message'] ?? ('HTTP ' . (int) $response->code)));
|
||||
}
|
||||
|
||||
$text = $this->extractText($body);
|
||||
if ($text === '') {
|
||||
throw new \RuntimeException('Brak treści odpowiedzi AI.');
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
|
||||
private function extractText(array $body): string
|
||||
{
|
||||
if (!empty($body['output_text']) && is_string($body['output_text'])) {
|
||||
return trim($body['output_text']);
|
||||
}
|
||||
|
||||
$parts = [];
|
||||
foreach ((array) ($body['output'] ?? []) as $output) {
|
||||
foreach ((array) ($output['content'] ?? []) as $content) {
|
||||
if (!empty($content['text']) && is_string($content['text'])) {
|
||||
$parts[] = $content['text'];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return trim(implode("\n", $parts));
|
||||
}
|
||||
}
|
||||
@@ -63,5 +63,11 @@ class HtmlView extends BaseHtmlView
|
||||
'COM_TESTQUESTIONS_RESULTS',
|
||||
'list'
|
||||
);
|
||||
|
||||
ToolbarHelper::link(
|
||||
'index.php?option=com_config&view=component&component=com_testquestions',
|
||||
'COM_TESTQUESTIONS_AI_SETTINGS_MENU',
|
||||
'cog'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace Komponent\Component\Testquestions\Administrator\View\Set;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
@@ -15,6 +16,8 @@ class HtmlView extends BaseHtmlView
|
||||
protected $questions;
|
||||
protected $categories;
|
||||
protected $variants;
|
||||
protected $isVariant;
|
||||
protected $parentTitle = '';
|
||||
|
||||
public function display($tpl = null)
|
||||
{
|
||||
@@ -23,6 +26,14 @@ class HtmlView extends BaseHtmlView
|
||||
$this->questions = $this->get('Questions');
|
||||
$this->categories = $this->get('Categories');
|
||||
$this->variants = $this->item && (int) $this->item->id > 0 ? $this->get('Variants') : [];
|
||||
$parentId = Factory::getApplication()->getInput()->getInt('parent_id');
|
||||
$this->isVariant = (int) ($this->item->parent_id ?? 0) > 0 || $parentId > 0;
|
||||
$this->parentTitle = (string) ($this->item->parent_title ?? '');
|
||||
|
||||
if ($this->isVariant && $this->parentTitle === '' && $parentId > 0) {
|
||||
$parent = $this->getModel()->getItem($parentId);
|
||||
$this->parentTitle = (string) ($parent->title ?? '');
|
||||
}
|
||||
|
||||
if (count($errors = $this->get('Errors'))) {
|
||||
throw new \RuntimeException(implode("\n", $errors));
|
||||
@@ -36,7 +47,6 @@ class HtmlView extends BaseHtmlView
|
||||
protected function addToolbar()
|
||||
{
|
||||
ToolbarHelper::title($this->item->id ? Text::_('COM_TESTQUESTIONS_EDIT_SET') : Text::_('COM_TESTQUESTIONS_NEW_SET'));
|
||||
ToolbarHelper::apply('set.apply', 'JTOOLBAR_APPLY');
|
||||
ToolbarHelper::custom('set.save', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE', false);
|
||||
ToolbarHelper::custom('set.saveandclose', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE_AND_CLOSE', false);
|
||||
ToolbarHelper::cancel('set.cancel', 'JTOOLBAR_CANCEL');
|
||||
|
||||
@@ -38,6 +38,16 @@
|
||||
<?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>
|
||||
<?php if (empty($answer['correct'])) : ?>
|
||||
<?php if ($question->question_type === 'open') : ?>
|
||||
<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">
|
||||
<?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_EVALUATE'); ?>
|
||||
</button>
|
||||
</div>
|
||||
<?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 endif; ?>
|
||||
<?php endif; ?>
|
||||
<div class="row mt-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>
|
||||
|
||||
@@ -8,18 +8,23 @@ 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">
|
||||
<?php $canOrderQuestions = $this->isVariant || (string) $this->item->set_type === 'ordinary'; ?>
|
||||
<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>
|
||||
<?php if ($this->isVariant) : ?>
|
||||
<div class="alert alert-info"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_PARENT'); ?>: <?php echo $this->escape($this->parentTitle); ?></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 if (!$this->isVariant) : ?>
|
||||
<?php echo $this->form->renderField('duration'); ?>
|
||||
<output id="set-duration-value" class="form-text mb-3"></output>
|
||||
<?php else : ?>
|
||||
<div class="alert alert-info"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_VARIANT_DURATION_INFO'); ?></div>
|
||||
<?php endif; ?>
|
||||
<?php echo $this->form->renderField('test_content'); ?>
|
||||
<?php echo $this->form->renderField('image'); ?>
|
||||
<?php echo $this->form->renderField('description'); ?>
|
||||
@@ -47,10 +52,14 @@ HTMLHelper::_('behavior.formvalidator');
|
||||
<?php if (!((string) $this->item->set_type === 'multi' && (int) $this->item->parent_id === 0)) : ?>
|
||||
<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">
|
||||
<?php if ($canOrderQuestions) : ?>
|
||||
<div class="form-text mb-2"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_REORDER_INFO'); ?></div>
|
||||
<?php endif; ?>
|
||||
<div id="set-selected-question-list" class="border rounded p-3" data-sortable="<?php echo $canOrderQuestions ? '1' : '0'; ?>">
|
||||
<?php $questionsById = []; foreach ($this->questions as $availableQuestion) : $questionsById[(int) $availableQuestion->id] = $availableQuestion; endforeach; ?>
|
||||
<?php foreach ((array) $this->item->question_ids as $selectedQuestionId) : ?>
|
||||
<?php $question = $questionsById[(int) $selectedQuestionId] ?? null; if (!$question) continue; ?>
|
||||
<div class="form-check set-question-row"<?php echo $canOrderQuestions ? ' draggable="true"' : ''; ?>>
|
||||
<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>
|
||||
@@ -120,6 +129,47 @@ HTMLHelper::_('behavior.formvalidator');
|
||||
<?php echo HTMLHelper::_('form.token'); ?>
|
||||
</form>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const list = document.getElementById('set-selected-question-list');
|
||||
|
||||
if (!list || list.dataset.sortable !== '1') {
|
||||
return;
|
||||
}
|
||||
|
||||
let dragged = null;
|
||||
|
||||
list.querySelectorAll('.set-question-row[draggable="true"]').forEach(function (row) {
|
||||
row.addEventListener('dragstart', function (event) {
|
||||
dragged = row;
|
||||
row.classList.add('opacity-50');
|
||||
event.dataTransfer.effectAllowed = 'move';
|
||||
});
|
||||
|
||||
row.addEventListener('dragend', function () {
|
||||
row.classList.remove('opacity-50');
|
||||
dragged = null;
|
||||
});
|
||||
|
||||
row.addEventListener('dragover', function (event) {
|
||||
event.preventDefault();
|
||||
event.dataTransfer.dropEffect = 'move';
|
||||
});
|
||||
|
||||
row.addEventListener('drop', function (event) {
|
||||
event.preventDefault();
|
||||
|
||||
if (!dragged || dragged === row) {
|
||||
return;
|
||||
}
|
||||
|
||||
const rect = row.getBoundingClientRect();
|
||||
const insertAfter = event.clientY > rect.top + rect.height / 2;
|
||||
list.insertBefore(dragged, insertAfter ? row.nextSibling : row);
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
<script>
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
const filter = document.getElementById('set-question-category');
|
||||
const rows = document.querySelectorAll('.set-available-question-row');
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<creationDate>2026-10-14</creationDate>
|
||||
<author>Komponent</author>
|
||||
<license>GNU General Public License version 2 or later</license>
|
||||
<version>1.37.3</version>
|
||||
<version>1.42.3</version>
|
||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||
<element>com_testquestions</element>
|
||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||
@@ -19,6 +19,7 @@
|
||||
<administration>
|
||||
<menu link="index.php?option=com_testquestions&view=questions">COM_TESTQUESTIONS</menu>
|
||||
<files folder="administrator/components/com_testquestions">
|
||||
<filename>config.xml</filename>
|
||||
<folder>forms</folder>
|
||||
<folder>services</folder>
|
||||
<folder>sql</folder>
|
||||
|
||||
@@ -10,6 +10,7 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
class SetModel extends BaseDatabaseModel
|
||||
{
|
||||
protected $resolvedSetId;
|
||||
protected $randomizeQuestions = true;
|
||||
|
||||
protected function getSetId(): int
|
||||
{
|
||||
@@ -44,6 +45,7 @@ class SetModel extends BaseDatabaseModel
|
||||
}
|
||||
|
||||
$this->resolvedSetId = $setId;
|
||||
$this->randomizeQuestions = $set->set_type !== 'multi';
|
||||
|
||||
if ($set->set_type === 'multi') {
|
||||
$variantId = (int) $db->setQuery(
|
||||
@@ -74,15 +76,16 @@ class SetModel extends BaseDatabaseModel
|
||||
return [];
|
||||
}
|
||||
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
$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'])
|
||||
->from($db->quoteName('#__testquestions_set_questions', 'sq'))
|
||||
->innerJoin($db->quoteName('#__testquestions_questions', 'q') . ' ON q.id = sq.question_id')
|
||||
->where('sq.set_id = ' . $setId)
|
||||
->where('q.published = 1')
|
||||
->order('sq.ordering ASC, q.id ASC')
|
||||
)->loadObjectList();
|
||||
->where('q.published = 1');
|
||||
|
||||
$query->order($this->randomizeQuestions ? 'RAND()' : 'sq.ordering ASC, q.id ASC');
|
||||
|
||||
return $db->setQuery($query)->loadObjectList();
|
||||
}
|
||||
|
||||
public function getSets()
|
||||
|
||||
Reference in New Issue
Block a user