outcome related fixes
authorskodak <skodak>
Wed, 1 Aug 2007 12:40:38 +0000 (12:40 +0000)
committerskodak <skodak>
Wed, 1 Aug 2007 12:40:38 +0000 (12:40 +0000)
grade/edit/tree/calculation.php
grade/edit/tree/index.php
grade/edit/tree/item.php
grade/edit/tree/item_form.php
grade/edit/tree/outcomeitem.php
grade/edit/tree/outcomeitem_form.php
grade/lib.php
lib/grade/grade_item.php

index 6474ea86e5949b1cc72444a54e144878a949c74b..0edf689a3c835072081dd52bc3d80be97507f5c4 100644 (file)
@@ -24,7 +24,8 @@ if (!$grade_item = grade_item::fetch(array('id'=>$id, 'courseid'=>$course->id)))
 }
 
 // module items and items without grade can not have calculation
-if ($grade_item->is_normal_item() or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
+if (($grade_item->is_normal_item() and !$grade_item->is_outcome_item())
+  or ($grade_item->gradetype != GRADE_TYPE_VALUE and $grade_item->gradetype != GRADE_TYPE_SCALE)) {
     redirect($returnurl, get_string('erornocalculationallowed', 'grades')); //TODO: localize
 }
 
index d4ab40c7df70d12d44c2e480d5b373f706d21229..da73d2c954f14f97290f0d035dcd73f69caf4b70 100644 (file)
@@ -202,7 +202,12 @@ function print_grade_tree(&$gtree, $element, $moving, &$gpr) {
                 $icon = '<img src="'.$CFG->modpixpath.'/'.$object->itemmodule.'/icon.gif" class="icon" alt="'.get_string('modulename', $object->itemmodule).'"/>';
             } else if ($object->itemtype == 'manual') {
                 //TODO: add manual grading icon
-                $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
+                if (empty($object->outcomeid)) {
+                    $icon = '<img src="'.$CFG->pixpath.'/t/edit.gif" class="icon" alt="'.get_string('manualgrade', 'grades').'"/>'; // TODO: localize
+                } else {
+                    $icon = '<img src="'.$CFG->pixpath.'/i/outcomes.gif" class="icon" alt="'.get_string('outcome', 'grades').'"/>';
+                    
+                }
             }
             break;
         case 'courseitem':
index e32af6f64fbaeb322ff2252a7fd45930df41e134..18f4abefd11d710bd42c7de08069af3fe1feae16 100644 (file)
@@ -29,7 +29,7 @@ if ($mform->is_cancelled()) {
 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
     // redirect if outcomeid present
     if (!empty($item->outcomeid) && !empty($CFG->enableoutcomes)) {
-        $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&amp;courseid='.$courseid;
+        $url = $CFG->wwwroot.'/grade/edit/tree/outcomeitem.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
 
index 7e3d9e9c320a6cd6274203e6ddda679f5a044955..71bc94fdea2fd80f365305f5c579f29b86074990 100644 (file)
@@ -117,18 +117,28 @@ class edit_item_form extends moodleform {
         if ($id = $mform->getElementValue('id')) {
             $grade_item = grade_item::fetch(array('id'=>$id));
 
-            if ($grade_item->is_normal_item()) {
-                // following items are set up from modules and should not be overrided by user
-                $mform->hardFreeze('itemname,idnumber,gradetype,grademax,grademin,scaleid');
-                $mform->removeElement('calculation');
-
-            } else if ($grade_item->is_manual_item()) {
-                // manual grade item does not use these - uses only final grades
+            if ($grade_item->is_outcome_item()) {
+                // we have to prevent incompatible modifications of outcomes
                 $mform->removeElement('plusfactor');
                 $mform->removeElement('multfactor');
+                $mform->removeElement('grademax');
+                $mform->removeElement('grademin');
+                $mform->removeElement('gradetype');
+                $mform->hardFreeze('scaleid');
 
+            } else {
+                if ($grade_item->is_normal_item()) {
+                    // following items are set up from modules and should not be overrided by user
+                    $mform->hardFreeze('itemname,idnumber,gradetype,grademax,grademin,scaleid');
+                    $mform->removeElement('calculation');
+    
+                } else if ($grade_item->is_manual_item()) {
+                    // manual grade item does not use these - uses only final grades
+                    $mform->removeElement('plusfactor');
+                    $mform->removeElement('multfactor');
+    
+                }
             }
-
             //remove the aggregation coef element if not needed
             if ($grade_item->is_course_item()) {
                 $mform->removeElement('aggregationcoef');
index 32020be9d5de0797a6061142ad65cc16f2984257..8101f2e52ffa778a745d39849942f616f1e2d906 100644 (file)
@@ -30,11 +30,11 @@ if ($mform->is_cancelled() || empty($CFG->enableoutcomes)) {
 if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
     // redirect if outcomeid present
     if (empty($item->outcomeid)) {
-        $url = $CFG->wwwroot.'/grade/edit/tree/outcome.php?id='.$id.'&amp;courseid='.$courseid;
+        $url = $CFG->wwwroot.'/grade/edit/tree/item.php?id='.$id.'&amp;courseid='.$courseid;
         redirect($gpr->add_url_params($url));
     }
 
-//    $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
+    $item->calculation = grade_item::denormalize_formula($item->calculation, $course->id);
 
     if ($item->itemtype == 'mod') {
         $cm = get_coursemodule_from_instance($item->itemmodule, $item->iteminstance, $item->courseid);
@@ -48,7 +48,7 @@ if ($item = get_record('grade_items', 'id', $id, 'courseid', $course->id)) {
 
 if ($data = $mform->get_data(false)) {
     if (array_key_exists('calculation', $data)) {
-//        $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
+        $data->calculation = grade_item::normalize_formula($data->calculation, $course->id);
     }
 
     $grade_item = new grade_item(array('id'=>$id, 'courseid'=>$courseid));
index eb9a5058a8a5281af0cfaffc7fd520a93733238d..49e70ed7066ef0e3d91f6a2155f4f1f2569b3d9a 100644 (file)
@@ -38,7 +38,7 @@ class edit_outcomeitem_form extends moodleform {
         $mform->setDefault('cmid', 0);
 
 
-//        $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
+        $mform->addElement('text', 'calculation', get_string('calculation', 'grades'));
 
         $mform->addElement('text', 'aggregationcoef', get_string('aggregationcoef', 'grades'));
         $mform->setDefault('aggregationcoef', 0.0);
index 0d939e189012e62eb6ef3d9bb23e3c662b5d50bb..11fccb78059339a19a0530e6c811ee529eb1cf00 100644 (file)
@@ -822,7 +822,8 @@ class grade_tree {
             $streditcalculation = get_string('editcalculation', 'grades');
 
             // show calculation icon only when calculation possible
-            if (!$object->is_normal_item() and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
+            if ((!$object->is_normal_item() or $object->is_outcome_item())
+              and ($object->gradetype == GRADE_TYPE_SCALE or $object->gradetype == GRADE_TYPE_VALUE)) {
                 $url = $CFG->wwwroot.'/grade/edit/tree/calculation.php?courseid='.$this->courseid.'&amp;id='.$object->id;
                 $url = $gpr->add_url_params($url);
                 $calculation_icon = '<a href="'. $url.'"><img src="'.$CFG->pixpath.'/t/calc.gif" class="iconsmall" alt="'
index 153288ea7e030f4bf7695f9859f79cd766b8043d..51e728c52268e9d3ec5fa3726e8bf58ed44620f5 100644 (file)
@@ -827,6 +827,14 @@ class grade_item extends grade_object {
         return ($this->itemtype == 'manual');
     }
 
+    /**
+     * Is this an outcome item?
+     * @return boolean
+     */
+    function is_outcome_item() {
+        return !empty($this->outcomeid);
+    }
+
     /**
      * Is the grade item normal - associated with module, plugin or something else?
      * @return boolean
@@ -1180,7 +1188,8 @@ class grade_item extends grade_object {
             }
 
             // if we can update the raw grade, do update it
-            if (!$this->is_normal_item() or $this->plusfactor != 0 or $this->multfactor != 1
+            if ($this->is_outcome_item() or !$this->is_normal_item()
+             or $this->plusfactor != 0 or $this->multfactor != 1
              or !events_is_registered('grade_updated', $this->itemtype.'/'.$this->itemmodule)) {
                 if (!$grade->overridden) {
                     $grade->overridden = time();
@@ -1260,7 +1269,8 @@ class grade_item extends grade_object {
         }
 
         // calculated grades can not be updated; course and category can not be updated  because they are aggregated
-        if ($this->is_calculated() or !$this->is_normal_item() or $this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
+        if ($this->is_calculated() or $this->is_outcome_item() or !$this->is_normal_item()
+         or $this->gradetype == GRADE_TYPE_NONE or $this->is_locked()) {
             return false;
         }