Skip to content

Commit cc87025

Browse files
nhaagenkergomard
authored andcommitted
Test: Show Autosave Content
See: https://mantis.ilias.de/view.php?id=37918 TA: minor glitches in rendering TA: 37918, cleanup TA: 37918, NumericQuestion
1 parent 5fc626d commit cc87025

22 files changed

Lines changed: 746 additions & 213 deletions

components/ILIAS/Test/src/Results/Data/Factory.php

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -250,20 +250,21 @@ private function buildAttemptResults(
250250
$show_inline_feedback
251251
);
252252

253-
if ($test_obj->getAutosave() &&
254-
$type === 'assTextQuestion'
255-
) {
256-
$usr_solution .= $question_gui->getAutoSavedSolutionOutput(
253+
$autosave_output = null;
254+
$show_autosave_title = false;
255+
if ($test_obj->getAutosave()) {
256+
$autosave_output = $question_gui->getAutoSavedSolutionOutput(
257257
$active_id,
258258
$attempt_id,
259-
false,
260-
false,
261-
false,
262-
false,
263-
false,
264-
false,
265-
false,
266-
true
259+
$graphical_output,
260+
$result_output,
261+
$show_question_only,
262+
$show_feedback,
263+
$show_correct_solution,
264+
$show_manual_scoring,
265+
$show_question_text,
266+
$show_autosave_title,
267+
$show_inline_feedback
267268
);
268269
}
269270

@@ -308,7 +309,8 @@ private function buildAttemptResults(
308309
$workedthrough,
309310
$answered,
310311
$requested_hints,
311-
$recapitulation
312+
$recapitulation,
313+
$autosave_output
312314
);
313315
}
314316

components/ILIAS/Test/src/Results/Data/QuestionResult.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ public function __construct(
3838
private readonly bool $workedthrough,
3939
private readonly bool $answered,
4040
private readonly int $requested_hints,
41-
private readonly ?string $content_for_recapitulation
41+
private readonly ?string $content_for_recapitulation,
42+
private readonly ?string $autosaved_answer
4243
) {
4344
}
4445

@@ -108,4 +109,9 @@ public function getNumberOfRequestedHints(): int
108109
{
109110
return $this->requested_hints;
110111
}
112+
public function getAutosavedAnswer(): ?string
113+
{
114+
return $this->autosaved_answer;
115+
}
116+
111117
}

components/ILIAS/Test/src/Results/Presentation/AttemptResultsTable.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,9 +224,15 @@ private function getMapping(): \Closure
224224
]);
225225
}
226226

