Index: questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/questiontype.php,v retrieving revision 1.74.2.16 diff -u -r1.74.2.16 questiontype.php --- questiontype.php 10 Dec 2008 07:06:18 -0000 1.74.2.16 +++ questiontype.php 22 Dec 2008 18:52:00 -0000 @@ -102,7 +102,13 @@ function extra_question_fields() { return null; } - + /** + * If you use extra_question_fields, overload this function to return true + * in case you table use deprecated question field name instead of questionid + */ + function deprecated_qid_col_name() { + return false; + } /** * If your question type has a table that extends the question_answers table, * make this method return an array wherer the first element is the table name, @@ -365,11 +371,12 @@ $question_extension_table = array_shift($extra_question_fields); $function = 'update_record'; - $options = get_record($question_extension_table, 'questionid', $question->id); + $qid_col_name= $this->deprecated_qid_col_name() ? 'question':'questionid'; + $options = get_record($question_extension_table, $qid_col_name, $question->id); if (!$options) { $function = 'insert_record'; $options = new stdClass; - $options->questionid = $question->id; + $options->$qid_col_name = $question->id; } foreach ($extra_question_fields as $field) { if (!isset($question->$field)) { @@ -437,7 +444,8 @@ $extra_question_fields = $this->extra_question_fields(); if (is_array($extra_question_fields)) { $question_extension_table = array_shift($extra_question_fields); - $extra_data = get_record($question_extension_table, 'questionid', $question->id, '', '', '', '', implode(', ', $extra_question_fields)); + $qid_col_name= $this->deprecated_qid_col_name() ? 'question':'questionid'; + $extra_data = get_record($question_extension_table, $qid_col_name, $question->id, '', '', '', '', implode(', ', $extra_question_fields)); if ($extra_data) { foreach ($extra_question_fields as $field) { $question->options->$field = $extra_data->$field; @@ -494,7 +502,8 @@ $extra_question_fields = $this->extra_question_fields(); if (is_array($extra_question_fields)) { $question_extension_table = array_shift($extra_question_fields); - $success = $success && delete_records($question_extension_table, 'questionid', $questionid); + $qid_col_name= $this->deprecated_qid_col_name() ? 'question':'questionid'; + $success = $success && delete_records($question_extension_table, $qid_col_name, $questionid); } $extra_answer_fields = $this->extra_answer_fields(); Index: shortanswer/questiontype.php =================================================================== RCS file: /cvsroot/moodle/moodle/question/type/shortanswer/questiontype.php,v retrieving revision 1.20.2.9 diff -u -r1.20.2.9 questiontype.php --- shortanswer/questiontype.php 12 Dec 2008 03:48:33 -0000 1.20.2.9 +++ shortanswer/questiontype.php 27 Dec 2008 22:29:38 -0000 @@ -22,19 +22,11 @@ return 'shortanswer'; } - function get_question_options(&$question) { - // Get additional information from database - // and attach it to the question object - if (!$question->options = get_record('question_shortanswer', 'question', $question->id)) { - notify('Error: Missing question options!'); - return false; - } - - if (!$question->options->answers = get_records('question_answers', 'question', - $question->id, 'id ASC')) { - notify('Error: Missing question answers for shortanswer question ' . $question->id . '!'); - return false; - } + function extra_question_fields() { + return array('question_shortanswer','answers','usecase'); + } + + function deprecated_qid_col_name() { return true; } @@ -61,8 +53,8 @@ $answer->answer = trim($dataanswer); $answer->fraction = $question->fraction[$key]; $answer->feedback = $question->feedback[$key]; - if (!update_record("question_answers", $answer)) { - $result->error = "Could not update quiz answer! (id=$answer->id)"; + if (!update_record('question_answers', $answer)) { + $result->error = 'Could not update quiz answer! (id='.$answer->id.')'; return $result; } } else { // This is a completely new answer @@ -71,8 +63,8 @@ $answer->question = $question->id; $answer->fraction = $question->fraction[$key]; $answer->feedback = $question->feedback[$key]; - if (!$answer->id = insert_record("question_answers", $answer)) { - $result->error = "Could not insert quiz answer!"; + if (!$answer->id = insert_record('question_answers', $answer)) { + $result->error = 'Could not insert quiz answer!'; return $result; } } @@ -82,22 +74,10 @@ } } - if ($options = get_record("question_shortanswer", "question", $question->id)) { - $options->answers = implode(",",$answers); - $options->usecase = $question->usecase; - if (!update_record("question_shortanswer", $options)) { - $result->error = "Could not update quiz shortanswer options! (id=$options->id)"; - return $result; - } - } else { - unset($options); - $options->question = $question->id; - $options->answers = implode(",",$answers); - $options->usecase = $question->usecase; - if (!insert_record("question_shortanswer", $options)) { - $result->error = "Could not insert quiz shortanswer options!"; - return $result; - } + $question->answers=implode(',',$answers); + $parentresult=parent:: save_question_options($question); + if($parentresult!==null) {//parent function returns null if all is OK + return $parentresult; } // delete old answer records @@ -110,24 +90,13 @@ /// Perform sanity checks on fractional grades if ($maxfraction != 1) { $maxfraction = $maxfraction * 100; - $result->noticeyesno = get_string("fractionsnomax", "quiz", $maxfraction); + $result->noticeyesno = get_string('fractionsnomax', 'quiz', $maxfraction); return $result; } else { return true; } } - /** - * Deletes question from the question-type specific tables - * - * @return boolean Success/Failure - * @param object $question The question being deleted - */ - function delete_question($questionid) { - delete_records("question_shortanswer", "question", $questionid); - return true; - } - function print_question_formulation_and_controls(&$question, &$state, $cmoptions, $options) { global $CFG; /// This implementation is also used by question type 'numerical'