Compare commits

..
4 Commits
Author SHA1 Message Date
Wojtek 3fd488e19e Add result list date and test filters 2026-10-15 21:41:34 +02:00
Wojtek 301f322017 Show percentages for original and corrected points 2026-10-15 21:39:34 +02:00
Wojtek 987373b565 Set result toolbar labels 2026-10-15 21:37:06 +02:00
Wojtek 96bdb73450 Fix save and close toolbar button 2026-10-15 21:34:41 +02:00
13 changed files with 62 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.30.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**.
@@ -74,7 +74,12 @@ 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_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.
@@ -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.test_name', $this->getUserStateFromRequest($this->context . '.filter.test_name', 'filter_test_name', '', 'string'));
$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,22 @@ 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 . ')');
} }
$testName = trim((string) $this->getState('filter.test_name'));
if ($testName !== '') {
$needle = $db->quote('%' . $db->escape($testName, true) . '%', false);
$query->where('s.title LIKE ' . $needle);
}
$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');
} }
} }
@@ -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);
@@ -10,7 +10,20 @@ 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 class="col-md-6">
<input type="text" name="filter_test_name" value="<?php echo $this->escape($this->state->get('filter.test_name')); ?>" class="form-control" placeholder="<?php echo $this->escape(\Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULTS_TEST_NAME')); ?>">
</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>
@@ -25,7 +38,10 @@ 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; ?>
<td><?php echo (int) $item->points_before; ?> (<?php echo $pointsBeforePercentage; ?>%) / <?php echo (int) $item->points_after; ?> (<?php echo $pointsAfterPercentage; ?>%)</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.30.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,
]; ];
} }