Compare commits

..
1 Commits
Author SHA1 Message Date
Wojtek 301f322017 Show percentages for original and corrected points 2026-10-15 21:39:34 +02:00
7 changed files with 19 additions and 3 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.2). W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.29.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**.
@@ -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,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;
@@ -25,7 +25,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.2</version> <version>1.29.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,
]; ];
} }