Beispiel #1
0
 /**
  * Returns the minimum and maximum number of points this grade is graded with respect to.
  *
  * @since  Moodle 2.8.7, 2.9.1
  * @return array A list containing, in order, the minimum and maximum number of points.
  */
 protected function get_grade_min_and_max()
 {
     global $CFG;
     $this->load_grade_item();
     // When the following setting is turned on we use the grade_grade raw min and max values.
     $minmaxtouse = grade_get_setting($this->grade_item->courseid, 'minmaxtouse', $CFG->grade_minmaxtouse);
     // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
     // wish to update the grades.
     $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->grade_item->courseid);
     // Gradebook is frozen, run through old code.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Only aggregate items use separate min grades.
         if ($minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE || $this->grade_item->is_aggregate_item()) {
             return array($this->rawgrademin, $this->rawgrademax);
         } else {
             return array($this->grade_item->grademin, $this->grade_item->grademax);
         }
     } else {
         // Only aggregate items use separate min grades, unless they are calculated grade items.
         if ($this->grade_item->is_aggregate_item() && !$this->grade_item->is_calculated() || $minmaxtouse == GRADE_MIN_MAX_FROM_GRADE_GRADE) {
             return array($this->rawgrademin, $this->rawgrademax);
         } else {
             return array($this->grade_item->grademin, $this->grade_item->grademax);
         }
     }
 }
Beispiel #2
0
 protected function sub_test_grade_item_is_calculated()
 {
     $grade_item = new grade_item($this->grade_items[1], false);
     $this->assertTrue(method_exists($grade_item, 'is_calculated'));
     $this->assertTrue($grade_item->is_calculated());
     $grade_item = new grade_item($this->grade_items[0], false);
     $this->assertFalse($grade_item->is_calculated());
 }
 /**
  * Some aggregation types may need to update their max grade.
  *
  * This must be executed after updating the weights as it relies on them.
  *
  * @return void
  */
 private function auto_update_max()
 {
     global $DB;
     if ($this->aggregation != GRADE_AGGREGATE_SUM) {
         // not needed at all
         return;
     }
     // Find grade items of immediate children (category or grade items) and force site settings.
     $this->load_grade_item();
     $depends_on = $this->grade_item->depends_on();
     // Check to see if the gradebook is frozen. This allows grades to not be altered at all until a user verifies that they
     // wish to update the grades.
     $gradebookcalculationsfreeze = get_config('core', 'gradebook_calculations_freeze_' . $this->courseid);
     // Only run if the gradebook isn't frozen.
     if ($gradebookcalculationsfreeze && (int) $gradebookcalculationsfreeze <= 20150627) {
         // Do nothing.
     } else {
         // Don't automatically update the max for calculated items.
         if ($this->grade_item->is_calculated()) {
             return;
         }
     }
     $items = false;
     if (!empty($depends_on)) {
         list($usql, $params) = $DB->get_in_or_equal($depends_on);
         $sql = "SELECT *\n                      FROM {grade_items}\n                     WHERE id {$usql}";
         $items = $DB->get_records_sql($sql, $params);
     }
     if (!$items) {
         if ($this->grade_item->grademax != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
             $this->grade_item->grademax = 0;
             $this->grade_item->grademin = 0;
             $this->grade_item->gradetype = GRADE_TYPE_VALUE;
             $this->grade_item->update('aggregation');
         }
         return;
     }
     //find max grade possible
     $maxes = array();
     foreach ($items as $item) {
         if ($item->aggregationcoef > 0) {
             // extra credit from this activity - does not affect total
             continue;
         } else {
             if ($item->aggregationcoef2 <= 0) {
                 // Items with a weight of 0 do not affect the total.
                 continue;
             }
         }
         if ($item->gradetype == GRADE_TYPE_VALUE) {
             $maxes[$item->id] = $item->grademax;
         } else {
             if ($item->gradetype == GRADE_TYPE_SCALE) {
                 $maxes[$item->id] = $item->grademax;
                 // 0 = nograde, 1 = first scale item, 2 = second scale item
             }
         }
     }
     if ($this->can_apply_limit_rules()) {
         // Apply droplow and keephigh.
         $this->apply_limit_rules($maxes, $items);
     }
     $max = array_sum($maxes);
     // update db if anything changed
     if ($this->grade_item->grademax != $max or $this->grade_item->grademin != 0 or $this->grade_item->gradetype != GRADE_TYPE_VALUE) {
         $this->grade_item->grademax = $max;
         $this->grade_item->grademin = 0;
         $this->grade_item->gradetype = GRADE_TYPE_VALUE;
         $this->grade_item->update('aggregation');
     }
 }