当前位置: 首页>>代码示例>>PHP>>正文


PHP grade_category::get_default_aggregation_coefficient_values方法代码示例

本文整理汇总了PHP中grade_category::get_default_aggregation_coefficient_values方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_category::get_default_aggregation_coefficient_values方法的具体用法?PHP grade_category::get_default_aggregation_coefficient_values怎么用?PHP grade_category::get_default_aggregation_coefficient_values使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在grade_category的用法示例。


在下文中一共展示了grade_category::get_default_aggregation_coefficient_values方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: set_aggregation_fields_for_aggregation

 /**
  * Update the aggregation fields when the aggregation changed.
  *
  * This method should always be called when the aggregation has changed, but also when
  * the item was moved to another category, even it if uses the same aggregation method.
  *
  * Some values such as the weight only make sense within a category, once moved the
  * values should be reset to let the user adapt them accordingly.
  *
  * Note that this method does not save the grade item.
  * {@link grade_item::update()} has to be called manually after using this method.
  *
  * @param  int $from Aggregation method constant value.
  * @param  int $to   Aggregation method constant value.
  * @return boolean   True when at least one field was changed, false otherwise
  */
 public function set_aggregation_fields_for_aggregation($from, $to)
 {
     $defaults = grade_category::get_default_aggregation_coefficient_values($to);
     $origaggregationcoef = $this->aggregationcoef;
     $origaggregationcoef2 = $this->aggregationcoef2;
     $origweighoverride = $this->weightoverride;
     if ($from == GRADE_AGGREGATE_SUM && $to == GRADE_AGGREGATE_SUM && $this->weightoverride) {
         // Do nothing. We are switching from SUM to SUM and the weight is overriden,
         // a teacher would not expect any change in this situation.
     } else {
         if ($from == GRADE_AGGREGATE_WEIGHTED_MEAN && $to == GRADE_AGGREGATE_WEIGHTED_MEAN) {
             // Do nothing. The weights can be kept in this case.
         } else {
             if (in_array($from, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2)) && in_array($to, array(GRADE_AGGREGATE_SUM, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2))) {
                 // Reset all but the the extra credit field.
                 $this->aggregationcoef2 = $defaults['aggregationcoef2'];
                 $this->weightoverride = $defaults['weightoverride'];
                 if ($to != GRADE_AGGREGATE_EXTRACREDIT_MEAN) {
                     // Normalise extra credit, except for 'Mean with extra credit' which supports higher values than 1.
                     $this->aggregationcoef = min(1, $this->aggregationcoef);
                 }
             } else {
                 // Reset all.
                 $this->aggregationcoef = $defaults['aggregationcoef'];
                 $this->aggregationcoef2 = $defaults['aggregationcoef2'];
                 $this->weightoverride = $defaults['weightoverride'];
             }
         }
     }
     $acoefdiff = grade_floats_different($origaggregationcoef, $this->aggregationcoef);
     $acoefdiff2 = grade_floats_different($origaggregationcoef2, $this->aggregationcoef2);
     $weightoverride = grade_floats_different($origweighoverride, $this->weightoverride);
     return $acoefdiff || $acoefdiff2 || $weightoverride;
 }
开发者ID:mongo0se,项目名称:moodle,代码行数:50,代码来源:grade_item.php

