Permalink
Browse files

MDL-28933 SCORM use a global function to check SCORM version to make …

…sure all methods of storing SCORM version are checked.
  • Loading branch information...
1 parent 05c2b85 commit e6402b54ad985d5114ae3cc28f04c573bbb0dcca @danmarsden danmarsden committed Aug 15, 2011
View
@@ -60,7 +60,7 @@
if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
//according to SCORM 2004 spec(RTE V1, 4.2.8), only cmi.exit==suspend should allow previous datamodel elements on re-launch
- if ($scorm->version != "SCORM_1.3" || (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) {
+ if (!scorm_version_check($scorm->version, SCORM_13) || (isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend'))) {
foreach ($usertrack as $key => $value) {
$userdata->$key = addslashes_js($value);
}
@@ -93,7 +93,7 @@
if (!$sco = scorm_get_sco($scoid)) {
print_error('cannotfindsco', 'scorm');
}
-if ($scorm->version == "SCORM_1.3") {
+if (scorm_version_check($scorm->version, SCORM_13)) {
$userdata->{'cmi.scaled_passing_score'} = $DB->get_field('scorm_seq_objective', 'minnormalizedmeasure', array('scoid'=>$scoid));
}
$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
@@ -85,11 +85,11 @@ function toggleLog () {
var logPopUpWindow = "N";
var debugSCORMVersion = '<?php echo $scorm->version; ?>';
<?php
- $LMS_prefix = ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) ? 'LMS' : '';
- $LMS_api = ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) ? 'API' : 'API_1484_11';
+ $LMS_prefix = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'LMS' : '';
+ $LMS_api = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11';
$LMS_elements = array();
- if ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) {
+ if (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) {
$LMS_elements = array( 'cmi.core._children',
'cmi.core.student_id',
'cmi.core.student_name',
@@ -653,8 +653,8 @@ function UpdateLog(s) {
+ ' id="commitButton"'
+ ' name="commitButton">'
+ ' <input type="button"'
- + ' value="<?php echo $scorm->version == 'scorm_12' ? 'LMSFinish' : 'Terminate'; ?>() "'
- + ' onclick="try<?php echo $scorm->version == 'scorm_12' ? 'LMSFinish' : 'LMSTerminate'; ?>();"'
+ + ' value="<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'Terminate'; ?>() "'
+ + ' onclick="try<?php echo scorm_version_check($scorm->version, SCORM_12) ? 'LMSFinish' : 'LMSTerminate'; ?>();"'
+ ' id="finishButton"'
+ ' name="finishButton">'
+ ' </td>'
View
@@ -34,6 +34,11 @@
define('SCORM_TOC_POPUP', 2);
define('SCORM_TOC_DISABLED', 3);
+//used to check what SCORM version is being used.
+define('SCORM_12', 1);
+define('SCORM_13', 2);
+define('SCORM_AICC', 3);
+
/**
* Given an object containing all the necessary data,
* (defined by the form in mod_form.php) this function
@@ -1084,3 +1089,38 @@ function scorm_page_type_list($pagetype, $parentcontext, $currentcontext) {
$module_pagetype = array('mod-scorm-*'=>get_string('page-mod-scorm-x', 'scorm'));
return $module_pagetype;
}
+
+/**
+ * Returns the SCORM version used.
+ * @param string $scormversion comes from $scorm->version
+ * @param string $version one of the defined vars SCORM_12, SCORM_13, SCORM_AICC (or empty)
+ * @return Scorm version.
+ */
+function scorm_version_check($scormversion, $version='') {
+ $scormversion = trim(strtolower($scormversion));
+ if (empty($version) || $version==SCORM_12) {
+ if ($scormversion == 'scorm_12' || $scormversion == 'scorm_1.2') {
+ return SCORM_12;
+ }
+ if (!empty($version)) {
+ return false;
+ }
+ }
+ if (empty($version) || $version == SCORM_13) {
+ if ($scormversion == 'scorm_13' || $scormversion == 'scorm_1.3') {
+ return SCORM_13;
+ }
+ if (!empty($version)) {
+ return false;
+ }
+ }
+ if (empty($version) || $version == SCORM_AICC) {
+ if (strpos($scormversion, 'aicc')) {
+ return SCORM_AICC;
+ }
+ if (!empty($version)) {
+ return false;
+ }
+ }
+ return false;
+}
View
@@ -86,7 +86,7 @@
if ($sco->scormtype == 'asset') {
$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
- $element = ($scorm->version == 'scorm_13' || $scorm->version == 'SCORM_1.3') ? 'cmi.completion_status':'cmi.core.lesson_status';
+ $element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status':'cmi.core.lesson_status';
$value = 'completed';
$result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
}
@@ -137,7 +137,7 @@
}
// which API are we looking for
-$LMS_api = ($scorm->version == 'scorm_12' || $scorm->version == 'SCORM_1.2' || empty($scorm->version)) ? 'API' : 'API_1484_11';
+$LMS_api = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11';
?>
<html>
<head>
@@ -61,7 +61,7 @@
require_login($course, false, $cm);
if ($usertrack = scorm_get_tracks($scoid, $USER->id, $attempt)) {
- if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
+ if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || (!scorm_version_check($scorm->version, SCORM_13))) {
foreach ($usertrack as $key => $value) {
$userdata->$key = addslashes_js($value);
}
View
@@ -886,7 +886,7 @@ function scorm_reconstitute_array_element($sversion, $userdata, $element_name, $
$count = 0;
$count_sub = 0;
$scormseperator = '_';
- if ($sversion == 'scorm_13') { //scorm 1.3 elements use a . instead of an _
+ if (scorm_version_check($sversion, SCORM_13)) { //scorm 1.3 elements use a . instead of an _
$scormseperator = '.';
}
// filter out the ones we want
@@ -902,7 +902,7 @@ function scorm_reconstitute_array_element($sversion, $userdata, $element_name, $
// generate JavaScript
foreach ($element_list as $element => $value) {
- if ($sversion == 'scorm_13') {
+ if (scorm_version_check($sversion, SCORM_13)) {
$element = preg_replace('/\.(\d+)\./', ".N\$1.", $element);
preg_match('/\.(N\d+)\./', $element, $matches);
} else {
@@ -929,7 +929,7 @@ function scorm_reconstitute_array_element($sversion, $userdata, $element_name, $
}
// now - flesh out the second level elements if there are any
- if ($sversion == 'scorm_13') {
+ if (scorm_version_check($sversion, SCORM_13)) {
$element = preg_replace('/(.*?\.N\d+\..*?)\.(\d+)\./', "\$1.N\$2.", $element);
preg_match('/.*?\.N\d+\.(.*?)\.(N\d+)\./', $element, $matches);
} else {
@@ -1113,7 +1113,7 @@ function scorm_get_attempt_count($userid, $scorm, $attempts_only=false) {
if ($scorm->grademethod == GRADESCOES) {
$element = 'cmi.core.lesson_status';
}
- if ($scorm->version == 'scorm_13' || $scorm->version == 'SCORM_1.3') {
+ if (scorm_version_check($scorm->version, SCORM_13)) {
$element = 'cmi.score.raw';
}
$attempts = $DB->get_records_select('scorm_scoes_track', "element=? AND userid=? AND scormid=?", array($element, $userid, $scorm->id), 'attempt', 'DISTINCT attempt AS attemptnumber');
@@ -1384,7 +1384,7 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
}
$strsuspended = get_string('suspended','scorm');
$exitvar = 'cmi.core.exit';
- if ($scorm->version == 'SCORM_1.3') {
+ if (scorm_version_check($scorm->version, SCORM_13)) {
$exitvar = 'cmi.exit';
}
if ($incomplete && isset($usertrack->{$exitvar}) && ($usertrack->{$exitvar} == 'suspend')) {
@@ -1410,8 +1410,7 @@ function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$sco
$previd = $sco->id;
}
}
-
- if ($scorm->version == 'SCORM_1.3') {
+ if (scorm_version_check($scorm->version, SCORM_13)) {
require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
$prereq = scorm_seq_evaluate($sco->id,$usertracks);
} else {
@@ -422,7 +422,7 @@ function display($scorm, $cm, $course, $download) {
if ($trackdata->score_raw != '') {
$score = $trackdata->score_raw;
// add max score if it exists
- if ($scorm->version == 'SCORM_1.3') {
+ if (scorm_version_check($scorm->version, SCORM_13)) {
$maxkey = 'cmi.score.max';
} else {
$maxkey = 'cmi.core.score.max';
View
@@ -180,7 +180,7 @@
$table->width = '100%';
$table->size = array('*', '*');
$existelements = false;
- if ($scorm->version == 'SCORM_1.3') {
+ if (scorm_version_check($scorm->version, SCORM_13)) {
$elements = array(
'raw' => 'cmi.score.raw',
'min' => 'cmi.score.min',

0 comments on commit e6402b5

Please sign in to comment.