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);
+1 -4
View File
@@ -207,10 +207,7 @@
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);
}
}
}
+11 -2
View File
@@ -69,9 +69,18 @@ class question_essay_qtype extends default_questiontype {
}
/**
* 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) {
+13 -1
View File
@@ -178,7 +178,19 @@ class default_questiontype {
}
/**
* 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
+10 -5
View File
@@ -123,6 +123,16 @@ class question_rqp_qtype extends default_questiontype {
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
*
@@ -131,11 +141,6 @@ class question_rqp_qtype extends default_questiontype {
*/
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;
}