Deleting attempts properly now

This commit is contained in:
gustav_delius
2006-03-22 18:27:28 +00:00
parent 8a18280393
commit 0429cd86c3
5 changed files with 66 additions and 12 deletions
+31
View File
@@ -317,6 +317,29 @@ function question_category_isused($categoryid, $recursive = false) {
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
@@ -341,6 +364,14 @@ function delete_question($questionid) {
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);