Introduced function quiz_delete_question() and questiontype methods delete_question()
This commit is contained in:
+2
-19
@@ -334,27 +334,10 @@ function quiz_delete_course($course, $feedback=true) {
|
||||
} else {
|
||||
//Category isn't being used so:
|
||||
//Delete it completely (questions and category itself)
|
||||
//deleting questions....not perfect until implemented in question classes (see bug 3366)
|
||||
//deleting questions
|
||||
if ($questions = get_records("quiz_questions", "category", $category->id)) {
|
||||
foreach ($questions as $question) {
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_match", "question", $question->id);
|
||||
delete_records("quiz_match_sub", "question", $question->id);
|
||||
delete_records("quiz_multianswers", "question", $question->id);
|
||||
delete_records("quiz_multichoice", "question", $question->id);
|
||||
delete_records("quiz_numerical", "question", $question->id);
|
||||
delete_records("quiz_numerical_units", "question", $question->id);
|
||||
delete_records("quiz_calculated", "question", $question->id);
|
||||
delete_records("quiz_question_datasets", "question", $question->id);
|
||||
delete_records("quiz_randomsamatch", "question", $question->id);
|
||||
delete_records("quiz_shortanswer", "question", $question->id);
|
||||
delete_records("quiz_truefalse", "question", $question->id);
|
||||
delete_records("quiz_rqp", "question", $question->id);
|
||||
delete_records("quiz_essay", "question", $question->id);
|
||||
delete_records("quiz_states", "question", $question->id);
|
||||
delete_records("quiz_newest_states", "questionid", $question->id);
|
||||
delete_records("quiz_question_versions", "oldquestion", $question->id);
|
||||
delete_records("quiz_question_versions", "newquestion", $question->id);
|
||||
quiz_delete_question($question);
|
||||
}
|
||||
delete_records("quiz_questions", "category", $category->id);
|
||||
}
|
||||
|
||||
@@ -116,6 +116,23 @@ class cmoptions {
|
||||
|
||||
/// FUNCTIONS //////////////////////////////////////////////////////
|
||||
|
||||
|
||||
/**
|
||||
* Deletes question from the database
|
||||
*
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function quiz_delete_question($question) {
|
||||
global $QUIZ_QTYPES;
|
||||
$QUIZ_QTYPES[$question->qtype]->delete_question($question);
|
||||
delete_records("quiz_answers", "question", $question->id);
|
||||
delete_records("quiz_states", "question", $question->id);
|
||||
delete_records("quiz_newest_states", "questionid", $question->id);
|
||||
delete_records("quiz_question_versions", "oldquestion", $question->id);
|
||||
delete_records("quiz_question_versions", "newquestion", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the question objects with question type specific
|
||||
* information by calling {@link get_question_options()}
|
||||
|
||||
@@ -197,6 +197,20 @@ class quiz_calculated_qtype extends quiz_dataset_dependent_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_calculated", "question", $question->id);
|
||||
delete_records("quiz_numerical_units", "question", $question->id);
|
||||
delete_records("quiz_question_datasets", "question", $question->id);
|
||||
//TODO: delete entries from the quiz_dataset_items and quiz_dataset_definitions tables
|
||||
return true;
|
||||
}
|
||||
|
||||
function print_question_formulation_and_controls(&$question, &$state, $cmoptions,
|
||||
$options) {
|
||||
// Substitute variables in questiontext before giving the data to the
|
||||
|
||||
@@ -68,6 +68,17 @@ class quiz_essay_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_essay", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
|
||||
|
||||
$answers = &$question->options->answers;
|
||||
|
||||
@@ -94,6 +94,18 @@ class quiz_match_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param integer $question->id
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_match", "question", $question->id);
|
||||
delete_records("quiz_match_sub", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
|
||||
if (!$state->options->subquestions = get_records('quiz_match_sub',
|
||||
'question', $question->id)) {
|
||||
|
||||
@@ -165,6 +165,17 @@ class quiz_embedded_cloze_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_multianswers", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_correct_responses(&$question, &$state) {
|
||||
global $QUIZ_QTYPES;
|
||||
$responses = array();
|
||||
|
||||
@@ -138,10 +138,22 @@ class quiz_multichoice_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_multichoice", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
|
||||
// Shuffle the answers if required
|
||||
// create an array of answerids ??? why so complicated ???
|
||||
$answerids = array_values(array_map(create_function('$val',
|
||||
'return $val->id;'), $question->options->answers));
|
||||
// Shuffle the answers if required
|
||||
if ($cmoptions->shuffleanswers) {
|
||||
$answerids = swapshuffle($answerids);
|
||||
}
|
||||
|
||||
@@ -222,6 +222,18 @@ class quiz_numerical_qtype extends quiz_shortanswer_qtype {
|
||||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_numerical", "question", $question->id);
|
||||
delete_records("quiz_numerical_units", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function compare_responses(&$question, &$state, &$teststate) {
|
||||
$response = isset($state->responses['']) ? $state->responses[''] : '';
|
||||
$testresponse = isset($teststate->responses[''])
|
||||
|
||||
@@ -172,6 +172,19 @@ class quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
/// The default question type does not have any tables of its own
|
||||
// therefore there is nothing to delete
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the number of question numbers which are used by the question
|
||||
*
|
||||
|
||||
@@ -57,6 +57,17 @@ class quiz_randomsamatch_qtype extends quiz_match_qtype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_randomsamatch", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function create_session_and_responses(&$question, &$state, $cmoptions, $attempt) {
|
||||
// Choose a random shortanswer question from the category:
|
||||
// We need to make sure that no question is used more than once in the
|
||||
|
||||
@@ -123,6 +123,18 @@ class quiz_rqp_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_rqp", "question", $questionid);
|
||||
//TODO: delete also the states from quiz_rqp_states
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a value or array of values which will give full marks if graded as
|
||||
* the $state->responses field
|
||||
|
||||
@@ -106,6 +106,18 @@ class quiz_shortanswer_qtype extends quiz_default_questiontype {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_shortanswer", "question", $question->id);
|
||||
//TODO: delete also the states from quiz_rqp_states
|
||||
return true;
|
||||
}
|
||||
|
||||
function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) {
|
||||
/// This implementation is also used by question type NUMERICAL
|
||||
$answers = &$question->options->answers;
|
||||
|
||||
@@ -110,6 +110,17 @@ class quiz_truefalse_qtype extends quiz_default_questiontype {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Deletes question from the question-type specific tables
|
||||
*
|
||||
* @return boolean Success/Failure
|
||||
* @param object $question The question being deleted
|
||||
*/
|
||||
function delete_question($question) {
|
||||
delete_records("quiz_truefalse", "question", $question->id);
|
||||
return true;
|
||||
}
|
||||
|
||||
function get_correct_responses(&$question, &$state) {
|
||||
foreach ($question->options->answers as $answer) {
|
||||
if (((int) $answer->fraction) === 1) {
|
||||
|
||||
Reference in New Issue
Block a user