Initial Joomla test questions component

This commit is contained in:
Wojtek
2026-10-14 22:29:10 +02:00
commit 9b093b278d
44 changed files with 964 additions and 0 deletions
@@ -0,0 +1,2 @@
COM_TESTQUESTIONS="Pytania testowe"
COM_TESTQUESTIONS_ENTER_ANSWER="Wpisz odpowiedź"
@@ -0,0 +1,12 @@
<?php
namespace Komponent\Component\Testquestions\Site\Controller;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\Controller\BaseController;
class DisplayController extends BaseController
{
protected $default_view = 'questions';
}
@@ -0,0 +1,21 @@
<?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 getListQuery()
{
$db = Factory::getContainer()->get('DatabaseDriver');
return $db->getQuery(true)
->select(['question_type', 'question', 'answer_a', 'answer_b', 'answer_c', 'answer_d', 'answer_open', 'correct_answer', 'image'])
->from($db->quoteName('#__testquestions_questions'))
->where($db->quoteName('published') . ' = 1')
->order($db->quoteName('ordering') . ' ASC, ' . $db->quoteName('id') . ' ASC');
}
}
@@ -0,0 +1,18 @@
<?php
namespace Komponent\Component\Testquestions\Site\View\Questions;
defined('_JEXEC') or die;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
class HtmlView extends BaseHtmlView
{
protected $items;
public function display($tpl = null)
{
$this->items = $this->get('Items');
return parent::display($tpl);
}
}
@@ -0,0 +1,28 @@
<?php
defined('_JEXEC') or die;
use Joomla\CMS\HTML\HTMLHelper;
?>
<div class="com-testquestions">
<h1><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS'); ?></h1>
<?php foreach ($this->items as $number => $item) : ?>
<article class="testquestion mb-4">
<h2><?php echo ($number + 1) . '. '; ?><?php echo $item->question; ?></h2>
<?php if ($item->image) : ?>
<img src="<?php echo htmlspecialchars($item->image, ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy">
<?php endif; ?>
<?php if ($item->question_type === 'open') : ?>
<label for="answer-<?php echo (int) $number; ?>"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ENTER_ANSWER'); ?></label>
<input type="text" id="answer-<?php echo (int) $number; ?>" name="answers[<?php echo (int) $number; ?>]" class="form-control">
<?php else : ?>
<ol type="A">
<li><?php echo $item->answer_a; ?></li>
<li><?php echo $item->answer_b; ?></li>
<li><?php echo $item->answer_c; ?></li>
<li><?php echo $item->answer_d; ?></li>
</ol>
<?php endif; ?>
</article>
<?php endforeach; ?>
</div>