MDL-28311 SCORM tidy up php warnings and display warning message to teacher that...
authorDan Marsden <dan@danmarsden.com>
Tue, 2 Aug 2011 12:03:19 +0000 (00:03 +1200)
committerDan Marsden <dan@danmarsden.com>
Wed, 3 Aug 2011 23:08:42 +0000 (11:08 +1200)
mod/scorm/datamodels/scormlib.php
mod/scorm/lang/en/scorm.php

index 8bee8d8..1d9dd02 100644 (file)
@@ -17,7 +17,7 @@
 function scorm_get_resources($blocks) {
     $resources = array();
     foreach ($blocks as $block) {
-        if ($block['name'] == 'RESOURCES') {
+        if ($block['name'] == 'RESOURCES' && isset($block['children'])) {
             foreach ($block['children'] as $resource) {
                 if ($resource['name'] == 'RESOURCE') {
                     $resources[addslashes_js($resource['attrs']['IDENTIFIER'])] = $resource['attrs'];
@@ -29,12 +29,14 @@ function scorm_get_resources($blocks) {
 }
 
 function scorm_get_manifest($blocks, $scoes) {
+    global $OUTPUT;
     static $parents = array();
     static $resources;
 
     static $manifest;
     static $organization;
 
+    $manifestresourcesnotfound = array();
     if (count($blocks) > 0) {
         foreach ($blocks as $block) {
             switch ($block['name']) {
@@ -130,11 +132,16 @@ function scorm_get_manifest($blocks, $scoes) {
                         if (isset($resources[$idref]['XML:BASE'])) {
                             $base = $resources[$idref]['XML:BASE'];
                         }
-                        $scoes->elements[$manifest][$organization][$identifier]->launch = $base.$resources[$idref]['HREF'];
-                        if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
-                            $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
+                        if (!isset($resources[$idref])) {
+                            $manifestresourcesnotfound[] = $idref;
+                            $scoes->elements[$manifest][$organization][$identifier]->launch = '';
+                        } else {
+                            $scoes->elements[$manifest][$organization][$identifier]->launch = $base.$resources[$idref]['HREF'];
+                            if (empty($resources[$idref]['ADLCP:SCORMTYPE'])) {
+                                $resources[$idref]['ADLCP:SCORMTYPE'] = 'asset';
+                            }
+                            $scoes->elements[$manifest][$organization][$identifier]->scormtype = $resources[$idref]['ADLCP:SCORMTYPE'];
                         }
-                        $scoes->elements[$manifest][$organization][$identifier]->scormtype = $resources[$idref]['ADLCP:SCORMTYPE'];
                     }
 
                     $parent = new stdClass();
@@ -473,6 +480,13 @@ function scorm_get_manifest($blocks, $scoes) {
             }
         }
     }
+    if (!empty($manifestresourcesnotfound)) {
+        //throw warning to user to let them know manifest contains references to resources that don't appear to exist.
+        if (!defined('DEBUGGING_PRINTED')) { //prevent redirect and display warning
+            define('DEBUGGING_PRINTED', 1);
+        }
+        echo $OUTPUT->notification(get_string('invalidmanifestresource', 'scorm').' '. implode(', ',$manifestresourcesnotfound));
+    }
     return $scoes;
 }
 
index 2fcb0ec..b972a29 100644 (file)
@@ -146,6 +146,7 @@ $string['incomplete'] = 'Incomplete';
 $string['info'] = 'Info';
 $string['interactions'] = 'Interactions';
 $string['invalidactivity'] = 'Scorm activity is incorrect';
+$string['invalidmanifestresource'] = 'WARNING: The following resources were referenced in your manifest but couldn\'t be found:';
 $string['last'] = 'Last accessed on';
 $string['lastaccess'] = 'Last access';
 $string['lastattempt'] = 'Last attempt';