]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12140, making most common non-weighted and weighted settings easy for teachers
authortoyomoyo <toyomoyo>
Wed, 14 Nov 2007 02:12:40 +0000 (02:12 +0000)
committertoyomoyo <toyomoyo>
Wed, 14 Nov 2007 02:12:40 +0000 (02:12 +0000)
grade/edit/tree/category.php
grade/edit/tree/category_form.php
lang/en_utf8/grades.php

index 05c7c417e98d5a552abea834e5a57d1dba7ea2c6..857da30b71aceb443f2756fbdc38fa47ed362479 100644 (file)
@@ -54,7 +54,10 @@ if ($id) {
     $category = $grade_category->get_record_data();
     // Get Category preferences
     $category->pref_aggregationview = grade_report::get_pref('aggregationview', $id);
-
+//GVA Patch
+    $grade_item = $grade_category->load_grade_item();
+    $category->aggregationcoef = $grade_item->aggregationcoef;
+//End Patch
 } else {
     $grade_category = new grade_category();
     $grade_category->courseid = $course->id;
@@ -89,7 +92,25 @@ if ($mform->is_cancelled()) {
             error("Could not set preference aggregationview to $value for this grade category");
         }
     }
+//GVA Patch
+
+    if (isset($data->weightcourse)) {
+        global $COURSE;
+        $course_category = grade_category::fetch_course_category($COURSE->id);
+        $course_category->aggregation = GRADE_AGGREGATE_WEIGHTED_MEAN;
+        $course_category->update();
+    }
+
+    if (!isset($grade_item)) {
+        $grade_item = $grade_category->load_grade_item();
+    }
+    if (isset($data->aggregationcoef)){
+        $data_item->aggregationcoef = $data->aggregationcoef;
+        grade_item::set_properties($grade_item, $data_item);
+        $grade_item->update();
+    }
 
+//End Patch
     redirect($returnurl);
 }
 
index 234a74a4af17a57da70909c236462b73bb76eb07..9a137b70da2e532a1e0ef1d1b4b2bd2e83df6134 100644 (file)
@@ -48,6 +48,14 @@ class edit_category_form extends moodleform {
         $mform->addElement('select', 'aggregation', get_string('aggregation', 'grades'), $options);
         $mform->setHelpButton('aggregation', array('aggregation', get_string('aggregation', 'grades'), 'grade'));
 
+//GVA Patch
+        $mform->addElement('checkbox', 'weightcourse', 'Weight grades for course'); //To Do Localize
+        $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoefweight', 'grades'));
+        $mform->setHelpButton('aggregationcoef', array(false, get_string('aggregationcoefweight', 'grades'),
+                                false, true, false, get_string('aggregationcoefweighthelp', 'grades')));
+        $mform->disabledIf('aggregationcoef', 'weightcourse', 'notchecked');
+//End Patch
+
         $mform->addElement('checkbox', 'aggregateonlygraded', get_string('aggregateonlygraded', 'grades'));
         $mform->setHelpButton('aggregateonlygraded', array(false, get_string('aggregateonlygraded', 'grades'),
                           false, true, false, get_string('aggregateonlygradedhelp', 'grades')));
@@ -116,7 +124,7 @@ class edit_category_form extends moodleform {
 
 /// tweak the form - depending on existing data
     function definition_after_data() {
-        global $CFG;
+        global $CFG, $COURSE;
 
         $mform =& $this->_form;
 
@@ -144,11 +152,52 @@ class edit_category_form extends moodleform {
                 $mform->removeElement('droplow');
             }
         }
+        
+//GVA Patch
+        if (!$id = $mform->getElementValue('id')) {
+            $mform->setDefault('aggregateonlygraded',1);
+            $parent_category = grade_category::fetch_course_category($COURSE->id);
+            if ($parent_category->is_aggregationcoef_used()) {
+                if ($mform->elementExists('weightcourse')) {
+                    $mform->removeElement('weightcourse');
+                }
+            }
+        }
+//End Patch
 
         if ($id = $mform->getElementValue('id')) {
             $grade_category = grade_category::fetch(array('id'=>$id));
             $grade_item = $grade_category->load_grade_item();
 
+//GVA Patch
+            $category = $grade_item->get_item_category();
+            if(!$category->aggregateonlygraded) {
+                $mform->setAdvanced('aggregateonlygraded', false);
+            }
+            if ($grade_item->is_course_item()) {  //An actual course, not a category, etc.
+
+                if ($mform->elementExists('aggregationcoef')) {
+                    $mform->removeElement('aggregationcoef');
+                }
+                if ($mform->elementExists('weightcourse')) {
+                    $mform->removeElement('weightcourse');
+                }
+            }
+            
+            if (!$grade_item->is_category_item()) {
+                if ($mform->elementExists('weightcourse')) {
+                    $mform->removeElement('weightcourse');
+                }
+            } else {
+                $category = $grade_item->get_item_category();
+                $parent_category = $category->get_parent_category();
+                if ($parent_category->is_aggregationcoef_used()) {
+                    if ($mform->elementExists('weightcourse')) {
+                        $mform->removeElement('weightcourse');
+                    }
+                }
+            }
+//End Patch
             if ($grade_item->is_calculated()) {
                 // following elements are ignored when calculation formula used
                 if ($mform->elementExists('aggregation')) {
index b57e4c4ee1afce3b0848cab28808f670b15f091c..e7035b842077e8f08bab703675dc9afbcae175f2 100644 (file)
@@ -454,6 +454,7 @@ $string['useweighted'] = 'Use weighted';
 $string['viewbygroup'] = 'Group';
 $string['viewgrades'] = 'View grades';
 $string['weight'] = 'weight';
+$string['weightcourse'] = 'Use weighted grades for course';
 $string['weightedascending'] = 'Sort by weighted percent ascending';
 $string['weighteddescending'] = 'Sort by weighted percent descending';
 $string['weightedpct'] = 'weighted %%';