Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support questions where answers are neither right nor wrong (choice interaction) #5

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions styles/choice.css
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,11 @@
border-radius: 5px;
}

.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 {
font-family: 'h5p-reporting-icons';
content: "\e90c";
Expand Down
26 changes: 18 additions & 8 deletions type-processors/choice-processor.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -77,26 +78,32 @@ private function generateDescription($description) {
* @return string Table element
*/
private function generateTable($extras, $correctAnswers, $responses) {
$hasNoRightOrWrong = !isset($correctAnswers);

$choices = $extras->choices;
$tableHeader =
'<tr class="h5p-choices-table-heading">' .
'<td class="h5p-choices-choice">Answers</td>' .
'<td class="h5p-choices-choice">Answers</td>';
$tableHeader .= ($hasNoRightOrWrong) ?
'<td class="h5p-choices-user-answer">Chosen</td>' :
'<td class="h5p-choices-user-answer">Your Answer</td>' .
'<td class="h5p-choices-crp-answer">Correct</td>' .
'</tr>';
'<td class="h5p-choices-crp-answer">Correct</td>';
$tableHeader .= '</tr>';

$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';
$crpClasses = 'h5p-choices-crp';
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';
Expand All @@ -108,10 +115,13 @@ private function generateTable($extras, $correctAnswers, $responses) {
'</td>' .
'<td class="h5p-choices-icon-cell">' .
'<span class="' . $userClasses . '"></span>' .
'</td>' .
'<td class="h5p-choices-icon-cell">' .
'<span class="' . $crpClasses . '"></span>' .
'</td>';
if (!$hasNoRightOrWrong) {
$row .=
'<td class="h5p-choices-icon-cell">' .
'<span class="' . $crpClasses . '"></span>' .
'</td>';
}

$rows .= '<tr>' . $row . '</tr>';
}
Expand Down