Read saved AI component parameters
This commit is contained in:
@@ -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.42.1).
|
||||
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.2).
|
||||
|
||||
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
-- No database changes required for version 1.42.2.
|
||||
@@ -91,9 +91,31 @@ class ResultModel extends BaseDatabaseModel
|
||||
}
|
||||
|
||||
$params = ComponentHelper::getParams('com_testquestions');
|
||||
$provider = trim((string) $params->get('ai_provider', 'openai'));
|
||||
$apiKey = trim((string) $params->get('ai_api_key', ''));
|
||||
|
||||
// Pole typu password może zwrócić zamaskowaną wartość zamiast pustej.
|
||||
// W takim przypadku odczytaj rzeczywiste parametry bezpośrednio z rekordu rozszerzenia.
|
||||
if ($apiKey === '' || preg_match('/^\*+$/', $apiKey)) {
|
||||
$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)) {
|
||||
$provider = trim((string) ($storedParams['ai_provider'] ?? $provider));
|
||||
$apiKey = trim((string) ($storedParams['ai_api_key'] ?? ''));
|
||||
}
|
||||
}
|
||||
|
||||
$feedback = (new AiService())->evaluate(
|
||||
(string) $params->get('ai_provider', 'openai'),
|
||||
(string) $params->get('ai_api_key', ''),
|
||||
$provider,
|
||||
$apiKey,
|
||||
strip_tags((string) $question->question),
|
||||
(string) ($answer['selected'] ?? ''),
|
||||
(string) $question->answer_open
|
||||
|
||||
@@ -4,7 +4,7 @@
|
||||
<creationDate>2026-10-14</creationDate>
|
||||
<author>Komponent</author>
|
||||
<license>GNU General Public License version 2 or later</license>
|
||||
<version>1.42.1</version>
|
||||
<version>1.42.2</version>
|
||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||
<element>com_testquestions</element>
|
||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||
|
||||
Reference in New Issue
Block a user