You are here

private function OpignoScorm::scormExtractManifestScosItems in Opigno SCORM 8

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

Helper function to recursively extract the manifest SCO items.

The data is extracted as a flat array - it contains to hierarchy. Because of this, the items are not extracted in logical order. However, each "level" is given a weight which allows us to know how to organize them.

Parameters

array $manifest: Manifest.

string|int $parent_identifier: Parent identifier.

string $organization: Organization.

Return value

array Manifest SCO items.

1 call to OpignoScorm::scormExtractManifestScosItems()
OpignoScorm::scormExtractManifestScos in src/OpignoScorm.php
Extract scos from the manifest.

File

src/OpignoScorm.php, line 454

Class

OpignoScorm
Class OpignoScorm.

Namespace

Drupal\opigno_scorm

Code

private function scormExtractManifestScosItems(array $manifest, $parent_identifier = 0, $organization = '') {
  $items = [];
  $weight = 0;
  foreach ($manifest as $item) {
    if (in_array($item['name'], [
      'ORGANIZATION',
      'ITEM',
    ]) && !empty($item['children'])) {
      $attributes = [];
      if (!empty($item['attrs']['IDENTIFIER'])) {
        $identifier = $item['attrs']['IDENTIFIER'];
      }
      else {
        $identifier = uniqid();
      }
      if (!empty($item['attrs']['LAUNCH'])) {
        $launch = $item['attrs']['LAUNCH'];
      }
      else {
        $launch = '';
      }
      if (!empty($item['attrs']['IDENTIFIERREF'])) {
        $resource_identifier = $item['attrs']['IDENTIFIERREF'];
      }
      else {
        $resource_identifier = '';
      }
      if (!empty($item['attrs']['PARAMETERS'])) {
        $attributes['parameters'] = $item['attrs']['PARAMETERS'];
      }
      if (!empty($item['attrs']['TYPE'])) {
        $type = $item['attrs']['TYPE'];
      }
      else {
        $type = '';
      }
      if (!empty($item['attrs']['ADLCP:SCORMTYPE'])) {
        $scorm_type = $item['attrs']['ADLCP:SCORMTYPE'];
      }
      else {
        $scorm_type = '';
      }

      // Find the title, which is also a child node.
      foreach ($item['children'] as $child) {
        if ($child['name'] == 'TITLE') {
          $title = $child['tagData'];
          break;
        }
      }

      // Find any sequencing control modes, which are also child nodes.
      $control_modes = [];
      foreach ($item['children'] as $child) {
        if ($child['name'] == 'IMSSS:SEQUENCING') {
          $control_modes = $this
            ->scormExtractItemSequencingControlModes($child);
          $attributes['objectives'] = $this
            ->scormExtractItemSequencingObjectives($child);
        }
      }

      // Failsafe - we cannot have elements without a title.
      if (empty($title)) {
        $title = 'NO TITLE';
      }
      $items[] = [
        'manifest' => '',
        'organization' => $organization,
        'title' => $title,
        'identifier' => $identifier,
        'parent_identifier' => $parent_identifier,
        'launch' => $launch,
        'resource_identifier' => $resource_identifier,
        'type' => $type,
        'scorm_type' => $scorm_type,
        'weight' => $weight,
        'attributes' => $control_modes + $attributes,
      ];

      // The first item is not an "item",
      // but an "organization" node. This is the organization
      // for the remainder of the tree.
      // Get it, and pass it along, so we know to which organization
      // the SCOs belong.
      if (empty($organization) && $item['name'] == 'ORGANIZATION') {
        $organization = $identifier;
      }

      // Recursively get child items, and merge them to get a flat list.
      $items = array_merge($this
        ->scormExtractManifestScosItems($item['children'], $identifier, $organization), $items);
    }
    $weight++;
  }
  return $items;
}