]> git.mjollnir.org Git - moodle.git/commitdiff
Bug #6033 - missing string for unknown questiontype. Also tidied up some messy code...
authortjhunt <tjhunt>
Tue, 18 Jul 2006 15:34:24 +0000 (15:34 +0000)
committertjhunt <tjhunt>
Tue, 18 Jul 2006 15:34:24 +0000 (15:34 +0000)
lang/en_utf8/quiz.php
lib/questionlib.php
question/type/missingtype/editquestion.php
question/type/missingtype/questiontype.php

index 9c1998cc25c6ee2522c4092eb1f14c9ddd5fd9cf..a429bc25b8895bf7f2788c619cbf69db670b3949 100644 (file)
@@ -495,7 +495,7 @@ $string['usedcategorymoved'] = 'This category has been preserved and moved to th
 $string['validate'] = 'Validate';
 $string['viewallanswers'] = 'View $a quiz attempts';
 $string['viewallreports'] = 'View reports for $a attempts';
-$string['warningmissingtype'] = '<p><b>This question is of a type that has not been installed on your Moodle yet.<br />Please alert your Moodle administrator.</b></p>';
+$string['warningmissingtype'] = '<b>This question is of a type that has not been installed on your Moodle yet.<br />Please alert your Moodle administrator.</b>';
 $string['warningsdetected'] = '$a warning(s) detected';
 $string['wheregrade'] = 'Where\'s my grade?';
 $string['webct'] = 'WebCT format';
index b7e645a433baceaef859bcaac01c9282282c1ea2..f49315e84ddce0cc71404d3d8b62d2e13fe130ac 100644 (file)
@@ -430,6 +430,7 @@ function question_delete_course($course, $feedback=true) {
                 //It's being used. Cannot delete it, so:
                 //Create a container category in SITEID course if it doesn't exist
                 if (!$concatid) {
+                    $concat = new stdClass;
                     $concat->course = SITEID;
                     if (!isset($course->shortname)) {
                         $course->shortname = 'id=' . $course->id;
@@ -489,6 +490,7 @@ function question_delete_course($course, $feedback=true) {
         }
         //Inform about changes performed if feedback is enabled
         if ($feedback) {
+            $table = new stdClass;
             $table->head = array(get_string('category','quiz'), get_string('action'));
             $table->data = $feedbackdata;
             print_table($table);
@@ -497,44 +499,43 @@ function question_delete_course($course, $feedback=true) {
     return true;
 }
 
-
 /**
-* Updates the question objects with question type specific
-* information by calling {@link get_question_options()}
-*
-* Can be called either with an array of question objects or with a single
-* question object.
-* @return bool            Indicates success or failure.
-* @param mixed $questions Either an array of question objects to be updated
-*                         or just a single question object
-*/
-function get_question_options(&$questions) {
+ * Private function to factor common code out of get_question_options().
+ * 
+ * @param object $question the question to tidy.
+ * @return boolean true if successful, else false. 
+ */
+function _tidy_question(&$question) {
     global $QTYPES;
+    if (!array_key_exists($question->qtype, $QTYPES)) {
+        $question->qtype = 'missingtype';
+        $question->questiontext = '<p>' . get_string('warningmissingtype', 'quiz') . '</p>' . $question->questiontext;
+    }
+    $question->name_prefix = question_make_name_prefix($question->id);
+    return $QTYPES[$question->qtype]->get_question_options($question);
+}
 
+/**
+ * Updates the question objects with question type specific
+ * information by calling {@link get_question_options()}
+ *
+ * Can be called either with an array of question objects or with a single
+ * question object.
+ * 
+ * @param mixed $questions Either an array of question objects to be updated
+ *         or just a single question object
+ * @return bool Indicates success or failure.
+ */
+function get_question_options(&$questions) {
     if (is_array($questions)) { // deal with an array of questions
-        // get the keys of the input array
-        $keys = array_keys($questions);
-        // update each question object
-        foreach ($keys as $i) {
-            if (!array_key_exists($questions[$i]->qtype, $QTYPES)) {
-                $questions[$i]->qtype = 'missingtype';
-                $questions[$i]->questiontext = get_string('warningmissingtype', 'quiz').$questions[$i]->questiontext;
-            }
-            
-            // set name prefix
-            $questions[$i]->name_prefix = question_make_name_prefix($i);
-
-            if (!$QTYPES[$questions[$i]->qtype]->get_question_options($questions[$i]))
+        foreach ($questions as $i => $notused) {
+            if (!_tidy_question($questions[$i])) {
                 return false;
+            }
         }
         return true;
     } else { // deal with single question
-        if (!array_key_exists($questions->qtype, $QTYPES)) {
-            $questions->qtype = 'missingtype';
-            $questions[$i]->questiontext = get_string('warningmissingtype', 'quiz').$questions[$i]->questiontext;
-        }
-        $questions->name_prefix = question_make_name_prefix($questions->id);
-        return $QTYPES[$questions->qtype]->get_question_options($questions);
+        return _tidy_question($questions);
     }
 }
 
@@ -1210,6 +1211,7 @@ function question_get_id_from_name_prefix($name) {
  */
 function question_new_attempt_uniqueid($modulename='quiz') {
     global $CFG;
+    $attempt = new stdClass;
     $attempt->modulename = $modulename;
     if (!$id = insert_record('question_attempts', $attempt)) {
         error('Could not create new entry in question_attempts table');
index 28710898c7613ab2da3b973e5200f5d924479ec8..5f69b9c7ba150f300721878fe4bd52c391827a79 100644 (file)
@@ -1,7 +1,7 @@
 <?php // $Id$
 
     if (!empty($options->answers)) {
-        $answersraw = get_records_list("question_answers", "id", $options->answers);
+        $answersraw = get_records_list('question_answers', 'id', $options->answers);
 
     }
 
     }
 
     $yesnooptions = array();
-    $yesnooptions[0] = get_string("no");
-    $yesnooptions[1] = get_string("yes");
+    $yesnooptions[0] = get_string('no');
+    $yesnooptions[1] = get_string('yes');
 
-    print_heading_with_help(get_string("editingmissingtype", "quiz"), "multichoice", "quiz");
+    print_heading(get_string('warningmissingtype', 'quiz'));
     require("$CFG->dirroot/question/type/missingtype/editquestion.html");
 
 ?>
index 45764e2d7e3925c2550ee938cb102463c9566715..6493f3bd9b85bbc27789129c2e65f5bdf63f9547 100644 (file)
@@ -38,6 +38,7 @@ class question_missingtype_qtype extends default_questiontype {
         $anss = array();
         if ($answers) {
             foreach ($answers as $answer) {
+                $a = new stdClass;
                 $a->text = format_text("$answer->answer", FORMAT_MOODLE, $formatoptions, $cmoptions->course);
     
                 $anss[] = clone($a);