/** * Process all the actions that were submitted as part of the current request. * * @param int $timestamp the timestamp that should be stored as the modifed * time in the database for these actions. If null, will use the current time. */ public function process_all_actions($timestamp) { global $DB; $this->quba->process_all_actions($timestamp); question_engine::save_questions_usage_by_activity($this->quba); $this->attempt->timemodified = $timestamp; if ($this->attempt->timefinish) { $this->attempt->sumgrades = $this->quba->get_total_mark(); } $DB->update_record('reader_attempts', $this->attempt); if (!$this->is_preview() && $this->attempt->timefinish) { reader_save_best_grade($this->get_reader(), $this->get_userid()); } }
function reader_delete_attempt($attempt, $reader) { global $DB; if (is_numeric($attempt)) { if (!($attempt = $DB->get_record('reader_attempts', array('id' => $attempt)))) { return; } } if ($attempt->reader != $reader->id) { debugging("Trying to delete attempt {$attempt->id} which belongs to reader {$attempt->reader} " . "but was passed reader {$reader->id}."); return; } $DB->delete_records('reader_attempts', array('id' => $attempt->id)); delete_attempt($attempt->uniqueid); // Search reader_attempts for other instances by this user. // If none, then delete record for this reader, this user from reader_grades // else recalculate best grade $userid = $attempt->userid; if (!record_exists('reader_attempts', 'userid', $userid, 'reader', $reader->id)) { $DB->delete_records('reader_grades', array('userid' => $userid, 'reader' => $reader->id)); } else { reader_save_best_grade($reader, $userid); } reader_update_grades($reader, $userid); }