Skip to content
Permalink
Browse files

Introduced function quiz_delete_question() and questiontype methods d…

…elete_question()
  • Loading branch information...
gustav_delius
gustav_delius committed Feb 7, 2006
1 parent de42177 commit cd00e988bb508fddc60d7f0a855d4c9a2515670c
@@ -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 @@ function validate_form($form) {
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 @@ function save_question_options($question) {
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 @@ function save_question_options($question) {
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 @@ function save_session_and_responses(&$question, &$state) {
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 @@ function save_question_options($question) {
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 @@ function save_numerical_units($question) {
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 @@ function get_question_options(&$question) {
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 @@ function save_question_options($question) {
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 @@ function get_question_options(&$question) {
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 @@ function save_question_options($question) {
}
}
/**
* 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 @@ function get_question_options(&$question) {
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) {

0 comments on commit cd00e98

Please sign in to comment.
You can’t perform that action at this time.