227-
$user_answer = $question->getUserAnswer();
227+
$listing = [
228+
$lng->txt('tst_header_participant') => $question->getUserAnswer()
229+
];
230+
if ($autosave_content = $question->getAutosavedAnswer()) {
231+
$listing[$lng->txt('autosavecontent')] = $autosave_content;
232+
}
233+
228234
$answer_contents = [
229-
$ui_factory->listing()->descriptive([$lng->txt('tst_header_participant') => $user_answer])
235+
$ui_factory->listing()->descriptive($listing)
230236
];
231237
if ($env->getShowBestSolution()) {
232238
$answer_contents[] = $ui_factory->listing()->descriptive([

components/ILIAS/Test/src/Scoring/Manual/class.TestScoringByParticipantGUI.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,11 +390,12 @@ private function buildManScoringParticipantForm(
390390
$form->setTitle(sprintf($this->lng->txt('manscoring_results_pass'), $pass + 1));
391391
$form->setTableWidth('100%');
392392

393+
$autosave_enabled = $this->object->getAutosave();
394+
$show_solutions_enabled = $this->object->getShowSolutionFeedback();
393395
foreach ($question_gui_list as $question_id => $question_gui) {
394396
$question_header = sprintf($this->lng->txt('tst_manscoring_question_section_header'), $question_gui->getObject()->getTitle());
395397
$question_solution = $question_gui->getSolutionOutput($active_id, $pass, false, false, true, false, false, true);
396398
$best_solution = $question_gui->getObject()->getSuggestedSolutionOutput();
397-
398399
$feedback = \ilObjTest::getSingleManualFeedback($active_id, $question_id, $pass);
399400

400401
$disabled = false;
@@ -410,6 +411,25 @@ private function buildManScoringParticipantForm(
410411
$cust->setHtml($question_solution);
411412
$form->addItem($cust);
412413

414+
if ($autosave_enabled) {
415+
$aresult_output = $question_gui->getAutoSavedSolutionOutput(
416+
$active_id,
417+
$pass,
418+
false,
419+
false,
420+
true,
421+
$show_solutions_enabled,
422+
false,
423+
true,
424+
false
425+
);
426+
if ($aresult_output !== null) {
427+
$cust = new \ilCustomInputGUI($this->lng->txt('autosavecontent'));
428+
$cust->setHtml($aresult_output);
429+
$form->addItem($cust);
430+
}
431+
}
432+
413433
$text = new \ilTextInputGUI($this->lng->txt('tst_change_points_for_question'), "question__{$question_id}__points");
414434
if ($initValues) {
415435
$text->setValue((string) \assQuestion::_getReachedPoints($active_id, $question_id, $pass));

components/ILIAS/Test/src/Scoring/Manual/class.TestScoringByQuestionGUI.php

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -296,8 +296,10 @@ private function buildFeedbackModal(
296296
$this->buildSolutionPanel($question_gui, $question_id, $attempt)
297297
];
298298

299-
if ($question_gui instanceof \assTextQuestionGUI && $this->object->getAutosave()) {
300-
$content[] = $this->buildAutosavedSolutionPanel($question_gui, $question_id, $attempt);
299+
if ($this->object->getAutosave()
300+
&& $autosave_content = $this->buildAutosavedSolutionPanel($question_gui, $question_id, $attempt)
301+
) {
302+
$content[] = $autosave_content;
301303
}
302304

303305
$reached_points = $question_gui->getObject()->getReachedPoints($active_id, $attempt);
@@ -358,22 +360,25 @@ private function buildSolutionPanel(
358360
}
359361

360362
private function buildAutosavedSolutionPanel(
361-
assQuestionGUI $question_gui,
363+
\assQuestionGUI $question_gui,
362364
int $active_id,
363365
int $attempt
364-
): StandardPanel {
366+
): ?StandardPanel {
367+
$autosave_content = $question_gui->getAutoSavedSolutionOutput(
368+
$active_id,
369+
$attempt,
370+
false,
371+
false,
372+
false,
373+
$this->object->getShowSolutionFeedback(),
374+
);
375+
if ($autosave_content === null) {
376+
return null;
377+
}
378+
365379
return $this->ui_factory->panel()->standard(
366380
$this->lng->txt('autosavecontent'),
367-
$this->ui_factory->legacy(
368-
$question_gui->getAutoSavedSolutionOutput(
369-
$active_id,
370-
$attempt,
371-
false,
372-
false,
373-
false,
374-
$this->object->getShowSolutionFeedback(),
375-
)
376-
)
381+
$this->ui_factory->legacy($autosave_content)
377382
);
378383
}
379384

components/ILIAS/Test/tests/Results/Data/QuestionResultTest.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ public function testTestQuestionResultBasicProperties(): void
3939
$worked_through = true,
4040
$answered = true,
4141
$requested_hints = 2,
42-
$recapitulation = 'some recap'
42+
$recapitulation = 'some recap',
43+
$autosave = 'some autosave content',
4344
);
4445

4546
$this->assertEquals($id, $qr->getId());
@@ -54,5 +55,6 @@ public function testTestQuestionResultBasicProperties(): void
5455
$this->assertTrue($qr->isAnswered());
5556
$this->assertEquals($recapitulation, $qr->getContentForRecapitulation());
5657
$this->assertEquals($requested_hints, $qr->getNumberOfRequestedHints());
58+
$this->assertEquals($autosave, $qr->getAutosavedAnswer());
5759
}
5860
}

components/ILIAS/TestQuestionPool/classes/class.assClozeTestGUI.php

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -820,16 +820,44 @@ public function getSolutionOutput(
820820
bool $show_question_text = true,
821821
bool $show_inline_feedback = true
822822
): string {
823-
// get the solution of the user for the active pass or from the last pass if allowed
824823
$user_solution = [];
825824
if (($active_id > 0) && (!$show_correct_solution)) {
826-
// get the solutions of a user
827825
$user_solution = $this->object->getSolutionValues($active_id, $pass);
828826
if (!is_array($user_solution)) {
829827
$user_solution = [];
830828
}
831829
}
832830

831+
return $this->renderSolutionOutput(
832+
$user_solution,
833+
$active_id,
834+
$pass,
835+
$graphical_output,
836+
$result_output,
837+
$show_question_only,
838+
$show_feedback,
839+
$show_correct_solution,
840+
$show_manual_scoring,
841+
$show_question_text,
842+
false,
843+
false
844+
);
845+
}
846+
847+
public function renderSolutionOutput(
848+
mixed $user_solutions,
849+
int $active_id,
850+
int $pass,
851+
bool $graphical_output = false,
852+
bool $result_output = false,
853+
bool $show_question_only = true,
854+
bool $show_feedback = false,
855+
bool $show_correct_solution = false,
856+
bool $show_manual_scoring = false,
857+
bool $show_question_text = true,
858+
bool $show_autosave_title = false,
859+
bool $show_inline_feedback = false,
860+
): ?string {
833861
$template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
834862
$output = $this->object->getClozeTextForHTMLOutput();
835863
$assClozeGapCombinationObject = new assClozeGapCombination();
@@ -838,7 +866,7 @@ public function getSolutionOutput(
838866
foreach ($this->object->getGaps() as $gap_index => $gap) {
839867
$gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", true, true, "components/ILIAS/TestQuestionPool");
840868
$found = [];
841-
foreach ($user_solution as $solutionarray) {
869+
foreach ($user_solutions as $solutionarray) {
842870
if ($solutionarray["value1"] == $gap_index) {
843871
$found = $solutionarray;
844872
}

components/ILIAS/TestQuestionPool/classes/class.assErrorTextGUI.php

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -236,12 +236,43 @@ public function getSolutionOutput(
236236
bool $show_question_text = true,
237237
bool $show_inline_feedback = true
238238
): string {
239-
// get the solution of the user for the active pass or from the last pass if allowed
240-
$template = new ilTemplate("tpl.il_as_qpl_errortext_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
239+
$user_solutions = $this->getUsersSolutionFromPreviewOrDatabase($active_id, $pass);
240+
return $this->renderSolutionOutput(
241+
$user_solutions,
242+
$active_id,
243+
$pass,
244+
$graphical_output,
245+
$result_output,
246+
$show_question_only,
247+
$show_feedback,
248+
$show_correct_solution,
249+
$show_manual_scoring,
250+
$show_question_text,
251+
false,
252+
$show_inline_feedback,
253+
);
254+
}
241255

256+
public function renderSolutionOutput(
257+
mixed $user_solutions,
258+
int $active_id,
259+
int $pass,
260+
bool $graphical_output = false,
261+
bool $result_output = false,
262+
bool $show_question_only = true,
263+
bool $show_feedback = false,
264+
bool $show_correct_solution = false,
265+
bool $show_manual_scoring = false,
266+
bool $show_question_text = true,
267+
bool $show_autosave_title = false,
268+
bool $show_inline_feedback = false,
269+
): ?string {
270+
$template = new ilTemplate("tpl.il_as_qpl_errortext_output_solution.html", true, true, "components/ILIAS/TestQuestionPool");
242271

243272
$selections = [
244-
'user' => $this->getUsersSolutionFromPreviewOrDatabase((int) $active_id, $pass)
273+
'user' => $user_solutions ?
274+
$user_solutions :
275+
$this->getUsersSolutionFromPreviewOrDatabase($active_id, $pass)
245276
];
246277
$selections['best'] = $this->object->getBestSelection();
247278

@@ -277,7 +308,7 @@ public function getSolutionOutput(
277308
$feedback = '';
278309
if ($show_feedback) {
279310
if (!$this->isTestPresentationContext()) {
280-
$fb = $this->getGenericFeedbackOutput((int) $active_id, $pass);
311+
$fb = $this->getGenericFeedbackOutput($active_id, $pass);
281312
$feedback .= mb_strlen($fb) ? $fb : '';
282313
}
283314

0 commit comments

Comments
 (0)