You are here

private function OpignoScorm::scormExtractItemSequencingObjectives in Opigno SCORM 8

Same name and namespace in other branches
  1. 3.x src/OpignoScorm.php \Drupal\opigno_scorm\OpignoScorm::scormExtractItemSequencingObjectives()

Extract the manifest SCO item sequencing objective.

This extracts sequencing objectives from an item. Objectives allow the system to know how to "grade" the SCORM object.

Parameters

array $item_manifest: Manifest.

Return value

array SCO item sequencing objective.

1 call to OpignoScorm::scormExtractItemSequencingObjectives()
OpignoScorm::scormExtractManifestScosItems in src/OpignoScorm.php
Helper function to recursively extract the manifest SCO items.

File

src/OpignoScorm.php, line 750

Class

OpignoScorm
Class OpignoScorm.

Namespace

Drupal\opigno_scorm

Code

private function scormExtractItemSequencingObjectives(array $item_manifest) {
  $objectives = [];
  foreach ($item_manifest['children'] as $child) {
    if ($child['name'] == 'IMSSS:OBJECTIVES') {
      foreach ($child['children'] as $child_objective) {
        if (!empty($child_objective['attrs']['OBJECTIVEID'])) {
          $id = $child_objective['attrs']['OBJECTIVEID'];
        }
        else {
          $id = uniqid();
        }
        if ($child_objective['name'] == 'IMSSS:PRIMARYOBJECTIVE') {

          // Note: boolean attributes are stored as a strings.
          // PHP does not know how to cast 'false' to FALSE.
          // Use string comparisons to bypass this limitation by PHP.
          // See below.
          $satisfied_by_measure = FALSE;
          if (!empty($child_objective['attrs']['SATISFIEDBYMEASURE'])) {
            $satisfied_by_measure = strtolower($child_objective['attrs']['SATISFIEDBYMEASURE']) === 'true';
          }
          $objective = [
            'primary' => TRUE,
            'secondary' => FALSE,
            'id' => $id,
            'satisfied_by_measure' => $satisfied_by_measure,
          ];
          foreach ($child_objective['children'] as $primary_obj_child) {
            if ($primary_obj_child['name'] == 'IMSSS:MINNORMALIZEDMEASURE') {
              $objective['min_normalized_measure'] = $primary_obj_child['tagData'];
            }
            elseif ($primary_obj_child['name'] == 'IMSSS:MAXNORMALIZEDMEASURE') {
              $objective['max_normalized_measure'] = $primary_obj_child['tagData'];
            }
          }
          $objectives[] = $objective;
        }
        elseif ($child_objective['name'] == 'IMSSS:OBJECTIVE') {
          $objectives[] = [
            'primary' => FALSE,
            'secondary' => TRUE,
            'id' => $id,
          ];
        }
      }
    }
  }
  return $objectives;
}