Evaluate all failed open answers with AI
This commit is contained in:
@@ -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()) {
|
||||
|
||||
Reference in New Issue
Block a user