From 03c348895731a83c5e087d472bf3f76e38f7ff97 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Wed, 3 Aug 2011 00:03:19 +1200 Subject: [PATCH] MDL-28311 SCORM tidy up php warnings and display warning message to teacher that their manifest is invalid --- mod/scorm/datamodels/scormlib.php | 24 +++++++++++++++++++----- mod/scorm/lang/en/scorm.php | 1 + 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/mod/scorm/datamodels/scormlib.php b/mod/scorm/datamodels/scormlib.php index 8bee8d8ce7a..1d9dd02705f 100644 --- a/mod/scorm/datamodels/scormlib.php +++ b/mod/scorm/datamodels/scormlib.php @@ -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; } diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index 2fcb0ec8ef6..b972a2970fc 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -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';