]> git.mjollnir.org Git - moodle.git/commitdiff
quiz editing: MDL-18173 Make clear in the UI whether a random question selects from...
authortjhunt <tjhunt>
Tue, 24 Feb 2009 05:16:23 +0000 (05:16 +0000)
committertjhunt <tjhunt>
Tue, 24 Feb 2009 05:16:23 +0000 (05:16 +0000)
lang/en_utf8/qtype_random.php
lang/en_utf8/question.php
lang/en_utf8/quiz.php
mod/quiz/editlib.php
pix/i/nosubcat.png [new file with mode: 0644]
pix/i/withsubcat.png [new file with mode: 0644]
question/category_class.php
question/type/multichoice/db/upgrade.php
question/type/multichoice/version.php
question/type/random/questiontype.php

index 8fec9a9dd1c7ddd7f326b3ad9150b6de51e8635b..efa07f99eff6f036d5e48e54ac96e031c3702461 100644 (file)
@@ -1,4 +1,6 @@
 <?php
 $string['configselectmanualquestions'] = 'Can the random question type select a manually graded question when it is making its random choice of a question from a category?';
+$string['randomqname'] = 'Random ($a)';
+$string['randomqplusname'] = 'Random ($a and sub-categories)';
 $string['selectmanualquestions'] = 'Random questions can use manually graded questions';
 ?>
index caced23647318a9fc30bf5b8a354b40f088f39e5..6a540c18af4f2088632e3dfb8a8b947981db6f6d 100644 (file)
@@ -46,6 +46,7 @@ $string['categorycurrent'] = 'Current Category';
 $string['categorycurrentuse'] = 'Use This Category';
 $string['categorymoveto'] = 'Save in Category';
 $string['changepublishstatuscat'] = '<a href=\"$a->caturl\">Category \"$a->name\"</a> in course \"$a->coursename\" will have it\'s sharing status changed from <strong>$a->changefrom to $a->changeto</strong>.';
+$string['chooseqtypetoadd'] = 'Choose a question type to add';
 $string['clicktoflag'] = 'Click to flag this question';
 $string['clicktounflag'] = 'Click to un-flag this question';
 $string['cwrqpfs'] = 'Random questions selecting questions from sub categories.';
index 0b6ec476ead1f41530adcf617e998b66874d84b0..045d229fa9981d8a9a89ac5dd129e4f11168e393 100644 (file)
@@ -549,10 +549,14 @@ $string['quiztimer'] = 'Quiz Timer';
 $string['quizwillopen'] = 'This quiz will open $a';
 $string['random'] = 'Random Question';
 $string['randomcreate'] = 'Create Random Questions';
+$string['randomfromcategory'] = 'Random question from all of category:';
+$string['randomfromcategoryonly'] = 'Random question from just category:';
+$string['randomnosubcat'] = 'Questions from this category only, not its subcategories.';
 $string['randomsamatch'] = 'Random Short-Answer Matching';
 $string['randomsamatchcreate'] = 'Create Random Short-Answer Matching questions';
 $string['randomsamatchintro'] = 'For each of the following questions, select the matching answer from the menu.';
 $string['randomsamatchnumber'] = 'Number of questions to select';
+$string['randomwithsubcat'] = 'Questions from this category and its subcategories.';
 $string['readytosend'] = 'You are about to send your whole quiz to be graded.  Are you sure you want to continue?';
 $string['reattemptquiz'] = 'Re-attempt quiz';
 $string['recentlyaddedquestion'] = 'Recently added question!';
@@ -722,7 +726,6 @@ $string['withselected'] = 'With selected';
 $string['withsummary'] = 'with Summary Statistics';
 $string['wronggrade'] = 'Wrong grade (after line $a) :';
 $string['wronguse'] = 'You can not use this page like that';
-$string['xfromcategory'] = '$a from category:';
 $string['xhtml'] = 'XHTML Format';
 $string['xml'] = 'Moodle XML format';
 $string['xmlimportnoname'] = 'Missing question name in xml file';
index 7a31dafc9513d798e1c7fed980c6dacf055cde81..55fb73e0f64ff5befe7eaa7196715d86a8acf70b 100644 (file)
@@ -705,7 +705,13 @@ function quiz_print_randomquestion(&$question, &$pageurl, &$quiz,$quiz_qbanktool
 
     echo '<div class="randomquestionfromcategory">';
     print_question_icon($question);
-    echo ' ' . get_string('xfromcategory', 'quiz', get_string('random', 'quiz')) . '</div>';
+    print_random_option_icon($question);
+    if (!empty($question->questiontext)) {
+        $string = 'randomfromcategory';
+    } else {
+        $string = 'randomfromcategoryonly';
+    }
+    echo ' ' . get_string($string, 'quiz') . '</div>';
 
     $a = new stdClass;
     $a->arrow = $THEME->rarrow;
@@ -792,6 +798,7 @@ function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz){
             quiz_question_action_icons($quiz, $quiz->cmid, $question, $returnurl) . '</span>';
     echo "</div>\n";
 }
+
 /**
  * Print a given random question in quiz for the reordertool tab of edit.php.
  * Meant to be used from quiz_print_question_list()
@@ -800,7 +807,6 @@ function quiz_print_singlequestion_reordertool($question, $returnurl, $quiz){
  * @param object $questionurl The url of the question editing page as a moodle_url object
  * @param object $quiz The quiz in the context of which the question is being displayed
  */
-
 function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
     global $DB, $QTYPES;
 
