Skip to content

Commit

Permalink
MDL-35870 mod_scorm : Separating js and php files
Browse files Browse the repository at this point in the history
  • Loading branch information
nobelium committed Jul 8, 2014
1 parent 4de51c2 commit 139f32c
Show file tree
Hide file tree
Showing 8 changed files with 2,588 additions and 2,461 deletions.
532 changes: 532 additions & 0 deletions mod/scorm/datamodels/aicc.js

Large diffs are not rendered by default.

569 changes: 45 additions & 524 deletions mod/scorm/datamodels/aicc.js.php

Large diffs are not rendered by default.

638 changes: 638 additions & 0 deletions mod/scorm/datamodels/scorm_12.js

Large diffs are not rendered by default.

714 changes: 49 additions & 665 deletions mod/scorm/datamodels/scorm_12.js.php

Large diffs are not rendered by default.

1,229 changes: 1,229 additions & 0 deletions mod/scorm/datamodels/scorm_13.js

Large diffs are not rendered by default.

1,307 changes: 49 additions & 1,258 deletions mod/scorm/datamodels/scorm_13.js.php

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions mod/scorm/loaddatamodel.php
Original file line number Diff line number Diff line change
Expand Up @@ -104,13 +104,26 @@
$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe.
if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php')) {
include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js.php');
echo js_writer::set_variable('api_url_static', '/mod/scorm/datamodels/'.$scorm->version.'.js');
} else {
include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
echo js_writer::set_variable('api_url_static', '/mod/scorm/datamodels/scorm_12.js');
}
// Set the start time of this SCO.
scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
?>

var pel_scorm_api = document.getElementById('scormapi-parent');
var el_scorm_api = document.getElementById("external-scormapi-static");

if(el_scorm_api){
el_scorm_api.parentNode.removeChild(el_scorm_api);
}
el_scorm_api = document.createElement('script');
el_scorm_api.setAttribute('id','external-scormapi-static');
el_scorm_api.setAttribute('type','text/javascript');
pel_scorm_api.appendChild(el_scorm_api);
document.getElementById('external-scormapi-static').src = M.cfg.wwwroot + api_url_static;

var errorCode = "0";
function underscore(str) {
Expand Down
47 changes: 33 additions & 14 deletions mod/scorm/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1008,6 +1008,7 @@ function scorm_reconstitute_array_element($sversion, $userdata, $elementname, $c
$count = 0;
$countsub = 0;
$scormseperator = '_';
$return = '';
if (scorm_version_check($sversion, SCORM_13)) { // Scorm 1.3 elements use a . instead of an _ .
$scormseperator = '.';
}
Expand All @@ -1032,8 +1033,8 @@ function scorm_reconstitute_array_element($sversion, $userdata, $elementname, $c
preg_match('/\_(\d+)\./', $element, $matches);
}
if (count($matches) > 0 && $current != $matches[1]) {
if ($countsub > 0) {
echo ' '.$elementname.$scormseperator.$current.'.'.$currentsubelement.'._count = '.$countsub.";\n";
if ($count_sub > 0) {
$return .= ' '.$element_name.$scormseperator.$current.'.'.$current_subelement.'._count = '.$count_sub.";\n";
}
$current = $matches[1];
$count++;
Expand All @@ -1042,11 +1043,11 @@ function scorm_reconstitute_array_element($sversion, $userdata, $elementname, $c
$countsub = 0;
$end = strpos($element, $matches[1]) + strlen($matches[1]);
$subelement = substr($element, 0, $end);
echo ' '.$subelement." = new Object();\n";
$return .= ' '.$subelement." = new Object();\n";
// now add the children
foreach ($children as $child) {
echo ' '.$subelement.".".$child." = new Object();\n";
echo ' '.$subelement.".".$child."._children = ".$child."_children;\n";
$return .= ' '.$subelement.".".$child." = new Object();\n";
$return .= ' '.$subelement.".".$child."._children = ".$child."_children;\n";
}
}

Expand All @@ -1060,16 +1061,16 @@ function scorm_reconstitute_array_element($sversion, $userdata, $elementname, $c
}

// Check the sub element type.
if (count($matches) > 0 && $currentsubelement != $matches[1]) {
if ($countsub > 0) {
echo ' '.$elementname.$scormseperator.$current.'.'.$currentsubelement.'._count = '.$countsub.";\n";
if (count($matches) > 0 && $current_subelement != $matches[1]) {
if ($count_sub > 0) {
$return .= ' '.$element_name.$scormseperator.$current.'.'.$current_subelement.'._count = '.$count_sub.";\n";
}
$currentsubelement = $matches[1];
$currentsub = '';
$countsub = 0;
$end = strpos($element, $matches[1]) + strlen($matches[1]);
$subelement = substr($element, 0, $end);
echo ' '.$subelement." = new Object();\n";
$return .= ' '.$subelement." = new Object();\n";
}

// Now check the subelement subscript.
Expand All @@ -1078,17 +1079,18 @@ function scorm_reconstitute_array_element($sversion, $userdata, $elementname, $c
$countsub++;
$end = strrpos($element, $matches[2]) + strlen($matches[2]);
$subelement = substr($element, 0, $end);
echo ' '.$subelement." = new Object();\n";
$return .= ' '.$subelement." = new Object();\n";
}

echo ' '.$element.' = \''.$value."';\n";
$return .= ' '.$element.' = \''.$value."';\n";
}
if ($countsub > 0) {
echo ' '.$elementname.$scormseperator.$current.'.'.$currentsubelement.'._count = '.$countsub.";\n";
if ($count_sub > 0) {
$return .= ' '.$element_name.$scormseperator.$current.'.'.$current_subelement.'._count = '.$count_sub.";\n";
}
if ($count > 0) {
echo ' '.$elementname.'._count = '.$count.";\n";
$return .= ' '.$element_name.'._count = '.$count.";\n";
}
return $return;
}

/**
Expand Down Expand Up @@ -1935,3 +1937,20 @@ function scorm_check_url($url) {

return true;
}

// Helper function.
function scorm_isset($userdata, $param, $ifempty = '') {
if (isset($userdata->$param)) {
return $userdata->$param;
} else {
return $ifempty;
}
}

function scorm_empty($userdata, $param, $ifempty = '', $addslash = false) {
if (!empty($userdata->$param)) {
return $addslash ? '\''.$userdata->$param.'\'' : $userdata->$param;
} else {
return $ifempty;
}
}

0 comments on commit 139f32c

Please sign in to comment.