Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

SCORM MDL-26942 merge scorm_get_toc to decrease duplicated code and s…

…implify toc display
  • Loading branch information...
commit db0a77cc1a58bb6fddd9a9672b2b6195fc42fc45 1 parent f6f6138
@danmarsden danmarsden authored
View
240 mod/scorm/datamodels/aicclib.php
@@ -341,243 +341,3 @@ function scorm_parse_aicc($scorm) {
return true;
}
-
-function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='',
- $scoid='', $mode='normal', $attempt='', $play=false, $tocheader=false) {
- global $CFG, $DB, $PAGE, $OUTPUT;
-
- $modestr = '';
- if ($mode == 'browse') {
- $modestr = '&mode='.$mode;
- }
-
- $result = new stdClass();
- if ($tocheader) {
- $result->toc = '<div id="scorm_layout">';
- $result->toc .= '<div id="scorm_toc">';
- $result->toc .= '<div id="scorm_tree">';
- }
- $result->toc .= '<ul>';
- $tocmenus = array();
- $result->prerequisites = true;
- $incomplete = false;
-
- //
- // Get the current organization infos
- //
- if (!empty($currentorg)) {
- if (($organizationtitle = $DB->get_field('scorm_scoes', 'title', array('scorm'=>$scorm->id, 'identifier'=>$currentorg))) != '') {
- if ($play) {
- $result->toctitle = "$organizationtitle";
- } else {
- $result->toc .= "\t<li>$organizationtitle</li>\n";
- }
- $tocmenus[] = $organizationtitle;
- }
- }
- //
- // If not specified retrieve the last attempt number
- //
- if (empty($attempt)) {
- $attempt = scorm_get_last_attempt($scorm->id, $user->id);
- }
- $result->attemptleft = $scorm->maxattempt - $attempt;
- if ($scoes = scorm_get_scoes($scorm->id, $currentorg)) {
- //
- // Retrieve user tracking data for each learning object
- //
- $usertracks = array();
- foreach ($scoes as $sco) {
- if (!empty($sco->launch)) {
- if (empty($scoid)) {
- $scoid = $sco->id;
- }
- if ($usertrack = scorm_get_tracks($sco->id, $user->id, $attempt)) {
- if ($usertrack->status == '') {
- $usertrack->status = 'notattempted';
- }
- $usertracks[$sco->identifier] = $usertrack;
- }
- }
- }
-
- $level=0;
- $sublist=1;
- $previd = 0;
- $nextid = 0;
- $findnext = false;
- $parents[$level]='/';
-
- foreach ($scoes as $pos => $sco) {
- $isvisible = false;
- $sco->title = $sco->title;
- if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
- $isvisible = true;
- }
- if ($parents[$level]!=$sco->parent) {
- if ($newlevel = array_search($sco->parent, $parents)) {
- for ($i=0; $i<($level-$newlevel); $i++) {
- $result->toc .= "\t\t</li></ul></li>\n";
- }
- $level = $newlevel;
- } else {
- $i = $level;
- $closelist = '';
- while (($i > 0) && ($parents[$level] != $sco->parent)) {
- $closelist .= "\t\t</li></ul></li>\n";
- $i--;
- }
- if (($i == 0) && ($sco->parent != $currentorg)) {
- $result->toc .= "\t\t<ul>\n";
- $level++;
- } else {
- $result->toc .= $closelist;
- $level = $i;
- }
- $parents[$level]=$sco->parent;
- }
- }
- if ($isvisible) {
- $result->toc .= "\t\t<li>";
- }
- if (isset($scoes[$pos+1])) {
- $nextsco = $scoes[$pos+1];
- } else {
- $nextsco = false;
- }
- $nextisvisible = false;
- if (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true'))) {
- $nextisvisible = true;
- }
- if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
- $sublist++;
- }
- if (empty($sco->title)) {
- $sco->title = $sco->identifier;
- }
- if (!empty($sco->launch)) {
- if ($isvisible) {
- $score = '';
- if (empty($scoid) && ($mode != 'normal')) {
- $scoid = $sco->id;
- }
- if (isset($usertracks[$sco->identifier])) {
- $usertrack = $usertracks[$sco->identifier];
- $strstatus = get_string($usertrack->status, 'scorm');
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched', 'scorm').'" title="'.get_string('assetlaunched', 'scorm').'" />';
- }
-
- if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
- $incomplete = true;
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- }
- if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE, $cmid))) {
- $score = '('.get_string('score', 'scorm').':&nbsp;'.$usertrack->score_raw.')';
- }
- $strsuspended = get_string('suspended', 'scorm');
- if ($incomplete && isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
- $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
- }
- } else {
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- $incomplete = true;
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted', 'scorm').'" title="'.get_string('notattempted', 'scorm').'" />';
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset', 'scorm').'" title="'.get_string('asset', 'scorm').'" />';
- }
- }
- if ($sco->id == $scoid) {
- $findnext = true;
- }
-
- if (($nextid == 0) && (scorm_count_launchable($scorm->id, $currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
- if (!empty($sco->launch)) {
- $previd = $sco->id;
- }
- }
- if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites, $usertracks)) {
- if ($sco->id == $scoid) {
- $result->prerequisites = true;
- }
-
- $thisscoidstr = '&scoid='.$sco->id;
- $link = 'a='.$scorm->id.$thisscoidstr.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
-
- if ($toclink == TOCFULLURL) { //display toc with urls for structure page
- $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
- $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
- } else {
- if ($sco->launch) {
- $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
- } else {
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- }
- }
- $tocmenus[$sco->id] = scorm_repeater('&minus;', $level) . '&gt;' . format_string($sco->title);
- } else {
- if ($sco->id == $scoid) {
- $result->prerequisites = false;
- }
- if ($play) {
- // should be disabled
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- } else {
- $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
- }
- }
- if (($nextsco === false) || $nextsco->parent == $sco->parent) {
- $result->toc .= '</li>';
- }
- }
- } else {
- $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
- }
- if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
- if (!empty($nextsco->launch)) {
- $nextid = $nextsco->id;
- }
- }
- }
- for ($i=0; $i<$level; $i++) {
- $result->toc .= "\t\t</ul></li>\n";
- }
-
- if ($play) {
- $sco = scorm_get_sco($scoid);
- $sco->previd = $previd;
- $sco->nextid = $nextid;
- $result->sco = $sco;
- $result->incomplete = $incomplete;
- } else {
- $result->incomplete = $incomplete;
- }
- }
- $result->toc .= '</ul>';
-
- // NEW IMS TOC
- if ($tocheader) {
- $result->toc .= '</div></div></div>';
- $result->toc .= '<div id="scorm_navpanel"></div>';
- }
-
- if ($scorm->hidetoc == 0) {
- $result->toc .= html_writer::script(js_writer::set_variable('scormdata', array(
- 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
- 'minusicon' => $OUTPUT->pix_url('minus', 'scorm'))));
- $result->toc .= html_writer::script('', $CFG->wwwroot.'/lib/cookies.js');
- $result->toc .= html_writer::script('', $CFG->wwwroot.'/mod/scorm/datamodels/scorm_datamodels.js');
- }
-
- $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
- $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
-
- return $result;
-}
View
248 mod/scorm/datamodels/scorm_12lib.php
@@ -120,251 +120,3 @@ function scorm_eval_prerequisites($prerequisites, $usertracks) {
}
return eval('return '.implode($stack).';');
}
-
-function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='',
- $scoid='', $mode='normal', $attempt='', $play=false, $tocheader=false) {
- global $CFG, $DB, $PAGE, $OUTPUT;
-
- $modestr = '';
- if ($mode == 'browse') {
- $modestr = '&amp;mode='.$mode;
- }
-
- $result = new stdClass();
- if ($tocheader) {
- $result->toc = '<div id="scorm_layout">';
- $result->toc .= '<div id="scorm_toc">';
- $result->toc .= '<div id="scorm_tree">';
- }
- $result->toc .= '<ul>';
- $tocmenus = array();
- $result->prerequisites = true;
- $incomplete = false;
-
- //
- // Get the current organization infos
- //
- if (!empty($currentorg)) {
- if (($organizationtitle = $DB->get_field('scorm_scoes', 'title',
- array('scorm'=>$scorm->id,
- 'identifier'=>$currentorg))) != '') {
- if ($play) {
- $result->toctitle = "$organizationtitle";
- } else {
- $result->toc .= "\t<li>$organizationtitle</li>\n";
- }
- $tocmenus[] = $organizationtitle;
- }
- }
-
- //
- // If not specified retrieve the last attempt number
- //
- if (empty($attempt)) {
- $attempt = scorm_get_attempt_count($user->id, $scorm);
- }
- $result->attemptleft = $scorm->maxattempt == 0 ? 1 : $scorm->maxattempt - $attempt;
- $conditions['scorm'] = $scorm->id;
- if ($scoes = scorm_get_scoes($scorm->id, $currentorg)) {
- //
- // Retrieve user tracking data for each learning object
- //
- $usertracks = array();
- foreach ($scoes as $sco) {
- if (!empty($sco->launch)) {
- if ($usertrack = scorm_get_tracks($sco->id, $user->id, $attempt)) {
- if ($usertrack->status == '') {
- $usertrack->status = 'notattempted';
- }
- $usertracks[$sco->identifier] = $usertrack;
- }
- }
- }
-
- $level=0;
- $sublist=1;
- $previd = 0;
- $nextid = 0;
- $findnext = false;
- $parents[$level]='/';
-
- foreach ($scoes as $pos => $sco) {
- $isvisible = false;
- $sco->title = $sco->title;
- if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
- $isvisible = true;
- }
- if ($parents[$level] != $sco->parent) {
- if ($newlevel = array_search($sco->parent, $parents)) {
- for ($i=0; $i<($level-$newlevel); $i++) {
- $result->toc .= "\t\t</li></ul></li>\n";
- }
- $level = $newlevel;
- } else {
- $i = $level;
- $closelist = '';
- while (($i > 0) && ($parents[$level] != $sco->parent)) {
- $closelist .= "\t\t</li></ul></li>\n";
- $i--;
- }
- if (($i == 0) && ($sco->parent != $currentorg)) {
- $result->toc .= "\t\t<ul>\n";
- $level++;
- } else {
- $result->toc .= $closelist;
- $level = $i;
- }
- $parents[$level] = $sco->parent;
- }
- }
- if ($isvisible) {
- $result->toc .= "<li>";
- }
- if (isset($scoes[$pos+1])) {
- $nextsco = $scoes[$pos+1];
- } else {
- $nextsco = false;
- }
- $nextisvisible = false;
- if (($nextsco !== false) && (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true')))) {
- $nextisvisible = true;
- }
- if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) && (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
- $sublist++;
- }
- if (empty($sco->title)) {
- $sco->title = $sco->identifier;
- }
- if (!empty($sco->launch)) {
- if ($isvisible) {
- $score = '';
- if (empty($scoid) && ($mode != 'normal')) {
- $scoid = $sco->id;
- }
- if (isset($usertracks[$sco->identifier])) {
- $usertrack = $usertracks[$sco->identifier];
- $strstatus = get_string($usertrack->status, 'scorm');
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched', 'scorm').'" title="'.get_string('assetlaunched', 'scorm').'" />';
- }
-
- if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
- $incomplete = true;
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- }
- if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE, $cmid))) {
- $score = '('.get_string('score', 'scorm').':&nbsp;'.$usertrack->score_raw.')';
- }
- $strsuspended = get_string('suspended', 'scorm');
- if ($incomplete && isset($usertrack->{'cmi.core.exit'}) && ($usertrack->{'cmi.core.exit'} == 'suspend')) {
- $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.
- $strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
- }
- } else {
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- $incomplete = true;
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').
- '" alt="'.get_string('notattempted', 'scorm').'" title="'.
- get_string('notattempted', 'scorm').'" />';
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').
- '" alt="'.get_string('asset', 'scorm').'" title="'.
- get_string('asset', 'scorm').'" />';
- }
- }
- if ($sco->id == $scoid) {
- $findnext = true;
- }
-
- if (($nextid == 0) && (scorm_count_launchable($scorm->id, $currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
- if (!empty($sco->launch)) {
- $previd = $sco->id;
- }
- }
- if (empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks)) {
- if ($sco->id == $scoid) {
- $result->prerequisites = true;
- }
- $thisscoidstr = '&scoid='.$sco->id;
- $link = 'a='.$scorm->id.$thisscoidstr.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
-
- if ($toclink == TOCFULLURL) { //display toc with urls for structure page
- $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
- $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
- } else { //display toc for inside scorm player
- if ($sco->launch) {
- $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
- } else {
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- }
- }
- $tocmenus[$sco->id] = scorm_repeater('&minus;', $level) . '&gt;' . format_string($sco->title);
- } else {
- if ($sco->id == $scoid) {
- $result->prerequisites = false;
- }
- if ($play) {
- // should be disabled
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- } else {
- $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
- }
- }
- if (($nextsco === false) || $nextsco->parent == $sco->parent) {
- $result->toc .= '</li>';
- }
- }
- } else {
- $result->toc .= '&nbsp;'.format_string($sco->title)."\n";
- }
- if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
- if (!empty($nextsco->launch)) {
- $nextid = $nextsco->id;
- }
- }
- }
- for ($i=0; $i<$level; $i++) {
- $result->toc .= "\t\t</ul></li>\n";
- }
-
- if ($play) {
- // it is possible that $scoid is still not set, in this case we don't want an empty object
- if ($scoid) {
- $sco = scorm_get_sco($scoid);
- }
- $sco->previd = $previd;
- $sco->nextid = $nextid;
- $result->sco = $sco;
- $result->incomplete = $incomplete;
- } else {
- $result->incomplete = $incomplete;
- }
- }
- $result->toc .= '</ul>';
-
- // NEW IMS TOC
- if ($tocheader) {
- $result->toc .= '</div></div></div>';
- $result->toc .= '<div id="scorm_navpanel"></div>';
- }
-
- if ($scorm->hidetoc == 0) {
- $PAGE->requires->data_for_js('scormdata', array(
- 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
- 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
- $PAGE->requires->js('/lib/cookies.js');
- $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
- }
-
- $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
- $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
-
- return $result;
-}
View
243 mod/scorm/datamodels/scorm_13lib.php
@@ -14,246 +14,3 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-
-function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='',
- $scoid='', $mode='normal', $attempt='', $play=false, $tocheader=false) {
- global $CFG, $DB, $PAGE, $OUTPUT;
-
- $modestr = '';
- if ($mode == 'browse') {
- $modestr = '&amp;mode='.$mode;
- }
-
- $result = new stdClass();
- if ($tocheader) {
- $result->toc = '<div id="scorm_layout">';
- $result->toc .= '<div id="scorm_toc">';
- $result->toc .= '<div id="scorm_tree">';
- }
- $result->toc .= '<ul>';
- $tocmenus = array();
- $result->prerequisites = true;
- $incomplete = false;
-
- //
- // Get the current organization infos
- //
- if (!empty($currentorg)) {
- if (($organizationtitle = $DB->get_field('scorm_scoes', 'title',
- array('scorm'=>$scorm->id,
- 'identifier'=>$currentorg))) != '') {
- if ($play) {
- $result->toctitle = "$organizationtitle";
- } else {
- $result->toc .= "\t<li>$organizationtitle</li>\n";
- }
- $tocmenus[] = $organizationtitle;
- }
- }
- //
- // If not specified retrieve the last attempt number
- //
- if (empty($attempt)) {
- $attempt = scorm_get_last_attempt($scorm->id, $user->id);
- }
- $result->attemptleft = $scorm->maxattempt - $attempt;
- if ($scoes = scorm_get_scoes($scorm->id, $currentorg)) {
- //
- // Retrieve user tracking data for each learning object
- //
-
- $usertracks = array();
- foreach ($scoes as $sco) {
- if (!empty($sco->launch)) {
- if ($usertrack = scorm_get_tracks($sco->id, $user->id, $attempt)) {
- if ($usertrack->status == '') {
- $usertrack->status = 'notattempted';
- }
- $usertracks[$sco->identifier] = $usertrack;
- }
- }
- }
-
- $level=0;
- $sublist=1;
- $previd = 0;
- $nextid = 0;
- $findnext = false;
- $parents[$level]='/';
- foreach ($scoes as $pos => $sco) {
- $isvisible = false;
- $sco->title = $sco->title;
- if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
- $isvisible = true;
- }
- if ($parents[$level]!=$sco->parent) {
- if ($newlevel = array_search($sco->parent, $parents)) {
- for ($i=0; $i<($level-$newlevel); $i++) {
- $result->toc .= "\t\t</li></ul></li>\n";
- }
- $level = $newlevel;
- } else {
- $i = $level;
- $closelist = '';
- while (($i > 0) && ($parents[$level] != $sco->parent)) {
- $closelist .= "\t\t</li></ul></li>\n";
- $i--;
- }
- if (($i == 0) && ($sco->parent != $currentorg)) {
- $result->toc .= "\t\t><ul>\n";
- $level++;
- } else {
- $result->toc .= $closelist;
- $level = $i;
- }
- $parents[$level]=$sco->parent;
- }
- }
- if ($isvisible) {
- $result->toc .= "<li>";
- }
- if (isset($scoes[$pos+1])) {
- $nextsco = $scoes[$pos+1];
- } else {
- $nextsco = false;
- }
- $nextisvisible = false;
- if (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true'))) {
- $nextisvisible = true;
- }
- if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
- (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
- $sublist++;
- }
- if (empty($sco->title)) {
- $sco->title = $sco->identifier;
- }
- if (!empty($sco->launch)) {
- if ($isvisible) {
- $score = '';
- if (empty($scoid) && ($mode != 'normal')) {
- $scoid = $sco->id;
- }
- if (isset($usertracks[$sco->identifier])) {
- $usertrack = $usertracks[$sco->identifier];
- $strstatus = get_string($usertrack->status, 'scorm');
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched', 'scorm').'" title="'.get_string('assetlaunched', 'scorm').'" />';
- }
-
- if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
- $incomplete = true;
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- }
- if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE, $cmid))) {
- $score = '('.get_string('score', 'scorm').':&nbsp;'.$usertrack->score_raw.')';
- }
- $strsuspended = get_string('suspended', 'scorm');
- if ($incomplete && isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} == 'suspend')) {
- $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
- }
- } else {
- if ($play && empty($scoid)) {
- $scoid = $sco->id;
- }
- if ($sco->scormtype == 'sco') {
- $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted', 'scorm').'" title="'.get_string('notattempted', 'scorm').'" />';
- $incomplete = true;
- } else {
- $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset', 'scorm').'" title="'.get_string('asset', 'scorm').'" />';
- }
- }
-
- if ($sco->id == $scoid) {
- $findnext = true;
- }
-
- if (($nextid == 0) && (scorm_count_launchable($scorm->id, $currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
- if (!empty($sco->launch)) {
- $previd = $sco->id;
- }
- }
- require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
- if (scorm_seq_evaluate($sco->id, $usertracks)) {
- if ($sco->id == $scoid) {
- $result->prerequisites = true;
- }
-
- if ($toclink == TOCFULLURL) { //display toc with urls for structure page
- $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
- $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
- } else {
- if ($sco->launch) {
- $link = 'a='.$scorm->id.'&scoid='.$sco->id.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
- $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
- } else {
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- }
- }
- $tocmenus[$sco->id] = scorm_repeater('&minus;', $level) . '&gt;' . format_string($sco->title);
- } else {
- if ($sco->id == $scoid) {
- $result->prerequisites = false;
- }
- if ($play) {
- // should be disabled
- $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
- } else {
- $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
- }
- }
- if (($nextsco === false) || $nextsco->parent == $sco->parent) {
- $result->toc .= '</li>';
- }
- }
- } else {
- $result->toc .= '&nbsp;'.format_string($sco->title)."</li>\n";
- }
- if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
- if (!empty($nextsco->launch)) {
- $nextid = $nextsco->id;
- }
- }
- }
- for ($i=0; $i<$level; $i++) {
- $result->toc .= "\t\t</ul></li>\n";
- }
-
- if ($play) {
- // it is possible that $scoid is still not set, in this case we don't want an empty object
- if ($scoid) {
- $sco = scorm_get_sco($scoid);
- }
- $sco->previd = $previd;
- $sco->nextid = $nextid;
- $result->sco = $sco;
- $result->incomplete = $incomplete;
- } else {
- $result->incomplete = $incomplete;
- }
- }
- $result->toc .= '</ul>';
-
- // NEW IMS TOC
- if ($tocheader) {
- $result->toc .= '</div></div></div>';
- $result->toc .= '<div id="scorm_navpanel"></div>';
- }
-
- if ($scorm->hidetoc == 0) {
- $PAGE->requires->data_for_js('scormdata', array(
- 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
- 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
- $PAGE->requires->js('/lib/cookies.js');
- $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
- }
-
- $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
- $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
-
- return $result;
-}
View
252 mod/scorm/datamodels/scormlib.php
@@ -758,6 +758,258 @@ function scorm_find_common_ancestor($ancestors, $sco) {
return $pos;
}
+function scorm_get_toc($user,$scorm,$cmid,$toclink=TOCJSLINK,$currentorg='',$scoid='',$mode='normal',$attempt='',$play=false, $tocheader=false) {
+ global $CFG, $DB, $PAGE, $OUTPUT;
+
+ $modestr = '';
+ if ($mode == 'browse') {
+ $modestr = '&amp;mode='.$mode;
+ }
+
+ $result = new stdClass();
+ if ($tocheader) {
+ $result->toc = '<div id="scorm_layout">';
+ $result->toc .= '<div id="scorm_toc">';
+ $result->toc .= '<div id="scorm_tree">';
+ }
+ $result->toc .= '<ul>';
+ $tocmenus = array();
+ $result->prerequisites = true;
+ $incomplete = false;
+
+ //
+ // Get the current organization infos
+ //
+ if (!empty($currentorg)) {
+ if (($organizationtitle = $DB->get_field('scorm_scoes','title', array('scorm'=>$scorm->id,'identifier'=>$currentorg))) != '') {
+ if ($play) {
+ $result->toctitle = "$organizationtitle";
+ }
+ else {
+ $result->toc .= "\t<li>$organizationtitle</li>\n";
+ }
+ $tocmenus[] = $organizationtitle;
+ }
+ }
+
+ //
+ // If not specified retrieve the last attempt number
+ //
+ if (empty($attempt)) {
+ $attempt = scorm_get_attempt_count($user->id, $scorm);
+ }
+ $result->attemptleft = $scorm->maxattempt == 0 ? 1 : $scorm->maxattempt - $attempt;
+ if ($scoes = scorm_get_scoes($scorm->id, $currentorg)){
+ //
+ // Retrieve user tracking data for each learning object
+ //
+ $usertracks = array();
+ foreach ($scoes as $sco) {
+ if (!empty($sco->launch)) {
+ if (empty($scoid)) {
+ $scoid = $sco->id;
+ }
+ if ($usertrack = scorm_get_tracks($sco->id,$user->id,$attempt)) {
+ if ($usertrack->status == '') {
+ $usertrack->status = 'notattempted';
+ }
+ $usertracks[$sco->identifier] = $usertrack;
+ }
+ }
+ }
+
+ $level=0;
+ $sublist=1;
+ $previd = 0;
+ $nextid = 0;
+ $findnext = false;
+ $parents[$level]='/';
+
+ foreach ($scoes as $pos => $sco) {
+ $isvisible = false;
+ $sco->title = $sco->title;
+ if (!isset($sco->isvisible) || (isset($sco->isvisible) && ($sco->isvisible == 'true'))) {
+ $isvisible = true;
+ }
+ if ($parents[$level] != $sco->parent) {
+ if ($newlevel = array_search($sco->parent,$parents)) {
+ for ($i=0; $i<($level-$newlevel); $i++) {
+ $result->toc .= "\t\t</li></ul></li>\n";
+ }
+ $level = $newlevel;
+ } else {
+ $i = $level;
+ $closelist = '';
+ while (($i > 0) && ($parents[$level] != $sco->parent)) {
+ $closelist .= "\t\t</li></ul></li>\n";
+ $i--;
+ }
+ if (($i == 0) && ($sco->parent != $currentorg)) {
+ $result->toc .= "\t\t<ul>\n";
+ $level++;
+ } else {
+ $result->toc .= $closelist;
+ $level = $i;
+ }
+ $parents[$level] = $sco->parent;
+ }
+ }
+ if ($isvisible) {
+ $result->toc .= "<li>";
+ }
+ if (isset($scoes[$pos+1])) {
+ $nextsco = $scoes[$pos+1];
+ } else {
+ $nextsco = false;
+ }
+ $nextisvisible = false;
+ if (($nextsco !== false) && (!isset($nextsco->isvisible) || (isset($nextsco->isvisible) && ($nextsco->isvisible == 'true')))) {
+ $nextisvisible = true;
+ }
+ if ($nextisvisible && ($nextsco !== false) && ($sco->parent != $nextsco->parent) &&
+ (($level==0) || (($level>0) && ($nextsco->parent == $sco->identifier)))) {
+ $sublist++;
+ }
+ if (empty($sco->title)) {
+ $sco->title = $sco->identifier;
+ }
+ if (!empty($sco->launch)) {
+ if ($isvisible) {
+ $score = '';
+ if (empty($scoid) && ($mode != 'normal')) {
+ $scoid = $sco->id;
+ }
+ if (isset($usertracks[$sco->identifier])) {
+ $usertrack = $usertracks[$sco->identifier];
+ $strstatus = get_string($usertrack->status,'scorm');
+ if ($sco->scormtype == 'sco') {
+ $statusicon = '<img src="'.$OUTPUT->pix_url($usertrack->status, 'scorm').'" alt="'.$strstatus.'" title="'.$strstatus.'" />';
+ } else {
+ $statusicon = '<img src="'.$OUTPUT->pix_url('assetc', 'scorm').'" alt="'.get_string('assetlaunched','scorm').'" title="'.get_string('assetlaunched','scorm').'" />';
+ }
+
+ if (($usertrack->status == 'notattempted') || ($usertrack->status == 'incomplete') || ($usertrack->status == 'browsed')) {
+ $incomplete = true;
+ if ($play && empty($scoid)) {
+ $scoid = $sco->id;
+ }
+ }
+ if ($usertrack->score_raw != '' && has_capability('mod/scorm:viewscores', get_context_instance(CONTEXT_MODULE,$cmid))) {
+ $score = '('.get_string('score','scorm').':&nbsp;'.$usertrack->score_raw.')';
+ }
+ $strsuspended = get_string('suspended','scorm');
+ $exitvar = 'cmi.core.exit';
+ if ($scorm->version == 'SCORM_1.3') {
+ $exitvar = 'cmi.exit';
+ }
+ if ($incomplete && isset($usertrack->{$exitvar}) && ($usertrack->{$exitvar} == 'suspend')) {
+ $statusicon = '<img src="'.$OUTPUT->pix_url('suspend', 'scorm').'" alt="'.$strstatus.' - '.$strsuspended.'" title="'.$strstatus.' - '.$strsuspended.'" />';
+ }
+ } else {
+ if ($play && empty($scoid)) {
+ $scoid = $sco->id;
+ }
+ $incomplete = true;
+ if ($sco->scormtype == 'sco') {
+ $statusicon = '<img src="'.$OUTPUT->pix_url('notattempted', 'scorm').'" alt="'.get_string('notattempted','scorm').'" title="'.get_string('notattempted','scorm').'" />';
+ } else {
+ $statusicon = '<img src="'.$OUTPUT->pix_url('asset', 'scorm').'" alt="'.get_string('asset','scorm').'" title="'.get_string('asset','scorm').'" />';
+ }
+ }
+ if ($sco->id == $scoid) {
+ $findnext = true;
+ }
+
+ if (($nextid == 0) && (scorm_count_launchable($scorm->id,$currentorg) > 1) && ($nextsco!==false) && (!$findnext)) {
+ if (!empty($sco->launch)) {
+ $previd = $sco->id;
+ }
+ }
+
+ if ($scorm->version == 'SCORM_1.3') {
+ require_once($CFG->dirroot.'/mod/scorm/datamodels/sequencinglib.php');
+ $prereq = scorm_seq_evaluate($sco->id,$usertracks);
+ } else {
+ $prereq = empty($sco->prerequisites) || scorm_eval_prerequisites($sco->prerequisites,$usertracks);
+ }
+ if ($prereq) {
+ if ($sco->id == $scoid) {
+ $result->prerequisites = true;
+ }
+
+ if ($toclink == TOCFULLURL) { //display toc with urls for structure page
+ $url = $CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;currentorg='.$currentorg.$modestr.'&amp;scoid='.$sco->id;
+ $result->toc .= $statusicon.'&nbsp;<a href="'.$url.'">'.format_string($sco->title).'</a>'.$score."\n";
+ } else { //display toc for inside scorm player
+ if ($sco->launch) {
+ $link = 'a='.$scorm->id.'&scoid='.$sco->id.'&currentorg='.$currentorg.$modestr.'&attempt='.$attempt;
+ $result->toc .= '<a title="'.$link.'">'.$statusicon.'&nbsp;'.format_string($sco->title).'&nbsp;'.$score.'</a>';
+ } else {
+ $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
+ }
+ }
+ $tocmenus[$sco->id] = scorm_repeater('&minus;',$level) . '&gt;' . format_string($sco->title);
+ } else {
+ if ($sco->id == $scoid) {
+ $result->prerequisites = false;
+ }
+ if ($play) {
+ // should be disabled
+ $result->toc .= '<span>'.$statusicon.'&nbsp;'.format_string($sco->title).'</span>';
+ } else {
+ $result->toc .= $statusicon.'&nbsp;'.format_string($sco->title)."\n";
+ }
+ }
+ if (($nextsco === false) || $nextsco->parent == $sco->parent) {
+ $result->toc .= '</li>';
+ }
+ }
+ } else {
+ $result->toc .= '&nbsp;'.format_string($sco->title)."\n";
+ }
+ if (($nextsco !== false) && ($nextid == 0) && ($findnext)) {
+ if (!empty($nextsco->launch)) {
+ $nextid = $nextsco->id;
+ }
+ }
+ }
+ for ($i=0;$i<$level;$i++) {
+ $result->toc .= "\t\t</ul></li>\n";
+ }
+
+ if ($play) {
+ $sco = scorm_get_sco($scoid);
+ $sco->previd = $previd;
+ $sco->nextid = $nextid;
+ $result->sco = $sco;
+ $result->incomplete = $incomplete;
+ } else {
+ $result->incomplete = $incomplete;
+ }
+ }
+ $result->toc .= '</ul>';
+
+ // NEW IMS TOC
+ if ($tocheader) {
+ $result->toc .= '</div></div></div>';
+ $result->toc .= '<div id="scorm_navpanel"></div>';
+ }
+
+
+ if ($scorm->hidetoc == 0) {
+ $PAGE->requires->data_for_js('scormdata', array(
+ 'plusicon' => $OUTPUT->pix_url('plus', 'scorm'),
+ 'minusicon' => $OUTPUT->pix_url('minus', 'scorm')));
+ $PAGE->requires->js('/lib/cookies.js');
+ $PAGE->requires->js('/mod/scorm/datamodels/scorm_datamodels.js');
+ }
+
+ $url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
+ $result->tocmenu = $OUTPUT->single_select($url, 'scoid', $tocmenus, $sco->id, null, "tocmenu");
+
+ return $result;
+}
+
/* Usage
Grab some XML data, either from a file, URL, etc. however you want. Assume storage in $strYourXML;
Please sign in to comment.
Something went wrong with that request. Please try again.