Add subject filter to question sets
This commit is contained in:
@@ -14,6 +14,7 @@ class SetsModel extends ListModel
|
||||
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'));
|
||||
$this->setState('filter.subject_id', $this->getUserStateFromRequest($this->context . '.filter.subject_id', 'filter_subject_id', '', 'int'));
|
||||
}
|
||||
|
||||
protected function getListQuery()
|
||||
@@ -36,6 +37,23 @@ class SetsModel extends ListModel
|
||||
$query->where('s.published = ' . (int) $published);
|
||||
}
|
||||
|
||||
if ((int) $this->getState('filter.subject_id') > 0) {
|
||||
$query->where('s.subject_id = ' . (int) $this->getState('filter.subject_id'));
|
||||
}
|
||||
|
||||
return $query->order('s.ordering ASC, s.title ASC');
|
||||
}
|
||||
|
||||
public function getSubjects()
|
||||
{
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['id', 'title'])
|
||||
->from($db->quoteName('#__testquestions_subjects'))
|
||||
->where($db->quoteName('published') . ' = 1')
|
||||
->order($db->quoteName('title') . ' ASC')
|
||||
)->loadObjectList();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,12 +14,14 @@ class HtmlView extends BaseHtmlView
|
||||
protected $items;
|
||||
protected $pagination;
|
||||
protected $state;
|
||||
protected $subjects;
|
||||
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->items = $this->get('Items');
|
||||
$this->pagination = $this->get('Pagination');
|
||||
$this->state = $this->get('State');
|
||||
$this->subjects = $this->get('Subjects');
|
||||
|
||||
if (count($errors = $this->get('Errors'))) {
|
||||
throw new \RuntimeException(implode("\n", $errors));
|
||||
|
||||
Reference in New Issue
Block a user