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.
This commit is contained in:
tjhunt 2008-11-26 04:25:42 +00:00
parent cc2c4572b1
commit 1e69a6562f
2 changed files with 5 additions and 11 deletions

View 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'));

View 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"');