42 lines
1.6 KiB
PHP
42 lines
1.6 KiB
PHP
<?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.*', 'sub.title AS subject_title', 'COUNT(sq.question_id) AS question_count'])
|
|
->from($db->quoteName('#__testquestions_sets', 's'))
|
|
->leftJoin($db->quoteName('#__testquestions_subjects', 'sub') . ' ON sub.id = s.subject_id')
|
|
->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');
|
|
}
|
|
}
|