Add bulk deletion for saved test results
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?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 ResultsController extends AdminController
|
||||
{
|
||||
public function delete()
|
||||
{
|
||||
if (!Session::checkToken()) {
|
||||
throw new \RuntimeException(Text::_('JINVALID_TOKEN'), 403);
|
||||
}
|
||||
|
||||
$user = Factory::getApplication()->getIdentity();
|
||||
if (!$user->authorise('core.delete', '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')
|
||||
), static function ($id) {
|
||||
return $id > 0;
|
||||
})));
|
||||
|
||||
if (!$ids) {
|
||||
$this->setRedirect(
|
||||
Route::_('index.php?option=com_testquestions&view=results', false),
|
||||
Text::_('COM_TESTQUESTIONS_RESULTS_DELETE_NONE'),
|
||||
'warning'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->delete($db->quoteName('#__testquestions_results'))
|
||||
->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')')
|
||||
)->execute();
|
||||
|
||||
$this->setRedirect(
|
||||
Route::_('index.php?option=com_testquestions&view=results', false),
|
||||
Text::sprintf('COM_TESTQUESTIONS_RESULTS_DELETED', $db->getAffectedRows())
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ use Joomla\CMS\HTML\HTMLHelper;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
use Joomla\CMS\Factory;
|
||||
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
@@ -25,6 +26,9 @@ class HtmlView extends BaseHtmlView
|
||||
$this->sets = $this->get('Sets');
|
||||
$this->aiUsageTotals = $this->get('AiUsageTotals');
|
||||
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS'));
|
||||
if (Factory::getApplication()->getIdentity()->authorise('core.delete', 'com_testquestions')) {
|
||||
ToolbarHelper::deleteList('', 'results.delete', 'JTOOLBAR_DELETE');
|
||||
}
|
||||
ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back');
|
||||
|
||||
return parent::display($tpl);
|
||||
|
||||
Reference in New Issue
Block a user