]> git.mjollnir.org Git - moodle.git/commitdiff
fixed typo in SQL query when starting a new HotPot attempt
authorgbateson <gbateson>
Sat, 13 Jan 2007 11:46:33 +0000 (11:46 +0000)
committergbateson <gbateson>
Sat, 13 Jan 2007 11:46:33 +0000 (11:46 +0000)
mod/hotpot/lib.php

index 15d5b63d9c3f81a997a31ba284361f060c37182e..13c7b62cc55a358e165e495813d615ba09c3a519 100644 (file)
@@ -1232,24 +1232,29 @@ function hotpot_scale_used ($hotpotid, $scaleid) {
 function hotpot_add_attempt($hotpotid) {
     global $db, $CFG, $USER;
 
+    // get start time of this attempt
+    $time = time();
+
     // set all previous "in progress" attempts at this quiz to "abandoned"
-    $db->Execute("
-        UPDATE
-            {$CFG->prefix}hotpot_attempts a
-        SET
-            a.timefinish = '".time()."',
-            a.status = '".HOTPOT_STATUS_ABANDONED."',
-        WHERE
-            a.hotpot='$hotpotid'
-            AND a.userid='$USER->id'
-            AND a.status='".HOTPOT_STATUS_INPROGRESS."'
-    ");
+    if ($attempts = get_records_select('hotpot_attempts', "hotpot='$hotpotid' AND userid='$USER->id' AND status='".HOTPOT_STATUS_INPROGRESS."'")) {
+        foreach ($attempts as $attempt) {
+            if ($attempt->timefinish==0) {
+                $attempt->timefinish = $time;
+            }
+            if ($attempt->clickreportid==0) {
+                $attempt->clickreportid = $attempt->id;
+            }
+            $attempt->status = HOTPOT_STATUS_ABANDONED;
+            update_record('hotpot_attempts', $attempt);
+        }
+    }    
 
     // create and add new attempt record
+    $attempt = new stdClass();
     $attempt->hotpot = $hotpotid;
     $attempt->userid = $USER->id;
     $attempt->attempt = hotpot_get_next_attempt($hotpotid);
-    $attempt->timestart = time();
+    $attempt->timestart = $time;
 
     return insert_record("hotpot_attempts", $attempt);
 }