Commit 2ced73f6 authored by Juan Leyva's avatar Juan Leyva
Browse files

MDL-63396 grade_report: Return locked and overridden info

parent 448bd578
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.
......
......@@ -491,6 +491,7 @@ class gradereport_user_external extends external_api {
'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),
......@@ -501,6 +502,8 @@ class gradereport_user_external extends external_api {
'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),
......
......@@ -491,7 +491,7 @@ class grade_report_user extends grade_report {
$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
......@@ -520,6 +520,7 @@ class grade_report_user extends grade_report {
$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
......@@ -551,6 +552,8 @@ class grade_report_user extends grade_report {
$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';
......
......@@ -255,6 +255,7 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas
$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']);
......@@ -269,6 +270,8 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas
$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']);
......@@ -280,16 +283,34 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas
$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']);
}
/**
......@@ -330,6 +351,7 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas
$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']);
......@@ -344,6 +366,8 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas
$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']);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment