You are here

public function OpignoScorm::scormExtractManifestData in Opigno SCORM 3.x

Same name and namespace in other branches
  1. 8 src/OpignoScorm.php \Drupal\opigno_scorm\OpignoScorm::scormExtractManifestData()

Extract manifest data from the manifest file.

Parameters

string $manifest_file: Path to manifest file.

Return value

array Manifest data.

1 call to OpignoScorm::scormExtractManifestData()
OpignoScorm::scormExtract in src/OpignoScorm.php
Extract and save Scorm data from Scorm package.

File

src/OpignoScorm.php, line 311

Class

OpignoScorm
Class OpignoScorm.

Namespace

Drupal\opigno_scorm

Code

public function scormExtractManifestData($manifest_file) {
  $data = [
    'manifest_id' => '',
  ];

  // Get the XML as a string.
  $manifest_string = file_get_contents($manifest_file);

  // Parse it as an array.
  $parser = new XML2Array();
  $manifest = $parser
    ->parse($manifest_string);

  // The parser returns an array of arrays - skip the first element.
  $manifest = array_shift($manifest);

  // Get the manifest ID, if any.
  if (!empty($manifest['attrs']['IDENTIFIER'])) {
    $data['manifest_id'] = $manifest['attrs']['IDENTIFIER'];
  }
  else {
    $data['manifest_id'] = '';
  }

  // Extract the global metadata information.
  $data['metadata'] = $this
    ->scormExtractManifestMetadata($manifest);

  // Extract the SCOs (course items).
  // Gets the default SCO and a list of all SCOs.
  $data['scos'] = $this
    ->scormExtractManifestScos($manifest);

  // Extract the resources, so we can combine the SCOs and resources.
  $data['resources'] = $this
    ->scormExtractManifestResources($manifest);

  // Combine the resources and SCOs.
  $data['scos']['items'] = $this
    ->scormCombineManifestScoAndResources($data['scos']['items'], $data['resources']);
  return $data;
}