diff --git a/README.md b/README.md index 12a3ebb..72b66ef 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.8). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.42.9). Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. diff --git a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini index 9553d6a..e979ba2 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -66,6 +66,9 @@ 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_SETTINGS_SAVED="Ustawienia AI zapisano." +COM_TESTQUESTIONS_AI_SAVE_FAILED="Nie udało się zapisać ustawień AI." +COM_TESTQUESTIONS_AI_PROVIDER_INVALID="Wybierz prawidłowego dostawcę 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." diff --git a/administrator/components/com_testquestions/sql/updates/mysql/1.42.9.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.42.9.sql new file mode 100644 index 0000000..dc73cc6 --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.42.9.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.42.9. diff --git a/administrator/components/com_testquestions/src/Controller/AiController.php b/administrator/components/com_testquestions/src/Controller/AiController.php new file mode 100644 index 0000000..4c5cfe4 --- /dev/null +++ b/administrator/components/com_testquestions/src/Controller/AiController.php @@ -0,0 +1,73 @@ +getIdentity(); + if (!$user->authorise('core.admin', 'com_testquestions') && !$user->authorise('core.options', 'com_testquestions')) { + throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403); + } + + $input = Factory::getApplication()->getInput(); + $provider = strtolower($input->post->getCmd('ai_provider', '')); + if (!in_array($provider, ['openai', 'grok'], true)) { + throw new \RuntimeException(Text::_('COM_TESTQUESTIONS_AI_PROVIDER_INVALID')); + } + + $db = Factory::getContainer()->get('DatabaseDriver'); + $row = $db->setQuery( + $db->getQuery(true) + ->select([$db->quoteName('extension_id'), $db->quoteName('params')]) + ->from($db->quoteName('#__extensions')) + ->where($db->quoteName('type') . ' = ' . $db->quote('component')) + ->where($db->quoteName('element') . ' = ' . $db->quote('com_testquestions')) + )->loadObject(); + + if (!$row) { + throw new \RuntimeException(Text::_('COM_TESTQUESTIONS_AI_SAVE_FAILED')); + } + + $settings = json_decode((string) $row->params, true); + $settings = is_array($settings) ? $settings : []; + $apiKey = trim((string) $input->post->get('ai_api_key', '', 'RAW')); + + $settings['ai_provider'] = $provider; + if ($apiKey !== '') { + $settings['ai_api_key'] = $apiKey; + } + + $extension = (object) [ + 'extension_id' => (int) $row->extension_id, + 'params' => json_encode($settings, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), + ]; + + if (!$db->updateObject('#__extensions', $extension, 'extension_id')) { + throw new \RuntimeException(Text::_('COM_TESTQUESTIONS_AI_SAVE_FAILED')); + } + + $this->setRedirect( + Route::_('index.php?option=com_testquestions&view=ai', false), + Text::_('COM_TESTQUESTIONS_AI_SETTINGS_SAVED') + ); + } + + public function cancel(): void + { + $this->setRedirect(Route::_('index.php?option=com_testquestions&view=questions', false)); + } +} diff --git a/administrator/components/com_testquestions/src/View/Ai/HtmlView.php b/administrator/components/com_testquestions/src/View/Ai/HtmlView.php new file mode 100644 index 0000000..95ffb1f --- /dev/null +++ b/administrator/components/com_testquestions/src/View/Ai/HtmlView.php @@ -0,0 +1,33 @@ +get('DatabaseDriver'); + $raw = (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(); + $this->settings = json_decode($raw, true) ?: []; + + ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_AI_SETTINGS')); + ToolbarHelper::link('index.php?option=com_testquestions&view=questions', 'COM_TESTQUESTIONS_QUESTIONS', 'arrow-left'); + + return parent::display($tpl); + } +} diff --git a/administrator/components/com_testquestions/src/View/Questions/HtmlView.php b/administrator/components/com_testquestions/src/View/Questions/HtmlView.php index e3defce..6a7f5bc 100644 --- a/administrator/components/com_testquestions/src/View/Questions/HtmlView.php +++ b/administrator/components/com_testquestions/src/View/Questions/HtmlView.php @@ -65,7 +65,7 @@ class HtmlView extends BaseHtmlView ); ToolbarHelper::link( - 'index.php?option=com_config&view=component&component=com_testquestions', + 'index.php?option=com_testquestions&view=ai', 'COM_TESTQUESTIONS_AI_SETTINGS_MENU', 'cog' ); diff --git a/administrator/components/com_testquestions/tmpl/ai/default.php b/administrator/components/com_testquestions/tmpl/ai/default.php new file mode 100644 index 0000000..ec1b589 --- /dev/null +++ b/administrator/components/com_testquestions/tmpl/ai/default.php @@ -0,0 +1,44 @@ + + + +settings['ai_provider'] ?? 'openai'); ?> +settings['ai_api_key'] ?? ''); ?> +
+
+
+
+ + +
+
+ +
+ + +
+ + + +
+ + + + +
+
+ + +
+ diff --git a/com_testquestions.xml b/com_testquestions.xml index 7bba2c6..08d5d58 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.8 + 1.42.9 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions