本文整理汇总了PHP中grade_item::set_aggregation_fields_for_aggregation方法的典型用法代码示例。如果您正苦于以下问题:PHP grade_item::set_aggregation_fields_for_aggregation方法的具体用法?PHP grade_item::set_aggregation_fields_for_aggregation怎么用?PHP grade_item::set_aggregation_fields_for_aggregation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类grade_item
的用法示例。
在下文中一共展示了grade_item::set_aggregation_fields_for_aggregation方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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);
//.........这里部分代码省略.........