diff --git a/README.md b/README.md index 72b66ef..5e9278f 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.9). +W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.0). 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 e979ba2..55409c2 100644 --- a/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini +++ b/administrator/components/com_testquestions/language/en-GB/com_testquestions.ini @@ -69,6 +69,10 @@ 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_ALL="AI — oceń wszystkie niezaliczone pytania otwarte (%s)" +COM_TESTQUESTIONS_AI_BULK_DONE="AI oceniło %s pytań." +COM_TESTQUESTIONS_AI_BULK_PARTIAL="AI oceniło %s pytań; nie udało się ocenić %s. Błąd: %s" +COM_TESTQUESTIONS_AI_NO_OPEN_QUESTIONS="Brak niezaliczonych pytań otwartych do oceny 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.43.0.sql b/administrator/components/com_testquestions/sql/updates/mysql/1.43.0.sql new file mode 100644 index 0000000..016666c --- /dev/null +++ b/administrator/components/com_testquestions/sql/updates/mysql/1.43.0.sql @@ -0,0 +1 @@ +-- No database changes required for version 1.43.0. diff --git a/administrator/components/com_testquestions/src/Controller/ResultController.php b/administrator/components/com_testquestions/src/Controller/ResultController.php index c60924a..a9965ce 100644 --- a/administrator/components/com_testquestions/src/Controller/ResultController.php +++ b/administrator/components/com_testquestions/src/Controller/ResultController.php @@ -63,6 +63,47 @@ class ResultController extends BaseController ); } + public function aiAll(): void + { + if (!Session::checkToken()) { + throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403); + } + + $input = Factory::getApplication()->getInput(); + $id = $input->post->getInt('id'); + $message = ''; + $type = 'message'; + + try { + $summary = $this->getModel('Result')->evaluateAllWithAi($id); + if ($summary['failed'] > 0) { + $message = Text::sprintf( + 'COM_TESTQUESTIONS_AI_BULK_PARTIAL', + $summary['evaluated'], + $summary['failed'], + $summary['first_error'] + ); + $type = 'warning'; + } else { + $message = Text::sprintf('COM_TESTQUESTIONS_AI_BULK_DONE', $summary['evaluated']); + } + } catch (\Throwable $error) { + $errorMessage = $error->getMessage(); + $message = $errorMessage === 'AI_NO_OPEN_QUESTIONS' + ? Text::_('COM_TESTQUESTIONS_AI_NO_OPEN_QUESTIONS') + : ($errorMessage === 'AI_NOT_CONFIGURED' + ? Text::_('COM_TESTQUESTIONS_AI_NOT_CONFIGURED') + : Text::sprintf('COM_TESTQUESTIONS_AI_ERROR', $errorMessage)); + $type = 'error'; + } + + $this->setRedirect( + Route::_('index.php?option=com_testquestions&view=result&id=' . $id, false), + $message, + $type + ); + } + private function saveAssessment(): void { if (!Session::checkToken()) { diff --git a/administrator/components/com_testquestions/src/Model/ResultModel.php b/administrator/components/com_testquestions/src/Model/ResultModel.php index 84874d7..8f4b796 100644 --- a/administrator/components/com_testquestions/src/Model/ResultModel.php +++ b/administrator/components/com_testquestions/src/Model/ResultModel.php @@ -153,4 +153,51 @@ class ResultModel extends BaseDatabaseModel return $feedback; } + + public function evaluateAllWithAi(int $id): array + { + $item = $this->getItem($id); + + if (!$item) { + throw new \RuntimeException('Nie znaleziono zapisanego testu.'); + } + + $questionIds = []; + foreach ($item->answers as $questionId => $answer) { + $question = $item->questions[(int) $questionId] ?? null; + if ($question && $question->question_type === 'open' && empty($answer['correct'])) { + $questionIds[] = (int) $questionId; + } + } + + if (!$questionIds) { + throw new \RuntimeException('AI_NO_OPEN_QUESTIONS'); + } + + $evaluated = 0; + $failed = 0; + $firstError = ''; + + foreach ($questionIds as $questionId) { + try { + $this->evaluateWithAi($id, $questionId); + $evaluated++; + } catch (\Throwable $error) { + $failed++; + $firstError = $firstError ?: $error->getMessage(); + + if (in_array($error->getMessage(), ['AI_NOT_CONFIGURED'], true) + || str_starts_with($error->getMessage(), 'AI_KEY_EMPTY|')) { + break; + } + } + } + + return [ + 'evaluated' => $evaluated, + 'failed' => $failed, + 'first_error' => $firstError, + 'total' => count($questionIds), + ]; + } } diff --git a/administrator/components/com_testquestions/tmpl/result/default.php b/administrator/components/com_testquestions/tmpl/result/default.php index 0a6021d..ff23873 100644 --- a/administrator/components/com_testquestions/tmpl/result/default.php +++ b/administrator/components/com_testquestions/tmpl/result/default.php @@ -25,6 +25,18 @@
item->execution_time / 60); ?>:item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?>
+ + item->answers as $questionId => $answer) : ?> + item->questions[(int) $questionId] ?? null; ?> + question_type === 'open' && empty($answer['correct'])) { $pendingAiCount++; } ?> + + 0) : ?> +
+ +
+

item->answers as $questionId => $answer) : ?> item->questions[(int) $questionId] ?? null; if (!$question) continue; ?> diff --git a/com_testquestions.xml b/com_testquestions.xml index 08d5d58..9b95aae 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.9 + 1.43.0 COM_TESTQUESTIONS_DESCRIPTION com_testquestions Komponent\Component\Testquestions