Compare commits

..
9 Commits
13 changed files with 65 additions and 17 deletions
+1 -1
View File
@@ -30,6 +30,6 @@ Szkielet komponentu Joomla 6 do gromadzenia pytań testowych.
## Instalacja
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.36).
W Joomla wybierz **System → Install → Install from Folder** i wskaż ten katalog. Manifestem instalacyjnym jest `com_testquestions.xml` (wersja 1.43.45).
Po instalacji komponent jest dostępny w panelu administratora jako **Pytania testowe**.
@@ -131,6 +131,7 @@ COM_TESTQUESTIONS_RESULT_SCORE="Wynik"
COM_TESTQUESTIONS_RESULT_POINTS_BEFORE_AFTER="Punkty przed / po korekcie"
COM_TESTQUESTIONS_RESULT_GRADE="Ocena"
COM_TESTQUESTIONS_RESULT_NOT_ASSESSED="Nie sprawdzono"
COM_TESTQUESTIONS_RESULT_AI_POINTS_COMMENT="Ocena AI: przyznano %s z %s punktów."
COM_TESTQUESTIONS_RESULT_GENERATE_PDF="Generuj PDF / drukuj"
COM_TESTQUESTIONS_RESULT_DATE="Data zakończenia"
COM_TESTQUESTIONS_RESULT_ANSWERS="Odpowiedzi"
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.37.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.38.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.39.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.40.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.41.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.42.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.43.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.44.
@@ -0,0 +1 @@
-- Brak zmian w schemacie bazy danych w wersji 1.43.45.
@@ -21,7 +21,7 @@ $resolveImageUrl = static function ($path) {
</button>
</div>
<style>
.pdf-only { display: none !important; }
.result-pdf-comment { display: none !important; }
@media print {
@page { size: A4; margin: 15mm; }
.no-print, .toolbar, #toolbar, .subhead, .sidebar-wrapper, #sidebar, .navbar,
@@ -32,8 +32,11 @@ $resolveImageUrl = static function ($path) {
article { break-inside: auto; border-color: #aaa !important; }
img { max-width: 100% !important; max-height: 150mm; object-fit: contain; }
.alert { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.pdf-only { display: block !important; }
.ai-feedback-screen, .ai-token-info { display: none !important; }
.result-question-heading { print-color-adjust: exact; -webkit-print-color-adjust: exact; }
.container-fluid .result-pdf-comment.has-print-comment { display: block !important; }
.result-pdf-comment-text { white-space: pre-wrap; }
.ai-token-info { display: none !important; }
.ai-feedback-screen { display: none !important; }
}
</style>
<script>
@@ -42,6 +45,23 @@ $resolveImageUrl = static function ($path) {
window.print();
});
});
window.addEventListener('beforeprint', function () {
document.querySelectorAll('.result-pdf-comment').forEach(function (commentBlock) {
const questionId = commentBlock.dataset.questionId;
let manualComment = document.getElementById('result-comment-' + questionId)?.value.trim() || '';
if (manualComment === '-' || manualComment === '—') {
manualComment = '';
}
const output = commentBlock.querySelector('.result-pdf-comment-text');
const aiComment = commentBlock.dataset.aiComment || '';
const selectedComment = manualComment || aiComment;
commentBlock.classList.toggle('has-print-comment', Boolean(selectedComment));
if (output && selectedComment) {
output.textContent = selectedComment;
}
});
});
</script>
<dl class="row">
<div class="row"<?php echo (int) $this->item->extra_time > 0 ? ' style="background-color: #fff3cd;"' : ''; ?>>
@@ -103,8 +123,10 @@ $resolveImageUrl = static function ($path) {
</div>
<?php endif; ?>
<h2><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_ANSWERS'); ?></h2>
<?php $questionNumber = 0; ?>
<?php foreach ($this->item->answers as $questionId => $answer) : ?>
<?php $question = $this->item->questions[(int) $questionId] ?? null; if (!$question) continue; ?>
<?php $questionNumber++; ?>
<?php $hasResponse = trim((string) ($answer['selected'] ?? '')) !== ''; ?>
<?php
$answerStatusCorrect = !empty($answer['correct']);
@@ -116,11 +138,24 @@ $resolveImageUrl = static function ($path) {
$answerStatusPartial = $awardedPoints > 0 && !$answerStatusCorrect;
}
$manualComment = trim((string) ($answer['comment'] ?? ''));
if ($manualComment === '-' || $manualComment === '—') {
$manualComment = '';
}
$aiComment = trim((string) ($answer['ai_feedback'] ?? ''));
if ($aiComment === '' && (array_key_exists('ai_feedback', $answer) || !empty($answer['ai_usage']) || !empty($answer['ai_usage_history']))) {
$aiComment = \Joomla\CMS\Language\Text::sprintf(
'COM_TESTQUESTIONS_RESULT_AI_POINTS_COMMENT',
(int) ($answer['awarded_points'] ?? 0),
(int) ($question->points ?? 0)
);
}
$printComment = $manualComment !== '' ? $manualComment : $aiComment;
?>
<article class="mb-4 border rounded p-3">
<div class="mb-2"><?php echo $question->question; ?></div>
<div class="result-question-heading d-flex align-items-start gap-2 mb-3 p-3 bg-light border-start border-4 border-primary rounded">
<span class="badge text-bg-primary flex-shrink-0"><?php echo $questionNumber; ?>.</span>
<div class="fw-semibold"><?php echo $question->question; ?></div>
</div>
<?php if (!empty($question->image)) : ?><div class="mb-3"><img src="<?php echo htmlspecialchars($resolveImageUrl($question->image), ENT_QUOTES, 'UTF-8'); ?>" alt="" loading="lazy" style="max-width: 100%; height: auto;"></div><?php endif; ?>
<?php if ($question->question_type === 'open') : ?>
<div><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_YOUR_ANSWER'); ?>:</strong> <?php echo htmlspecialchars($answer['selected'] ?: '—', ENT_QUOTES, 'UTF-8'); ?></div>
@@ -129,8 +164,19 @@ $resolveImageUrl = static function ($path) {
<div><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_SELECTED_ANSWER'); ?>:</strong> <?php echo $answer['selected'] ? chr(64 + (int) $answer['selected']) : '—'; ?></div>
<?php endif; ?>
<div class="mt-2 <?php echo $answerStatusCorrect ? 'text-success' : ($answerStatusPartial ? 'text-warning' : 'text-danger'); ?>"><?php echo $answerStatusCorrect ? '✓ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_CORRECT') : ($answerStatusPartial ? '◐ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_PARTIALLY_CORRECT') : '✗ ' . \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_ANSWER_INCORRECT')); ?></div>
<?php if ($printComment !== '') : ?>
<div class="pdf-only mt-3"><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_COMMENT'); ?>:</strong><br><?php echo nl2br(htmlspecialchars($printComment, ENT_QUOTES, 'UTF-8')); ?></div>
<?php if ($question->question_type === 'open') : ?>
<div class="result-pdf-comment mt-3<?php echo $printComment !== '' ? ' has-print-comment' : ''; ?>" data-question-id="<?php echo (int) $questionId; ?>" data-ai-comment="<?php echo htmlspecialchars($aiComment, ENT_QUOTES, 'UTF-8'); ?>">
<strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_RESULT_COMMENT'); ?>:</strong><br>
<span class="result-pdf-comment-text"><?php echo nl2br(htmlspecialchars($printComment, ENT_QUOTES, 'UTF-8')); ?></span>
</div>
<?php endif; ?>
<?php if ($question->question_type === 'open' && !empty($answer['ai_feedback'])) : ?>
<?php
$aiPoints = (int) ($answer['awarded_points'] ?? 0);
$maxPoints = (int) ($question->points ?? 0);
$aiAlertClass = $aiPoints <= 0 ? 'alert-danger' : ($aiPoints >= $maxPoints ? 'alert-success' : 'alert-info');
?>
<div class="alert <?php echo $aiAlertClass; ?> mt-3 ai-feedback-screen" data-question-id="<?php echo (int) $questionId; ?>"><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_RESULT'); ?>:</strong><br><span class="ai-feedback-text"><?php echo nl2br(htmlspecialchars((string) $answer['ai_feedback'], ENT_QUOTES, 'UTF-8')); ?></span></div>
<?php endif; ?>
<?php if (empty($answer['correct'])) : ?>
<?php if ($question->question_type === 'open' && $hasResponse) : ?>
@@ -150,17 +196,9 @@ $resolveImageUrl = static function ($path) {
</span>
<?php endif; ?>
</div>
<?php if (!empty($answer['ai_feedback'])) : ?>
<?php
$aiPoints = (int) ($answer['awarded_points'] ?? 0);
$maxPoints = (int) ($question->points ?? 0);
$aiAlertClass = $aiPoints <= 0 ? 'alert-danger' : ($aiPoints >= $maxPoints ? 'alert-success' : 'alert-info');
?>
<div class="alert <?php echo $aiAlertClass; ?> mt-3 ai-feedback-screen"><strong><?php echo \Joomla\CMS\Language\Text::_('COM_TESTQUESTIONS_AI_RESULT'); ?>:</strong><br><?php echo nl2br(htmlspecialchars((string) $answer['ai_feedback'], ENT_QUOTES, 'UTF-8')); ?></div>
<?php endif; ?>
<?php endif; ?>
<?php if ($question->question_type === 'open' && $hasResponse) : ?>
<div class="row mt-3">
<div class="row mt-3 no-print">
<div class="col-md-3">
<label for="awarded-points-<?php echo (int) $questionId; ?>" class="form-label"><?php echo \Joomla\CMS\Language\Text::sprintf('COM_TESTQUESTIONS_RESULT_AWARDED_POINTS', (int) ($question->points ?? 0)); ?></label>
<input type="number" min="0" max="<?php echo (int) ($question->points ?? 0); ?>" name="awarded_points[<?php echo (int) $questionId; ?>]" id="awarded-points-<?php echo (int) $questionId; ?>" class="form-control" value="<?php echo (int) ($answer['awarded_points'] ?? 0); ?>">
+1 -1
View File
@@ -4,7 +4,7 @@
<creationDate>2026-10-14</creationDate>
<author>Komponent</author>
<license>GNU General Public License version 2 or later</license>
<version>1.43.36</version>
<version>1.43.45</version>
<description>COM_TESTQUESTIONS_DESCRIPTION</description>
<element>com_testquestions</element>
<namespace path="src">Komponent\Component\Testquestions</namespace>