From 8d285f8ec6fa18ad8a8adc1ba66b5aee3076a277 Mon Sep 17 00:00:00 2001 From: David Szkiba Date: Mon, 14 Oct 2024 13:14:18 +0200 Subject: [PATCH 1/2] GH-694 Fix: duplicated text in heading and comment --- .../feedbackgenerator/customscalefeedback.php | 54 +++++++++++-------- 1 file changed, 31 insertions(+), 23 deletions(-) diff --git a/classes/teststrategy/feedbackgenerator/customscalefeedback.php b/classes/teststrategy/feedbackgenerator/customscalefeedback.php index 510dd5ba4..c1fc698ce 100644 --- a/classes/teststrategy/feedbackgenerator/customscalefeedback.php +++ b/classes/teststrategy/feedbackgenerator/customscalefeedback.php @@ -92,35 +92,14 @@ public function get_studentfeedback(array $data): array { $data['catscales'] ); $firstelement = $data['customscalefeedback_abilities'][array_key_first($data['customscalefeedback_abilities'])]; - if (!empty($firstelement['estimated'])) { - if (!isset($firstelement['fraction'])) { - $comment = get_string('estimatedbecause:default', 'local_catquiz'); - } else { - switch ((int) $firstelement['fraction']) { - case 1 : - $comment = get_string('estimatedbecause:allanswerscorrect', 'local_catquiz'); - break; - case 0 : - if (count($this->get_progress()->get_playedquestions()) === 0) { - $comment = get_string('error:nminscale', 'local_catquiz'); - } else { - $comment = get_string('estimatedbecause:allanswersincorrect', 'local_catquiz'); - } - break; - default : - $comment = get_string('estimatedbecause:default', 'local_catquiz'); - break; - - } - } - } + $comment = $this->get_comment($firstelement); if (empty($customscalefeedback)) { return []; } else { return [ 'heading' => $this->get_heading(), - 'comment' => $comment ?? "", + 'comment' => $comment, 'content' => $customscalefeedback, ]; } @@ -342,4 +321,33 @@ private function getfeedbackforrange(int $catscaleid, int $groupnumber, array $q return $content; } + + /** + * Get the comment line for the feedback + * + * @param array $firstelement + * @return string + */ + private function get_comment(array $firstelement): string { + if (empty($firstelement['estimated'])) { + return ""; + } + + if (count($this->get_progress()->get_playedquestions()) === 0) { + return ""; + } + + if (!isset($firstelement['fraction'])) { + return get_string('estimatedbecause:default', 'local_catquiz'); + } + + switch ((int) $firstelement['fraction']) { + case 1: + return get_string('estimatedbecause:allanswerscorrect', 'local_catquiz'); + case 0: + return get_string('estimatedbecause:allanswersincorrect', 'local_catquiz'); + } + + return get_string('estimatedbecause:default', 'local_catquiz'); + } } From 43145a6dfabcb2df6f3f7d7f080a1fbe8c7403cd Mon Sep 17 00:00:00 2001 From: David Szkiba Date: Mon, 14 Oct 2024 16:26:38 +0200 Subject: [PATCH 2/2] GH-678 Remove reduntant description for missing result If no specific scale can be identified, we already show a text with this information. In addition, there was a comment also providing information about why there is no result. To simplify and prevent confusion, the extra comments are removed. --- .../feedbackgenerator/customscalefeedback.php | 42 +++---------------- .../customscalefeedback_test.php | 3 -- 2 files changed, 5 insertions(+), 40 deletions(-) diff --git a/classes/teststrategy/feedbackgenerator/customscalefeedback.php b/classes/teststrategy/feedbackgenerator/customscalefeedback.php index c1fc698ce..401dbc8e3 100644 --- a/classes/teststrategy/feedbackgenerator/customscalefeedback.php +++ b/classes/teststrategy/feedbackgenerator/customscalefeedback.php @@ -91,18 +91,15 @@ public function get_studentfeedback(array $data): array { (array) $progress->get_quiz_settings(), $data['catscales'] ); - $firstelement = $data['customscalefeedback_abilities'][array_key_first($data['customscalefeedback_abilities'])]; - $comment = $this->get_comment($firstelement); if (empty($customscalefeedback)) { return []; - } else { - return [ - 'heading' => $this->get_heading(), - 'comment' => $comment, - 'content' => $customscalefeedback, - ]; } + + return [ + 'heading' => $this->get_heading(), + 'content' => $customscalefeedback, + ]; } /** @@ -321,33 +318,4 @@ private function getfeedbackforrange(int $catscaleid, int $groupnumber, array $q return $content; } - - /** - * Get the comment line for the feedback - * - * @param array $firstelement - * @return string - */ - private function get_comment(array $firstelement): string { - if (empty($firstelement['estimated'])) { - return ""; - } - - if (count($this->get_progress()->get_playedquestions()) === 0) { - return ""; - } - - if (!isset($firstelement['fraction'])) { - return get_string('estimatedbecause:default', 'local_catquiz'); - } - - switch ((int) $firstelement['fraction']) { - case 1: - return get_string('estimatedbecause:allanswerscorrect', 'local_catquiz'); - case 0: - return get_string('estimatedbecause:allanswersincorrect', 'local_catquiz'); - } - - return get_string('estimatedbecause:default', 'local_catquiz'); - } } diff --git a/tests/teststrategy/feedbackgenerator/customscalefeedback_test.php b/tests/teststrategy/feedbackgenerator/customscalefeedback_test.php index 2ab653c3c..09ad4ae53 100644 --- a/tests/teststrategy/feedbackgenerator/customscalefeedback_test.php +++ b/tests/teststrategy/feedbackgenerator/customscalefeedback_test.php @@ -131,7 +131,6 @@ public static function get_studentfeedback_provider(): array { 'expected' => [ 'heading' => 'Feedback', 'content' => '

adsfafs<\/p>
', - 'comment' => '', ], ], 'noscalestoreport' => [ @@ -171,10 +170,8 @@ public static function get_studentfeedback_provider(): array { 'expected' => [ 'heading' => 'Feedback', 'content' => 'No valid feedback could be generated.', - 'comment' => '', ], ], ]; } - }