Merge branch 'MDL-47637-master' of git://github.com/FMCorz/moodle
authorDan Poltawski <dan@moodle.com>
Thu, 23 Oct 2014 15:16:07 +0000 (16:16 +0100)
committerDan Poltawski <dan@moodle.com>
Thu, 23 Oct 2014 15:16:07 +0000 (16:16 +0100)
1  2 
lib/grade/grade_category.php

@@@ -779,24 -779,6 +779,24 @@@ class grade_category extends grade_obje
      private function set_usedinaggregation($userid, $usedweights, $novalue, $dropped, $extracredit) {
          global $DB;
  
 +        // First set them all to weight null and status = 'unknown'.
 +        if ($allitems = grade_item::fetch_all(array('categoryid'=>$this->id))) {
 +            list($itemsql, $itemlist) = $DB->get_in_or_equal(array_keys($allitems), SQL_PARAMS_NAMED, 'g');
 +
 +            $itemlist['userid'] = $userid;
 +
 +            $DB->set_field_select('grade_grades',
 +                                  'aggregationstatus',
 +                                  'unknown',
 +                                  "itemid $itemsql AND userid = :userid",
 +                                  $itemlist);
 +            $DB->set_field_select('grade_grades',
 +                                  'aggregationweight',
 +                                  0,
 +                                  "itemid $itemsql AND userid = :userid",
 +                                  $itemlist);
 +        }
 +
          // Included.
          if (!empty($usedweights)) {
              // The usedweights items are updated individually to record the weights.
              if ($gradeitem->gradetype == GRADE_TYPE_NONE || $gradeitem->gradetype == GRADE_TYPE_TEXT) {
                  // Text items and none items do not have a weight.
                  continue;
+             } else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
+                 // We will not aggregate outcome items, so we can ignore them.
+                 continue;
              }
  
              // Record the ID and the weight for this grade item.
                  // Text items and none items do not have a weight, no need to set their weight to
                  // zero as they must never be used during aggregation.
                  continue;
+             } else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
+                 // We will not aggregate outcome items, so we can ignore updating their weights.
+                 continue;
              }
  
              if (!$gradeitem->weightoverride) {