46 lines
1.5 KiB
PHP
46 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\AdminController;
|
|
use Joomla\CMS\Router\Route;
|
|
use Joomla\CMS\Session\Session;
|
|
|
|
class QuestionsController extends AdminController
|
|
{
|
|
protected $text_prefix = 'COM_TESTQUESTIONS';
|
|
|
|
public function getModel($name = 'Question', $prefix = 'Administrator', $config = ['ignore_request' => true])
|
|
{
|
|
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));
|
|
}
|
|
}
|