Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6daca5be59 | ||
|
|
dc6b5ad3e8 |
@@ -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.1).
|
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.3).
|
||||||
|
|
||||||
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||||
|
|||||||
@@ -65,6 +65,8 @@ COM_TESTQUESTIONS_SET_VARIANT_DURATION_INFO="Czas testu jest pobierany z zestawu
|
|||||||
COM_TESTQUESTIONS_AI_SETTINGS="Ustawienia AI"
|
COM_TESTQUESTIONS_AI_SETTINGS="Ustawienia AI"
|
||||||
COM_TESTQUESTIONS_AI_PROVIDER="Dostawca AI"
|
COM_TESTQUESTIONS_AI_PROVIDER="Dostawca AI"
|
||||||
COM_TESTQUESTIONS_AI_API_KEY="Klucz API"
|
COM_TESTQUESTIONS_AI_API_KEY="Klucz API"
|
||||||
|
COM_TESTQUESTIONS_AI_OPENAI_KEY="Klucz API OpenAI"
|
||||||
|
COM_TESTQUESTIONS_AI_GROK_KEY="Klucz API Grok"
|
||||||
COM_TESTQUESTIONS_AI_SETTINGS_MENU="Konfiguracja AI"
|
COM_TESTQUESTIONS_AI_SETTINGS_MENU="Konfiguracja AI"
|
||||||
COM_TESTQUESTIONS_AI_SETTINGS_SAVED="Ustawienia AI zapisano."
|
COM_TESTQUESTIONS_AI_SETTINGS_SAVED="Ustawienia AI zapisano."
|
||||||
COM_TESTQUESTIONS_AI_SAVE_FAILED="Nie udało się zapisać ustawień AI."
|
COM_TESTQUESTIONS_AI_SAVE_FAILED="Nie udało się zapisać ustawień AI."
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
-- No database changes required for version 1.43.2.
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
-- No database changes required for version 1.43.3.
|
||||||
@@ -44,12 +44,22 @@ class AiController extends BaseController
|
|||||||
|
|
||||||
$settings = json_decode((string) $row->params, true);
|
$settings = json_decode((string) $row->params, true);
|
||||||
$settings = is_array($settings) ? $settings : [];
|
$settings = is_array($settings) ? $settings : [];
|
||||||
$apiKey = trim((string) $input->post->get('ai_api_key', '', 'RAW'));
|
$legacyKey = trim((string) ($settings['ai_api_key'] ?? ''));
|
||||||
|
|
||||||
$settings['ai_provider'] = $provider;
|
$settings['ai_provider'] = $provider;
|
||||||
if ($apiKey !== '') {
|
foreach (['openai', 'grok'] as $keyProvider) {
|
||||||
$settings['ai_api_key'] = $apiKey;
|
$fieldName = 'ai_' . $keyProvider . '_api_key';
|
||||||
|
$apiKey = trim((string) $input->post->get($fieldName, '', 'RAW'));
|
||||||
|
|
||||||
|
if ($apiKey !== '') {
|
||||||
|
$settings[$fieldName] = $apiKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($keyProvider === $provider && empty($settings[$fieldName]) && $legacyKey !== '') {
|
||||||
|
$settings[$fieldName] = $legacyKey;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
unset($settings['ai_api_key']);
|
||||||
|
|
||||||
$extension = (object) [
|
$extension = (object) [
|
||||||
'extension_id' => (int) $row->extension_id,
|
'extension_id' => (int) $row->extension_id,
|
||||||
|
|||||||
@@ -92,7 +92,9 @@ class ResultModel extends BaseDatabaseModel
|
|||||||
|
|
||||||
$params = ComponentHelper::getParams('com_testquestions');
|
$params = ComponentHelper::getParams('com_testquestions');
|
||||||
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
||||||
$apiKey = trim((string) $params->get('ai_api_key', ''));
|
$provider = strtolower(preg_replace('/[^a-z]/', '', $provider));
|
||||||
|
$keyName = 'ai_' . $provider . '_api_key';
|
||||||
|
$apiKey = trim((string) $params->get($keyName, $params->get('ai_api_key', '')));
|
||||||
$componentKeyLength = mb_strlen($apiKey);
|
$componentKeyLength = mb_strlen($apiKey);
|
||||||
|
|
||||||
// Odczytaj zapisane parametry bezpośrednio z bazy. Dzięki temu nie użyjemy
|
// Odczytaj zapisane parametry bezpośrednio z bazy. Dzięki temu nie użyjemy
|
||||||
@@ -115,14 +117,21 @@ class ResultModel extends BaseDatabaseModel
|
|||||||
if ($storedProvider !== '') {
|
if ($storedProvider !== '') {
|
||||||
$provider = $storedProvider;
|
$provider = $storedProvider;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ($storedApiKey !== '' && !preg_match('/^\*+$/', $storedApiKey)) {
|
$provider = strtolower(preg_replace('/[^a-z]/', '', $provider));
|
||||||
$apiKey = $storedApiKey;
|
$keyName = 'ai_' . $provider . '_api_key';
|
||||||
}
|
$apiKey = trim((string) $params->get($keyName, $params->get('ai_api_key', '')));
|
||||||
|
$componentKeyLength = mb_strlen($apiKey);
|
||||||
|
$storedApiKey = is_array($storedParams)
|
||||||
|
? trim((string) ($storedParams[$keyName] ?? $storedParams['ai_api_key'] ?? ''))
|
||||||
|
: '';
|
||||||
|
if ($storedApiKey !== '' && !preg_match('/^\*+$/', $storedApiKey)) {
|
||||||
|
$apiKey = $storedApiKey;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (trim($apiKey) === '') {
|
if (trim($apiKey) === '') {
|
||||||
$databaseKey = is_array($storedParams) ? trim((string) ($storedParams['ai_api_key'] ?? '')) : '';
|
$databaseKey = $storedApiKey;
|
||||||
$databaseKeyLength = preg_match('/^\*+$/', $databaseKey) ? 0 : mb_strlen($databaseKey);
|
$databaseKeyLength = preg_match('/^\*+$/', $databaseKey) ? 0 : mb_strlen($databaseKey);
|
||||||
throw new \RuntimeException(
|
throw new \RuntimeException(
|
||||||
'AI_KEY_EMPTY|provider=' . ($provider !== '' ? $provider : '(pusty)')
|
'AI_KEY_EMPTY|provider=' . ($provider !== '' ? $provider : '(pusty)')
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
<?php use Joomla\CMS\HTML\HTMLHelper; ?>
|
<?php use Joomla\CMS\HTML\HTMLHelper; ?>
|
||||||
<?php use Joomla\CMS\Router\Route; ?>
|
<?php use Joomla\CMS\Router\Route; ?>
|
||||||
<?php $provider = (string) ($this->settings['ai_provider'] ?? 'openai'); ?>
|
<?php $provider = (string) ($this->settings['ai_provider'] ?? 'openai'); ?>
|
||||||
<?php $apiKey = (string) ($this->settings['ai_api_key'] ?? ''); ?>
|
<?php $legacyKey = (string) ($this->settings['ai_api_key'] ?? ''); ?>
|
||||||
|
<?php $openaiKey = (string) ($this->settings['ai_openai_api_key'] ?? ($provider === 'openai' ? $legacyKey : '')); ?>
|
||||||
|
<?php $grokKey = (string) ($this->settings['ai_grok_api_key'] ?? ($provider === 'grok' ? $legacyKey : '')); ?>
|
||||||
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=ai'); ?>" method="post" name="adminForm" id="adminForm">
|
<form action="<?php echo Route::_('index.php?option=com_testquestions&view=ai'); ?>" method="post" name="adminForm" id="adminForm">
|
||||||
<div class="card" style="max-width: 900px;">
|
<div class="card" style="max-width: 900px;">
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
@@ -14,13 +16,23 @@
|
|||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
<div class="mb-3">
|
<div class="mb-3">
|
||||||
<label for="ai-api-key" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_API_KEY'); ?></label>
|
<label for="ai-openai-api-key" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_OPENAI_KEY'); ?></label>
|
||||||
<div class="input-group">
|
<div class="input-group">
|
||||||
<input type="password" id="ai-api-key" name="ai_api_key" value="<?php echo htmlspecialchars($apiKey, ENT_QUOTES, 'UTF-8'); ?>" class="form-control" size="120" maxlength="4096" autocomplete="new-password">
|
<input type="password" id="ai-openai-api-key" name="ai_openai_api_key" value="<?php echo htmlspecialchars($openaiKey, ENT_QUOTES, 'UTF-8'); ?>" class="form-control" size="120" maxlength="4096" autocomplete="new-password">
|
||||||
<button type="button" class="btn btn-outline-secondary" id="ai-key-toggle">Pokaż</button>
|
<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="ai-openai-api-key">Pokaż</button>
|
||||||
</div>
|
</div>
|
||||||
<small class="form-text text-muted">
|
<small class="form-text text-muted">
|
||||||
<?php echo $apiKey !== '' ? 'Zapisany klucz: ' . mb_strlen($apiKey) . ' znaków. Pozostaw pole bez zmian, aby zachować klucz.' : 'Nie zapisano jeszcze klucza API.'; ?>
|
<?php echo $openaiKey !== '' ? 'Zapisany klucz: ' . mb_strlen($openaiKey) . ' znaków. Pozostaw pole bez zmian, aby go zachować.' : 'Nie zapisano klucza OpenAI.'; ?>
|
||||||
|
</small>
|
||||||
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<label for="ai-grok-api-key" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_GROK_KEY'); ?></label>
|
||||||
|
<div class="input-group">
|
||||||
|
<input type="password" id="ai-grok-api-key" name="ai_grok_api_key" value="<?php echo htmlspecialchars($grokKey, ENT_QUOTES, 'UTF-8'); ?>" class="form-control" size="120" maxlength="4096" autocomplete="new-password">
|
||||||
|
<button type="button" class="btn btn-outline-secondary" data-ai-key-toggle="ai-grok-api-key">Pokaż</button>
|
||||||
|
</div>
|
||||||
|
<small class="form-text text-muted">
|
||||||
|
<?php echo $grokKey !== '' ? 'Zapisany klucz: ' . mb_strlen($grokKey) . ' znaków. Pozostaw pole bez zmian, aby go zachować.' : 'Nie zapisano klucza Grok.'; ?>
|
||||||
</small>
|
</small>
|
||||||
</div>
|
</div>
|
||||||
<button type="submit" class="btn btn-primary" onclick="this.form.task.value='ai.save';">
|
<button type="submit" class="btn btn-primary" onclick="this.form.task.value='ai.save';">
|
||||||
@@ -35,10 +47,12 @@
|
|||||||
<?php echo HTMLHelper::_('form.token'); ?>
|
<?php echo HTMLHelper::_('form.token'); ?>
|
||||||
</form>
|
</form>
|
||||||
<script>
|
<script>
|
||||||
document.getElementById('ai-key-toggle')?.addEventListener('click', function () {
|
document.querySelectorAll('[data-ai-key-toggle]').forEach(function (button) {
|
||||||
const input = document.getElementById('ai-api-key');
|
button.addEventListener('click', function () {
|
||||||
const visible = input.type === 'text';
|
const input = document.getElementById(this.dataset.aiKeyToggle);
|
||||||
input.type = visible ? 'password' : 'text';
|
const visible = input.type === 'text';
|
||||||
this.textContent = visible ? 'Pokaż' : 'Ukryj';
|
input.type = visible ? 'password' : 'text';
|
||||||
|
this.textContent = visible ? 'Pokaż' : 'Ukryj';
|
||||||
|
});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|||||||
@@ -60,16 +60,18 @@
|
|||||||
<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>
|
<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; ?>
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
<div class="row mt-3">
|
<?php if ($question->question_type === 'open') : ?>
|
||||||
<div class="col-md-3">
|
<div class="row mt-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>
|
<div class="col-md-3">
|
||||||
<input type="number" min="0" max="<?php echo (int) ($question->points ?? 0); ?>" name="awarded_points[<?php echo (int) $questionId; ?>]" id="awarded-points-<?php echo (int) $questionId; ?>" class="form-control" value="<?php echo (int) ($answer['awarded_points'] ?? 0); ?>">
|
<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>
|
||||||
|
<input type="number" min="0" max="<?php echo (int) ($question->points ?? 0); ?>" name="awarded_points[<?php echo (int) $questionId; ?>]" id="awarded-points-<?php echo (int) $questionId; ?>" class="form-control" value="<?php echo (int) ($answer['awarded_points'] ?? 0); ?>">
|
||||||
|
</div>
|
||||||
|
<div class="col-md-9">
|
||||||
|
<label for="result-comment-<?php echo (int) $questionId; ?>" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_COMMENT'); ?></label>
|
||||||
|
<textarea name="comments[<?php echo (int) $questionId; ?>]" id="result-comment-<?php echo (int) $questionId; ?>" class="form-control" rows="2"><?php echo htmlspecialchars((string) ($answer['comment'] ?? ''), ENT_QUOTES, 'UTF-8'); ?></textarea>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-9">
|
<?php endif; ?>
|
||||||
<label for="result-comment-<?php echo (int) $questionId; ?>" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_COMMENT'); ?></label>
|
|
||||||
<textarea name="comments[<?php echo (int) $questionId; ?>]" id="result-comment-<?php echo (int) $questionId; ?>" class="form-control" rows="2"><?php echo htmlspecialchars((string) ($answer['comment'] ?? ''), ENT_QUOTES, 'UTF-8'); ?></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</article>
|
</article>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
|
|||||||
@@ -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.1</version>
|
<version>1.43.3</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>
|
||||||
|
|||||||
Reference in New Issue
Block a user