diff --git a/README.md b/README.md index 89f5ad3..7278bef 100644 --- a/README.md +++ b/README.md @@ -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**. diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.42.2.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.42.2.sql new file mode 100644 index 0000000..ed001da --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.42.2.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.42.2. diff --git a/administrator/components/com_testquestions/src/Model/ResultModel.php b/administrator/components/com_testquestions/src/Model/ResultModel.php index 2fc065c..3786fc3 100644 --- a/administrator/components/com_testquestions/src/Model/ResultModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultModel.php @@ -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 diff --git a/com_testquestions.xml b/com_testquestions.xml index 2bfb90d..ec98edd 100644 --- a/com_testquestions.xml +++ b/com_testquestions.xml @@ -4,7 +4,7 @@ 2026-10-14 Komponent GNU General Public License version 2 or later - 1.42.1 + 1.42.2 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions