diff --git a/components/ILIAS/TestQuestionPool/classes/class.assErrorTextGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assErrorTextGUI.php index 4fa6450c0f7b..2963e0f15635 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assErrorTextGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assErrorTextGUI.php @@ -513,9 +513,7 @@ public function getAnswersFrequency($relevant_answers, $question_index): array $error_text_hashed = md5($error_text); if (!isset($answers[$error_text_hashed])) { - $answers[$error_text_hashed] = [ - 'answer' => $error_text, 'frequency' => 0 - ]; + $answers[$error_text_hashed] = ['answer' => $error_text, 'frequency' => 0, 'sanitized' => true]; } $answers[$error_text_hashed]['frequency']++; diff --git a/components/ILIAS/TestQuestionPool/classes/class.assKprimChoiceGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assKprimChoiceGUI.php index eed0f4be4cda..5ad6d50c12e0 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assKprimChoiceGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assKprimChoiceGUI.php @@ -860,15 +860,14 @@ private function aggregateAnswers($rawSolutionData, $answers): array public function getAnswersFrequency($relevantAnswers, $questionIndex): array { - $agg = $this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()); - $answers = []; - foreach ($agg as $ans) { + foreach ($this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()) as $ans) { $answers[] = [ 'answer' => $ans['answertext'], 'frequency_true' => $ans['count_true'], - 'frequency_false' => $ans['count_false'] + 'frequency_false' => $ans['count_false'], + 'sanitized' => true ]; } diff --git a/components/ILIAS/TestQuestionPool/classes/class.assMultipleChoiceGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assMultipleChoiceGUI.php index 790a6e4197d7..6301fa7ccbe0 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assMultipleChoiceGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assMultipleChoiceGUI.php @@ -988,15 +988,10 @@ protected function buildEditForm(bool $is_singleline = true): ilPropertyFormGUI public function getAnswersFrequency($relevantAnswers, $questionIndex): array { - $agg = $this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()); - $answers = []; - foreach ($agg as $ans) { - $answers[] = [ - 'answer' => $ans['answertext'], - 'frequency' => $ans['count_checked'] - ]; + foreach ($this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()) as $ans) { + $answers[] = ['answer' => $ans['answertext'], 'frequency' => $ans['count_checked'], 'sanitized' => true]; } return $answers; diff --git a/components/ILIAS/TestQuestionPool/classes/class.assOrderingHorizontalGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assOrderingHorizontalGUI.php index ec594448ebfd..104dbff5536b 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assOrderingHorizontalGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assOrderingHorizontalGUI.php @@ -389,9 +389,7 @@ public function getAnswersFrequency($relevantAnswers, $questionIndex): array $ans['value1'] ); - $answers[$md5] = [ - 'answer' => $answer, 'frequency' => 0 - ]; + $answers[$md5] = ['answer' => $answer, 'frequency' => 0, 'sanitized' => true]; } $answers[$md5]['frequency']++; diff --git a/components/ILIAS/TestQuestionPool/classes/class.assOrderingQuestionGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assOrderingQuestionGUI.php index 2605757d2f4f..43484774bd37 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assOrderingQuestionGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assOrderingQuestionGUI.php @@ -666,37 +666,16 @@ protected function getAnswerStatisticOrderingElementHtml(ilAssOrderingElement $e protected function getAnswerStatisticOrderingVariantHtml(ilAssOrderingElementList $list): string { - $html = ''; - } - - $html .= ''; + $list = array_map( + fn(ilAssOrderingElement $elem): string => htmlspecialchars( + $this->getAnswerStatisticOrderingElementHtml($elem) ?? '', + ENT_QUOTES | ENT_SUBSTITUTE, + 'utf-8' + ), + $list->getElements() + ); - return $html; + return $this->ui->renderer()->render($this->ui->factory()->listing()->unordered($list)); } public function getAnswersFrequency($relevantAnswers, $questionIndex): array @@ -730,9 +709,7 @@ public function getAnswersFrequency($relevantAnswers, $questionIndex): array $orderingElementList ); - $answers[$hash] = [ - 'answer' => $variantHtml, 'frequency' => 0 - ]; + $answers[$hash] = ['answer' => $variantHtml, 'frequency' => 0, 'sanitized' => true]; } $answers[$hash]['frequency']++; diff --git a/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php index 10eccce369b9..7efe8bbb0d9b 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assQuestionGUI.php @@ -18,6 +18,7 @@ declare(strict_types=1); +use ILIAS\DI\UIServices; use ILIAS\TestQuestionPool\QuestionPoolDIC; use ILIAS\TestQuestionPool\RequestDataCollector; use ILIAS\TestQuestionPool\ilTestLegacyFormsHelper; @@ -98,7 +99,7 @@ abstract class assQuestionGUI 'uploaddefintions' ]; - private $ui; + protected UIServices $ui; private ilObjectDataCache $ilObjDataCache; private ilHelpGUI $ilHelp; private ilAccessHandler $access; diff --git a/components/ILIAS/TestQuestionPool/classes/class.assSingleChoiceGUI.php b/components/ILIAS/TestQuestionPool/classes/class.assSingleChoiceGUI.php index 3f987142f604..134bfcb19cf6 100755 --- a/components/ILIAS/TestQuestionPool/classes/class.assSingleChoiceGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/class.assSingleChoiceGUI.php @@ -816,15 +816,10 @@ private function populateInlineFeedback($template, $answer_id, $user_solution): public function getAnswersFrequency($relevantAnswers, $questionIndex): array { - $agg = $this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()); - $answers = []; - foreach ($agg as $ans) { - $answers[] = [ - 'answer' => $ans['answertext'], - 'frequency' => $ans['count_checked'] - ]; + foreach ($this->aggregateAnswers($relevantAnswers, $this->object->getAnswers()) as $ans) { + $answers[] = ['answer' => $ans['answertext'], 'frequency' => $ans['count_checked'], 'sanitized' => true]; } return $answers; diff --git a/components/ILIAS/TestQuestionPool/classes/tables/class.ilAnswerFrequencyStatisticTableGUI.php b/components/ILIAS/TestQuestionPool/classes/tables/class.ilAnswerFrequencyStatisticTableGUI.php index 8fefe81007e8..f82aefc57729 100755 --- a/components/ILIAS/TestQuestionPool/classes/tables/class.ilAnswerFrequencyStatisticTableGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/tables/class.ilAnswerFrequencyStatisticTableGUI.php @@ -111,7 +111,9 @@ public function initColumns(): void public function fillRow(array $a_set): void { - $a_set['answer'] = ilLegacyFormElementsUtil::prepareFormOutput((string) $a_set['answer']); + if (!isset($a_set['sanitized']) || !$a_set['sanitized']) { + $a_set['answer'] = ilLegacyFormElementsUtil::prepareFormOutput((string) $a_set['answer']); + } $this->tpl->setCurrentBlock('answer'); $this->tpl->setVariable('ANSWER', $a_set['answer']); diff --git a/components/ILIAS/TestQuestionPool/classes/tables/class.ilKprimChoiceAnswerFreqStatTableGUI.php b/components/ILIAS/TestQuestionPool/classes/tables/class.ilKprimChoiceAnswerFreqStatTableGUI.php index bedffd6a4d69..1ec2e0eddfa0 100755 --- a/components/ILIAS/TestQuestionPool/classes/tables/class.ilKprimChoiceAnswerFreqStatTableGUI.php +++ b/components/ILIAS/TestQuestionPool/classes/tables/class.ilKprimChoiceAnswerFreqStatTableGUI.php @@ -58,8 +58,12 @@ public function initColumns(): void public function fillRow(array $a_set): void { + if (!isset($a_set['sanitized']) || !$a_set['sanitized']) { + $a_set['answer'] = htmlspecialchars($a_set['answer'], ENT_QUOTES | ENT_SUBSTITUTE, 'utf-8'); + } + $this->tpl->setCurrentBlock('answer'); - $this->tpl->setVariable('ANSWER', ilLegacyFormElementsUtil::prepareFormOutput($a_set['answer'])); + $this->tpl->setVariable('ANSWER', $a_set['answer']); $this->tpl->parseCurrentBlock(); $this->tpl->setCurrentBlock('frequency');