Skip to content

Commit

Permalink
Merge branch 'MDL-63396-master' of git://github.com/jleyva/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
stronk7 committed Oct 29, 2018
2 parents 77ac4d8 + 2ced73f commit 82bd1fa
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 1 deletion.
6 changes: 6 additions & 0 deletions grade/report/upgrade.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
This files describes API changes in /grade/report/*,
information provided here is intended especially for developers.

=== 3.6 ===
* External function gradereport_user_external::get_grade_items now return the following information (only for course managers).
- locked: Whether the grade item is locked.
- gradeislocked: Whether the user grade is locked.
- gradeisoverridden: Whether the user grade is overridden.

=== 3.2 ===
* External function gradereport_user_external::get_grades_table now has an optional groupid parameter.
Is recommended to use this parameter in courses with separate groups or when the user requesting the report is in more than one group.
Expand Down
3 changes: 3 additions & 0 deletions grade/report/user/externallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,6 +491,7 @@ public static function get_grade_items_returns() {
'categoryid' => new external_value(PARAM_INT, 'Grade item category id'),
'outcomeid' => new external_value(PARAM_INT, 'Outcome id'),
'scaleid' => new external_value(PARAM_INT, 'Scale id'),
'locked' => new external_value(PARAM_BOOL, 'Grade item for user locked?', VALUE_OPTIONAL),
'cmid' => new external_value(PARAM_INT, 'Course module id (if type mod)', VALUE_OPTIONAL),
'weightraw' => new external_value(PARAM_FLOAT, 'Weight raw', VALUE_OPTIONAL),
'weightformatted' => new external_value(PARAM_NOTAGS, 'Weight', VALUE_OPTIONAL),
Expand All @@ -501,6 +502,8 @@ public static function get_grade_items_returns() {
'gradehiddenbydate' => new external_value(PARAM_BOOL, 'Grade hidden by date?', VALUE_OPTIONAL),
'gradeneedsupdate' => new external_value(PARAM_BOOL, 'Grade needs update?', VALUE_OPTIONAL),
'gradeishidden' => new external_value(PARAM_BOOL, 'Grade is hidden?', VALUE_OPTIONAL),
'gradeislocked' => new external_value(PARAM_BOOL, 'Grade is locked?', VALUE_OPTIONAL),
'gradeisoverridden' => new external_value(PARAM_BOOL, 'Grade overridden?', VALUE_OPTIONAL),
'gradeformatted' => new external_value(PARAM_NOTAGS, 'The grade formatted', VALUE_OPTIONAL),
'grademin' => new external_value(PARAM_FLOAT, 'Grade min', VALUE_OPTIONAL),
'grademax' => new external_value(PARAM_FLOAT, 'Grade max', VALUE_OPTIONAL),
Expand Down
5 changes: 4 additions & 1 deletion grade/report/user/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,7 @@ private function fill_table_recursive(&$element) {
$excluded = ' excluded';
}
**/

