From 4388bd45b273e4688e601504dedb85fc217ab063 Mon Sep 17 00:00:00 2001 From: Dan Marsden Date: Sat, 5 Nov 2011 21:51:24 +1300 Subject: [PATCH] SCORM MDL-30146 AICC - add ability to link direct to a simple AICC url --- mod/scorm/datamodels/aicclib.php | 47 ++++++++++++++++++++++++++++++++ mod/scorm/lang/en/scorm.php | 7 ++++- mod/scorm/lib.php | 7 +++-- mod/scorm/locallib.php | 9 +++++- mod/scorm/mod_form.php | 15 ++++++++-- mod/scorm/settings.php | 2 ++ 6 files changed, 79 insertions(+), 8 deletions(-) diff --git a/mod/scorm/datamodels/aicclib.php b/mod/scorm/datamodels/aicclib.php index 1340181f366..c0aca14f744 100644 --- a/mod/scorm/datamodels/aicclib.php +++ b/mod/scorm/datamodels/aicclib.php @@ -110,6 +110,9 @@ function scorm_forge_cols_regexp($columns, $remodule='(".*")?,') { function scorm_parse_aicc($scorm) { global $DB; + if ($scorm->scormtype == SCORM_TYPE_AICCURL) { + return scorm_aicc_generate_simple_sco($scorm); + } if (!isset($scorm->cmid)) { $cm = get_coursemodule_from_instance('scorm', $scorm->id); $scorm->cmid = $cm->id; @@ -388,4 +391,48 @@ function scorm_aicc_confirm_hacp_session($hacpsession) { $DB->update_record('scorm_aicc_session', $hacpsession); } return $hacpsession; +} + +/** + * generate a simple single activity AICC object + * structure to wrap around and externally linked + * AICC package URL + * + * @param object $scorm package record + */ +function scorm_aicc_generate_simple_sco($scorm) { + global $DB; + // find the old one + $scos = $DB->get_records('scorm_scoes', array('scorm'=>$scorm->id)); + if (!empty($scos)) { + $sco = array_shift($scos); + } else { + $sco = new object(); + } + // get rid of old ones + foreach($scos as $oldsco) { + $DB->delete_records('scorm_scoes', array('id'=>$oldsco->id)); + $DB->delete_records('scorm_scoes_track', array('scoid'=>$oldsco->id)); + } + + $sco->identifier = 'A1'; + $sco->scorm = $scorm->id; + $sco->organization = ''; + $sco->title = $scorm->name; + $sco->parent = '/'; + // add the HACP signal to the activity launcher + if (preg_match('/\?/', $scorm->reference)) { + $sco->launch = $scorm->reference.'&CMI=HACP'; + } + else { + $sco->launch = $scorm->reference.'?CMI=HACP'; + } + $sco->scormtype = 'sco'; + if (isset($sco->id)) { + $DB->update_record('scorm_scoes', $sco); + $id = $sco->id; + } else { + $id = $DB->insert_record('scorm_scoes', $sco); + } + return $id; } \ No newline at end of file diff --git a/mod/scorm/lang/en/scorm.php b/mod/scorm/lang/en/scorm.php index 119f1a0f9bd..eba24e9e8e2 100644 --- a/mod/scorm/lang/en/scorm.php +++ b/mod/scorm/lang/en/scorm.php @@ -34,6 +34,8 @@ $string['adminsettings'] = 'Admin settings'; $string['advanced'] = 'Parameters'; $string['allowapidebug'] = 'Activate API debug and tracing (set the capture mask with apidebugmask)'; $string['allowtypeexternal'] = 'Enable external package type'; +$string['allowtypeexternalaicc'] = 'Enable direct AICC url'; +$string['allowtypeexternalaicc_desc'] = 'If enabled this allows a direct url to a simple AICC package'; $string['allowtypeimsrepository'] = 'Enable IMS package type'; $string['allowtypelocalsync'] = 'Enable downloaded package type'; $string['allowtypeaicchacp'] = 'Enable AICC HACP'; @@ -166,6 +168,7 @@ $string['interactionstype'] = 'Type of question'; $string['interactionsweight'] = 'Weight assigned to the element'; $string['interactionslearnerresponse'] = 'Learner\'s Response'; $string['invalidactivity'] = 'Scorm activity is incorrect'; +$string['invalidurl'] = 'Invalid URL specified'; $string['invalidhacpsession'] = 'Invalid HACP Session'; $string['invalidmanifestresource'] = 'WARNING: The following resources were referenced in your manifest but couldn\'t be found:'; $string['last'] = 'Last accessed on'; @@ -265,7 +268,8 @@ $string['scormtype_help'] = 'This setting determines how the package is included * Uploaded package - Enables a SCORM package to be chosen via the file picker * External SCORM manifest - Enables an imsmanifest.xml URL to be specified. Note: If the URL has a different domain name than your site, then "Downloaded package" is a better option, since otherwise grades are not saved. * Downloaded package - Enables a package URL to be specified. The package will be unzipped and saved locally, and updated when the external SCORM package is updated. -* Local IMS content repository - Enables a package to be selected from within an IMS repository'; +* Local IMS content repository - Enables a package to be selected from within an IMS repository +* External AICC URL - this URL is the launch URL for a single AICC Activity. A psuedo package will be constructed around this.'; $string['scorm:viewreport'] = 'View reports'; $string['scorm:viewscores'] = 'View scores'; $string['scrollbars'] = 'Allow the window to be scrolled'; @@ -297,6 +301,7 @@ $string['too_many_children'] = 'Tag {$a->tag} has too many children'; $string['totaltime'] = 'Time'; $string['trackingloose'] = 'WARNING: The tracking data of this package will be lost!'; $string['type'] = 'Type'; +$string['typeaiccurl'] = 'External AICC URL'; $string['typeexternal'] = 'External SCORM manifest'; $string['typeimsrepository'] = 'Local IMS content repository'; $string['typelocal'] = 'Uploaded package'; diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 27288897669..b4c84a94fa4 100644 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -28,6 +28,8 @@ define('SCORM_TYPE_LOCALSYNC', 'localsync'); define('SCORM_TYPE_EXTERNAL', 'external'); /** SCORM_TYPE_IMSREPOSITORY = imsrepository */ define('SCORM_TYPE_IMSREPOSITORY', 'imsrepository'); +/** SCORM_TYPE_AICCURL = external AICC url */ +define('SCORM_TYPE_AICCURL', 'aiccurl'); define('SCORM_TOC_SIDE', 0); define('SCORM_TOC_HIDDEN', 1); @@ -103,13 +105,12 @@ function scorm_add_instance($scorm, $mform=null) { } else if ($record->scormtype === SCORM_TYPE_LOCALSYNC) { $record->reference = $scorm->packageurl; - } else if ($record->scormtype === SCORM_TYPE_EXTERNAL) { $record->reference = $scorm->packageurl; - } else if ($record->scormtype === SCORM_TYPE_IMSREPOSITORY) { $record->reference = $scorm->packageurl; - + } else if ($record->scormtype === SCORM_TYPE_AICCURL) { + $record->reference = $scorm->packageurl; } else { return false; } diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index b9f2619c09f..727b872186c 100644 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -244,6 +244,7 @@ function scorm_parse($scorm, $full) { if (!scorm_parse_aicc($scorm)) { $scorm->version = 'ERROR'; } + $scorm->version = 'AICC'; } } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL and $cfg_scorm->allowtypeexternal) { @@ -266,7 +267,13 @@ function scorm_parse($scorm, $full) { $scorm->version = 'ERROR'; } $newhash = sha1($scorm->reference); - + } else if ($scorm->scormtype === SCORM_TYPE_AICCURL and $cfg_scorm->allowtypeexternalaicc) { + require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); + // AICC + if (!scorm_parse_aicc($scorm)) { + $scorm->version = 'ERROR'; + } + $scorm->version = 'AICC'; } else { // sorry, disabled type return; diff --git a/mod/scorm/mod_form.php b/mod/scorm/mod_form.php index 98dda8b3880..1f17c00991d 100644 --- a/mod/scorm/mod_form.php +++ b/mod/scorm/mod_form.php @@ -62,6 +62,10 @@ class mod_scorm_mod_form extends moodleform_mod { $options[SCORM_TYPE_IMSREPOSITORY] = get_string('typeimsrepository', 'scorm'); } + if ($cfg_scorm->allowtypeexternalaicc) { + $options[SCORM_TYPE_AICCURL] = get_string('typeaiccurl', 'scorm'); + } + // Reference if (count($options) > 1) { $mform->addElement('select', 'scormtype', get_string('scormtype', 'scorm'), $options); @@ -360,19 +364,24 @@ class mod_scorm_mod_form extends moodleform_mod { } else if ($type === SCORM_TYPE_EXTERNAL) { $reference = $data['packageurl']; if (!preg_match('/(http:\/\/|https:\/\/|www).*\/imsmanifest.xml$/i', $reference)) { - $errors['packageurl'] = get_string('required'); // TODO: improve help + $errors['packageurl'] = get_string('invalidurl', 'scorm'); } } else if ($type === 'packageurl') { $reference = $data['reference']; if (!preg_match('/(http:\/\/|https:\/\/|www).*(\.zip|\.pif)$/i', $reference)) { - $errors['packageurl'] = get_string('required'); // TODO: improve help + $errors['packageurl'] = get_string('invalidurl', 'scorm'); } } else if ($type === SCORM_TYPE_IMSREPOSITORY) { $reference = $data['packageurl']; if (stripos($reference, '#') !== 0) { - $errors['packageurl'] = get_string('required'); + $errors['packageurl'] = get_string('invalidurl', 'scorm'); + } + } else if ($type === SCORM_TYPE_AICCURL) { + $reference = $data['packageurl']; + if (!preg_match('/(http:\/\/|https:\/\/|www).*/', $reference)) { + $errors['packageurl'] = get_string('invalidurl', 'scorm'); } } diff --git a/mod/scorm/settings.php b/mod/scorm/settings.php index 06de0aaadbf..e45d0ce7888 100644 --- a/mod/scorm/settings.php +++ b/mod/scorm/settings.php @@ -123,6 +123,8 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configcheckbox('scorm/allowtypeimsrepository', get_string('allowtypeimsrepository', 'scorm'), '', 0)); + $settings->add(new admin_setting_configcheckbox('scorm/allowtypeexternalaicc', get_string('allowtypeexternalaicc', 'scorm'), get_string('allowtypeexternalaicc_desc', 'scorm'), 0)); + $settings->add(new admin_setting_configcheckbox('scorm/allowaicchacp', get_string('allowtypeaicchacp', 'scorm'), get_string('allowtypeaicchacp_desc', 'scorm'), 0)); $settings->add(new admin_setting_configtext('scorm/aicchacptimeout',