@@ -819,6 +825,7 @@ function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
     echo '<div class="randomquestionfromcategory">';
     echo $reordercheckboxlabel;
     print_question_icon($question);
+    print_random_option_icon($question);
 
     if ($questioncount == 0) {
         echo '<span class="error">';
@@ -841,6 +848,25 @@ function quiz_print_randomquestion_reordertool(&$question, &$pageurl, &$quiz){
     echo '</div>';
 
 }
+
+/**
+ * Print an icon to indicate the 'include subcategories' state of a random question.
+ * @param $question the random question.
+ */
+function print_random_option_icon($question) {
+    global $CFG;
+    if (!empty($question->questiontext)) {
+        $icon = 'withsubcat';
+        $tooltip = get_string('randomwithsubcat', 'quiz');
+    } else {
+        $icon = 'nosubcat';
+        $tooltip = get_string('randomnosubcat', 'quiz');
+    }
+    echo  '<img src="' . $CFG->pixpath . '/i/' . $icon . '.png" alt="' .
+            $tooltip . '" title="' . $tooltip . '" />';
+    
+}
+
 /**
  * Creates a textual representation of a question for display.
  * 
diff --git a/pix/i/nosubcat.png b/pix/i/nosubcat.png
new file mode 100644 (file)
index 0000000..09fde4e
Binary files /dev/null and b/pix/i/nosubcat.png differ
diff --git a/pix/i/withsubcat.png b/pix/i/withsubcat.png
new file mode 100644 (file)
index 0000000..bafe55a
Binary files /dev/null and b/pix/i/withsubcat.png differ
index 633fcc09c9e3afe473729f2a18fa33611b83ae32..fb489afe82c44633eb66c6ae2ee3349e86bf9c4a 100644 (file)
@@ -467,9 +467,13 @@ class question_category_object {
 
         // If the category name has changed, rename any random questions in that category.
         if ($oldcat->name != $cat->name) {
-            $randomqname = $QTYPES[RANDOM]->question_name($cat);
-            $DB->set_field('question', 'name', $randomqname, array('category' => $cat->id), 'qtype', RANDOM);
-            // Ignore errors here. It is not a big deal if the questions are not renamed.
+            $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";
+
+            $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
+            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
+
+            $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
+            $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
         }
 
         // Then redirect to an appropriate place.
index cc8041c11b06c6361048ec5e68b2ba7a5660ce87..04087a1bc82fad71cc317ef41e92b13784950c6d 100644 (file)
@@ -26,6 +26,33 @@ function xmldb_qtype_multichoice_upgrade($oldversion) {
     $dbman = $DB->get_manager();
     $result = true;
 
+    // This upgrade actually belongs to the random question type,
+    // but that does not have a DB upgrade script. Therefore, multichoice
+    // is doing it.
+    // Rename random questions to give them more helpful names. 
+    if ($result && $oldversion < 2008021800) {
+        require_once($CFG->libdir . '/questionlib.php');
+        // Get all categories containing random questions.
+        $categories = $DB->get_recordset_sql("
+                SELECT qc.id, qc.name
+                FROM {question_categories} qc
+                JOIN {question} q ON q.category = qc.id
+                WHERE q.qtype = 'random'
+                GROUP BY qc.id, qc.name");
+
+        // Rename the random qusetions in those categories.
+        $where = "qtype = 'random' AND category = ? AND " . $DB->sql_compare_text('questiontext') . " = ?";
+        foreach ($categories as $cat) {
+            $randomqname = $QTYPES[RANDOM]->question_name($cat, false);
+            $result = $result && $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '0'));
+
+            $randomqname = $QTYPES[RANDOM]->question_name($cat, true);
+            $result = $result && $DB->set_field_select('question', 'name', $randomqname, $where, array($cat->id, '1'));
+        }
+
+        upgrade_plugin_savepoint($result, 2008021800, 'qtype', 'multichoice');
+    }
+
     return $result;
 }
 
index 536367b0aca137a3ffcd31ebd13e303668ed1d2e..c52c71debbff4bcd0c099e85a2e334f637638f8e 100644 (file)
@@ -1,6 +1,6 @@
 <?PHP // $Id$
 
-$plugin->version  = 2007081700;
+$plugin->version  = 2009021800;
 $plugin->requires = 2007101000;
 
 ?>
index f9089b6db69d78de847a48dd92e747eee0989bb9..0655be19d19fe08ccb5f37f66294c201d11f7e9f 100644 (file)
@@ -103,9 +103,17 @@ class random_qtype extends default_questiontype {
     /**
      * Random questions always get a question name that is Random (cateogryname).
      * This function is a centralised place to calculate that, given the category.
+     * @param object $category the category this question picks from. (Only $category->name is used.)
+     * @param boolean $includesubcategories whether this question also picks from subcategories.
+     * @return string the name this question should have.
      */
-    function question_name($category) {
-        return get_string('random', 'quiz') .' ('. $category->name .')';
+    function question_name($category, $includesubcategories) {
+        if ($includesubcategories) {
+            $string = 'randomqplusname';
+        } else {
+            $string = 'randomqname';
+        }
+        return get_string($string, 'qtype_random', $category->name);
     }
 
     function save_question($question, $form, $course) {
@@ -129,7 +137,7 @@ class random_qtype extends default_questiontype {
         if (!$category = $DB->get_record('question_categories', array('id' => $question->category))) {
             print_error('cannotretrieveqcat', 'question');
         }
-        $updateobject->name = $this->question_name($category);
+        $updateobject->name = $this->question_name($category, !empty($question->questiontext));
         return $DB->update_record('question', $updateobject);
     }