From: tjhunt Date: Wed, 26 Nov 2008 04:25:42 +0000 (+0000) Subject: MDL-17361 Problems with the question category editing forms. X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=1e69a6562f3d5998ab1e00d94c72cabd15cffc55;p=moodle.git MDL-17361 Problems with the question category editing forms. 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. --- diff --git a/question/category_form.php b/question/category_form.php index 1dd2011f53..6f6b1eb6d1 100644 --- a/question/category_form.php +++ b/question/category_form.php @@ -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')); diff --git a/question/category_form_randomquestion.php b/question/category_form_randomquestion.php index d06efaa5f8..d63cc149c7 100644 --- a/question/category_form_randomquestion.php +++ b/question/category_form_randomquestion.php @@ -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"');