Use all sets in result filter

This commit is contained in:
Wojtek
2026-10-15 21:43:24 +02:00
parent 3fd488e19e
commit 33783399f9
7 changed files with 30 additions and 8 deletions
@@ -13,7 +13,7 @@ class ResultsModel extends ListModel
{
parent::populateState($ordering, $direction);
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.test_name', $this->getUserStateFromRequest($this->context . '.filter.test_name', 'filter_test_name', '', 'string'));
$this->setState('filter.set_id', $this->getUserStateFromRequest($this->context . '.filter.set_id', 'filter_set_id', 0, 'int'));
$this->setState('filter.date_from', $this->getUserStateFromRequest($this->context . '.filter.date_from', 'filter_date_from', '', 'string'));
$this->setState('filter.date_to', $this->getUserStateFromRequest($this->context . '.filter.date_to', 'filter_date_to', '', 'string'));
}
@@ -33,10 +33,9 @@ class ResultsModel extends ListModel
$query->where('(r.participant_name LIKE ' . $needle . ' OR s.title LIKE ' . $needle . ')');
}
$testName = trim((string) $this->getState('filter.test_name'));
if ($testName !== '') {
$needle = $db->quote('%' . $db->escape($testName, true) . '%', false);
$query->where('s.title LIKE ' . $needle);
$setId = (int) $this->getState('filter.set_id');
if ($setId > 0) {
$query->where('r.set_id = ' . $setId);
}
$dateFrom = (string) $this->getState('filter.date_from');
@@ -51,4 +50,17 @@ class ResultsModel extends ListModel
return $query->order('r.created DESC, r.id DESC');
}
public function getSets(): array
{
$db = Factory::getContainer()->get('DatabaseDriver');
return $db->setQuery(
$db->getQuery(true)
->select(['s.id', 's.title', 's.published', 'sub.title AS subject_title'])
->from($db->quoteName('#__testquestions_sets', 's'))
->leftJoin($db->quoteName('#__testquestions_subjects', 'sub') . ' ON sub.id = s.subject_id')
->order('sub.title ASC, s.title ASC, s.id ASC')
)->loadObjectList();
}
}