You are here

function delete_attempt in Quiz 6.6

Same name and namespace in other branches
  1. 6.5 includes/moodle/lib/questionlib.php \delete_attempt()

Deletes all data associated to an attempt from the database

Parameters

integer $attemptid The id of the attempt being deleted:

File

includes/moodle/lib/questionlib.php, line 425

Code

function delete_attempt($attemptid) {
  global $QTYPES;
  $states = get_records('question_states', 'attempt', $attemptid);
  if ($states) {
    $stateslist = implode(',', array_keys($states));

    // delete question-type specific data
    foreach ($QTYPES as $qtype) {
      $qtype
        ->delete_states($stateslist);
    }
  }

  // delete entries from all other question tables
  // It is important that this is done only after calling the questiontype functions
  delete_records("question_states", "attempt", $attemptid);
  delete_records("question_sessions", "attemptid", $attemptid);
  delete_records("question_attempts", "id", $attemptid);
}