Add question set management
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php
|
||||
|
||||
namespace Komponent\Component\Testquestions\Administrator\Model;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\ListModel;
|
||||
|
||||
class SetsModel extends ListModel
|
||||
{
|
||||
protected function populateState($ordering = 's.ordering', $direction = 'asc')
|
||||
{
|
||||
parent::populateState($ordering, $direction);
|
||||
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
|
||||
$this->setState('filter.published', $this->getUserStateFromRequest($this->context . '.filter.published', 'filter_published', '', 'string'));
|
||||
}
|
||||
|
||||
protected function getListQuery()
|
||||
{
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$query = $db->getQuery(true)
|
||||
->select(['s.*', 'COUNT(sq.question_id) AS question_count'])
|
||||
->from($db->quoteName('#__testquestions_sets', 's'))
|
||||
->leftJoin($db->quoteName('#__testquestions_set_questions', 'sq') . ' ON sq.set_id = s.id')
|
||||
->group('s.id');
|
||||
|
||||
$search = trim((string) $this->getState('filter.search'));
|
||||
if ($search !== '') {
|
||||
$query->where('s.title LIKE ' . $db->quote('%' . $db->escape($search, true) . '%', false));
|
||||
}
|
||||
|
||||
$published = $this->getState('filter.published');
|
||||
if ($published !== '' && $published !== null) {
|
||||
$query->where('s.published = ' . (int) $published);
|
||||
}
|
||||
|
||||
return $query->order('s.ordering ASC, s.title ASC');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user