You are here

class H5PReport in Opigno module 8

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

Class H5PReport.

Hierarchy

Expanded class hierarchy of H5PReport

4 files declare their use of H5PReport
ChoiceProcessor.php in ActivityTypes/opigno_h5p/src/TypeProcessors/ChoiceProcessor.php
CompoundProcessor.php in ActivityTypes/opigno_h5p/src/TypeProcessors/CompoundProcessor.php
ModuleResultForm.php in src/Form/ModuleResultForm.php
opigno_h5p.module in ActivityTypes/opigno_h5p/opigno_h5p.module
Module main functionality.

File

ActivityTypes/opigno_h5p/src/H5PReport.php, line 8

Namespace

Drupal\opigno_h5p
View source
class H5PReport {
  private static $processorMap = [
    'compound' => 'Drupal\\opigno_h5p\\TypeProcessors\\CompoundProcessor',
    'fill-in' => 'Drupal\\opigno_h5p\\TypeProcessors\\FillInProcessor',
    'true-false' => 'Drupal\\opigno_h5p\\TypeProcessors\\TrueFalseProcessor',
    'matching' => 'Drupal\\opigno_h5p\\TypeProcessors\\MatchingProcessor',
    'choice' => 'Drupal\\opigno_h5p\\TypeProcessors\\ChoiceProcessor',
    'long-choice' => 'Drupal\\opigno_h5p\\TypeProcessors\\LongChoiceProcessor',
  ];
  private $processors = [];

  /**
   * Generate the proper report depending on xAPI data.
   *
   * @param object $xapiData
   *   XAPI data.
   * @param string $forcedProcessor
   *   Force a processor type.
   * @param bool $disableScoring
   *   Disables scoring for the report.
   *
   * @return string
   *   A report.
   */
  public function generateReport($xapiData, $forcedProcessor = NULL, $disableScoring = TRUE) {
    $interactionType = isset($forcedProcessor) ? $forcedProcessor : $xapiData->interaction_type;
    if (!isset(self::$processorMap[$interactionType])) {

      // No processor found.
      return '';
    }
    if (!isset($this->processors[$interactionType])) {

      // Not used before. Initialize new processor.
      $this->processors[$interactionType] = new self::$processorMap[$interactionType]();
    }

    // Generate and return report from xAPI data.
    return $this->processors[$interactionType]
      ->generateReport($xapiData, $disableScoring);
  }

  /**
   * List of CSS stylesheets used by the processors when rendering the report.
   */
  public function getStylesUsed() {
    $styles = [];

    // Fetch style used by each report processor.
    foreach ($this->processors as $processor) {
      $style = $processor
        ->getStyle();
      if (!empty($style)) {
        $styles[] = $style;
      }
    }
    return $styles;
  }

  /**
   * Caches instance of report generator.
   */
  public static function getInstance() {
    static $instance;
    if (!$instance) {
      $instance = new H5PReport();
    }
    return $instance;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
H5PReport::$processorMap private static property
H5PReport::$processors private property
H5PReport::generateReport public function Generate the proper report depending on xAPI data.
H5PReport::getInstance public static function Caches instance of report generator.
H5PReport::getStylesUsed public function List of CSS stylesheets used by the processors when rendering the report.