Format exam sheet labels
This commit is contained in:
@@ -21,6 +21,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych.
|
|||||||
|
|
||||||
## Instalacja
|
## Instalacja
|
||||||
|
|
||||||
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.6.1).
|
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.6.2).
|
||||||
|
|
||||||
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
|
||||||
|
|||||||
@@ -0,0 +1 @@
|
|||||||
|
-- Display formatted exam sheet labels on the frontend.
|
||||||
@@ -4,7 +4,7 @@
|
|||||||
<creationDate>2026-10-14</creationDate>
|
<creationDate>2026-10-14</creationDate>
|
||||||
<author>Komponent</author>
|
<author>Komponent</author>
|
||||||
<license>GNU General Public License version 2 or later</license>
|
<license>GNU General Public License version 2 or later</license>
|
||||||
<version>1.6.1</version>
|
<version>1.6.2</version>
|
||||||
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
|
||||||
<element>com_testquestions</element>
|
<element>com_testquestions</element>
|
||||||
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
<namespace path="src">Komponent\Component\Testquestions</namespace>
|
||||||
|
|||||||
@@ -45,14 +45,16 @@ class QuestionsModel extends ListModel
|
|||||||
return $db->setQuery(
|
return $db->setQuery(
|
||||||
$db->getQuery(true)
|
$db->getQuery(true)
|
||||||
->select([
|
->select([
|
||||||
$db->quoteName('test_symbol', 'value'),
|
'q.' . $db->quoteName('test_symbol'),
|
||||||
$db->quoteName('test_symbol', 'text'),
|
'q.' . $db->quoteName('exam_year'),
|
||||||
|
'c.' . $db->quoteName('title', 'category_title'),
|
||||||
])
|
])
|
||||||
->from($db->quoteName('#__testquestions_questions'))
|
->from($db->quoteName('#__testquestions_questions', 'q'))
|
||||||
->where($db->quoteName('published') . ' = 1')
|
->leftJoin($db->quoteName('#__testquestions_categories', 'c') . ' ON c.id = q.category_id')
|
||||||
->where($db->quoteName('test_symbol') . ' <> ' . $db->quote(''))
|
->where('q.' . $db->quoteName('published') . ' = 1')
|
||||||
->group($db->quoteName('test_symbol'))
|
->where('q.' . $db->quoteName('test_symbol') . ' <> ' . $db->quote(''))
|
||||||
->order($db->quoteName('test_symbol') . ' ASC')
|
->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();
|
)->loadObjectList();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,6 +12,32 @@ class HtmlView extends BaseHtmlView
|
|||||||
protected $symbol;
|
protected $symbol;
|
||||||
protected $symbols;
|
protected $symbols;
|
||||||
|
|
||||||
|
public function formatSheetLabel($sheet)
|
||||||
|
{
|
||||||
|
$qualification = (string) ($sheet->category_title ?: '');
|
||||||
|
|
||||||
|
if (preg_match('/^([A-Z]+)(\d+)$/i', $qualification, $matches)) {
|
||||||
|
$qualification = strtoupper($matches[1]) . '.' . $matches[2];
|
||||||
|
}
|
||||||
|
|
||||||
|
$months = [
|
||||||
|
1 => 'Styczeń', 2 => 'Luty', 3 => 'Marzec', 4 => 'Kwiecień',
|
||||||
|
5 => 'Maj', 6 => 'Czerwiec', 7 => 'Lipiec', 8 => 'Sierpień',
|
||||||
|
9 => 'Wrzesień', 10 => 'Październik', 11 => 'Listopad', 12 => 'Grudzień',
|
||||||
|
];
|
||||||
|
$period = '';
|
||||||
|
|
||||||
|
if (preg_match('/-(\d{2})\.(\d{2})$/', (string) $sheet->test_symbol, $matches)) {
|
||||||
|
$month = (int) $matches[2];
|
||||||
|
$year = (int) $sheet->exam_year ?: 2000 + (int) $matches[1];
|
||||||
|
$period = ($months[$month] ?? '') . ' ' . $year;
|
||||||
|
} elseif ($sheet->exam_year) {
|
||||||
|
$period = (string) $sheet->exam_year;
|
||||||
|
}
|
||||||
|
|
||||||
|
return trim('Kwalifikacja ' . $qualification . ($period ? ' - ' . $period : '') . ' (' . $sheet->test_symbol . ')');
|
||||||
|
}
|
||||||
|
|
||||||
public function display($tpl = null)
|
public function display($tpl = null)
|
||||||
{
|
{
|
||||||
$this->items = $this->get('Items');
|
$this->items = $this->get('Items');
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ use Joomla\CMS\HTML\HTMLHelper;
|
|||||||
<select id="test-symbol" name="test_symbol" class="form-select" required>
|
<select id="test-symbol" name="test_symbol" class="form-select" required>
|
||||||
<option value=""><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SELECT_TEST_SYMBOL'); ?></option>
|
<option value=""><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SELECT_TEST_SYMBOL'); ?></option>
|
||||||
<?php foreach ($this->symbols as $symbol) : ?>
|
<?php foreach ($this->symbols as $symbol) : ?>
|
||||||
<option value="<?php echo htmlspecialchars($symbol->value, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $this->symbol === $symbol->value ? 'selected' : ''; ?>><?php echo htmlspecialchars($symbol->text, ENT_QUOTES, 'UTF-8'); ?></option>
|
<option value="<?php echo htmlspecialchars($symbol->test_symbol, ENT_QUOTES, 'UTF-8'); ?>" <?php echo $this->symbol === $symbol->test_symbol ? 'selected' : ''; ?>><?php echo htmlspecialchars($this->formatSheetLabel($symbol), ENT_QUOTES, 'UTF-8'); ?></option>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</select>
|
</select>
|
||||||
<button type="submit" class="btn btn-primary"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SHOW_TEST'); ?></button>
|
<button type="submit" class="btn btn-primary"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SHOW_TEST'); ?></button>
|
||||||
|
|||||||
Reference in New Issue
Block a user