Add read-only test question preview
This commit is contained in:
@@ -4,7 +4,11 @@ namespace Komponent\Component\Testquestions\Administrator\Controller;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\Controller\AdminController;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Session\Session;
|
||||
|
||||
class QuestionsController extends AdminController
|
||||
{
|
||||
@@ -14,4 +18,28 @@ class QuestionsController extends AdminController
|
||||
{
|
||||
return parent::getModel($name, $prefix, $config);
|
||||
}
|
||||
|
||||
public function preview(): void
|
||||
{
|
||||
if (!Session::checkToken()) {
|
||||
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
}
|
||||
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
if (!$user->authorise('core.edit', 'com_testquestions') && !$user->authorise('core.manage', 'com_testquestions')) {
|
||||
throw new \RuntimeException(Text::_('JERROR_ALERTNOAUTHOR'), 403);
|
||||
}
|
||||
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', (array) $this->input->post->get('cid', [], 'array')))));
|
||||
if (!$ids) {
|
||||
$this->setRedirect(
|
||||
Route::_('index.php?option=com_testquestions&view=questions', false),
|
||||
Text::_('COM_TESTQUESTIONS_PREVIEW_SELECT_QUESTIONS'),
|
||||
'warning'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->setRedirect(Route::_('index.php?option=com_testquestions&view=preview&ids=' . implode(',', $ids), false));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user