52 lines
1.5 KiB
PHP
52 lines
1.5 KiB
PHP
<?php
|
|
|
|
namespace Komponent\Component\Testquestions\Administrator\Controller;
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\Language\Text;
|
|
use Joomla\CMS\MVC\Controller\BaseController;
|
|
use Joomla\CMS\Router\Route;
|
|
use Joomla\CMS\Session\Session;
|
|
|
|
class ResultController extends BaseController
|
|
{
|
|
public function save(): void
|
|
{
|
|
$this->saveAssessment();
|
|
$id = Factory::getApplication()->getInput()->post->getInt('id');
|
|
|
|
$this->setRedirect(
|
|
Route::_('index.php?option=com_testquestions&view=result&id=' . $id, false),
|
|
Text::_('COM_TESTQUESTIONS_RESULT_SAVED')
|
|
);
|
|
}
|
|
|
|
public function save2close(): void
|
|
{
|
|
$this->saveAssessment();
|
|
$this->setRedirect(
|
|
Route::_('index.php?option=com_testquestions&view=results', false),
|
|
Text::_('COM_TESTQUESTIONS_RESULT_SAVED')
|
|
);
|
|
}
|
|
|
|
private function saveAssessment(): void
|
|
{
|
|
if (!Session::checkToken()) {
|
|
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
|
}
|
|
|
|
$input = Factory::getApplication()->getInput();
|
|
$id = $input->post->getInt('id');
|
|
$points = (array) $input->post->get('awarded_points', [], 'array');
|
|
$comments = (array) $input->post->get('comments', [], 'array');
|
|
$model = $this->getModel('Result');
|
|
|
|
if (!$model->saveAssessment($id, $points, $comments)) {
|
|
throw new \RuntimeException(Text::_('COM_TESTQUESTIONS_RESULT_NOT_FOUND'));
|
|
}
|
|
}
|
|
}
|