示例2: format_float

}
if ($parent_category->aggregation == GRADE_AGGREGATE_SUM) {
    $item->aggregationcoef2 = format_float($item->aggregationcoef2 * 100.0);
}
$item->cancontrolvisibility = $grade_item->can_control_visibility();
$mform = new edit_item_form(null, array('current' => $item, 'gpr' => $gpr));
if ($mform->is_cancelled()) {
    redirect($returnurl);
} else {
    if ($data = $mform->get_data(false)) {
        // This is a new item, and the category chosen is different than the default category.
        if (empty($grade_item->id) && isset($data->parentcategory) && $parent_category->id != $data->parentcategory) {
            $parent_category = grade_category::fetch(array('id' => $data->parentcategory));
        }
        // If unset, give the aggregation values a default based on parent aggregation method.
        $defaults = grade_category::get_default_aggregation_coefficient_values($parent_category->aggregation);
        if (!isset($data->aggregationcoef) || $data->aggregationcoef == '') {
            $data->aggregationcoef = $defaults['aggregationcoef'];
        }
        if (!isset($data->weightoverride)) {
            $data->weightoverride = $defaults['weightoverride'];
        }
        if (!isset($data->gradepass) || $data->gradepass == '') {
            $data->gradepass = 0;
        }
        if (!isset($data->grademin) || $data->grademin == '') {
            $data->grademin = 0;
        }
        $hidden = empty($data->hidden) ? 0 : $data->hidden;
        $hiddenuntil = empty($data->hiddenuntil) ? 0 : $data->hiddenuntil;
        unset($data->hidden);
开发者ID:alanaipe2015,项目名称:moodle,代码行数:31,代码来源:item.php

示例3: test_set_aggregation_fields_for_aggregation

 public function test_set_aggregation_fields_for_aggregation()
 {
     $course = $this->getDataGenerator()->create_course();
     $gi = new grade_item(array('courseid' => $course->id, 'itemtype' => 'manual'), false);
     $methods = array(GRADE_AGGREGATE_MEAN, GRADE_AGGREGATE_MEDIAN, GRADE_AGGREGATE_MIN, GRADE_AGGREGATE_MAX, GRADE_AGGREGATE_MODE, GRADE_AGGREGATE_WEIGHTED_MEAN, GRADE_AGGREGATE_WEIGHTED_MEAN2, GRADE_AGGREGATE_EXTRACREDIT_MEAN, GRADE_AGGREGATE_SUM);
     // Switching from and to the same aggregation using the defaults.
     foreach ($methods as $method) {
         $defaults = grade_category::get_default_aggregation_coefficient_values($method);
         $gi->aggregationcoef = $defaults['aggregationcoef'];
         $gi->aggregationcoef2 = $defaults['aggregationcoef2'];
         $gi->weightoverride = $defaults['weightoverride'];
         $this->assertFalse($gi->set_aggregation_fields_for_aggregation($method, $method));
         $this->assertEquals($defaults['aggregationcoef'], $gi->aggregationcoef);
         $this->assertEquals($defaults['aggregationcoef2'], $gi->aggregationcoef2);
         $this->assertEquals($defaults['weightoverride'], $gi->weightoverride);
     }
     // Extra credit is kept across aggregation methods that support it.
     foreach ($methods as $from) {
         $fromsupportsec = grade_category::aggregation_uses_extracredit($from);
         $fromdefaults = grade_category::get_default_aggregation_coefficient_values($from);
         foreach ($methods as $to) {
             $tosupportsec = grade_category::aggregation_uses_extracredit($to);
             $todefaults = grade_category::get_default_aggregation_coefficient_values($to);
             // Set the item to be extra credit, if supported.
             if ($fromsupportsec) {
                 $gi->aggregationcoef = 1;
             } else {
                 $gi->aggregationcoef = $fromdefaults['aggregationcoef'];
             }
             // We ignore those fields, we know it is never used for extra credit.
             $gi->aggregationcoef2 = $todefaults['aggregationcoef2'];
             $gi->weightoverride = $todefaults['weightoverride'];
             if ($fromsupportsec && $tosupportsec) {
                 $this->assertFalse($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
                 $this->assertEquals(1, $gi->aggregationcoef);
             } else {
                 if ($fromsupportsec && !$tosupportsec) {
                     if ($to == GRADE_AGGREGATE_WEIGHTED_MEAN) {
                         // Special case, aggregationcoef is used but for weights.
                         $this->assertFalse($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
                         $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
                     } else {
                         $this->assertTrue($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
                         $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
                     }
                 } else {
                     // The source does not support extra credit, everything will be reset.
                     if (($from == GRADE_AGGREGATE_WEIGHTED_MEAN || $to == GRADE_AGGREGATE_WEIGHTED_MEAN) && $from != $to) {
                         // Special case, aggregationcoef is used but for weights.
                         $this->assertTrue($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
                         $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
                     } else {
                         $this->assertFalse($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
                         $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
                     }
                 }
             }
         }
     }
     // Extra credit can be higher than one for GRADE_AGGREGATE_EXTRACREDIT_MEAN, but will be normalised for others.
     $from = GRADE_AGGREGATE_EXTRACREDIT_MEAN;
     $fromdefaults = grade_category::get_default_aggregation_coefficient_values($from);
     foreach ($methods as $to) {
         if (!grade_category::aggregation_uses_extracredit($to)) {
             continue;
         }
         $todefaults = grade_category::get_default_aggregation_coefficient_values($to);
         $gi->aggregationcoef = 8;
         // Ignore those fields, they are not used for extra credit.
         $gi->aggregationcoef2 = $todefaults['aggregationcoef2'];
         $gi->weightoverride = $todefaults['weightoverride'];
         if ($to == $from) {
             $this->assertFalse($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
             $this->assertEquals(8, $gi->aggregationcoef);
         } else {
             $this->assertTrue($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
             $this->assertEquals(1, $gi->aggregationcoef);
         }
     }
     // Weights are reset.
     $from = GRADE_AGGREGATE_SUM;
     $fromdefaults = grade_category::get_default_aggregation_coefficient_values($from);
     $gi->aggregationcoef = $fromdefaults['aggregationcoef'];
     $gi->aggregationcoef2 = 0.321;
     $gi->weightoverride = $fromdefaults['weightoverride'];
     $to = GRADE_AGGREGATE_WEIGHTED_MEAN;
     $todefaults = grade_category::get_default_aggregation_coefficient_values($to);
     $this->assertTrue($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
     $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
     $this->assertEquals($todefaults['aggregationcoef2'], $gi->aggregationcoef2);
     $this->assertEquals($todefaults['weightoverride'], $gi->weightoverride);
     $gi->aggregationcoef = $fromdefaults['aggregationcoef'];
     $gi->aggregationcoef2 = 0.321;
     $gi->weightoverride = $fromdefaults['weightoverride'];
     $to = GRADE_AGGREGATE_SUM;
     $todefaults = grade_category::get_default_aggregation_coefficient_values($to);
     $this->assertTrue($gi->set_aggregation_fields_for_aggregation($from, $to), "From: {$from}, to: {$to}");
     $this->assertEquals($todefaults['aggregationcoef'], $gi->aggregationcoef);
     $this->assertEquals($todefaults['aggregationcoef2'], $gi->aggregationcoef2);
     $this->assertEquals($todefaults['weightoverride'], $gi->weightoverride);
//.........这里部分代码省略.........
开发者ID:evltuma,项目名称:moodle,代码行数:101,代码来源:grade_item_test.php


注:本文中的grade_category::get_default_aggregation_coefficient_values方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。