Skip to content

Commit

Permalink
TA: 37918, show autosave content
Browse files Browse the repository at this point in the history
  • Loading branch information
nhaagen authored and kergomard committed Dec 16, 2024
1 parent 708c205 commit 82a8bd2
Show file tree
Hide file tree
Showing 21 changed files with 800 additions and 267 deletions.
8 changes: 7 additions & 1 deletion Modules/Test/classes/Results/class.ilQuestionResult.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,8 @@ public function __construct(
protected bool $workedthrough,
protected bool $answered,
protected int $requested_hints,
protected ?string $content_for_recapitulation
protected ?string $content_for_recapitulation,
protected ?string $autosaved_answer
) {
}

Expand Down Expand Up @@ -110,4 +111,9 @@ public function getNumberOfRequestedHints(): int
{
return $this->requested_hints;
}
public function getAutosavedAnswer(): ?string
{
return $this->autosaved_answer;
}

}
30 changes: 18 additions & 12 deletions Modules/Test/classes/Results/class.ilTestPassResultsTable.php
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ protected function applyControls(
string $sortation,
array $question_results
) {
switch($mode) {
switch ($mode) {
case self::MODE_OPT_CORRECT:
$filter = static fn($qr) => $qr->getCorrect() === ilQuestionResult::CORRECT_FULL;
break;
Expand All @@ -110,8 +110,8 @@ protected function applyControls(
protected function getViewControlNamespace(): array
{
$namespace = self::URL_NAMESPACE;
$namespace[] = (string)$this->test_results->getActiveId();
$namespace[] = (string)$this->test_results->getPass();
$namespace[] = (string) $this->test_results->getActiveId();
$namespace[] = (string) $this->test_results->getPass();
return $namespace;
}

Expand Down Expand Up @@ -180,22 +180,22 @@ protected function getMapping(): \Closure
$title = sprintf(
'%s [ID: %s]',
$question->getTitle(),
(string)$question->getId()
(string) $question->getId()
);

$important_fields = [
$lng->txt('question_id') => (string)$question->getId(),
$lng->txt('question_id') => (string) $question->getId(),
$lng->txt('question_type') => $lng->txt($question->getType()),
$lng->txt('points') => sprintf(
'%s/%s (%s%%)',
(string)$question->getUserScore(),
(string)$question->getQuestionScore(),
(string)$question->getUserScorePercent()
(string) $question->getUserScore(),
(string) $question->getQuestionScore(),
(string) $question->getUserScorePercent()
)
];

$stats_fields = $important_fields;
$stats_fields[$lng->txt('tst_question_hints_requested_hint_count_header')] = (string)$question->getNumberOfRequestedHints();
$stats_fields[$lng->txt('tst_question_hints_requested_hint_count_header')] = (string) $question->getNumberOfRequestedHints();
$stats = $ui_factory->listing()->characteristicValue()->text($stats_fields);


Expand All @@ -216,9 +216,15 @@ protected function getMapping(): \Closure
]);
}

$user_answer = $question->getUserAnswer();
$listing = [
$lng->txt('tst_header_participant') => $question->getUserAnswer()
];
if ($autosave_content = $question->getAutosavedAnswer()) {
$listing[$lng->txt('autosavecontent')] = $autosave_content;
}

$answer_contents = [
$ui_factory->listing()->descriptive([$lng->txt('tst_header_participant') => $user_answer])
$ui_factory->listing()->descriptive($listing)
];
if ($env->getShowBestSolution()) {
$answer_contents[] = $ui_factory->listing()->descriptive([
Expand All @@ -231,7 +237,7 @@ protected function getMapping(): \Closure

$content = $ui_factory->layout()->alignment()->vertical(...$contents);

switch($question->getCorrect()) {
switch ($question->getCorrect()) {
case ilQuestionResult::CORRECT_FULL:
$icon_name = 'icon_ok.svg';
$label = $lng->txt("answer_is_right");
Expand Down
28 changes: 15 additions & 13 deletions Modules/Test/classes/Results/class.ilTestResultsFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,20 +114,21 @@ protected function buildPassResults(
$show_inline_feedback
);

if ($test_obj->getAutosave() &&
$type === 'assTextQuestion'
) {
$usr_solution .= $question_gui->getAutoSavedSolutionOutput(
$autosave_output = null;
$show_autosave_title = false;
if ($test_obj->getAutosave()) {
$autosave_output = $question_gui->getAutoSavedSolutionOutput(
$active_id,
$pass_id,
false,
false,
false,
false,
false,
false,
false,
true
$graphical_output,
$result_output,
$show_question_only,
$show_feedback,
$show_correct_solution,
$show_manual_scoring,
$show_question_text,
$show_autosave_title,
$show_inline_feedback
);
}

Expand Down Expand Up @@ -172,7 +173,8 @@ protected function buildPassResults(
$workedthrough,
$answered,
$requested_hints,
$recapitulation
$recapitulation,
$autosave_output
);
}

Expand Down
8 changes: 5 additions & 3 deletions Modules/Test/classes/class.ilTestScoringByQuestionsGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -445,7 +445,7 @@ protected function getAnswerDetail(): void
$participant = $data->getParticipant($active_id);
$question_gui = $this->object->createQuestionGUI('', $question_id);
$tmp_tpl = new ilTemplate('tpl.il_as_tst_correct_solution_output.html', true, true, 'Modules/Test');
if ($question_gui instanceof assTextQuestionGUI && $this->object->getAutosave()) {
if ($this->object->getAutosave()) {
$aresult_output = $question_gui->getAutoSavedSolutionOutput(
$active_id,
$pass,
Expand All @@ -457,8 +457,10 @@ protected function getAnswerDetail(): void
true,
false
);
$tmp_tpl->setVariable('TEXT_ASOLUTION_OUTPUT', $this->lng->txt('autosavecontent'));
$tmp_tpl->setVariable('ASOLUTION_OUTPUT', $aresult_output);
if ($aresult_output) {
$tmp_tpl->setVariable('TEXT_ASOLUTION_OUTPUT', $this->lng->txt('autosavecontent'));
$tmp_tpl->setVariable('ASOLUTION_OUTPUT', $aresult_output);
}
}
$result_output = $question_gui->getSolutionOutput(
$active_id,
Expand Down
20 changes: 13 additions & 7 deletions Modules/Test/classes/class.ilTestScoringGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,8 @@ private function buildManScoringParticipantForm(
$form->setTitle(sprintf($this->lng->txt('manscoring_results_pass'), $pass + 1));
$form->setTableWidth('100%');

$autosave_enabled = $this->object->getAutosave();
$show_solutions_enabled = $this->object->getShowSolutionFeedback();
foreach ($questionGuiList as $questionId => $questionGUI) {
$questionHeader = sprintf($this->lng->txt('tst_manscoring_question_section_header'), $questionGUI->object->getTitle());
$questionSolution = $questionGUI->getSolutionOutput($active_id, $pass, false, false, true, false, false, true);
Expand All @@ -394,23 +396,27 @@ private function buildManScoringParticipantForm(
$cust->setHtml($questionSolution);
$form->addItem($cust);

if ($questionGUI instanceof assTextQuestionGUI && $this->object->getAutosave()) {
if ($autosave_enabled) {
$aresult_output = $questionGUI->getAutoSavedSolutionOutput(
$active_id,
$pass,
false,
false,
true,
$show_solutions_enabled,
false,
false,
false,
false,
true,
false
);
$cust = new ilCustomInputGUI($this->lng->txt('autosavecontent'));
$cust->setHtml($aresult_output);
$form->addItem($cust);
if ($aresult_output) {
$cust = new ilCustomInputGUI($this->lng->txt('autosavecontent'));
$cust->setHtml($aresult_output);
$form->addItem($cust);
}
}



$text = new ilTextInputGUI($this->lng->txt('tst_change_points_for_question'), "question__{$questionId}__points");
if ($initValues) {
$text->setValue((string) assQuestion::_getReachedPoints($active_id, $questionId, $pass));
Expand Down
4 changes: 3 additions & 1 deletion Modules/Test/test/TestResultsQuestionResultsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public function testTestResultsQuestionResultsBasicProps(): void
$worked_through = true,
$answered = true,
$requested_hints = 2,
$recapitulation = 'some recap'
$recapitulation = 'some recap',
$autosave = 'some autosave content',
);

$this->assertEquals($id, $qr->getId());
Expand All @@ -53,5 +54,6 @@ public function testTestResultsQuestionResultsBasicProps(): void
$this->assertTrue($qr->isAnswered());
$this->assertEquals($recapitulation, $qr->getContentForRecapitulation());
$this->assertEquals($requested_hints, $qr->getNumberOfRequestedHints());
$this->assertEquals('some autosave content', $qr->getAutosavedAnswer());
}
}
55 changes: 43 additions & 12 deletions Modules/TestQuestionPool/classes/class.assClozeTestGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -937,7 +937,7 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
* Get the question solution output
* @param integer $active_id The active user id
* @param integer $pass The test pass
* @param boolean $graphicalOutput Show visual feedback for right/wrong answers
* @param boolean $graphical_output Show visual feedback for right/wrong answers
* @param boolean $result_output Show the reached points for parts of the question
* @param boolean $show_question_only Show the question without the ILIAS content around
* @param boolean $show_feedback Show the question feedback
Expand All @@ -949,13 +949,13 @@ public function getPreview($show_question_only = false, $showInlineFeedback = fa
public function getSolutionOutput(
$active_id,
$pass = null,
$graphicalOutput = false,
$result_output = false,
$show_question_only = true,
$show_feedback = false,
$show_correct_solution = false,
$show_manual_scoring = false,
$show_question_text = true
bool $graphical_output = false,
bool $result_output = false,
bool $show_question_only = true,
bool $show_feedback = false,
bool $show_correct_solution = false,
bool $show_manual_scoring = false,
bool $show_question_text = true
): string {
// get the solution of the user for the active pass or from the last pass if allowed
$user_solution = [];
Expand All @@ -967,6 +967,37 @@ public function getSolutionOutput(
}
}

return $this->renderSolutionOutput(
$user_solution,
$active_id,
$pass,
$graphical_output,
$result_output,
$show_question_only,
$show_feedback,
$show_correct_solution,
$show_manual_scoring,
$show_question_text,
false,
false
);
}

public function renderSolutionOutput(
mixed $user_solutions,
int $active_id,
int $pass,
bool $graphical_output = false,
bool $result_output = false,
bool $show_question_only = true,
bool $show_feedback = false,
bool $show_correct_solution = false,
bool $show_manual_scoring = false,
bool $show_question_text = true,
bool $show_autosave_title = false,
bool $show_inline_feedback = false,
): ?string {

$template = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution.html", true, true, "Modules/TestQuestionPool");
$output = $this->object->getClozeTextForHTMLOutput();
$assClozeGapCombinationObject = new assClozeGapCombination();
Expand All @@ -975,14 +1006,14 @@ public function getSolutionOutput(
foreach ($this->object->getGaps() as $gap_index => $gap) {
$gaptemplate = new ilTemplate("tpl.il_as_qpl_cloze_question_output_solution_gap.html", true, true, "Modules/TestQuestionPool");
$found = [];
foreach ($user_solution as $solutionarray) {
foreach ($user_solutions as $solutionarray) {
if ($solutionarray["value1"] == $gap_index) {
$found = $solutionarray;
}
}

if ($active_id) {
if ($graphicalOutput) {
if ($graphical_output) {
// output of ok/not ok icons for user entered solutions
$details = $this->object->calculateReachedPoints($active_id, $pass, true, true);
$check = $details[$gap_index] ?? [];
Expand All @@ -995,7 +1026,7 @@ public function getSolutionOutput(
foreach ($gaps_used_in_combination as $key => $value) {
$a = 0;
if ($value == $combination_id) {
foreach ($user_solution as $solution_key => $solution_value) {
foreach ($user_solutions as $solution_key => $solution_value) {
if ($solution_value['value1'] == $key) {
$result_row = [];
$result_row['gap_id'] = $solution_value['value1'];
Expand Down Expand Up @@ -1115,7 +1146,7 @@ public function getSolutionOutput(
}

$fb = $this->getSpecificFeedbackOutput(
$this->object->fetchIndexedValuesFromValuePairs($user_solution)
$this->object->fetchIndexedValuesFromValuePairs($user_solutions)
);
$feedback .= strlen($fb) ? $fb : '';
}
Expand Down
Loading

0 comments on commit 82a8bd2

Please sign in to comment.