You are here

function opigno_scorm_combine_manifest_sco_and_resources in Opigno 7

Combine resources and SCO data.

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

Parameters

array $scos:

array $resources:

Return value

array

1 call to opigno_scorm_combine_manifest_sco_and_resources()
opigno_scorm_extract_manifest_data in modules/scorm/includes/opigno_scorm.manifest.inc
Extract the manifest data.

File

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

Code

function opigno_scorm_combine_manifest_sco_and_resources($scos, $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;
          }
        }
      }
    }
  }
  else {
    if (!empty($resources)) {

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

        // 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;
}