You are here

function _opigno_scorm_extract_manifest_scos_items in Opigno 7

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:

string|int $parent_identifier = 0:

string $organization = '':

Return value

array

1 call to _opigno_scorm_extract_manifest_scos_items()
opigno_scorm_extract_manifest_scos in modules/scorm/includes/opigno_scorm.manifest.inc
Extract the manifest SCO items.

File

modules/scorm/includes/opigno_scorm.manifest.inc, line 279
Manifest file extraction logic.

Code

function _opigno_scorm_extract_manifest_scos_items($manifest, $parent_identifier = 0, $organization = '') {
  $items = array();
  $weight = 0;
  foreach ($manifest as $item) {
    if (in_array($item['name'], array(
      OPIGNO_SCORM_MANIFEST_ORGANIZATION,
      OPIGNO_SCORM_MANIFEST_ITEM,
    )) && !empty($item['children'])) {
      $attributes = array();
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_ID_ATTR])) {
        $identifier = $item['attrs'][OPIGNO_SCORM_MANIFEST_ID_ATTR];
      }
      else {
        $identifier = uniqid();
      }
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_LAUNCH_ATTR])) {
        $launch = $item['attrs'][OPIGNO_SCORM_MANIFEST_LAUNCH_ATTR];
      }
      else {
        $launch = '';
      }
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_REFID_ATTR])) {
        $resource_identifier = $item['attrs'][OPIGNO_SCORM_MANIFEST_REFID_ATTR];
      }
      else {
        $resource_identifier = '';
      }
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_PARAM_ATTR])) {
        $attributes['parameters'] = $item['attrs'][OPIGNO_SCORM_MANIFEST_PARAM_ATTR];
      }
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_TYPE_ATTR])) {
        $type = $item['attrs'][OPIGNO_SCORM_MANIFEST_TYPE_ATTR];
      }
      else {
        $type = '';
      }
      if (!empty($item['attrs'][OPIGNO_SCORM_MANIFEST_SCORM_TYPE_ATTR])) {
        $scorm_type = $item['attrs'][OPIGNO_SCORM_MANIFEST_SCORM_TYPE_ATTR];
      }
      else {
        $scorm_type = '';
      }

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

      // Find any sequencing control modes, which are also child nodes.
      $control_modes = array();
      foreach ($item['children'] as $child) {
        if ($child['name'] == OPIGNO_SCORM_MANIFEST_SEQUENCING) {
          $control_modes = opigno_scorm_extract_item_sequencing_control_modes($child);
          $attributes['objectives'] = opigno_scorm_extract_item_sequencing_objectives($child);
        }
      }

      // Failsafe - we cannot have elements without a title.
      if (empty($title)) {
        $title = 'NO TITLE';
      }
      $items[] = array(
        'manifest' => '',
        // @deprecated
        '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'] == OPIGNO_SCORM_MANIFEST_ORGANIZATION) {
        $organization = $identifier;
      }

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