TrueFalseProcessor.php in Opigno module 3.x
File
ActivityTypes/opigno_h5p/src/TypeProcessors/TrueFalseProcessor.php
View source
<?php
namespace Drupal\opigno_h5p\TypeProcessors;
class TrueFalseProcessor extends TypeProcessor {
public function generateHTML($description, $crp, $response, $extras = NULL, $scoreSettings = NULL) {
$this
->setStyle('opigno_h5p/opigno_h5p.true-false');
return $this
->getContent($description, $crp, $response, $scoreSettings) . $this
->generateFooter();
}
private function getContent($description, $crp, $response, $scoreSettings) {
$isCorrectClass = $response === $crp[0] ? 'h5p-true-false-user-response-correct' : 'h5p-true-false-user-response-wrong';
$header = $this
->generateHeader($description, $scoreSettings);
return '<div class="h5p-reporting-container h5p-true-false-container">' . $header . '<p class="h5p-true-false-task"><span class="h5p-true-false-correct-responses-pattern">' . $crp[0] . '</span><span class="' . $isCorrectClass . '">' . $response . '</span></p>' . '</div>';
}
private function generateHeader($description, $scoreSettings) {
$descriptionHtml = "<p class='h5p-reporting-description h5p-true-false-task-description'>{$description}</p>";
$scoreHtml = $this
->generateScoreHtml($scoreSettings);
return "<div class='h5p-choices-header'>{$descriptionHtml}{$scoreHtml}</div>";
}
public function generateFooter() {
return '<div class="h5p-true-false-footer">' . '<span class="h5p-true-false-correct-responses-pattern">' . t('Correct Answer') . '</span>' . '<span class="h5p-true-false-user-response-correct">' . t('Your correct answer') . '</span>' . '<span class="h5p-true-false-user-response-wrong">' . t('Your incorrect answer') . '</span>' . '</div>';
}
}