63 lines
2.6 KiB
PHP
63 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace Komponent\Component\Testquestions\Site\Model;
|
|
|
|
defined('_JEXEC') or die;
|
|
|
|
use Joomla\CMS\Factory;
|
|
use Joomla\CMS\MVC\Model\ListModel;
|
|
|
|
class QuestionsModel extends ListModel
|
|
{
|
|
protected function populateState($ordering = 'ordering', $direction = 'asc')
|
|
{
|
|
parent::populateState($ordering, $direction);
|
|
$menu = Factory::getApplication()->getMenu()->getActive();
|
|
$menuSymbol = $menu ? (string) $menu->getParams()->get('test_symbol', '') : '';
|
|
$symbol = Factory::getApplication()->getInput()->getString('test_symbol', $menuSymbol);
|
|
$this->setState('filter.test_symbol', trim($symbol));
|
|
$this->setState('list.limit', 0);
|
|
}
|
|
|
|
protected function getListQuery()
|
|
{
|
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
|
$query = $db->getQuery(true)
|
|
->select(['id', 'test_symbol', 'question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer', 'image', 'time_limit', 'points'])
|
|
->from($db->quoteName('#__testquestions_questions'))
|
|
->where($db->quoteName('published') . ' = 1')
|
|
->order($db->quoteName('ordering') . ' ASC, ' . $db->quoteName('id') . ' ASC');
|
|
|
|
$symbol = $this->getState('filter.test_symbol');
|
|
|
|
if ($symbol !== '') {
|
|
$query->where($db->quoteName('test_symbol') . ' = ' . $db->quote($symbol));
|
|
} else {
|
|
$query->where('1 = 0');
|
|
}
|
|
|
|
return $query;
|
|
}
|
|
|
|
public function getTestSymbols()
|
|
{
|
|
$db = Factory::getContainer()->get('DatabaseDriver');
|
|
|
|
return $db->setQuery(
|
|
$db->getQuery(true)
|
|
->select([
|
|
'q.' . $db->quoteName('test_symbol'),
|
|
'q.' . $db->quoteName('exam_year'),
|
|
'c.' . $db->quoteName('title', 'category_title'),
|
|
])
|
|
->from($db->quoteName('#__testquestions_questions', 'q'))
|
|
->leftJoin($db->quoteName('#__testquestions_categories', 'c') . ' ON c.id = q.category_id')
|
|
->where('q.' . $db->quoteName('published') . ' = 1')
|
|
->where('q.' . $db->quoteName('test_symbol') . ' <> ' . $db->quote(''))
|
|
->where('q.' . $db->quoteName('test_symbol') . ' LIKE ' . $db->quote('E%'))
|
|
->group(['q.' . $db->quoteName('test_symbol'), 'q.' . $db->quoteName('exam_year'), 'c.' . $db->quoteName('title')])
|
|
->order('q.' . $db->quoteName('exam_year') . ' DESC, q.' . $db->quoteName('test_symbol') . ' ASC')
|
|
)->loadObjectList();
|
|
}
|
|
}
|