You are here

class TrueFalseProcessor in Opigno module 8

Same name and namespace in other branches
  1. 3.x ActivityTypes/opigno_h5p/src/TypeProcessors/TrueFalseProcessor.php \Drupal\opigno_h5p\TypeProcessors\TrueFalseProcessor

Class FillInProcessor.

Processes and generates HTML report for 'fill-in' interaction type.

Hierarchy

Expanded class hierarchy of TrueFalseProcessor

File

ActivityTypes/opigno_h5p/src/TypeProcessors/TrueFalseProcessor.php, line 10

Namespace

Drupal\opigno_h5p\TypeProcessors
View source
class TrueFalseProcessor extends TypeProcessor {

  /**
   * Options for interaction and generates a human readable HTML report.
   *
   * @inheritdoc
   */
  public function generateHTML($description, $crp, $response, $extras = NULL, $scoreSettings = NULL) {

    // We need some style for our report.
    $this
      ->setStyle('opigno_h5p/opigno_h5p.true-false');
    return $this
      ->getContent($description, $crp, $response, $scoreSettings) . $this
      ->generateFooter();
  }

  /**
   * Get report content.
   */
  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>';
  }

  /**
   * Generate header element.
   */
  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>";
  }

  /**
   * Generate footer.
   */
  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>';
  }

}

Members

Namesort descending Modifiers Type Description Overrides
TrueFalseProcessor::generateFooter public function Generate footer.
TrueFalseProcessor::generateHeader private function Generate header element.
TrueFalseProcessor::generateHTML public function Options for interaction and generates a human readable HTML report. Overrides TypeProcessor::generateHTML
TrueFalseProcessor::getContent private function Get report content.
TypeProcessor::$disableScoring protected property
TypeProcessor::$style private property
TypeProcessor::$xapiData protected property
TypeProcessor::generateReport public function Generate HTML for report.
TypeProcessor::generateScoreHtml protected function Generate score html.
TypeProcessor::getCRP protected function Decode and retrieve Correct Responses Pattern from xAPI data.
TypeProcessor::getDescription protected function Decode and retrieve 'en-US' description from xAPI data.
TypeProcessor::getExtras protected function Decode extras from xAPI data.
TypeProcessor::getResponse protected function Decode and retrieve user response from xAPI data.
TypeProcessor::getScoreSettings protected function Get score settings.
TypeProcessor::getStyle public function Get style used by processor if used.
TypeProcessor::setStyle protected function Set style used by the processor.