public function MultichoiceQuestion::delete in Quiz 7
Same name and namespace in other branches
- 6.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::delete()
- 7.6 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::delete()
- 7.4 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::delete()
- 7.5 question_types/multichoice/multichoice.classes.inc \MultichoiceQuestion::delete()
Implementation of delete
Overrides QuizQuestion::delete
See also
QuizQuestion#delete()
File
- question_types/
multichoice/ multichoice.classes.inc, line 296 - The main classes for the multichoice question type.
Class
- MultichoiceQuestion
- Extension of QuizQuestion.
Code
public function delete($only_this_version = FALSE) {
$delete_properties = db_delete('quiz_multichoice_properties')
->condition('nid', $this->node->nid);
$delete_answers = db_delete('quiz_multichoice_answers')
->condition('question_nid', $this->node->nid);
$delete_results = db_delete('quiz_multichoice_user_answers')
->condition('question_nid', $this->node->nid);
if ($only_this_version) {
$delete_properties
->condition('vid', $this->node->vid);
$delete_answers
->condition('question_vid', $this->node->vid);
$delete_results
->condition('question_vid', $this->node->vid);
}
$delete_properties
->execute();
$delete_answers
->execute();
$delete_results
->execute();
// Delete from table quiz_multichoice_user_answer_multi
$user_answer_id = array();
if ($only_this_version) {
$query = db_query('SELECT id FROM {quiz_multichoice_user_answers} WHERE question_nid = :nid AND question_vid = :vid AND result_id = :result_id', array(
':nid' => $this->node->nid,
':vid' => $this->node->vid,
':result_id' => $this->rid,
));
}
else {
$query = db_query('SELECT id FROM {quiz_multichoice_user_answers} WHERE question_nid = :nid AND result_id = :result_id', array(
':nid' => $this->node->nid,
':result_id' => $this->rid,
));
}
while ($user_answer = $query
->fetch()) {
$user_answer_id[] = $user_answer->id;
}
if (count($user_answer_id)) {
db_delete('quiz_multichoice_user_answer_multi')
->condition('user_answer_id', $user_answer_id, 'IN')
->execute();
}
parent::delete($only_this_version);
}