Compare commits

..
7 Commits
18 changed files with 103 additions and 6 deletions
+1 -1
View File
@@ -30,6 +30,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.28.0). W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.33.0).
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**. Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
@@ -68,13 +68,20 @@ COM_TESTQUESTIONS_RESULT_NOT_FOUND="Nie znaleziono zapisanego testu."
COM_TESTQUESTIONS_RESULT_PARTICIPANT="Użytkownik" COM_TESTQUESTIONS_RESULT_PARTICIPANT="Użytkownik"
COM_TESTQUESTIONS_RESULT_SCORE="Wynik" COM_TESTQUESTIONS_RESULT_SCORE="Wynik"
COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER="Punkty przed / po korekcie" COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER="Punkty przed / po korekcie"
COM_TESTQUESTIONS_RESULT_GRADE="Ocena"
COM_TESTQUESTIONS_RESULT_DATE="Data zakończenia" COM_TESTQUESTIONS_RESULT_DATE="Data zakończenia"
COM_TESTQUESTIONS_RESULT_ANSWERS="Odpowiedzi" COM_TESTQUESTIONS_RESULT_ANSWERS="Odpowiedzi"
COM_TESTQUESTIONS_RESULT_EXECUTION_TIME="Czas wykonania" COM_TESTQUESTIONS_RESULT_EXECUTION_TIME="Czas wykonania"
COM_TESTQUESTIONS_RESULT_AWARDED_POINTS="Uznane punkty (maksymalnie %s)" COM_TESTQUESTIONS_RESULT_AWARDED_POINTS="Uznane punkty (maksymalnie %s)"
COM_TESTQUESTIONS_RESULT_COMMENT="Komentarz" COM_TESTQUESTIONS_RESULT_COMMENT="Komentarz"
COM_TESTQUESTIONS_RESULT_SAVED="Dane wyniku zostały zapisane." COM_TESTQUESTIONS_RESULT_SAVED="Dane wyniku zostały zapisane."
COM_TESTQUESTIONS_RESULT_SAVE="Zapisz"
COM_TESTQUESTIONS_RESULT_SAVE_AND_CLOSE="Zapisz i zamknij"
COM_TESTQUESTIONS_RESULTS_SEARCH="Szukaj po użytkowniku lub zestawie..." COM_TESTQUESTIONS_RESULTS_SEARCH="Szukaj po użytkowniku lub zestawie..."
COM_TESTQUESTIONS_RESULTS_TEST_NAME="Nazwa testu"
COM_TESTQUESTIONS_RESULTS_ALL_TESTS="Wszystkie zestawy"
COM_TESTQUESTIONS_RESULTS_DATE_FROM="Data od"
COM_TESTQUESTIONS_RESULTS_DATE_TO="Data do"
COM_TESTQUESTIONS_YOUR_ANSWER="Twoja odpowiedź" COM_TESTQUESTIONS_YOUR_ANSWER="Twoja odpowiedź"
COM_TESTQUESTIONS_SELECTED_ANSWER="Zaznaczona odpowiedź" COM_TESTQUESTIONS_SELECTED_ANSWER="Zaznaczona odpowiedź"
COM_TESTQUESTIONS_ANSWER_CORRECT="Poprawna odpowiedź" COM_TESTQUESTIONS_ANSWER_CORRECT="Poprawna odpowiedź"
@@ -84,6 +84,7 @@ CREATE TABLE IF NOT EXISTS `#__testquestions_results` (
`correct_count` smallint unsigned NOT NULL DEFAULT 0, `correct_count` smallint unsigned NOT NULL DEFAULT 0,
`total_count` smallint unsigned NOT NULL DEFAULT 0, `total_count` smallint unsigned NOT NULL DEFAULT 0,
`percentage` decimal(5,2) NOT NULL DEFAULT 0.00, `percentage` decimal(5,2) NOT NULL DEFAULT 0.00,
`points_total` int unsigned NOT NULL DEFAULT 0,
`points_before` int unsigned NOT NULL DEFAULT 0, `points_before` int unsigned NOT NULL DEFAULT 0,
`points_after` int unsigned NOT NULL DEFAULT 0, `points_after` int unsigned NOT NULL DEFAULT 0,
`answers` longtext NULL, `answers` longtext NULL,
@@ -0,0 +1 @@
-- No database changes required for version 1.28.1.
@@ -0,0 +1 @@
-- No database changes required for version 1.28.2.
@@ -0,0 +1,6 @@
ALTER TABLE `#__testquestions_results`
ADD COLUMN `points_total` int unsigned NOT NULL DEFAULT 0 AFTER `percentage`;
UPDATE `#__testquestions_results`
SET `points_total` = `total_count`
WHERE `points_total` = 0;
@@ -0,0 +1 @@
-- No database changes required for version 1.30.0.
@@ -0,0 +1 @@
-- No database changes required for version 1.31.0.
@@ -0,0 +1 @@
-- No database changes required for version 1.32.0.
@@ -0,0 +1 @@
-- No database changes required for version 1.33.0.
@@ -13,6 +13,9 @@ class ResultsModel extends ListModel
{ {
parent::populateState($ordering, $direction); parent::populateState($ordering, $direction);
$this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string')); $this->setState('filter.search', $this->getUserStateFromRequest($this->context . '.filter.search', 'filter_search', '', 'string'));
$this->setState('filter.set_id', $this->getUserStateFromRequest($this->context . '.filter.set_id', 'filter_set_id', 0, 'int'));
$this->setState('filter.date_from', $this->getUserStateFromRequest($this->context . '.filter.date_from', 'filter_date_from', '', 'string'));
$this->setState('filter.date_to', $this->getUserStateFromRequest($this->context . '.filter.date_to', 'filter_date_to', '', 'string'));
} }
protected function getListQuery() protected function getListQuery()
@@ -30,6 +33,34 @@ class ResultsModel extends ListModel
$query->where('(r.participant_name LIKE ' . $needle . ' OR s.title LIKE ' . $needle . ')'); $query->where('(r.participant_name LIKE ' . $needle . ' OR s.title LIKE ' . $needle . ')');
} }
$setId = (int) $this->getState('filter.set_id');
if ($setId > 0) {
$query->where('r.set_id = ' . $setId);
}
$dateFrom = (string) $this->getState('filter.date_from');
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateFrom)) {
$query->where('r.created >= ' . $db->quote($dateFrom . ' 00:00:00'));
}
$dateTo = (string) $this->getState('filter.date_to');
if (preg_match('/^\d{4}-\d{2}-\d{2}$/', $dateTo)) {
$query->where('r.created <= ' . $db->quote($dateTo . ' 23:59:59'));
}
return $query->order('r.created DESC, r.id DESC'); return $query->order('r.created DESC, r.id DESC');
} }
public function getSets(): array
{
$db = Factory::getContainer()->get('DatabaseDriver');
return $db->setQuery(
$db->getQuery(true)
->select(['s.id', 's.title', 's.published', 'sub.title AS subject_title'])
->from($db->quoteName('#__testquestions_sets', 's'))
->leftJoin($db->quoteName('#__testquestions_subjects', 'sub') . ' ON sub.id = s.subject_id')
->order('sub.title ASC, s.title ASC, s.id ASC')
)->loadObjectList();
}
} }
@@ -21,8 +21,8 @@ class HtmlView extends BaseHtmlView
} }
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULT_PREVIEW')); ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULT_PREVIEW'));
ToolbarHelper::save('result.save', 'JTOOLBAR_SAVE'); ToolbarHelper::save('result.save', 'COM_TESTQUESTIONS_RESULT_SAVE');
ToolbarHelper::save2close('result.save2close', 'JTOOLBAR_SAVE_AND_CLOSE'); ToolbarHelper::custom('result.save2close', 'save', 'save', 'COM_TESTQUESTIONS_RESULT_SAVE_AND_CLOSE', false);
ToolbarHelper::link('index.php?option=com_testquestions&view=results', 'COM_TESTQUESTIONS_RESULTS', 'back'); ToolbarHelper::link('index.php?option=com_testquestions&view=results', 'COM_TESTQUESTIONS_RESULTS', 'back');
return parent::display($tpl); return parent::display($tpl);
@@ -14,12 +14,14 @@ class HtmlView extends BaseHtmlView
protected $items; protected $items;
protected $pagination; protected $pagination;
protected $state; protected $state;
protected $sets;
public function display($tpl = null) public function display($tpl = null)
{ {
$this->items = $this->get('Items'); $this->items = $this->get('Items');
$this->pagination = $this->get('Pagination'); $this->pagination = $this->get('Pagination');
$this->state = $this->get('State'); $this->state = $this->get('State');
$this->sets = $this->get('Sets');
ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS')); ToolbarHelper::title(Text::_('COM_TESTQUESTIONS_RESULTS'));
ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back'); ToolbarHelper::link('index.php?option=com_testquestions&view=sets', 'COM_TESTQUESTIONS_SETS', 'back');
@@ -13,6 +13,14 @@
<dd class="col-sm-9"><?php echo (int) $this->item->correct_count; ?> / <?php echo (int) $this->item->total_count; ?> (<?php echo htmlspecialchars((string) $this->item->percentage, ENT_QUOTES, 'UTF-8'); ?>%)</dd> <dd class="col-sm-9"><?php echo (int) $this->item->correct_count; ?> / <?php echo (int) $this->item->total_count; ?> (<?php echo htmlspecialchars((string) $this->item->percentage, ENT_QUOTES, 'UTF-8'); ?>%)</dd>
<dt class="col-sm-3"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></dt> <dt class="col-sm-3"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></dt>
<dd class="col-sm-9"><?php echo (int) $this->item->points_before; ?> / <?php echo (int) $this->item->points_after; ?></dd> <dd class="col-sm-9"><?php echo (int) $this->item->points_before; ?> / <?php echo (int) $this->item->points_after; ?></dd>
<?php $pointsTotal = (int) $this->item->points_total ?: (int) $this->item->total_count; ?>
<?php $pointsAfterPercentage = $pointsTotal ? round(((int) $this->item->points_after / $pointsTotal) * 100, 2) : 0; ?>
<?php $grade = 'NDST'; ?>
<?php foreach ([['CEL', 100], ['BDB', 90], ['BDB-', 80], ['DB+', 75], ['DB', 70], ['DB-', 65], ['DST+', 60], ['DST', 55], ['DST-', 50], ['DOP+', 45], ['DOP', 40], ['DOP-', 35], ['NDST+', 30], ['NDST', 0]] as $gradeScale) : ?>
<?php if ($pointsAfterPercentage >= $gradeScale[1]) { $grade = $gradeScale[0]; break; } ?>
<?php endforeach; ?>
<dt class="col-sm-3"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_GRADE'); ?></dt>
<dd class="col-sm-9"><?php echo $this->escape($grade); ?></dd>
<dt class="col-sm-3"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_EXECUTION_TIME'); ?></dt> <dt class="col-sm-3"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_EXECUTION_TIME'); ?></dt>
<dd class="col-sm-9"><?php echo floor((int) $this->item->execution_time / 60); ?>:<?php echo str_pad((string) ((int) $this->item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?></dd> <dd class="col-sm-9"><?php echo floor((int) $this->item->execution_time / 60); ?>:<?php echo str_pad((string) ((int) $this->item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?></dd>
</dl> </dl>
@@ -10,13 +10,35 @@ use Joomla\CMS\Router\Route;
<div class="col-md-6"> <div class="col-md-6">
<input type="text" name="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" class="form-control" placeholder="<?php echo $this->escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_SEARCH')); ?>"> <input type="text" name="filter_search" value="<?php echo $this->escape($this->state->get('filter.search')); ?>" class="form-control" placeholder="<?php echo $this->escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_SEARCH')); ?>">
</div> </div>
<div class="col-md-3"><button type="submit" class="btn btn-primary"><?php echo \Joomla\CMS\Language\Text::_('JSEARCH_FILTER_SUBMIT'); ?></button></div> </div>
<div class="row mb-3">
<div class="col-md-6">
<label for="filter-set-id" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_TEST_NAME'); ?></label>
<select name="filter_set_id" id="filter-set-id" class="form-select">
<option value="0"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_ALL_TESTS'); ?></option>
<?php foreach ($this->sets as $set) : ?>
<option value="<?php echo (int) $set->id; ?>" <?php echo (int) $this->state->get('filter.set_id') === (int) $set->id ? 'selected' : ''; ?>><?php echo $this->escape(($set->subject_title ? $set->subject_title . ' — ' : '') . $set->title . (!(int) $set->published ? ' (nieopublikowany)' : '')); ?></option>
<?php endforeach; ?>
</select>
</div>
</div>
<div class="row mb-3">
<div class="col-md-3">
<label for="filter-date-from" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_DATE_FROM'); ?></label>
<input type="date" name="filter_date_from" id="filter-date-from" value="<?php echo $this->escape($this->state->get('filter.date_from')); ?>" class="form-control">
</div>
<div class="col-md-3">
<label for="filter-date-to" class="form-label"><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_DATE_TO'); ?></label>
<input type="date" name="filter_date_to" id="filter-date-to" value="<?php echo $this->escape($this->state->get('filter.date_to')); ?>" class="form-control">
</div>
<div class="col-md-3 align-self-end"><button type="submit" class="btn btn-primary"><?php echo \Joomla\CMS\Language\Text::_('JSEARCH_FILTER_SUBMIT'); ?></button></div>
</div> </div>
<table class="table table-striped"> <table class="table table-striped">
<thead><tr> <thead><tr>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_PARTICIPANT'); ?></th> <th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_PARTICIPANT'); ?></th>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TITLE'); ?></th> <th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SET_TITLE'); ?></th>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></th> <th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER'); ?></th>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_GRADE'); ?></th>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_EXECUTION_TIME'); ?></th> <th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_EXECUTION_TIME'); ?></th>
<th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_DATE'); ?></th> <th><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_DATE'); ?></th>
</tr></thead> </tr></thead>
@@ -25,7 +47,15 @@ use Joomla\CMS\Router\Route;
<tr class="<?php echo (int) $item->extra_time > 0 ? 'table-warning' : ''; ?>"> <tr class="<?php echo (int) $item->extra_time > 0 ? 'table-warning' : ''; ?>">
<th><a href="<?php echo Route::_('index.php?option=com_testquestions&view=result&id=' . (int) $item->id); ?>"><?php echo $this->escape($item->participant_name); ?></a></th> <th><a href="<?php echo Route::_('index.php?option=com_testquestions&view=result&id=' . (int) $item->id); ?>"><?php echo $this->escape($item->participant_name); ?></a></th>
<td><?php echo $this->escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?></td> <td><?php echo $this->escape(($item->subject_title ? $item->subject_title . ' — ' : '') . $item->set_title); ?></td>
<td><?php echo (int) $item->points_before; ?> / <?php echo (int) $item->points_after; ?></td> <?php $pointsTotal = (int) $item->points_total ?: (int) $item->total_count; ?>
<?php $pointsBeforePercentage = $pointsTotal ? round(((int) $item->points_before / $pointsTotal) * 100, 2) : 0; ?>
<?php $pointsAfterPercentage = $pointsTotal ? round(((int) $item->points_after / $pointsTotal) * 100, 2) : 0; ?>
<?php $grade = 'NDST'; ?>
<?php foreach ([['CEL', 100], ['BDB', 90], ['BDB-', 80], ['DB+', 75], ['DB', 70], ['DB-', 65], ['DST+', 60], ['DST', 55], ['DST-', 50], ['DOP+', 45], ['DOP', 40], ['DOP-', 35], ['NDST+', 30], ['NDST', 0]] as $gradeScale) : ?>
<?php if ($pointsAfterPercentage >= $gradeScale[1]) { $grade = $gradeScale[0]; break; } ?>
<?php endforeach; ?>
<td><?php echo (int) $item->points_before; ?> (<?php echo $pointsBeforePercentage; ?>%) / <?php echo (int) $item->points_after; ?> (<?php echo $pointsAfterPercentage; ?>%)</td>
<td><?php echo $this->escape($grade); ?></td>
<td><?php echo floor((int) $item->execution_time / 60); ?>:<?php echo str_pad((string) ((int) $item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?></td> <td><?php echo floor((int) $item->execution_time / 60); ?>:<?php echo str_pad((string) ((int) $item->execution_time % 60), 2, '0', STR_PAD_LEFT); ?></td>
<td><?php echo HTMLHelper::_('date', $item->created, 'Y-m-d H:i'); ?></td> <td><?php echo HTMLHelper::_('date', $item->created, 'Y-m-d H:i'); ?></td>
</tr> </tr>
+1 -1
View File
@@ -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.28.0</version> <version>1.33.0</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>
@@ -82,7 +82,9 @@ class SetModel extends BaseDatabaseModel
} }
$pointsBefore = 0; $pointsBefore = 0;
$pointsTotal = 0;
foreach (($result['items'] ?? []) as $item) { foreach (($result['items'] ?? []) as $item) {
$pointsTotal += (int) ($item['points'] ?? 0);
if (!empty($item['correct'])) { if (!empty($item['correct'])) {
$pointsBefore += (int) ($item['points'] ?? 0); $pointsBefore += (int) ($item['points'] ?? 0);
} }
@@ -97,6 +99,7 @@ class SetModel extends BaseDatabaseModel
'correct_count' => (int) ($result['correct'] ?? 0), 'correct_count' => (int) ($result['correct'] ?? 0),
'total_count' => (int) ($result['total'] ?? 0), 'total_count' => (int) ($result['total'] ?? 0),
'percentage' => (float) ($result['percentage'] ?? 0), 'percentage' => (float) ($result['percentage'] ?? 0),
'points_total' => $pointsTotal,
'points_before' => $pointsBefore, 'points_before' => $pointsBefore,
'points_after' => $pointsBefore, 'points_after' => $pointsBefore,
'answers' => json_encode($result['items'] ?? [], JSON_UNESCAPED_UNICODE), 'answers' => json_encode($result['items'] ?? [], JSON_UNESCAPED_UNICODE),
@@ -85,6 +85,9 @@ class HtmlView extends BaseHtmlView
'items' => $results, 'items' => $results,
'correct' => $correct, 'correct' => $correct,
'total' => count($items), 'total' => count($items),
'points_total' => array_sum(array_map(static function ($item) {
return (int) ($item->points ?? 0);
}, $items)),
'percentage' => count($items) ? round(($correct / count($items)) * 100, 2) : 0, 'percentage' => count($items) ? round(($correct / count($items)) * 100, 2) : 0,
]; ];
} }