From ea460db140e380130bddef35fc3c95b4a6374f57 Mon Sep 17 00:00:00 2001 From: otacke Date: Mon, 6 May 2019 16:28:01 +0200 Subject: [PATCH 1/3] Support questions where answers are neither right nor wrong The xAPI specification allows questions where answers are neither right nor wrong. In that case, the correct responses pattern is omitted, cmp. https://github.com/adlnet/xAPI-Spec/blob/master/xAPI-Data.md#correct-responses-pattern Currently, this is interpreted wrong. With these changes, if the xAPI statement does not contain a correct responses pattern for an xAPI choice interaction, it will use a blue checkmark for indicating that the answer was given, relabel the "Answers" column to "Chosen" and suppress the "Correct Answers" column. The behavior for xAPI choice interactions that provide a correct responses pattern is not changed, so existing content types such as the multiple choice quiz are not affected. --- styles/choice.css | 4 ++++ type-processors/choice-processor.class.php | 24 +++++++++++++++------- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/styles/choice.css b/styles/choice.css index d4f31aa..8092a84 100644 --- a/styles/choice.css +++ b/styles/choice.css @@ -60,6 +60,10 @@ border-radius: 5px; } +.h5p-choices-user.h5p-choices-answered.h5p-choices-user-correct.h5p-choices-no-correct { + background-color: #186df7; +} + .h5p-choices-user.h5p-choices-answered.h5p-choices-user-correct:before { font-family: 'h5p-reporting-icons'; content: "\e90c"; diff --git a/type-processors/choice-processor.class.php b/type-processors/choice-processor.class.php index 4ae1946..3182d50 100644 --- a/type-processors/choice-processor.class.php +++ b/type-processors/choice-processor.class.php @@ -24,7 +24,8 @@ public function generateHTML($description, $crp, $response, $extras = NULL, $sco // We need some style for our report $this->setStyle('styles/choice.css'); - $correctAnswers = explode('[,]', $crp[0]); + // choice type exercises lack correct reponses pattern if there's no right/wrong answer + $correctAnswers = (isset($crp)) ? explode('[,]', $crp[0]) : NULL; $responses = explode('[,]', $response); $headerHtml = $this->generateHeader($description, $scoreSettings); @@ -77,14 +78,17 @@ private function generateDescription($description) { * @return string Table element */ private function generateTable($extras, $correctAnswers, $responses) { + $hasNoRightOrWrong = !isset($correctAnswers); $choices = $extras->choices; $tableHeader = '' . - 'Answers' . + 'Answers'; + $tableHeader .= ($hasNoRightOrWrong) ? + 'Chosen' : 'Your Answer' . - 'Correct' . - ''; + 'Correct'; + $tableHeader .= ''; $rows = ''; foreach($choices as $choice) { @@ -97,6 +101,9 @@ private function generateTable($extras, $correctAnswers, $responses) { if ($isAnswered) { $userClasses .= ' h5p-choices-answered'; } + if ($hasNoRightOrWrong) { + $userClasses .= ' h5p-choices-user-correct h5p-choices-no-correct'; + } if ($isCRP) { $userClasses .= ' h5p-choices-user-correct'; $crpClasses .= ' h5p-choices-crp-correct'; @@ -108,10 +115,13 @@ private function generateTable($extras, $correctAnswers, $responses) { '' . '' . '' . - '' . - '' . - '' . ''; + if (!$hasNoRightOrWrong) { + $row .= + '' . + '' . + ''; + } $rows .= '' . $row . ''; } From d021e6991c702f371b74602f9f650435dd5c631d Mon Sep 17 00:00:00 2001 From: otacke Date: Tue, 7 May 2019 13:29:46 +0200 Subject: [PATCH 2/3] Fix PHP warnings for $crp check --- type-processors/choice-processor.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/type-processors/choice-processor.class.php b/type-processors/choice-processor.class.php index 3182d50..9c4b5ad 100644 --- a/type-processors/choice-processor.class.php +++ b/type-processors/choice-processor.class.php @@ -93,7 +93,7 @@ private function generateTable($extras, $correctAnswers, $responses) { $rows = ''; foreach($choices as $choice) { $choiceID = $choice->id; - $isCRP = in_array($choiceID, $correctAnswers); + $isCRP = !$hasNoRightOrWrong && in_array($choiceID, $correctAnswers); $isAnswered = in_array($choiceID, $responses); $userClasses = 'h5p-choices-user'; From f5d63c9bf24220a782fcba267514d1593c67124b Mon Sep 17 00:00:00 2001 From: otacke Date: Wed, 8 May 2019 17:18:42 +0200 Subject: [PATCH 3/3] Remove border around item with no-right-or-wrong answer --- styles/choice.css | 1 + 1 file changed, 1 insertion(+) diff --git a/styles/choice.css b/styles/choice.css index 8092a84..3da28f8 100644 --- a/styles/choice.css +++ b/styles/choice.css @@ -62,6 +62,7 @@ .h5p-choices-user.h5p-choices-answered.h5p-choices-user-correct.h5p-choices-no-correct { background-color: #186df7; + border: none; } .h5p-choices-user.h5p-choices-answered.h5p-choices-user-correct:before {