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" 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; return insert_record("hotpot_attempts", $attempt); }
/** * @global object * @global stdClass * @global object * @uses HOTPOT_STATUS_INPROGRESS * @uses HOTPOT_STATUS_ABANDONED * @param int @hotpotid * @return bool */ 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" if ($attempts = $DB->get_records('hotpot_attempts', array('hotpot' => $hotpotid, 'userid' => $USER->id, '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; $DB->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; return $DB->insert_record("hotpot_attempts", $attempt); }