diff --git a/grade/report/user/externallib.php b/grade/report/user/externallib.php index da5f8668631..4988d2a6680 100644 --- a/grade/report/user/externallib.php +++ b/grade/report/user/externallib.php @@ -165,6 +165,7 @@ class gradereport_user_external extends external_api { 'courseid' => $course->id, 'userid' => $user->id, 'userfullname' => fullname($user), + 'useridnumber' => $user->idnumber, 'maxdepth' => $report->maxdepth, ); if ($tabledata) { @@ -191,6 +192,7 @@ class gradereport_user_external extends external_api { 'courseid' => $course->id, 'userid' => $currentuser->id, 'userfullname' => fullname($currentuser), + 'useridnumber' => $currentuser->idnumber, 'maxdepth' => $report->maxdepth, ); if ($tabledata) { @@ -478,6 +480,7 @@ class gradereport_user_external extends external_api { 'courseid' => new external_value(PARAM_INT, 'course id'), 'userid' => new external_value(PARAM_INT, 'user id'), 'userfullname' => new external_value(PARAM_TEXT, 'user fullname'), + 'useridnumber' => new external_value(PARAM_TEXT, 'user idnumber'), 'maxdepth' => new external_value(PARAM_INT, 'table max depth (needed for printing it)'), 'gradeitems' => new external_multiple_structure( new external_single_structure( @@ -488,6 +491,7 @@ class gradereport_user_external extends external_api { 'itemmodule' => new external_value(PARAM_PLUGIN, 'Grade item module'), 'iteminstance' => new external_value(PARAM_INT, 'Grade item instance'), 'itemnumber' => new external_value(PARAM_INT, 'Grade item item number'), + 'idnumber' => new external_value(PARAM_TEXT, 'Grade item idnumber'), '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'), diff --git a/grade/report/user/lib.php b/grade/report/user/lib.php index 7290b184898..98593b8497f 100644 --- a/grade/report/user/lib.php +++ b/grade/report/user/lib.php @@ -517,6 +517,7 @@ class grade_report_user extends grade_report { $gradeitemdata['itemmodule'] = $grade_object->itemmodule; $gradeitemdata['iteminstance'] = $grade_object->iteminstance; $gradeitemdata['itemnumber'] = $grade_object->itemnumber; + $gradeitemdata['idnumber'] = $grade_object->idnumber; $gradeitemdata['categoryid'] = $grade_object->categoryid; $gradeitemdata['outcomeid'] = $grade_object->outcomeid; $gradeitemdata['scaleid'] = $grade_object->outcomeid; diff --git a/grade/report/user/tests/externallib_test.php b/grade/report/user/tests/externallib_test.php index 6057a386ba7..b781d42c9ed 100644 --- a/grade/report/user/tests/externallib_test.php +++ b/grade/report/user/tests/externallib_test.php @@ -52,7 +52,7 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas $course = $this->getDataGenerator()->create_course(array('groupmode' => SEPARATEGROUPS, 'groupmodeforce' => 1)); $studentrole = $DB->get_record('role', array('shortname' => 'student')); - $student1 = $this->getDataGenerator()->create_user(); + $student1 = $this->getDataGenerator()->create_user(array('idnumber' => 'testidnumber')); $this->getDataGenerator()->enrol_user($student1->id, $course->id, $studentrole->id); $student2 = $this->getDataGenerator()->create_user(); @@ -76,8 +76,8 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas $modcontext = get_coursemodule_from_instance('assign', $assignment->id, $course->id); $assignment->cmidnumber = $modcontext->id; - $student1grade = array('userid' => $student1->id, 'rawgrade' => $s1grade); - $student2grade = array('userid' => $student2->id, 'rawgrade' => $s2grade); + $student1grade = array('userid' => $student1->id, 'rawgrade' => $s1grade, 'idnumber' => 'testidnumber1'); + $student2grade = array('userid' => $student2->id, 'rawgrade' => $s2grade, 'idnumber' => 'testidnumber2'); $studentgrades = array($student1->id => $student1grade, $student2->id => $student2grade); assign_grade_item_update($assignment, $studentgrades); @@ -347,6 +347,7 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas $this->assertEquals($course->id, $studentgrades['usergrades'][0]['courseid']); $this->assertEquals($student1->id, $studentgrades['usergrades'][0]['userid']); + $this->assertEquals($student1->idnumber, $studentgrades['usergrades'][0]['useridnumber']); $this->assertEquals($assignment->name, $studentgrades['usergrades'][0]['gradeitems'][0]['itemname']); $this->assertEquals('mod', $studentgrades['usergrades'][0]['gradeitems'][0]['itemtype']); $this->assertEquals('assign', $studentgrades['usergrades'][0]['gradeitems'][0]['itemmodule']); @@ -373,6 +374,10 @@ class gradereport_user_externallib_testcase extends externallib_advanced_testcas $this->assertEquals(2, $studentgrades['usergrades'][0]['gradeitems'][0]['numusers']); $this->assertEquals(70, $studentgrades['usergrades'][0]['gradeitems'][0]['averageformatted']); + // Check that the idnumber for assignment grades is equal to the cmid. + $this->assertEquals((string) $studentgrades['usergrades'][0]['gradeitems'][0]['cmid'], + $studentgrades['usergrades'][0]['gradeitems'][0]['idnumber']); + // Hide one grade for the user. $gradegrade = new grade_grade(array('userid' => $student1->id, 'itemid' => $studentgrades['usergrades'][0]['gradeitems'][0]['id']), true);