Add category filter to set question selection
This commit is contained in:
@@ -44,6 +44,31 @@ class SetModel extends AdminModel
|
||||
return Factory::getApplication()->getUserState('com_testquestions.edit.set.data', []) ?: $this->getItem();
|
||||
}
|
||||
|
||||
public function getQuestions()
|
||||
{
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['q.id', 'q.question', 'q.category_id', 'c.title AS category_title'])
|
||||
->from($db->quoteName('#__testquestions_questions', 'q'))
|
||||
->leftJoin($db->quoteName('#__testquestions_categories', 'c') . ' ON c.id = q.category_id')
|
||||
->order('c.title ASC, q.ordering ASC, q.id ASC')
|
||||
)->loadObjectList();
|
||||
}
|
||||
|
||||
public function getCategories()
|
||||
{
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['id', 'title'])
|
||||
->from($db->quoteName('#__testquestions_categories'))
|
||||
->order($db->quoteName('title') . ' ASC')
|
||||
)->loadObjectList();
|
||||
}
|
||||
|
||||
public function save($data)
|
||||
{
|
||||
$questionIds = array_values(array_unique(array_filter(array_map('intval', (array) ($data['question_ids'] ?? [])))));
|
||||
|
||||
@@ -12,11 +12,15 @@ class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $form;
|
||||
protected $item;
|
||||
protected $questions;
|
||||
protected $categories;
|
||||
|
||||
public function display($tpl = null)
|
||||
{
|
||||
$this->form = $this->get('Form');
|
||||
$this->item = $this->get('Item');
|
||||
$this->questions = $this->get('Questions');
|
||||
$this->categories = $this->get('Categories');
|
||||
|
||||
if (count($errors = $this->get('Errors'))) {
|
||||
throw new \RuntimeException(implode("\n", $errors));
|
||||
|
||||
Reference in New Issue
Block a user