Add read-only preview for question sets
This commit is contained in:
@@ -9,16 +9,47 @@ use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
||||
class PreviewModel extends BaseDatabaseModel
|
||||
{
|
||||
public function getSet()
|
||||
{
|
||||
$setId = Factory::getApplication()->getInput()->getInt('set_id');
|
||||
if ($setId < 1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['id', 'title', 'test_content', 'image'])
|
||||
->from($db->quoteName('#__testquestions_sets'))
|
||||
->where($db->quoteName('id') . ' = ' . $setId)
|
||||
)->loadObject();
|
||||
}
|
||||
|
||||
public function getItems(): array
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$setId = $input->getInt('set_id');
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
|
||||
if ($setId > 0) {
|
||||
return $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['q.id', 'q.question_type', 'q.question', 'q.answer_a', 'q.answer_b', 'q.answer_c', 'q.answer_d', 'q.answer_open', 'q.correct_answer', 'q.image'])
|
||||
->from($db->quoteName('#__testquestions_set_questions', 'sq'))
|
||||
->innerJoin($db->quoteName('#__testquestions_questions', 'q') . ' ON q.id = sq.question_id')
|
||||
->where('sq.set_id = ' . $setId)
|
||||
->where('q.published = 1')
|
||||
->order('sq.ordering ASC, q.id ASC')
|
||||
)->loadObjectList();
|
||||
}
|
||||
|
||||
$ids = array_values(array_unique(array_filter(array_map('intval', explode(',', $input->getString('ids', ''))))));
|
||||
|
||||
if (!$ids) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$db = Factory::getContainer()->get('DatabaseDriver');
|
||||
$rows = $db->setQuery(
|
||||
$db->getQuery(true)
|
||||
->select(['id', 'question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer', 'image'])
|
||||
|
||||
@@ -7,11 +7,13 @@ defined('_JEXEC') or die;
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\Language\Text;
|
||||
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
|
||||
use Joomla\CMS\Router\Route;
|
||||
use Joomla\CMS\Toolbar\ToolbarHelper;
|
||||
|
||||
class HtmlView extends BaseHtmlView
|
||||
{
|
||||
protected $items = [];
|
||||
protected $set;
|
||||
|
||||
public function display($tpl = null)
|
||||
{
|
||||
@@ -21,12 +23,19 @@ class HtmlView extends BaseHtmlView
|
||||
}
|
||||
|
||||
$this->items = $this->get('Items');
|
||||
$this->set = $this->get('Set');
|
||||
$this->getDocument()->getWebAssetManager()->registerAndUseStyle(
|
||||
'com_testquestions.exam',
|
||||
'media/com_testquestions/egzamin.css'
|
||||
);
|
||||
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_PREVIEW_TITLE'));
|
||||
ToolbarHelper::link('index.php?option=com_testquestions&view=questions', 'COM_TESTQUESTIONS', 'arrow-left');
|
||||
ToolbarHelper::link(
|
||||
$this->set
|
||||
? Route::_('index.php?option=com_testquestions&task=set.edit&id=' . (int) $this->set->id)
|
||||
: Route::_('index.php?option=com_testquestions&view=questions'),
|
||||
$this->set ? 'COM_TESTQUESTIONS_EDIT_SET' : 'COM_TESTQUESTIONS',
|
||||
'arrow-left'
|
||||
);
|
||||
|
||||
return parent::display($tpl);
|
||||
}
|
||||
|
||||
@@ -47,6 +47,13 @@ class HtmlView extends BaseHtmlView
|
||||
protected function addToolbar()
|
||||
{
|
||||
ToolbarHelper::title($this->item->id ? Text::_('COM_TESTQUESTIONS_EDIT_SET') : Text::_('COM_TESTQUESTIONS_NEW_SET'));
|
||||
if (!empty($this->item->id) && ((string) $this->item->set_type !== 'multi' || $this->isVariant)) {
|
||||
ToolbarHelper::link(
|
||||
'index.php?option=com_testquestions&view=preview&set_id=' . (int) $this->item->id,
|
||||
'COM_TESTQUESTIONS_PREVIEW_SET',
|
||||
'eye'
|
||||
);
|
||||
}
|
||||
ToolbarHelper::custom('set.save', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE', false);
|
||||
ToolbarHelper::custom('set.saveandclose', 'save', 'save', 'COM_TESTQUESTIONS_SET_SAVE_AND_CLOSE', false);
|
||||
ToolbarHelper::cancel('set.cancel', 'JTOOLBAR_CANCEL');
|
||||
|
||||
Reference in New Issue
Block a user