/** * Deletes question and all associated data from the database * * It will not delete a question if it is used by an activity module * @param object $question The question being deleted */ function delete_question($questionid) { global $QTYPES; if (!($question = get_record('question', 'id', $questionid))) { // In some situations, for example if this was a child of a // Cloze question that was previously deleted, the question may already // have gone. In this case, just do nothing. return; } // Do not delete a question if it is used by an activity module if (count(question_list_instances($questionid))) { return; } // delete questiontype-specific data question_require_capability_on($question, 'edit'); if ($question) { if (isset($QTYPES[$question->qtype])) { $QTYPES[$question->qtype]->delete_question($questionid); } } else { echo "Question with id {$questionid} does not exist.<br />"; } if ($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("question_states", "question", $questionid); delete_records("question_sessions", "questionid", $questionid); // Now recursively delete all child questions if ($children = get_records('question', 'parent', $questionid)) { foreach ($children as $child) { if ($child->id != $questionid) { delete_question($child->id); } } } // Finally delete the question record itself delete_records('question', 'id', $questionid); return; }
function RWSIQCUsed($r_qci) { global $DB; global $CFG; $r_chn = $DB->get_records("question_categories", array("parent" => $r_qci)); if (count($r_chn) > 0) { foreach ($r_chn as $r_chd) { if (RWSIQCUsed($r_chd->id)) { return true; } } } $r_qsts = $DB->get_records("question", array("category" => $r_qci)); if (count($r_qsts) > 0) { if (respondusws_floatcompare($CFG->version, 2011070100, 2) >= 0) { $r_qis = array(); foreach ($r_qsts as $r_q) { $r_qis[] = $r_q->id; } if (questions_in_use($r_qis)) { return true; } } else { foreach ($r_qsts as $r_q) { if (count(question_list_instances($r_q->id)) > 0) { return true; } } } } return false; }
/** * Deletes question and all associated data from the database * * It will not delete a question if it is used by an activity module * * @global object * @global object * @param object $question The question being deleted */ function delete_question($questionid) { global $QTYPES, $DB; $question = $DB->get_record_sql(' SELECT q.*, qc.contextid FROM {question} q JOIN {question_categories} qc ON qc.id = q.category WHERE q.id = ?', array($questionid)); if (!$question) { // In some situations, for example if this was a child of a // Cloze question that was previously deleted, the question may already // have gone. In this case, just do nothing. return; } // Do not delete a question if it is used by an activity module if (count(question_list_instances($questionid))) { return; } // delete questiontype-specific data question_require_capability_on($question, 'edit'); if (isset($QTYPES[$question->qtype])) { $QTYPES[$question->qtype]->delete_question($questionid, $question->contextid); } if ($states = $DB->get_records('question_states', array('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 $DB->delete_records('question_answers', array('question' => $questionid)); $DB->delete_records('question_states', array('question' => $questionid)); $DB->delete_records('question_sessions', array('questionid' => $questionid)); // Now recursively delete all child questions if ($children = $DB->get_records('question', array('parent' => $questionid), '', 'id,qtype')) { foreach ($children as $child) { if ($child->id != $questionid) { delete_question($child->id); } } } // Finally delete the question record itself $DB->delete_records('question', array('id' => $questionid)); }
/** * Deletes question and all associated data from the database * * It will not delete a question if it is used by an activity module * @param object $question The question being deleted */ function delete_question($questionid) { global $QTYPES; // Do not delete a question if it is used by an activity module if (count(question_list_instances($questionid))) { return; } // delete questiontype-specific data if ($question = get_record('question', 'id', $questionid)) { if (isset($QTYPES[$question->qtype])) { $QTYPES[$question->qtype]->delete_question($questionid); } } else { echo "Question with id {$questionid} does not exist.<br />"; } if ($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("question_states", "question", $questionid); delete_records("question_sessions", "questionid", $questionid); // Now recursively delete all child questions if ($children = get_records('question', 'parent', $questionid)) { foreach ($children as $child) { if ($child->id != $questionid) { delete_question($child->id); } } } // Finally delete the question record itself delete_records('question', 'id', $questionid); return; }