]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19015 removed category item editing from normal item edit form
authorskodak <skodak>
Wed, 29 Apr 2009 14:35:47 +0000 (14:35 +0000)
committerskodak <skodak>
Wed, 29 Apr 2009 14:35:47 +0000 (14:35 +0000)
grade/edit/tree/item.php
grade/edit/tree/item_form.php

index 33d5ff7d11609d4f43132fc3830f43b76f0c0edd..cca77c9ebbb920f5c891987f1346c31fc952c6a3 100644 (file)
@@ -57,19 +57,16 @@ if ($grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$courseid))) {
         $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
+    if ($grade_item->is_course_item() or $grade_item->is_category_item()) {
+        $grade_category = $grade_item->get_item_category();
+        $url = $CFG->wwwroot.'/grade/edit/tree/category.php?id='.$grade_category->id.'&amp;courseid='.$courseid;
+        redirect($gpr->add_url_params($url));
+    }
+
     $item = $grade_item->get_record_data();
+    $parent_category = $grade_item->get_parent_category();
+    $item->parentcategory = $parent_category->id;
 
-    if ($grade_item->is_course_item()) {
-        $parent_category = null;
-        $item->parentcategory = 0;
-    } else if ($grade_item->is_category_item()) {
-        $parent_category = $grade_item->get_parent_category();
-        $parent_category = $parent_category->get_parent_category();
-        $item->parentcategory = $parent_category->id;
-    } else {
-        $parent_category = $grade_item->get_parent_category();
-        $item->parentcategory = $parent_category->id;
-    }
 } else {
     $heading = get_string('newitem', 'grades');
     $grade_item = new grade_item(array('courseid'=>$courseid, 'itemtype'=>'manual'), false);
@@ -94,9 +91,7 @@ $item->gradepass       = format_float($item->gradepass, $decimalpoints);
 $item->multfactor      = format_float($item->multfactor, 4);
 $item->plusfactor      = format_float($item->plusfactor, 4);
 
-if (empty($parent_category)) {
-    $item->aggregationcoef = 0;
-} else if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
+if ($parent_category->aggregation == GRADE_AGGREGATE_SUM or $parent_category->aggregation == GRADE_AGGREGATE_WEIGHTED_MEAN2) {
     $item->aggregationcoef = $item->aggregationcoef == 0 ? 0 : 1;
 } else {
     $item->aggregationcoef = format_float($item->aggregationcoef, 4);
index 4b689dc0cf1bed4f8e6f83fdd1c5abe249f92fc4..4dd0cd20264b9512e8a0346d20f153c7774bdb62 100644 (file)
@@ -146,17 +146,12 @@ class edit_item_form extends moodleform {
         $mform->addElement('header', 'headerparent', get_string('parentcategory', 'grades'));
 
         $options = array();
-        $default = '';
         $coefstring = '';
         $categories = grade_category::fetch_all(array('courseid'=>$COURSE->id));
 
         foreach ($categories as $cat) {
             $cat->apply_forced_settings();
             $options[$cat->id] = $cat->get_name();
-
-            if ($cat->is_course_category()) {
-                $default = $cat->id;
-            }
         }
 
         if (count($categories) > 1) {
@@ -223,60 +218,38 @@ class edit_item_form extends moodleform {
                 }
             }
 
-            //remove the aggregation coef element if not needed
-            if ($grade_item->is_course_item()) {
-                if ($mform->elementExists('parentcategory')) {
-                    $mform->removeElement('parentcategory');
-                }
+            // if we wanted to change parent of existing item - we would have to verify there are no circular references in parents!!!
+            if ($mform->elementExists('parentcategory')) {
+                $mform->hardFreeze('parentcategory');
+            }
+
+            $parent_category = $grade_item->get_parent_category();
+            $parent_category->apply_forced_settings();
+
+            if (!$parent_category->is_aggregationcoef_used()) {
                 if ($mform->elementExists('aggregationcoef')) {
                     $mform->removeElement('aggregationcoef');
                 }
 
             } else {
-                // if we wanted to change parent of existing item - we would have to verify there are no circular references in parents!!!
-                if ($mform->elementExists('parentcategory')) {
-                    $mform->hardFreeze('parentcategory');
-                }
+                $coefstring = $grade_item->get_coefstring();
 
-                if ($grade_item->is_category_item()) {
-                    $category = $grade_item->get_item_category();
-                    $parent_category = $category->get_parent_category();
-                } else {
-                    $parent_category = $grade_item->get_parent_category();
-                }
-
-                $parent_category->apply_forced_settings();
-
-                if (!$parent_category->is_aggregationcoef_used()) {
-                    if ($mform->elementExists('aggregationcoef')) {
-                        $mform->removeElement('aggregationcoef');
-                    }
-                } else {
-                    if ($grade_item->is_category_item()) {
-                        $parent_category = $parent_category->get_parent_category();
-                        $coefstring = $parent_category->get_grade_item()->get_coefstring();
+                if ($coefstring !== '') {
+                    if ($coefstring == 'aggregationcoefextrasum') {
+                        // advcheckbox is not compatible with disabledIf!
+                        $element =& $mform->createElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
                     } else {
-                        $parent_category->apply_forced_settings();
-                        $coefstring = $grade_item->get_coefstring();
+                        $element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
                     }
-
-                    if ($coefstring !== '') {
-                        if ($coefstring == 'aggregationcoefextrasum') {
-                            // advcheckbox is not compatible with disabledIf!
-                            $element =& $mform->createElement('checkbox', 'aggregationcoef', get_string($coefstring, 'grades'));
-                        } else {
-                            $element =& $mform->createElement('text', 'aggregationcoef', get_string($coefstring, 'grades'));
-                        }
-                        if ($mform->elementExists('parentcategory')) {
-                            $mform->insertElementBefore($element, 'parentcategory');
-                        } else {
-                            $mform->insertElementBefore($element, 'id');
-                        }
-                        $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
+                    if ($mform->elementExists('parentcategory')) {
+                        $mform->insertElementBefore($element, 'parentcategory');
+                    } else {
+                        $mform->insertElementBefore($element, 'id');
                     }
-
-                    $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
+                    $mform->setHelpButton('aggregationcoef', array($coefstring, get_string($coefstring, 'grades'), 'grade'), true);
                 }
+
+                $mform->disabledIf('aggregationcoef', 'parentcategory', 'eq', $parent_category->id);
             }
 
             if ($category = $grade_item->get_item_category()) {