Add read-only test question preview
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace Komponent\Component\Testquestions\Administrator\Model;
|
||||
|
||||
defined('_JEXEC') or die;
|
||||
|
||||
use Joomla\CMS\Factory;
|
||||
use Joomla\CMS\MVC\Model\BaseDatabaseModel;
|
||||
|
||||
class PreviewModel extends BaseDatabaseModel
|
||||
{
|
||||
public function getItems(): array
|
||||
{
|
||||
$input = Factory::getApplication()->getInput();
|
||||
$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'])
|
||||
->from($db->quoteName('#__testquestions_questions'))
|
||||
->where($db->quoteName('id') . ' IN (' . implode(',', $ids) . ')')
|
||||
)->loadObjectList('id');
|
||||
|
||||
$items = [];
|
||||
foreach ($ids as $id) {
|
||||
if (isset($rows[$id])) {
|
||||
$items[] = $rows[$id];
|
||||
}
|
||||
}
|
||||
|
||||
return $items;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user