Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-16184 - patch to correct the calculation of first, and last acces…

…s to a SCORM attempt. backport to 1.9. + missing php tag in debug.
  • Loading branch information...
commit 5893fbd8e1fe6290f28dd5f48982d501a916c0e1 1 parent e6dcae9
piers authored
10 mod/scorm/api.php
View
@@ -2,7 +2,7 @@
require_once("../../config.php");
require_once('locallib.php');
-
+
$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
@@ -34,7 +34,7 @@
}
require_login($course->id, false, $cm);
-
+
if ($usertrack = scorm_get_tracks($scoid,$USER->id,$attempt)) {
if ((isset($usertrack->{'cmi.exit'}) && ($usertrack->{'cmi.exit'} != 'time-out')) || ($scorm->version != "SCORM_1.3")) {
foreach ($usertrack as $key => $value) {
@@ -58,7 +58,7 @@
$userdata->credit = 'credit';
} else {
$userdata->credit = 'no-credit';
- }
+ }
if ($scodatas = scorm_get_sco($scoid, SCO_DATA)) {
foreach ($scodatas as $key => $value) {
$userdata->$key = addslashes_js($value);
@@ -75,6 +75,10 @@
} else {
include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.js.php');
}
+
+ // set the start time of this SCO
+ scorm_insert_track($USER->id,$scorm->id,$scoid,$attempt,'x.start.time',time());
+
?>
var errorCode = "0";
2  mod/scorm/datamodels/debug.js.php
View
@@ -588,7 +588,7 @@ function UpdateLog(s) {
+ ' </select>'
+ ' <input type="text" name="API_ELEMENT" id="API_ELEMENT" size="40"><br />'
+ ' <br />'
- + ' <label><b>Select API Function to Call</b></label> &nbsp;&nbsp;&nbsp;&nbsp; <input type = "button" value = "<?echo $LMS_prefix; ?>GetValue()"'
+ + ' <label><b>Select API Function to Call</b></label> &nbsp;&nbsp;&nbsp;&nbsp; <input type = "button" value = "<?php echo $LMS_prefix; ?>GetValue()"'
+ ' onclick = "tryLMSGetValue();" id="lmsGetButton"'
+ ' name="lmsGetButton">&nbsp;&nbsp;-- OR --&nbsp;&nbsp;'
+ ' <input type="button" value="<?php echo $LMS_prefix; ?>SetValue()"'
44 mod/scorm/locallib.php
View
@@ -369,6 +369,9 @@ function scorm_get_tracks($scoid,$userid,$attempt='') {
$element = $track->element;
$usertrack->{$element} = $track->value;
switch ($element) {
+ case 'x.start.time':
+ $usertrack->x_start_time = $track->value;
+ break;
case 'cmi.core.lesson_status':
case 'cmi.completion_status':
if ($track->value == 'not attempted') {
@@ -402,6 +405,45 @@ function scorm_get_tracks($scoid,$userid,$attempt='') {
}
}
+/* Find the start and finsh time for a a given SCO attempt
+ *
+ * @param int $scormid SCORM Id
+ * @param int $scoid SCO Id
+ * @param int $userid User Id
+ * @param int $attemt Attempt Id
+ *
+ * @return object start and finsh time EPOC secods
+ *
+ */
+function scorm_get_sco_runtime($scormid, $scoid, $userid, $attempt=1) {
+
+ $timedata = new object();
+ $sql = !empty($scoid) ? "userid=$userid AND scormid=$scormid AND scoid=$scoid AND attempt=$attempt" : "userid=$userid AND scormid=$scormid AND attempt=$attempt";
+ $tracks = get_records_select('scorm_scoes_track',"$sql ORDER BY timemodified ASC");
+ if ($tracks) {
+ $tracks = array_values($tracks);
+ }
+
+ if ($start_track = get_records_select('scorm_scoes_track',"$sql AND element='x.start.time' ORDER BY scoid ASC")) {
+ $start_track = array_values($start_track);
+ $timedata->start = $start_track[0]->value;
+ }
+ else if ($tracks) {
+ $timedata->start = $tracks[0]->timemodified;
+ }
+ else {
+ $timedata->start = false;
+ }
+ if ($tracks && $track = array_pop($tracks)) {
+ $timedata->finish = $track->timemodified;
+ }
+ else {
+ $timedata->finish = $timedata->start;
+ }
+ return $timedata;
+}
+
+
function scorm_get_user_data($userid) {
/// Gets user info required to display the table of scorm results
/// for report.php
@@ -707,7 +749,7 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
}
function scorm_simple_play($scorm,$user) {
$result = false;
-
+
if ($scorm->updatefreq == UPDATE_EVERYTIME) {
scorm_parse($scorm);
}
13 mod/scorm/report.php
View
@@ -177,14 +177,17 @@
fullname($userdata).'</a>';
$row[] = '<a href="report.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$a.'">'.$a.'</a>';
$select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a;
- $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
+// $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');
+ $timetracks = scorm_get_sco_runtime($scorm->id, false, $scouser->userid, $a);
// jump out here if this attempt doesnt exist
- if (!$timetracks->started) {
+// if (!$timetracks->started) {
+ if (!$timetracks->start) {
continue;
}
- $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
- $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
-
+// $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
+// $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
+ $row[] = userdate($timetracks->start, get_string('strftimedaydatetime'));
+ $row[] = userdate($timetracks->finish, get_string('strftimedaydatetime'));
$row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a);
$table->data[] = $row;
}
Please sign in to comment.
Something went wrong with that request. Please try again.