Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge branch 'm21_MDL-26942' of git://github.com/danmarsden/moodle in…

…to MOODLE_21_STABLE
  • Loading branch information...
commit 1187c38d6d5b24aba8defd83b2d677bc10e91164 2 parents a19c77b + 60201a6
Eloy Lafuente (stronk7) stronk7 authored
241 mod/scorm/datamodels/aicclib.php
@@ -329,244 +329,3 @@ function scorm_parse_aicc($scorm) {
329 329
330 330 return true;
331 331 }
332   -
333   -function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
334   - global $CFG, $DB, $PAGE, $OUTPUT;
335   -
336   - $modestr = '';
337   - if ($mode == 'browse') {
338   - $modestr = '&mode='.$mode;
339   - }
340   -
341   - $result = new stdClass();
342   - if ($tocheader) {
343   - $result->toc = '<div id="scorm_layout">';
344   - $result->toc .= '<div id="scorm_toc">';
345   - $result->toc .= '<div id="scorm_tree">';
346   - }
347   - $result->toc .= '<ul>';
348   - $tocmenus = array();
349   - $result->prerequisites = true;
350   - $incomplete = false;
351   -
352   - //
353   - // Get the current organization infos
354   - //
355   - if (!empty($currentorg)) {
356   - if (($organizationtitle = $DB->get_field('scorm_scoes','title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
357   - if ($play) {
358   - $result->toctitle = "$organizationtitle";
359   - }
360   - else {
361   - $result->toc .= "\t<li>$organizationtitle</li>\n";
362   - }
363   - $tocmenus[] = $organizationtitle;
364   - }
365   - }
366   - //
367   - // If not specified retrieve the last attempt number
368   - //
369   - if (empty($attempt)) {
370   - $attempt = scorm_get_last_attempt($scorm->id, $user->id);
371   - }
372   - $result->attemptleft = $scorm->maxattempt - $attempt;
373   - if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
374   - //
375   - // Retrieve user tracking data for each learning object
376   - //
377   - $usertracks = array();
378   - foreach ($scoes as $sco) {
379   - if (!empty($sco->launch)) {
380   - if (empty($scoid)) {
381   - $scoid = $sco->id;
382   - }
383   - if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
384   - if ($usertrack->status == '') {
385   - $usertrack->status = 'notattempted';
386   - }
387   - $usertracks[$sco->identifier] = $usertrack;
388   - }
389   - }
390   - }
391   -
392   - $level=0;
393   - $sublist=1;
394   - $previd = 0;
395   - $nextid = 0;
396   - $findnext = false;
397   - $parents[$level]='/';
398   -
399   - foreach ($scoes as $pos => $sco) {
400   - $isvisible = false;
401   - $sco->title = $sco->title;
402   - if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
403   - $isvisible = true;
404   - }
405   - if ($parents[$level]!=$sco->parent) {
406   - if ($newlevel = array_search($sco->parent,$parents)) {
407   - for ($i=0; $i<($level-$newlevel); $i++) {
408   - $result->toc .= "\t\t</li></ul></li>\n";
409   - }
410   - $level = $newlevel;
411   - } else {
412   - $i = $level;
413   - $closelist = '';
414   - while (($i > 0) && ($parents[$level] != $sco->parent)) {
415   - $closelist .= "\t\t</li></ul></li>\n";
416   - $i--;
417   - }
418   - if (($i == 0) && ($sco->parent != $currentorg)) {
419   - $result->toc .= "\t\t<ul>\n";
420   - $level++;
421   - } else {
422   - $result->toc .= $closelist;
423   - $level = $i;
424   - }
425   - $parents[$level]=$sco->parent;
426   - }
427   - }
428   - if ($isvisible) {
429   - $result->toc .= "\t\t<li>";
430   - }
431   - if (isset($scoes[$pos+1])) {
432   - $nextsco = $scoes[$pos+1];
433   - } else {
434   - $nextsco = false;
435   - }
436   - $nextisvisible = false;
437   - if (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true'))) {
438   - $nextisvisible = true;
439   - }
440   - if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
441   - $sublist++;
442   - }
443   - if (empty($sco->title)) {
444   - $sco->title = $sco->identifier;
445   - }
446   - if (!empty($sco->launch)) {
447   - if ($isvisible) {
448   - $score = '';
449   - if (empty($scoid) && ($mode != 'normal')) {
450   - $scoid = $sco->id;
451   - }
452   - if (isset($usertracks[$sco->identifier])) {
453   - $usertrack = $usertracks[$sco->identifier];
454   - $strstatus = get_string($usertrack->status,'scorm');
455   - if ($sco->scormtype == 'sco') {
456   - $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
457   - } else {
458   - $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
459   - }
460   -
461   - if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
462   - $incomplete = true;
463   - if ($play && empty($scoid)) {
464   - $scoid = $sco->id;
465   - }
466   - }
467   - if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE,$cmid))) {
468   - $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
469   - }
470   - $strsuspended = get_string('suspended','scorm');
471   - if ($incomplete && isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
472   - $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
473   - }
474   - } else {
475   - if ($play && empty($scoid)) {
476   - $scoid = $sco->id;
477   - }
478   - $incomplete = true;
479   - if ($sco->scormtype == 'sco') {
480   - $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
481   - } else {
482   - $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
483   - }
484   - }
485   - if ($sco->id == $scoid) {
486   - $findnext = true;
487   - }
488   -
489   - if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
490   - if (!empty($sco->launch)) {
491   - $previd = $sco->id;
492   - }
493   - }
494   - if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
495   - if ($sco->id == $scoid) {
496   - $result->prerequisites = true;
497   - }
498   -
499   - $thisscoidstr = '&scoid='.$sco->id;
500   - $link = 'a='.$scorm->id.$thisscoidstr.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
501   -
502   - if ($toclink == TOCFULLURL) { //display toc with urls for structure page
503   - $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
504   - $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
505   - } else {
506   - if ($sco->launch) {
507   - $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
508   - } else {
509   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
510   - }
511   - }
512   - $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
513   - } else {
514   - if ($sco->id == $scoid) {
515   - $result->prerequisites = false;
516   - }
517   - if ($play) {
518   - // should be disabled
519   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
520   - } else {
521   - $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
522   - }
523   - }
524   - if (($nextsco === false) || $nextsco->parent == $sco->parent) {
525   - $result->toc .= '</li>';
526   - }
527   - }
528   - } else {
529   - $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
530   - }
531   - if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
532   - if (!empty($nextsco->launch)) {
533   - $nextid = $nextsco->id;
534   - }
535   - }
536   - }
537   - for ($i=0;$i<$level;$i++) {
538   - $result->toc .= "\t\t</ul></li>\n";
539   - }
540   -
541   - if ($play) {
542   - $sco = scorm_get_sco($scoid);
543   - $sco->previd = $previd;
544   - $sco->nextid = $nextid;
545   - $result->sco = $sco;
546   - $result->incomplete = $incomplete;
547   - } else {
548   - $result->incomplete = $incomplete;
549   - }
550   - }
551   - $result->toc .= '</ul>';
552   -
553   - // NEW IMS TOC
554   - if ($tocheader) {
555   - $result->toc .= '</div></div></div>';
556   - $result->toc .= '<div id="scorm_navpanel"></div>';
557   - }
558   -
559   -
560   - if ($scorm->hidetoc == 0) {
561   - $result->toc .= html_writer::script(js_writer::set_variable('scormdata', array(
562   - 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
563   - 'minusicon' => $OUTPUT->pix_url('minus', 'scorm'))));
564   - $result->toc .= html_writer::script('', $CFG->wwwroot.'/lib/cookies.js');
565   - $result->toc .= html_writer::script('', $CFG->wwwroot.'/mod/scorm/datamodels/scorm_datamodels.js');
566   - }
567   -
568   - $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
569   - $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
570   -
571   - return $result;
572   -}
242 mod/scorm/datamodels/scorm_12lib.php
@@ -105,245 +105,3 @@ function scorm_eval_prerequisites($prerequisites, $usertracks) {
105 105 }
106 106 return eval('return '.implode($stack).';');
107 107 }
108   -
109   -function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
110   - global $CFG, $DB, $PAGE, $OUTPUT;
111   -
112   - $modestr = '';
113   - if ($mode == 'browse') {
114   - $modestr = '&amp;mode='.$mode;
115   - }
116   -
117   - $result = new stdClass();
118   - if ($tocheader) {
119   - $result->toc = '<div id="scorm_layout">';
120   - $result->toc .= '<div id="scorm_toc">';
121   - $result->toc .= '<div id="scorm_tree">';
122   - }
123   - $result->toc .= '<ul>';
124   - $tocmenus = array();
125   - $result->prerequisites = true;
126   - $incomplete = false;
127   -
128   - //
129   - // Get the current organization infos
130   - //
131   - if (!empty($currentorg)) {
132   - if (($organizationtitle = $DB->get_field('scorm_scoes','title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
133   - if ($play) {
134   - $result->toctitle = "$organizationtitle";
135   - }
136   - else {
137   - $result->toc .= "\t<li>$organizationtitle</li>\n";
138   - }
139   - $tocmenus[] = $organizationtitle;
140   - }
141   - }
142   -
143   - //
144   - // If not specified retrieve the last attempt number
145   - //
146   - if (empty($attempt)) {
147   - $attempt = scorm_get_attempt_count($user->id, $scorm);
148   - }
149   - $result->attemptleft = $scorm->maxattempt == 0 ? 1 : $scorm->maxattempt - $attempt;
150   - $conditions['scorm'] = $scorm->id;
151   - if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
152   - //
153   - // Retrieve user tracking data for each learning object
154   - //
155   - $usertracks = array();
156   - foreach ($scoes as $sco) {
157   - if (!empty($sco->launch)) {
158   - if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
159   - if ($usertrack->status == '') {
160   - $usertrack->status = 'notattempted';
161   - }
162   - $usertracks[$sco->identifier] = $usertrack;
163   - }
164   - }
165   - }
166   -
167   - $level=0;
168   - $sublist=1;
169   - $previd = 0;
170   - $nextid = 0;
171   - $findnext = false;
172   - $parents[$level]='/';
173   -
174   - foreach ($scoes as $pos => $sco) {
175   - $isvisible = false;
176   - $sco->title = $sco->title;
177   - if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
178   - $isvisible = true;
179   - }
180   - if ($parents[$level] != $sco->parent) {
181   - if ($newlevel = array_search($sco->parent,$parents)) {
182   - for ($i=0; $i<($level-$newlevel); $i++) {
183   - $result->toc .= "\t\t</li></ul></li>\n";
184   - }
185   - $level = $newlevel;
186   - } else {
187   - $i = $level;
188   - $closelist = '';
189   - while (($i > 0) && ($parents[$level] != $sco->parent)) {
190   - $closelist .= "\t\t</li></ul></li>\n";
191   - $i--;
192   - }
193   - if (($i == 0) && ($sco->parent != $currentorg)) {
194   - $result->toc .= "\t\t<ul>\n";
195   - $level++;
196   - } else {
197   - $result->toc .= $closelist;
198   - $level = $i;
199   - }
200   - $parents[$level] = $sco->parent;
201   - }
202   - }
203   - if ($isvisible) {
204   - $result->toc .= "<li>";
205   - }
206   - if (isset($scoes[$pos+1])) {
207   - $nextsco = $scoes[$pos+1];
208   - } else {
209   - $nextsco = false;
210   - }
211   - $nextisvisible = false;
212   - if (($nextsco !== false) && (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true')))) {
213   - $nextisvisible = true;
214   - }
215   - if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
216   - $sublist++;
217   - }
218   - if (empty($sco->title)) {
219   - $sco->title = $sco->identifier;
220   - }
221   - if (!empty($sco->launch)) {
222   - if ($isvisible) {
223   - $score = '';
224   - if (empty($scoid) && ($mode != 'normal')) {
225   - $scoid = $sco->id;
226   - }
227   - if (isset($usertracks[$sco->identifier])) {
228   - $usertrack = $usertracks[$sco->identifier];
229   - $strstatus = get_string($usertrack->status,'scorm');
230   - if ($sco->scormtype == 'sco') {
231   - $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
232   - } else {
233   - $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
234   - }
235   -
236   - if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
237   - $incomplete = true;
238   - if ($play && empty($scoid)) {
239   - $scoid = $sco->id;
240   - }
241   - }
242   - if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE,$cmid))) {
243   - $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
244   - }
245   - $strsuspended = get_string('suspended','scorm');
246   - if ($incomplete && isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
247   - $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
248   - }
249   - } else {
250   - if ($play && empty($scoid)) {
251   - $scoid = $sco->id;
252   - }
253   - $incomplete = true;
254   - if ($sco->scormtype == 'sco') {
255   - $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
256   - } else {
257   - $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
258   - }
259   - }
260   - if ($sco->id == $scoid) {
261   - $findnext = true;
262   - }
263   -
264   - if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
265   - if (!empty($sco->launch)) {
266   - $previd = $sco->id;
267   - }
268   - }
269   - if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
270   - if ($sco->id == $scoid) {
271   - $result->prerequisites = true;
272   - }
273   - $thisscoidstr = '&scoid='.$sco->id;
274   - $link = 'a='.$scorm->id.$thisscoidstr.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
275   -
276   - if ($toclink == TOCFULLURL) { //display toc with urls for structure page
277   - $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
278   - $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
279   - } else { //display toc for inside scorm player
280   - if ($sco->launch) {
281   - $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
282   - } else {
283   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
284   - }
285   - }
286   - $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
287   - } else {
288   - if ($sco->id == $scoid) {
289   - $result->prerequisites = false;
290   - }
291   - if ($play) {
292   - // should be disabled
293   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
294   - } else {
295   - $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
296   - }
297   - }
298   - if (($nextsco === false) || $nextsco->parent == $sco->parent) {
299   - $result->toc .= '</li>';
300   - }
301   - }
302   - } else {
303   - $result->toc .= '&nbsp;'.format_string($sco->title)."\n";
304   - }
305   - if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
306   - if (!empty($nextsco->launch)) {
307   - $nextid = $nextsco->id;
308   - }
309   - }
310   - }
311   - for ($i=0;$i<$level;$i++) {
312   - $result->toc .= "\t\t</ul></li>\n";
313   - }
314   -
315   - if ($play) {
316   - // it is possible that $scoid is still not set, in this case we don't want an empty object
317   - if ($scoid) {
318   - $sco = scorm_get_sco($scoid);
319   - }
320   - $sco->previd = $previd;
321   - $sco->nextid = $nextid;
322   - $result->sco = $sco;
323   - $result->incomplete = $incomplete;
324   - } else {
325   - $result->incomplete = $incomplete;
326   - }
327   - }
328   - $result->toc .= '</ul>';
329   -
330   - // NEW IMS TOC
331   - if ($tocheader) {
332   - $result->toc .= '</div></div></div>';
333   - $result->toc .= '<div id="scorm_navpanel"></div>';
334   - }
335   -
336   -
337   - if ($scorm->hidetoc == 0) {
338   - $PAGE->requires->data_for_js('scormdata', array(
339   - 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
340   - 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
341   - $PAGE->requires->js('/lib/cookies.js');
342   - $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
343   - }
344   -
345   - $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
346   - $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
347   -
348   - return $result;
349   -}
244 mod/scorm/datamodels/scorm_13lib.php
... ... @@ -1,244 +0,0 @@
1   -<?php
2   -
3   -function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
4   - global $CFG, $DB, $PAGE, $OUTPUT;
5   -
6   - $modestr = '';
7   - if ($mode == 'browse') {
8   - $modestr = '&amp;mode='.$mode;
9   - }
10   -
11   - $result = new stdClass();
12   - if ($tocheader) {
13   - $result->toc = '<div id="scorm_layout">';
14   - $result->toc .= '<div id="scorm_toc">';
15   - $result->toc .= '<div id="scorm_tree">';
16   - }
17   - $result->toc .= '<ul>';
18   - $tocmenus = array();
19   - $result->prerequisites = true;
20   - $incomplete = false;
21   -
22   - //
23   - // Get the current organization infos
24   - //
25   - if (!empty($currentorg)) {
26   - if (($organizationtitle = $DB->get_field('scorm_scoes', 'title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
27   - if ($play) {
28   - $result->toctitle = "$organizationtitle";
29   - }
30   - else {
31   - $result->toc .= "\t<li>$organizationtitle</li>\n";
32   - }
33   - $tocmenus[] = $organizationtitle;
34   - }
35   - }
36   - //
37   - // If not specified retrieve the last attempt number
38   - //
39   - if (empty($attempt)) {
40   - $attempt = scorm_get_last_attempt($scorm->id, $user->id);
41   - }
42   - $result->attemptleft = $scorm->maxattempt - $attempt;
43   - if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
44   - //
45   - // Retrieve user tracking data for each learning object
46   - //
47   -
48   - $usertracks = array();
49   - foreach ($scoes as $sco) {
50   - if (!empty($sco->launch)) {
51   - if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
52   - if ($usertrack->status == '') {
53   - $usertrack->status = 'notattempted';
54   - }
55   - $usertracks[$sco->identifier] = $usertrack;
56   - }
57   - }
58   - }
59   -
60   - $level=0;
61   - $sublist=1;
62   - $previd = 0;
63   - $nextid = 0;
64   - $findnext = false;
65   - $parents[$level]='/';
66   - foreach ($scoes as $pos => $sco) {
67   - $isvisible = false;
68   - $sco->title = $sco->title;
69   - if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
70   - $isvisible = true;
71   - }
72   - if ($parents[$level]!=$sco->parent) {
73   - if ($newlevel = array_search($sco->parent,$parents)) {
74   - for ($i=0; $i<($level-$newlevel); $i++) {
75   - $result->toc .= "\t\t</li></ul></li>\n";
76   - }
77   - $level = $newlevel;
78   - } else {
79   - $i = $level;
80   - $closelist = '';
81   - while (($i > 0) && ($parents[$level] != $sco->parent)) {
82   - $closelist .= "\t\t</li></ul></li>\n";
83   - $i--;
84   - }
85   - if (($i == 0) && ($sco->parent != $currentorg)) {
86   - $result->toc .= "\t\t><ul>\n";
87   - $level++;
88   - } else {
89   - $result->toc .= $closelist;
90   - $level = $i;
91   - }
92   - $parents[$level]=$sco->parent;
93   - }
94   - }
95   - if ($isvisible) {
96   - $result->toc .= "<li>";
97   - }
98   - if (isset($scoes[$pos+1])) {
99   - $nextsco = $scoes[$pos+1];
100   - } else {
101   - $nextsco = false;
102   - }
103   - $nextisvisible = false;
104   - if (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true'))) {
105   - $nextisvisible = true;
106   - }
107   - if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
108   - (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
109   - $sublist++;
110   - }
111   - if (empty($sco->title)) {
112   - $sco->title = $sco->identifier;
113   - }
114   - if (!empty($sco->launch)) {
115   - if ($isvisible) {
116   - $score = '';
117   - if (empty($scoid) && ($mode != 'normal')) {
118   - $scoid = $sco->id;
119   - }
120   - if (isset($usertracks[$sco->identifier])) {
121   - $usertrack = $usertracks[$sco->identifier];
122   - $strstatus = get_string($usertrack->status,'scorm');
123   - if ($sco->scormtype == 'sco') {
124   - $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
125   - } else {
126   - $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
127   - }
128   -
129   - if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
130   - $incomplete = true;
131   - if ($play && empty($scoid)) {
132   - $scoid = $sco->id;
133   - }
134   - }
135   - if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE,$cmid))) {
136   - $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
137   - }
138   - $strsuspended = get_string('suspended','scorm');
139   - if ($incomplete && isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend')) {
140   - $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
141   - }
142   - } else {
143   - if ($play && empty($scoid)) {
144   - $scoid = $sco->id;
145   - }
146   - if ($sco->scormtype == 'sco') {
147   - $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
148   - $incomplete = true;
149   - } else {
150   - $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
151   - }
152   - }
153   -
154   - if ($sco->id == $scoid) {
155   - $findnext = true;
156   - }
157   -
158   - if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
159   - if (!empty($sco->launch)) {
160   - $previd = $sco->id;
161   - }
162   - }
163   - require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
164   - if (scorm_seq_evaluate($sco->id,$usertracks)) {
165   - if ($sco->id == $scoid) {
166   - $result->prerequisites = true;
167   - }
168   -
169   - if ($toclink == TOCFULLURL) { //display toc with urls for structure page
170   - $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
171   - $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
172   - } else {
173   - if ($sco->launch) {
174   - $link = 'a='.$scorm->id.'&scoid='.$sco->id.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
175   - $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
176   - } else {
177   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
178   - }
179   - }
180   - $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
181   - } else {
182   - if ($sco->id == $scoid) {
183   - $result->prerequisites = false;
184   - }
185   - if ($play) {
186   - // should be disabled
187   - $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
188   - } else {
189   - $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
190   - }
191   - }
192   - if (($nextsco === false) || $nextsco->parent == $sco->parent) {
193   - $result->toc .= '</li>';
194   - }
195   - }
196   - } else {
197   - $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
198   - }
199   - if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
200   - if (!empty($nextsco->launch)) {
201   - $nextid = $nextsco->id;
202   - }
203   - }
204   - }
205   - for ($i=0;$i<$level;$i++) {
206   - $result->toc .= "\t\t</ul></li>\n";
207   - }
208   -
209   - if ($play) {
210   - // it is possible that $scoid is still not set, in this case we don't want an empty object
211   - if ($scoid) {
212   - $sco = scorm_get_sco($scoid);
213   - }
214   - $sco->previd = $previd;
215   - $sco->nextid = $nextid;
216   - $result->sco = $sco;
217   - $result->incomplete = $incomplete;
218   - } else {
219   - $result->incomplete = $incomplete;
220   - }
221   - }
222   - $result->toc .= '</ul>';
223   -
224   -
225   - // NEW IMS TOC
226   - if ($tocheader) {
227   - $result->toc .= '</div></div></div>';
228   - $result->toc .= '<div id="scorm_navpanel"></div>';
229   - }
230   -
231   -
232   - if ($scorm->hidetoc == 0) {
233   - $PAGE->requires->data_for_js('scormdata', array(
234   - 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
235   - 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
236   - $PAGE->requires->js('/lib/cookies.js');
237   - $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
238   - }
239   -
240   - $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
241   - $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
242   -
243   - return $result;
244   -}
259 mod/scorm/locallib.php
@@ -1227,3 +1227,262 @@ function scorm_format_duration($duration) {
1227 1227
1228 1228 return $result;
1229 1229 }
  1230 +
  1231 +function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
  1232 + global $CFG, $DB, $PAGE, $OUTPUT;
  1233 +
  1234 + $modestr = '';
  1235 + if ($mode == 'browse') {
  1236 + $modestr = '&amp;mode='.$mode;
  1237 + }
  1238 +
  1239 + $result = new stdClass();
  1240 + if ($tocheader) {
  1241 + $result->toc = '<div id="scorm_layout">';
  1242 + $result->toc .= '<div id="scorm_toc">';
  1243 + $result->toc .= '<div id="scorm_tree">';
  1244 + }
  1245 + $result->toc .= '<ul>';
  1246 + $tocmenus = array();
  1247 + $result->prerequisites = true;
  1248 + $incomplete = false;
  1249 +
  1250 + //
  1251 + // Get the current organization infos
  1252 + //
  1253 + if (!empty($currentorg)) {
  1254 + if (($organizationtitle = $DB->get_field('scorm_scoes','title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
  1255 + if ($play) {
  1256 + $result->toctitle = "$organizationtitle";
  1257 + }
  1258 + else {
  1259 + $result->toc .= "\t<li>$organizationtitle</li>\n";
  1260 + }
  1261 + $tocmenus[] = $organizationtitle;
  1262 + }
  1263 + }
  1264 +
  1265 + //
  1266 + // If not specified retrieve the last attempt number
  1267 + //
  1268 + if (empty($attempt)) {
  1269 + $attempt = scorm_get_attempt_count($user->id, $scorm);
  1270 + }
  1271 + $result->attemptleft = $scorm->maxattempt == 0 ? 1 : $scorm->maxattempt - $attempt;
  1272 + if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
  1273 + //
  1274 + // Retrieve user tracking data for each learning object
  1275 + //
  1276 + $usertracks = array();
  1277 + foreach ($scoes as $sco) {
  1278 + if (!empty($sco->launch)) {
  1279 + if (empty($scoid)) {
  1280 + $scoid = $sco->id;
  1281 + }
  1282 + if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
  1283 + if ($usertrack->status == '') {
  1284 + $usertrack->status = 'notattempted';
  1285 + }
  1286 + $usertracks[$sco->identifier] = $usertrack;
  1287 + }
  1288 + }
  1289 + }
  1290 +
  1291 + $level=0;
  1292 + $sublist=1;
  1293 + $previd = 0;
  1294 + $nextid = 0;
  1295 + $findnext = false;
  1296 + $parents[$level]='/';
  1297 + foreach ($scoes as $pos => $sco) {
  1298 + $isvisible = false;
  1299 + $sco->title = $sco->title;
  1300 + if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
  1301 + $isvisible = true;
  1302 + }
  1303 + if ($parents[$level] != $sco->parent) {
  1304 + if ($newlevel = array_search($sco->parent,$parents)) {
  1305 + for ($i=0; $i<($level-$newlevel); $i++) {
  1306 + $result->toc .= "\t\t</li></ul></li>\n";
  1307 + }
  1308 + $level = $newlevel;
  1309 + } else {
  1310 + $i = $level;
  1311 + $closelist = '';
  1312 + while (($i > 0) && ($parents[$level] != $sco->parent)) {
  1313 + if ($i === 1 && $level > 1) {
  1314 + $closelist .= "\t\t</ul></li>\n";
  1315 + } else {
  1316 + $closelist .= "\t</li></ul></li>\n";
  1317 + }
  1318 + $i--;
  1319 + }
  1320 + if (($i == 0) && ($sco->parent != $currentorg)) {
  1321 + $result->toc .= "\n\t<ul>\n";
  1322 + $level++;
  1323 + } else {
  1324 + $result->toc .= $closelist;
  1325 + $level = $i;
  1326 + }
  1327 + $parents[$level] = $sco->parent;
  1328 + }
  1329 + }
  1330 + if ($isvisible) {
  1331 + $result->toc .= "<li>";
  1332 + }
  1333 + if (isset($scoes[$pos+1])) {
  1334 + $nextsco = $scoes[$pos+1];
  1335 + } else {
  1336 + $nextsco = false;
  1337 + }
  1338 + $nextisvisible = false;
  1339 + if (($nextsco !== false) && (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true')))) {
  1340 + $nextisvisible = true;
  1341 + }
  1342 + if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
  1343 + (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
  1344 + $sublist++;
  1345 + }
  1346 + if (empty($sco->title)) {
  1347 + $sco->title = $sco->identifier;
  1348 + }
  1349 + if ($isvisible) {
  1350 + if (!empty($sco->launch)) {
  1351 + $score = '';
  1352 + if (empty($scoid) && ($mode != 'normal')) {
  1353 + $scoid = $sco->id;
  1354 + }
  1355 + if (isset($usertracks[$sco->identifier])) {
  1356 + $usertrack = $usertracks[$sco->identifier];
  1357 + $strstatus = get_string($usertrack->status,'scorm');
  1358 + if ($sco->scormtype == 'sco') {
  1359 + $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
  1360 + } else {
  1361 + $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
  1362 + }
  1363 +
  1364 + if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
  1365 + $incomplete = true;
  1366 + if ($play && empty($scoid)) {
  1367 + $scoid = $sco->id;
  1368 + }
  1369 + }
  1370 + if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE,$cmid))) {
  1371 + $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
  1372 + }
  1373 + $strsuspended = get_string('suspended','scorm');
  1374 + $exitvar = 'cmi.core.exit';
  1375 + if ($scorm->version == 'SCORM_1.3') {
  1376 + $exitvar = 'cmi.exit';
  1377 + }
  1378 + if ($incomplete && isset($usertrack->{$exitvar}) && ($usertrack->{$exitvar} == 'suspend')) {
  1379 + $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
  1380 + }
  1381 + } else {
  1382 + if ($play && empty($scoid)) {
  1383 + $scoid = $sco->id;
  1384 + }
  1385 + $incomplete = true;
  1386 + if ($sco->scormtype == 'sco') {
  1387 + $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
  1388 + } else {
  1389 + $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
  1390 + }
  1391 + }
  1392 + if ($sco->id == $scoid) {
  1393 + $findnext = true;
  1394 + }
  1395 +
  1396 + if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
  1397 + if (!empty($sco->launch)) {
  1398 + $previd = $sco->id;
  1399 + }
  1400 + }
  1401 +
  1402 + if ($scorm->version == 'SCORM_1.3') {
  1403 + require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
  1404 + $prereq = scorm_seq_evaluate($sco->id,$usertracks);
  1405 + } else {
  1406 + //TODO: split check for sco->prerequisites only for AICC as I think that's the only case it's set.
  1407 + $prereq = empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks);
  1408 + }
  1409 + if ($prereq) {
  1410 + if ($sco->id == $scoid) {
  1411 + $result->prerequisites = true;
  1412 + }
  1413 +
  1414 + if ($toclink == TOCFULLURL) { //display toc with urls for structure page
  1415 + $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
  1416 + $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
  1417 + } else { //display toc for inside scorm player
  1418 + if ($sco->launch) {
  1419 + $link = 'a='.$scorm->id.'&scoid='.$sco->id.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
  1420 + $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
  1421 + } else {
  1422 + $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
  1423 + }
  1424 + }
  1425 + $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
  1426 + } else {
  1427 + if ($sco->id == $scoid) {
  1428 + $result->prerequisites = false;
  1429 + }
  1430 + if ($play) {
  1431 + // should be disabled
  1432 + $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
  1433 + } else {
  1434 + $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
  1435 + }
  1436 + }
  1437 + } else {
  1438 + $result->toc .= '&nbsp;'.format_string($sco->title);
  1439 + }
  1440 + if (($nextsco === false) || $nextsco->parent == $sco->parent) {
  1441 + $result->toc .= "</li>\n";
  1442 + }
  1443 + }
  1444 + if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
  1445 + if (!empty($nextsco->launch)) {
  1446 + $nextid = $nextsco->id;
  1447 + }
  1448 + }
  1449 + }
  1450 + for ($i=0;$i<$level;$i++) {
  1451 + $result->toc .= "\t\t</ul></li>\n";
  1452 + }
  1453 +
  1454 + if ($play) {
  1455 + if (empty($scoid)) {
  1456 + $scoid = reset($scoes)->id;
  1457 + }
  1458 + $sco = scorm_get_sco($scoid);
  1459 + $sco->previd = $previd;
  1460 + $sco->nextid = $nextid;
  1461 + $result->sco = $sco;
  1462 + $result->incomplete = $incomplete;
  1463 + } else {
  1464 + $result->incomplete = $incomplete;
  1465 + }
  1466 + }
  1467 + $result->toc .= '</ul>';
  1468 +
  1469 + // NEW IMS TOC
  1470 + if ($tocheader) {
  1471 + $result->toc .= '</div></div></div>';
  1472 + $result->toc .= '<div id="scorm_navpanel"></div>';
  1473 + }
  1474 +
  1475 +
  1476 + if ($scorm->hidetoc == 0) {
  1477 + $PAGE->requires->data_for_js('scormdata', array(
  1478 + 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
  1479 + 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
  1480 + $PAGE->requires->js('/lib/cookies.js');
  1481 + $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
  1482 + }
  1483 +
  1484 + $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
  1485 + $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
  1486 +
  1487 + return $result;
  1488 +}

0 comments on commit 1187c38

Please sign in to comment.
Something went wrong with that request. Please try again.