Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-37524 SCORM: mode not calculated correctly.

  • Loading branch information...
commit 7cf1d8bd603cca8e3381cf414c79c7ef0a895c19 1 parent 444433b
Dan Marsden danmarsden authored
Showing with 52 additions and 42 deletions.
  1. +34 −0 mod/scorm/lib.php
  2. +4 −4 mod/scorm/locallib.php
  3. +14 −38 mod/scorm/player.php
34 mod/scorm/lib.php
View
@@ -1349,3 +1349,37 @@ function scorm_set_completion($scorm, $userid, $completionstate = COMPLETION_COM
$completion->update_state($cm, $completionstate, $userid);
}
}
+
+/**
+ * Check and set the correct mode and attempt when entering a SCORM package.
+ *
+ * @param object $scorm object
+ * @param string $newattempt should a new attempt be generated here.
+ * @param int $attempt the attempt number this is for.
+ * @param int $userid the userid of the user.
+ * @param string $mode the current mode that has been selected.
+ */
+function scorm_check_mode($scorm, $newattempt, &$attempt, $userid, &$mode) {
+ global $DB;
+ if (($newattempt == 'on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
+ $attempt++;
+ $mode = 'normal';
+ } else if ($mode != 'browse') { // Check if review mode should be set.
+ $mode = 'normal'; // Set to normal mode by default.
+
+ // If all tracks == passed, failed or completed then use review mode.
+ $tracks = $DB->get_recordset('scorm_scoes_track', array('scormid' => $scorm->id, 'userid' => $userid,
+ 'attempt' => $attempt, 'element' => 'cmi.core.lesson_status'));
+ foreach ($tracks as $track) {
+ if (($track->value == 'completed') || ($track->value == 'passed') || ($track->value == 'failed')) {
+ $mode = 'review';
+ } else { // Found an incomplete sco so exit and use normal mode.
+ $mode = 'normal';
+ break;
+ }
+ }
+ $tracks->close();
+ } else if (($mode == 'browse') && ($scorm->hidebrowse == 1)) { // Prevent Browse mode if hidebrowse is set.
+ $mode = 'normal';
+ }
+}
8 mod/scorm/locallib.php
View
@@ -1378,8 +1378,8 @@ function scorm_get_toc_object($user, $scorm, $currentorg='', $scoid='', $mode='n
global $CFG, $DB, $PAGE, $OUTPUT;
$modestr = '';
- if ($mode == 'browse') {
- $modestr = '&amp;mode='.$mode;
+ if ($mode != 'normal') {
+ $modestr = '&mode='.$mode;
}
$result = array();
@@ -1791,8 +1791,8 @@ function scorm_get_toc($user, $scorm, $cmid, $toclink=TOCJSLINK, $currentorg='',
$tocmenu = scorm_format_toc_for_droplist($scorm, $scoes['scoes'][0]->children, $scoes['usertracks'], $currentorg, $organizationsco);
$modestr = '';
- if ($mode == 'browse') {
- $modestr = '&amp;mode='.$mode;
+ if ($mode != 'normal') {
+ $modestr = '&mode='.$mode;
}
$url = new moodle_url('/mod/scorm/player.php?a='.$scorm->id.'&currentorg='.$currentorg.$modestr);
52 mod/scorm/player.php
View
@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
-/// This page prints a particular instance of aicc/scorm package
+// This page prints a particular instance of aicc/scorm package.
require_once('../../config.php');
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
@@ -25,8 +25,8 @@
$scoid = required_param('scoid', PARAM_INT); // sco ID
$mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
$currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
-$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
-$displaymode = optional_param('display','',PARAM_ALPHA);
+$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt.
+$displaymode = optional_param('display', '', PARAM_ALPHA);
// IE 9 workaround for Flash bug: MDL-29213
// Note that it's not clear if appending the meta tag via $CFG->additionalhtmlhead
@@ -63,6 +63,11 @@
} else {
print_error('missingparameter');
}
+// If new attempt is being triggered set normal mode and increment attempt number.
+$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
+
+// Check mode is correct and set mode/attempt (uses pass by reference).
+scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode);
$url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
if ($mode !== 'normal') {
@@ -104,7 +109,7 @@
die;
}
-//check if scorm closed
+// Check if scorm closed.
$timenow = time();
if ($scorm->timeclose !=0) {
if ($scorm->timeopen > $timenow) {
@@ -121,17 +126,11 @@
}
}
// TOC processing
-$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
+$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe.
if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
$scorm->version = 'scorm_12';
}
require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
-$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
-if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
- $attempt++;
- $mode = 'normal';
-}
-$attemptstr = '&amp;attempt=' . $attempt;
$result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
$sco = $result->sco;
@@ -142,33 +141,11 @@
exit;
}
-if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
- $mode = 'normal';
-}
-if ($mode != 'browse') {
- if ($trackdata = scorm_get_tracks($sco->id, $USER->id, $attempt)) {
- if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
- $mode = 'review';
- } else {
- $mode = 'normal';
- }
- } else {
- $mode = 'normal';
- }
-}
-
add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
$scoidstr = '&amp;scoid='.$sco->id;
-$scoidpop = '&scoid='.$sco->id;
$modestr = '&amp;mode='.$mode;
-if ($mode == 'browse') {
- $modepop = '&mode='.$mode;
-} else {
- $modepop = '';
-}
-$orgstr = '&currentorg='.$currentorg;
$SESSION->scorm = new stdClass();
$SESSION->scorm->scoid = $sco->id;
@@ -176,11 +153,11 @@
$SESSION->scorm->scormmode = $mode;
$SESSION->scorm->attempt = $attempt;
-// Mark module viewed
+// Mark module viewed.
$completion = new completion_info($course);
$completion->set_module_viewed($cm);
-// Print the page header
+// Print the page header.
if (empty($scorm->popup) || $displaymode=='popup') {
$exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
$PAGE->set_button($exitlink);
@@ -198,7 +175,6 @@
$PAGE->requires->js('/lib/cookies.js', true);
echo $OUTPUT->header();
-// NEW IMS TOC
$PAGE->requires->string_for_js('navigation', 'scorm');
$PAGE->requires->string_for_js('toc', 'scorm');
$PAGE->requires->string_for_js('hide', 'moodle');
@@ -252,7 +228,7 @@
}
$name = 'scorm_'.$name;
echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
- $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup'));
+ $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup', 'mode' => $mode));
echo html_writer::script(
js_writer::function_call('scorm_openpopup', Array($url->out(false),
$name, $scorm->options,
@@ -276,7 +252,7 @@
<?php
$scoes = scorm_get_toc_object($USER, $scorm, "", $sco->id, $mode, $attempt);
$adlnav = scorm_get_adlnav_json($scoes['scoes']);
-// NEW IMS TOC
+
if (empty($scorm->popup) || $displaymode == 'popup') {
if (!isset($result->toctitle)) {
$result->toctitle = get_string('toc', 'scorm');
Please sign in to comment.
Something went wrong with that request. Please try again.