Skip to content
This repository has been archived by the owner on Apr 8, 2022. It is now read-only.

Commit

Permalink
Merge branch 'MDL-47703-master' of git://github.com/FMCorz/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
danpoltawski committed Oct 28, 2014
2 parents b547875 + 37fc69a commit 31d6d2a
Show file tree
Hide file tree
Showing 5 changed files with 137 additions and 3 deletions.
4 changes: 3 additions & 1 deletion grade/edit/tree/category_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ function definition_after_data() {
}

// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
// Or if the item is a scale and scales are not used in aggregation.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM
|| (empty($CFG->grade_includescalesinaggregation) && $grade_item->gradetype == GRADE_TYPE_SCALE)) {
if ($mform->elementExists('grade_item_weightoverride')) {
$mform->removeElement('grade_item_weightoverride');
}
Expand Down
4 changes: 3 additions & 1 deletion grade/edit/tree/item_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ function definition_after_data() {
}

// Remove fields used by natural weighting if the parent category is not using natural weighting.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM) {
// Or if the item is a scale and scales are not used in aggregation.
if ($parent_category->aggregation != GRADE_AGGREGATE_SUM
|| (empty($CFG->grade_includescalesinaggregation) && $grade_item->gradetype == GRADE_TYPE_SCALE)) {
if ($mform->elementExists('weightoverride')) {
$mform->removeElement('weightoverride');
}
Expand Down
4 changes: 3 additions & 1 deletion grade/edit/tree/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,7 @@ public function get_category_cell($category, $levelclass, $params) {
}

public function get_item_cell($item, $params) {
global $CFG;
if (empty($params['element'])) {
throw new Exception('Array key (element) missing from 2nd param of grade_edit_tree_column_weightorextracredit::get_item_cell($item, $params)');
}
Expand All @@ -715,7 +716,8 @@ public function get_item_cell($item, $params) {

if (!in_array($object->itemtype, array('courseitem', 'categoryitem', 'category'))
&& !in_array($object->gradetype, array(GRADE_TYPE_NONE, GRADE_TYPE_TEXT))
&& (!$object->is_outcome_item() || $object->load_parent_category()->aggregateoutcomes)) {
&& (!$object->is_outcome_item() || $object->load_parent_category()->aggregateoutcomes)
&& ($object->gradetype != GRADE_TYPE_SCALE || !empty($CFG->grade_includescalesinaggregation))) {
$itemcell->text = grade_edit_tree::get_weight_input($item);
}

Expand Down
121 changes: 121 additions & 0 deletions grade/tests/behat/grade_scales_aggregation.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
@core @core_grades
Feature: Control the aggregation of the scales
In order to use control the aggregation of the scales
As an admin
I can change use administration setting

Background:
Given the following "courses" exist:
| fullname | shortname |
| Course 1 | C1 |
And the following "users" exist:
| username | firstname | lastname | email | idnumber |
| teacher1 | Teacher | 1 | teacher1@asd.com | t1 |
| student1 | Student | 1 | student1@asd.com | s1 |
And the following "course enrolments" exist:
| user | course | role |
| teacher1 | C1 | editingteacher |
| student1 | C1 | student |
And I log in as "admin"
And I set the following administration settings values:
| grade_aggregations_visible | Mean of grades,Weighted mean of grades,Simple weighted mean of grades,Mean of grades (with extra credits),Median of grades,Lowest grade,Highest grade,Mode of grades,Natural |
| grade_report_user_showcontributiontocoursetotal | 1 |
And I navigate to "Scales" node in "Site administration > Grades"
And I press "Add a new scale"
And I set the following fields to these values:
| Name | Letterscale |
| Scale | F,D,C,B,A |
And I press "Save changes"
And the following "grade items" exist:
| itemname | course |
| Grade me | C1 |
And the following "grade items" exist:
| itemname | course | scale |
| Scale me | C1 | Letterscale |

@javascript
Scenario Outline: Scales can be exluded from aggregation
Given I set the following administration settings values:
| grade_includescalesinaggregation | 0 |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
When I give the grade "10" to the user "Student 1" for the grade item "Grade me"
And I give the grade "B" to the user "Student 1" for the grade item "Scale me"
And I press "Save changes"
And I set the following settings for grade item "Course 1":
| Aggregation | <aggregation> |
And I follow "User report"
And I set the field "Select all or one user" to "Student 1"
Then the following should exist in the "user-grade" table:
| Grade item | Grade | Percentage | Contribution to course total |
| Grade me | 10.00 | 10.00 % | <gradecontrib> |
| Scale me | B | 75.00 % | <scalecontrib> |
| Course total<totalstr> | <coursetotal> | <coursepc> | - |
And I log out
And I log in as "admin"
And I set the following administration settings values:
| grade_includescalesinaggregation | 1 |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I follow "User report"
And I set the field "Select all or one user" to "Student 1"
And the following should exist in the "user-grade" table:
| Grade item | Grade | Percentage | Contribution to course total |
| Grade me | 10.00 | 10.00 % | <gradecontrib2> |
| Scale me | B | 75.00 % | <scalecontrib2> |
| Course total<totalstr> | <coursetotal2> | <coursepc2> | - |

Examples:
| aggregation | totalstr | coursetotal | coursepc | gradecontrib | scalecontrib | coursetotal2 | coursepc2 | gradecontrib2 | scalecontrib2 |
| Natural | | 10.00 | 10.00 % | 10.00 | 0.00 | 14.00 | 13.33 % | 9.52 % | 3.81 % |
| Mean of grades | Mean of grades. | 10.00 | 10.00 % | 10.00 | 0.00 | 42.50 | 42.50 % | 5.00 % | 37.50 % |
| Weighted mean of grades | Weighted mean of grades. | 10.00 | 10.00 % | 10.00 | 0.00 | 42.50 | 42.50 % | 5.00 % | 37.50 % |
| Simple weighted mean of grades | Simple weighted mean of grades. | 10.00 | 10.00 % | 10.00 | 0.00 | 12.50 | 12.50 % | 9.62 % | 2.88 % |
| Mean of grades (with extra credits) | Mean of grades (with extra credits). | 10.00 | 10.00 % | 10.00 | 0.00 | 42.50 | 42.50 % | 5.00 % | 37.50 % |
| Median of grades | Median of grades. | 10.00 | 10.00 % | 10.00 | 0.00 | 42.50 | 42.50 % | 5.00 % | 37.50 % |
| Lowest grade | Lowest grade. | 10.00 | 10.00 % | 10.00 | 0.00 | 10.00 | 10.00 % | 10.00 % | 0.00 % |
| Highest grade | Highest grade. | 10.00 | 10.00 % | 10.00 | 0.00 | 75.00 | 75.00 % | 0.00 % | 75.00 % |
| Mode of grades | Mode of grades. | 10.00 | 10.00 % | 10.00 | 0.00 | 75.00 | 75.00 % | 0.00 % | 75.00 % |

@javascript
Scenario: Weights of scales cannot be edited when they are not aggregated
Given I set the following administration settings values:
| grade_includescalesinaggregation | 0 |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I turn editing mode on
When I set the following settings for grade item "Course 1":
| Aggregation | Natural |
And I navigate to "Categories and items" node in "Grade administration > Setup"
And I set the field "Override weight of Grade me" to "1"
Then the field "Override weight of Grade me" matches value "100.00"
And I click on "Edit" "link" in the "Scale me" "table_row"
And I click on "Edit settings" "link" in the "Scale me" "table_row"
And I follow "Show more..."
And I should not see "Weight adjusted"
And I should not see "Weight"
And I log out
And I log in as "admin"
And I set the following administration settings values:
| grade_includescalesinaggregation | 1 |
And I log out
And I log in as "teacher1"
And I follow "Course 1"
And I follow "Grades"
And I navigate to "Categories and items" node in "Grade administration > Setup"
And I set the field "Override weight of Grade me" to "1"
And the field "Override weight of Grade me" matches value "95.238"
And I set the field "Override weight of Scale me" to "1"
And the field "Override weight of Scale me" matches value "4.8"
And I click on "Edit" "link" in the "Scale me" "table_row"
And I click on "Edit settings" "link" in the "Scale me" "table_row"
And I follow "Show more..."
And I should see "Weight adjusted"
And I should see "Weight"
7 changes: 7 additions & 0 deletions lib/grade/grade_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -1419,6 +1419,7 @@ private function auto_update_max() {
* @return void
*/
private function auto_update_weights() {
global $CFG;
if ($this->aggregation != GRADE_AGGREGATE_SUM) {
// This is only required if we are using natural weights.
return;
Expand Down Expand Up @@ -1457,6 +1458,9 @@ private function auto_update_weights() {
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore them.
continue;
} else if (empty($CFG->grade_includescalesinaggregation) && $gradeitem->gradetype == GRADE_TYPE_SCALE) {
// The scales are not included in the aggregation, ignore them.
continue;
}

// Record the ID and the weight for this grade item.
Expand Down Expand Up @@ -1532,6 +1536,9 @@ private function auto_update_weights() {
} else if (!$this->aggregateoutcomes && $gradeitem->is_outcome_item()) {
// We will not aggregate outcome items, so we can ignore updating their weights.
continue;
} else if (empty($CFG->grade_includescalesinaggregation) && $gradeitem->gradetype == GRADE_TYPE_SCALE) {
// We will not aggregate the scales, so we can ignore upating their weights.
continue;
}

if (!$gradeitem->weightoverride) {
Expand Down

0 comments on commit 31d6d2a

Please sign in to comment.