MDL-16184 - patch to correct the calculation of first, and last access to a SCORM...
authorpiers <piers>
Sat, 20 Dec 2008 06:20:43 +0000 (06:20 +0000)
committerpiers <piers>
Sat, 20 Dec 2008 06:20:43 +0000 (06:20 +0000)
mod/scorm/loaddatamodel.php
mod/scorm/locallib.php
mod/scorm/report.php

index ca6613a..29b2e10 100644 (file)
@@ -75,6 +75,9 @@
     } 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";
index d6f3637..95e1142 100755 (executable)
@@ -411,6 +411,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') {
@@ -444,6 +447,47 @@ 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) {
+       global $DB;
+
+    $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 = $DB->get_records_select('scorm_scoes_track',"$sql ORDER BY timemodified ASC");
+    if ($tracks) {
+        $tracks = array_values($tracks);
+    }
+
+    if ($start_track = $DB->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) {
     global $DB;
 /// Gets user info required to display the table of scorm results
index e3a6ec1..3142a9f 100755 (executable)
                         $row[] = '<a href="report.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$a.'">'.$a.'</a>';
                         $select = 'scormid = ? and userid = ? and attempt = ?';
                         $params = array($scorm->id, $scouser->userid, $a);
-                        $timetracks = $DB->get_record_select('scorm_scoes_track', $select, $params, '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->start) {
                             continue;
                         }
-                        $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;