return false;
}
+/**
+ * Deletes all data associated to an attempt from the database
+ *
+ * @param object $question The question being deleted
+ */
+function delete_attempt($attemptid) {
+ global $QTYPES;
+
+ $states = get_records('question_states', 'attempt', $attemptid);
+ $stateslist = implode(',', array_keys($states));
+
+ // delete questiontype-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);
+
+ return;
+}
/**
* Deletes question and all associated data from the database
echo "Question with id $questionid does not exist.<br />";
}
+ $states = get_records('question_states', 'question', $questionid);
+ $stateslist = implode(',', array_keys($states));
+
+ // delete questiontype-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_answers", "question", $questionid);
delete_records('quiz_grades', 'quiz', $quiz->id, 'userid', $USER->id);
foreach ($oldattempts as $oldattempt) {
// there should only be one but we loop just in case
- // TODO: the following should become a function in questionlib.php which
- // really deletes all records associated to this attempt.
- delete_records('question_states', 'attempt', $oldattempt->uniqueid);
- delete_records('question_sessions', 'attemptid', $oldattempt->uniqueid);
+ delete_attempt($oldattempt->uniqueid);
}
}
}
}
/**
- * Deletes question from the question-type specific tables
+ * Deletes states from the question-type specific tables
+ *
+ * @param string $stateslist Comma separated list of state ids to be deleted
+ */
+ function delete_states($stateslist) {
+ delete_records_select("question_essay_states", "stateid IN ($stateslist)");
+ return true;
+ }
+
+ /**
+ * Deletes a question from the question-type specific tables
*
- * @return boolean Success/Failure
* @param object $question The question being deleted
*/
function delete_question($questionid) {
}
/**
- * Deletes question from the question-type specific tables
+ * Deletes states from the question-type specific tables
+ *
+ * @param string $stateslist Comma separated list of state ids to be deleted
+ */
+ function delete_states($stateslist) {
+ /// The default question type does not have any tables of its own
+ // therefore there is nothing to delete
+
+ return true;
+ }
+
+ /**
+ * Deletes a question from the question-type specific tables
*
* @return boolean Success/Failure
* @param object $question The question being deleted
return true;
}
+ /**
+ * Deletes states from the question-type specific tables
+ *
+ * @param string $stateslist Comma separated list of state ids to be deleted
+ */
+ function delete_states($stateslist) {
+ delete_records_select("question_rqp_states", "stateid IN ($stateslist)");
+ return true;
+ }
+
/**
* Deletes question from the question-type specific tables
*
*/
function delete_question($questionid) {
delete_records("question_rqp", "question", $questionid);
- if ($states = get_records('question_states', 'question', $questionid)) {
- foreach ($states as $state) {
- delete_records('question_rqp_states', 'stateid', $state->id);
- }
- }
return true;
}