Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added prerequisites support

  • Loading branch information...
commit d771d90c8afd89e3c36ad36c8b8cad69f5d3e021 1 parent e3931ca
bobopinna authored
Showing with 216 additions and 13 deletions.
  1. +5 −2 lang/en/scorm.php
  2. +192 −6 mod/scorm/lib.php
  3. +19 −5 mod/scorm/playscorm.php
7 lang/en/scorm.php
View
@@ -41,10 +41,10 @@
$string['expcoll'] = 'Expand/Collide';
$string['exit'] = 'Exit from SCORM course';
$string['details'] = 'SCO track details';
-$string['enablebrowse'] = 'Enable preview mode';
+$string['hidebrowse'] = 'Hide preview mode button';
$string['frameheight'] = 'This preference set the default height of SCO frame';
$string['framewidth'] = 'This preference set the default width of SCO frame';
-$string['stagesize'] = 'Frame/Windows size';
+$string['stagesize'] = 'Frame/Window size';
$string['width'] = 'Width';
$string['height'] = 'Height';
$string['trackingloose'] = 'WARNING: The tracking data of this package will be lost!';
@@ -55,6 +55,9 @@
$string['lastaccess'] = 'Last access';
$string['scormcourse'] = 'SCORM Course';
$string['advanced'] = 'Advanced';
+$string['window'] = 'Frame/Window';
+$string['hidetoc'] = 'Hide course structure from player window';
+$string['noprerequisites'] = 'Sorry but you don\'t reach enough prerequisites to access this learning object';
// Validation
$string['attr_error'] = 'Bad value for attribute ($a->attr) in tag $a->tag.';
198 mod/scorm/lib.php
View
@@ -980,6 +980,172 @@ function scorm_string_round($stringa, $len=11) {
}
}
+/*function scorm_id_search($id, $usertracks) {
+ foreach ($usertracks as $key => $usertrack) {
+ if ($usertrack->identifier == $id) {
+ return $key;
+ }
+ }
+ return false;
+} */
+
+function scorm_eval_prerequisites($prerequisites,$usertracks) {
+ $element = '';
+ $stack = array();
+ $statuses = array(
+ 'passed' => 'passed',
+ 'completed' => 'completed',
+ 'failed' => 'failed',
+ 'incomplete' => 'incomplete',
+ 'browsed' => 'browsed',
+ 'not attempted' => 'notattempted',
+ 'p' => 'passed',
+ 'c' => 'completed',
+ 'f' => 'failed',
+ 'i' => 'incomplete',
+ 'b' => 'browsed',
+ 'n' => 'notattempted'
+ );
+ $i=0;
+ while ($i<strlen($prerequisites)) {
+ $symbol = $prerequisites[$i];
+ switch ($symbol) {
+ case '&':
+ case '|':
+ $symbol .= $symbol;
+ case '~':
+ case '(':
+ case ')':
+ case '*':
+ case '{':
+ case '}':
+ case ',':
+ $element = trim($element);
+
+ if (!empty($element)) {
+ $element = trim($element);
+ if (isset($usertracks[$element])) {
+ $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
+ '(\''.$usertracks[$element]->status.'\' == \'passed\'))';
+ } else if (($operator = strpos($element,'=')) !== false) {
+ $item = trim(substr($element,0,$operator));
+ if (!isset($usertracks[$item])) {
+ return false;
+ }
+
+ $value = trim(trim(substr($element,$operator+1)),'"');
+ if (isset($statuses[$value])) {
+ $status = $statuses[$value];
+ } else {
+ return false;
+ }
+
+ $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
+ } else if (($operator = strpos($element,'<>')) !== false) {
+ $item = trim(substr($element,0,$operator));
+ if (!isset($usertracks[$item])) {
+ return false;
+ }
+
+ $value = trim(trim(substr($element,$operator+2)),'"');
+ if (isset($statuses[$value])) {
+ $status = $statuses[$value];
+ } else {
+ return false;
+ }
+
+ $element = '(\''.$usertracks[$item]->status.'\' != \''.$status.'\')';
+ } else if (is_numeric($element)) {
+ if ($symbol == '*') {
+ $symbol = '';
+ $open = strpos($prerequisites,'{',$i);
+ $opened = 1;
+ $closed = 0;
+ for ($close=$open+1; (($opened > $closed) && ($close<strlen($prerequisites))); $close++) {
+ if ($prerequisites[$close] == '}') {
+ $closed++;
+ } else if ($prerequisites[$close] == '{') {
+ $opened++;
+ }
+ }
+ $i = $close;
+
+ $setelements = explode(',', substr($prerequisites, $open+1, $close-($open+1)-1));
+ $settrue = 0;
+ foreach ($setelements as $setelement) {
+ if (scorm_eval_prerequisites($setelement,$usertracks)) {
+ $settrue++;
+ }
+ }
+
+ if ($settrue >= $element) {
+ $element = 'true';
+ } else {
+ $element = 'false';
+ }
+ }
+ } else {
+ return false;
+ }
+
+ array_push($stack,$element);
+ $element = '';
+ }
+ if ($symbol == '~') {
+ $symbol = '!';
+ }
+ if (!empty($symbol)) {
+ array_push($stack,$symbol);
+ }
+ break;
+ default:
+ $element .= $symbol;
+ break;
+ }
+ $i++;
+ }
+ if (!empty($element)) {
+ $element = trim($element);
+ if (isset($usertracks[$element])) {
+ $element = '((\''.$usertracks[$element]->status.'\' == \'completed\') || '.
+ '(\''.$usertracks[$element]->status.'\' == \'passed\'))';
+ } else if (($operator = strpos($element,'=')) !== false) {
+ $item = trim(substr($element,0,$operator));
+ if (!isset($usertracks[$item])) {
+ return false;
+ }
+
+ $value = trim(trim(substr($element,$operator+1)),'"');
+ if (isset($statuses[$value])) {
+ $status = $statuses[$value];
+ } else {
+ return false;
+ }
+
+ $element = '(\''.$usertracks[$item]->status.'\' == \''.$status.'\')';
+ } else if (($operator = strpos($element,'<>')) !== false) {
+ $item = trim(substr($element,0,$operator));
+ if (!isset($usertracks[$item])) {
+ return false;
+ }
+
+ $value = trim(trim(substr($element,$operator+1)),'"');
+ if (isset($statuses[$value])) {
+ $status = $statuses[$value];
+ } else {
+ return false;
+ }
+
+ $element = '(\''.$usertracks[$item]->status.'\' != \''.trim($status).'\')';
+ } else {
+ return false;
+ }
+
+ array_push($stack,$element);
+ }
+ return eval('return '.implode($stack).';');
+}
+
function scorm_external_link($link) {
// check if a link is external
$result = false;
@@ -1010,6 +1176,18 @@ function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal'
$organizationsql = "AND organization='$currentorg'";
}
if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' $organizationsql order by id ASC")){
+ $usertracks = array();
+ foreach ($scoes as $sco) {
+ if (!empty($sco->launch)) {
+ if ($usertrack=scorm_get_tracks($sco->id,$USER->id)) {
+ if ($usertrack->status == '') {
+ $usertrack->status = 'notattempted';
+ }
+ $usertracks[$sco->identifier] = $usertrack;
+ }
+ }
+ }
+
$level=0;
$sublist=1;
$previd = 0;
@@ -1050,17 +1228,15 @@ function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal'
if (empty($sco->title)) {
$sco->title = $sco->identifier;
}
- if ($sco->launch) {
+ if (!empty($sco->launch)) {
$startbold = '';
$endbold = '';
$score = '';
if (empty($scoid) && ($mode != 'normal')) {
$scoid = $sco->id;
}
- if ($usertrack=scorm_get_tracks($sco->id,$USER->id)) {
- if ($usertrack->status == '') {
- $usertrack->status = 'notattempted';
- }
+ if (isset($usertracks[$sco->identifier])) {
+ $usertrack = $usertracks[$sco->identifier];
$strstatus = get_string($usertrack->status,'scorm');
$result->toc .= "<img src='".$CFG->wwwroot."/mod/scorm/pix/".$usertrack->status.".gif' alt='$strstatus' title='$strstatus' />";
if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
@@ -1097,7 +1273,17 @@ function scorm_get_toc($scorm,$liststyle,$currentorg='',$scoid='',$mode='normal'
if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ( $nextsco!==false)) {
$previd = $sco->id;
}
- $result->toc .= "&nbsp;$startbold<a href='javascript:playSCO(".$sco->id.");'>$sco->title</a> $score$endbold</li>\n";
+ if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
+ if ($sco->id == $scoid) {
+ $result->prerequisites = true;
+ }
+ $result->toc .= "&nbsp;$startbold<a href='javascript:playSCO(".$sco->id.");'>$sco->title</a> $score$endbold</li>\n";
+ } else {
+ if ($sco->id == $scoid) {
+ $result->prerequisites = false;
+ }
+ $result->toc .= "&nbsp;$sco->title</li>\n";
+ }
} else {
$result->toc .= "&nbsp;$sco->title</li>\n";
}
24 mod/scorm/playscorm.php
View
@@ -5,15 +5,15 @@
require_once('../../config.php');
require_once('lib.php');
+ //
+ // Checkin' script parameters
+ //
$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
$a = optional_param('a', '', PARAM_INT); // scorm ID
$scoid = required_param('scoid', '', PARAM_INT); // sco ID
$mode = optional_param('mode', '', PARAM_ALPHA); // navigation mode
- $currentorg = optional_param('currentorg', '', PARAM_); // selected organization
+ $currentorg = optional_param('currentorg', '', PARAM_ALPHANUM); // selected organization
- //
- // Checkin script parameters
- //
$modestring = '';
$scoidstring = '';
$currentorgstring = '';
@@ -147,12 +147,20 @@
if ($scorm->popup == 0) {
?>
<tr><td class="right">
+<?php
+ if ($result->prerequisites) {
+?>
<iframe name="main" class="scoframe" width="<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>" height="<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>" src="loadSCO.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>"></iframe>
+<?php
+ } else {
+ print_simple_box(get_string('noprerequisites','scorm'),'center');
+ }
+?>
</td></tr>
- </table>
<?php
}
?>
+ </table>
</td>
</tr>
</table>
@@ -161,9 +169,15 @@
<!--
<?php
if ($scorm->popup == 1) {
+ if ($result->prerequisites) {
?>
top.main = window.open("loadSCO.php?id=<?php echo $cm->id.$scoidstring.$modestring ?>","","width=<?php echo $scorm->width<=100 ? $scorm->width.'%' : $scorm->width ?>,height=<?php echo $scorm->height<=100 ? $scorm->height.'%' : $scorm->height ?>,scrollbars=1");
<?php
+ } else {
+?>
+ alert("<?php print_string('noprerequisites','scorm') ?>");
+<?php
+ }
}
?>
function playSCO(scoid) {
Please sign in to comment.
Something went wrong with that request. Please try again.