Skip to content

Commit

Permalink
GH-694 Fix: duplicated text in heading and comment
Browse files Browse the repository at this point in the history
  • Loading branch information
davidszkiba committed Oct 15, 2024
1 parent 19fd48b commit 2bb499f
Showing 1 changed file with 31 additions and 23 deletions.
54 changes: 31 additions & 23 deletions classes/teststrategy/feedbackgenerator/customscalefeedback.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,35 +100,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,
];
}
Expand Down Expand Up @@ -360,4 +339,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');
}
}

0 comments on commit 2bb499f

Please sign in to comment.