]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17361 Problems with the question category editing forms.
authortjhunt <tjhunt>
Wed, 26 Nov 2008 04:25:42 +0000 (04:25 +0000)
committertjhunt <tjhunt>
Wed, 26 Nov 2008 04:25:42 +0000 (04:25 +0000)
When editing an existing category, the logic should have been to prevent you from moving the category if it was the last remaining top-level category in its context.

When creating a new category as part of creating a random question, there should be no restriction.

question/category_form.php
question/category_form_randomquestion.php

index 1dd2011f53e937f235eccf28cfb8f8a568637ef4..6f6b1eb6d156353763a708f036ca9cec83e6be08 100644 (file)
@@ -16,11 +16,15 @@ class question_category_edit_form extends moodleform {
         $questioncategoryel = $mform->addElement('questioncategory', 'parent', get_string('parent', 'quiz'),
                     array('contexts'=>$contexts, 'top'=>true, 'currentcat'=>$currentcat, 'nochildrenof'=>$currentcat));
         $mform->setType('parent', PARAM_SEQUENCE);
+        // This next test is actually looking to see if $currentcat is the id of
+        // a category that already exists, and is the only top-level category in
+        // it context. If so, we stop it from being moved.
         if (1 == $DB->count_records_sql("SELECT count(*)
                                            FROM {question_categories} c1,
                                                 {question_categories} c2
                                           WHERE c2.id = ?
-                                            AND c1.contextid = c2.contextid", array($currentcat))){
+                                            AND c1.contextid = c2.contextid
+                                            AND c1.parent = 0 AND c2.parent = 0", array($currentcat))){
             $mform->hardFreeze('parent');
         }
         $mform->setHelpButton('parent', array('categoryparent', get_string('parent', 'quiz'), 'question'));
index d06efaa5f8d8633f29ce64dfa73baa4caf32ef6d..d63cc149c71a1711eb4aeb06e860681478358521 100644 (file)
@@ -16,16 +16,6 @@ class question_category_edit_form_randomquestion extends moodleform {
         $questioncategoryel = $mform->addElement('questioncategory', 'parent', get_string('parentcategory', 'quiz'),
                     array('contexts'=>$contexts, 'top'=>true, 'currentcat'=>$currentcat, 'nochildrenof'=>$currentcat));
         $mform->setType('parent', PARAM_SEQUENCE);
-        if (1 == $DB->count_records_sql("SELECT count(*)
-                                           FROM {question_categories} c1,
-                                                {question_categories} c2
-                                          WHERE c2.id = ?
-                                            AND c1.contextid = c2.contextid", array($currentcat))){
-            //TODO: Tim? why does the above evaluate true, breaking the form?
-            // and more importantly, if this is a valid situation, how should we react,
-            // that is, what does this mean?
-            //$mform->hardFreeze('parent');
-        }
         $mform->setHelpButton('parent', array('categoryparent', get_string('parent', 'quiz'), 'question'));
 
         $mform->addElement('text','name', get_string('name'),'maxlength="254" size="50"');