$canviewall = has_capability('moodle/grade:viewall', $this->context);
/// Other class information
$class .= $hidden . $excluded;
if ($this->switch) { // alter style based on whether aggregation is first or last
Expand Down Expand Up @@ -520,6 +520,7 @@ private function fill_table_recursive(&$element) {
$gradeitemdata['categoryid'] = $grade_object->categoryid;
$gradeitemdata['outcomeid'] = $grade_object->outcomeid;
$gradeitemdata['scaleid'] = $grade_object->outcomeid;
$gradeitemdata['locked'] = $canviewall ? $grade_grade->grade_item->is_locked() : null;

if ($this->showfeedback) {
// Copy $class before appending itemcenter as feedback should not be centered
Expand Down Expand Up @@ -551,6 +552,8 @@ private function fill_table_recursive(&$element) {
$gradeitemdata['gradeishidden'] = $grade_grade->is_hidden();
$gradeitemdata['gradedatesubmitted'] = $grade_grade->get_datesubmitted();
$gradeitemdata['gradedategraded'] = $grade_grade->get_dategraded();
$gradeitemdata['gradeislocked'] = $canviewall ? $grade_grade->is_locked() : null;
$gradeitemdata['gradeisoverridden'] = $canviewall ? $grade_grade->is_overridden() : null;

if ($grade_grade->grade_item->needsupdate) {
$data['grade']['class'] = $class.' gradingerror';
Expand Down
24 changes: 24 additions & 0 deletions grade/report/user/tests/externallib_test.php
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ public function test_get_grade_items_teacher() {
$this->assertEquals('mod', $studentgrades['usergrades'][0]['gradeitems'][0]['itemtype']);
$this->assertEquals('assign', $studentgrades['usergrades'][0]['gradeitems'][0]['itemmodule']);
$this->assertEquals($assignment->id, $studentgrades['usergrades'][0]['gradeitems'][0]['iteminstance']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['locked']);
$this->assertEquals($assignment->cmidnumber, $studentgrades['usergrades'][0]['gradeitems'][0]['cmid']);
$this->assertEquals(0, $studentgrades['usergrades'][0]['gradeitems'][0]['itemnumber']);
$this->assertEmpty($studentgrades['usergrades'][0]['gradeitems'][0]['outcomeid']);
Expand All @@ -269,6 +270,8 @@ public function test_get_grade_items_teacher() {
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradehiddenbydate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeneedsupdate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeishidden']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeislocked']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeisoverridden']);
$this->assertEquals('B-', $studentgrades['usergrades'][0]['gradeitems'][0]['lettergradeformatted']);
$this->assertEquals(1, $studentgrades['usergrades'][0]['gradeitems'][0]['rank']);
$this->assertEquals(2, $studentgrades['usergrades'][0]['gradeitems'][0]['numusers']);
Expand All @@ -280,16 +283,34 @@ public function test_get_grade_items_teacher() {
$this->assertEquals('80.00', $studentgrades['usergrades'][0]['gradeitems'][1]['gradeformatted']);
$this->assertEquals(0, $studentgrades['usergrades'][0]['gradeitems'][1]['grademin']);
$this->assertEquals(100, $studentgrades['usergrades'][0]['gradeitems'][1]['grademax']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['locked']);
$this->assertEquals('0–100', $studentgrades['usergrades'][0]['gradeitems'][1]['rangeformatted']);
$this->assertEquals('80.00 %', $studentgrades['usergrades'][0]['gradeitems'][1]['percentageformatted']);
$this->assertEmpty($studentgrades['usergrades'][0]['gradeitems'][1]['feedback']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['gradehiddenbydate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['gradeneedsupdate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['gradeishidden']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['gradeislocked']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][1]['gradeisoverridden']);
$this->assertEquals('B-', $studentgrades['usergrades'][0]['gradeitems'][1]['lettergradeformatted']);
$this->assertEquals(1, $studentgrades['usergrades'][0]['gradeitems'][1]['rank']);
$this->assertEquals(2, $studentgrades['usergrades'][0]['gradeitems'][1]['numusers']);
$this->assertEquals(70, $studentgrades['usergrades'][0]['gradeitems'][1]['averageformatted']);

// Now, override and lock a grade.
$gradegrade = grade_grade::fetch(['itemid' => $studentgrades['usergrades'][0]['gradeitems'][0]['id'],
'userid' => $studentgrades['usergrades'][0]['userid']]);
$gradegrade->set_overridden(true);
$gradegrade->set_locked(1);

$studentgrades = gradereport_user_external::get_grade_items($course->id);
$studentgrades = external_api::clean_returnvalue(gradereport_user_external::get_grade_items_returns(), $studentgrades);
// No warnings returned.
$this->assertCount(0, $studentgrades['warnings']);

// Module grades.
$this->assertTrue($studentgrades['usergrades'][0]['gradeitems'][0]['gradeislocked']);
$this->assertTrue($studentgrades['usergrades'][0]['gradeitems'][0]['gradeisoverridden']);
}

/**
Expand Down Expand Up @@ -330,6 +351,7 @@ public function test_get_grade_items_student() {
$this->assertEquals('mod', $studentgrades['usergrades'][0]['gradeitems'][0]['itemtype']);
$this->assertEquals('assign', $studentgrades['usergrades'][0]['gradeitems'][0]['itemmodule']);
$this->assertEquals($assignment->id, $studentgrades['usergrades'][0]['gradeitems'][0]['iteminstance']);
$this->assertNull($studentgrades['usergrades'][0]['gradeitems'][0]['locked']);
$this->assertEquals($assignment->cmidnumber, $studentgrades['usergrades'][0]['gradeitems'][0]['cmid']);
$this->assertEquals(0, $studentgrades['usergrades'][0]['gradeitems'][0]['itemnumber']);
$this->assertEmpty($studentgrades['usergrades'][0]['gradeitems'][0]['outcomeid']);
Expand All @@ -344,6 +366,8 @@ public function test_get_grade_items_student() {
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradehiddenbydate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeneedsupdate']);
$this->assertFalse($studentgrades['usergrades'][0]['gradeitems'][0]['gradeishidden']);
$this->assertNull($studentgrades['usergrades'][0]['gradeitems'][0]['gradeislocked']);
$this->assertNull($studentgrades['usergrades'][0]['gradeitems'][0]['gradeisoverridden']);
$this->assertEquals('B-', $studentgrades['usergrades'][0]['gradeitems'][0]['lettergradeformatted']);
$this->assertEquals(1, $studentgrades['usergrades'][0]['gradeitems'][0]['rank']);
$this->assertEquals(2, $studentgrades['usergrades'][0]['gradeitems'][0]['numusers']);
Expand Down

0 comments on commit 82bd1fa

Please sign in to comment.