You are here

private function OpignoScorm::scormCombineManifestScoAndResources in Opigno SCORM 8

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

Combine resources and SCO data.

Update SCO data to include resource information (if necessary). Return the updated SCO list.

Parameters

array $scos: Scos.

array $resources: Resources.

Return value

array SCO data.

1 call to OpignoScorm::scormCombineManifestScoAndResources()
OpignoScorm::scormExtractManifestData in src/OpignoScorm.php
Extract manifest data from the manifest file.

File

src/OpignoScorm.php, line 628

Class

OpignoScorm
Class OpignoScorm.

Namespace

Drupal\opigno_scorm

Code

private function scormCombineManifestScoAndResources(array $scos, array $resources) {
  if (!empty($scos)) {
    foreach ($scos as &$sco) {

      // If the SCO has a resource identifier ("identifierref"),
      // we need to combine them.
      if (!empty($sco['resource_identifier'])) {

        // Check all resources, and break when the correct one is found.
        foreach ($resources as $resource) {
          if (!empty($resource['identifier']) && $resource['identifier'] == $sco['resource_identifier']) {

            // If the SCO has no launch attribute, get the resource href.
            if (!empty($resource['href']) && empty($sco['launch'])) {
              $sco['launch'] = $resource['href'];
            }

            // Set the SCO type, if available.
            if (!empty($resource['type']) && empty($sco['type'])) {
              $sco['type'] = $resource['type'];
            }

            // Set the SCO scorm type, if available.
            if (!empty($resource['scorm_type']) && empty($sco['scorm_type'])) {
              $sco['scorm_type'] = $resource['scorm_type'];
            }
            break;
          }
        }
      }
    }
  }
  elseif (!empty($resources)) {

    // Init scos array.
    $scos = [];
    foreach ($resources as $resource) {
      $sco = [];

      // Add lunch key for the sco.
      if (!empty($resource['href'])) {
        $sco['launch'] = $resource['href'];
      }

      // Add type key for the sco.
      if (!empty($resource['type'])) {
        $sco['type'] = $resource['type'];
      }

      // Add scorm type key for the sco.
      if (!empty($resource['scorm_type'])) {
        $sco['scorm_type'] = $resource['scorm_type'];
      }

      // Add scorm type key for the sco.
      if (empty($resource['title']) && !empty($resource['identifier'])) {
        $sco['title'] = $resource['identifier'];
      }

      // Set identifier and default values.
      $sco['identifier'] = $resource['identifier'];
      $sco['parent_identifier'] = 0;
      $sco['weight'] = 0;

      // Add created sco to scos list.
      $scos[] = $sco;
    }
  }
  return $scos;
}