mirror of
https://github.com/moodle/moodle.git
synced 2025-01-18 22:08:20 +01:00
MDL-71439 core_grades: return result of new method in web services
This commit is contained in:
parent
85eda546b3
commit
4eecb896a2
@ -136,14 +136,13 @@ class fetch extends external_api {
|
||||
}
|
||||
|
||||
$hasgrade = $gradeitem->user_has_grade($gradeduser);
|
||||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
|
||||
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
|
||||
|
||||
// Set up some items we need to return on other interfaces.
|
||||
$gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
|
||||
$gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
|
||||
$maxgrade = (int) $gradeitem->get_grade_item()->grademax;
|
||||
|
||||
return self::get_fetch_data($grade, $hasgrade, $maxgrade, $gradername);
|
||||
return self::get_fetch_data($grade, $hasgrade, (int) $grade->maxgrade, $gradername);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -161,7 +160,7 @@ class fetch extends external_api {
|
||||
'hasgrade' => $hasgrade,
|
||||
'grade' => [
|
||||
'grade' => $grade->grade,
|
||||
'usergrade' => $grade->grade,
|
||||
'usergrade' => $grade->usergrade,
|
||||
'maxgrade' => $maxgrade,
|
||||
'gradedby' => $gradername,
|
||||
'timecreated' => $grade->timecreated,
|
||||
|
@ -170,13 +170,12 @@ class store extends external_api {
|
||||
}
|
||||
|
||||
// Fetch the updated grade back out.
|
||||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
|
||||
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
|
||||
|
||||
$gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
|
||||
$gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
|
||||
$maxgrade = (int) $gradeitem->get_grade_item()->grademax;
|
||||
|
||||
return fetch::get_fetch_data($grade, $hasgrade, $maxgrade, $gradername);
|
||||
return fetch::get_fetch_data($grade, $hasgrade, (int) $grade->maxgrade, $gradername);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -155,7 +155,7 @@ class fetch extends external_api {
|
||||
global $USER;
|
||||
|
||||
$hasgrade = $gradeitem->user_has_grade($gradeduser);
|
||||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
|
||||
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
|
||||
$currentgrade = (int) unformat_float($grade->grade);
|
||||
|
||||
$menu = $gradeitem->get_grade_menu();
|
||||
@ -172,7 +172,7 @@ class fetch extends external_api {
|
||||
'hasgrade' => $hasgrade,
|
||||
'grade' => [
|
||||
'options' => $values,
|
||||
'usergrade' => $grade->grade,
|
||||
'usergrade' => $grade->usergrade,
|
||||
'maxgrade' => $maxgrade,
|
||||
'gradedby' => $gradername,
|
||||
'timecreated' => $grade->timecreated,
|
||||
|
@ -154,7 +154,7 @@ class fetch extends external_api {
|
||||
global $USER;
|
||||
|
||||
$hasgrade = $gradeitem->user_has_grade($gradeduser);
|
||||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
|
||||
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
|
||||
$instance = $gradeitem->get_advanced_grading_instance($USER, $grade);
|
||||
if (!$instance) {
|
||||
throw new moodle_exception('error:gradingunavailable', 'grading');
|
||||
@ -237,7 +237,7 @@ class fetch extends external_api {
|
||||
'criterion' => $criterion,
|
||||
'hascomments' => !empty($comments),
|
||||
'comments' => $comments,
|
||||
'usergrade' => $grade->grade,
|
||||
'usergrade' => $grade->usergrade,
|
||||
'maxgrade' => $maxgrade,
|
||||
'gradedby' => $gradername,
|
||||
'timecreated' => $grade->timecreated,
|
||||
|
@ -136,7 +136,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0, $result['grade']['usergrade']);
|
||||
$this->assertEquals('- / 100.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -275,7 +275,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(25, $result['grade']['usergrade']);
|
||||
$this->assertEquals('25.00 / 100.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -168,7 +168,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0.5, $result['grade']['usergrade']);
|
||||
$this->assertEquals('0.50 / 2.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -147,7 +147,7 @@ class fetch extends external_api {
|
||||
global $USER;
|
||||
// Set up all the controllers etc that we'll be needing.
|
||||
$hasgrade = $gradeitem->user_has_grade($gradeduser);
|
||||
$grade = $gradeitem->get_grade_for_user($gradeduser, $USER);
|
||||
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
|
||||
$instance = $gradeitem->get_advanced_grading_instance($USER, $grade);
|
||||
if (!$instance) {
|
||||
throw new moodle_exception('error:gradingunavailable', 'grading');
|
||||
@ -252,7 +252,7 @@ class fetch extends external_api {
|
||||
'rubricmode' => 'evaluate editable',
|
||||
'teacherdescription' => $teacherdescription,
|
||||
'canedit' => false,
|
||||
'usergrade' => $grade->grade,
|
||||
'usergrade' => $grade->usergrade,
|
||||
'maxgrade' => $maxgrade,
|
||||
'gradedby' => $gradername,
|
||||
'timecreated' => $grade->timecreated,
|
||||
|
@ -137,7 +137,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0, $result['grade']['usergrade']);
|
||||
$this->assertEquals('- / 100.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -282,7 +282,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(50, $result['grade']['usergrade']);
|
||||
$this->assertEquals('50.00 / 100.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -167,7 +167,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(1, $result['grade']['usergrade']);
|
||||
$this->assertEquals('1.00 / 2.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -138,7 +138,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0, $result['grade']['usergrade']);
|
||||
$this->assertEquals('- / 5.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -239,7 +239,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(4, $result['grade']['usergrade']);
|
||||
$this->assertEquals('4.00 / 5.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -174,7 +174,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(null, $result['grade']['usergrade']);
|
||||
$this->assertEquals('- / 5.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -217,7 +217,6 @@ class store_test extends advanced_testcase {
|
||||
$formdata = [
|
||||
'grade' => 4,
|
||||
];
|
||||
$formattedvalue = grade_floatval(unformat_float(4));
|
||||
|
||||
$gradeitem = component_gradeitem::instance('mod_forum', $forum->get_context(), 'forum');
|
||||
|
||||
@ -240,14 +239,14 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsArray($result['grade']);
|
||||
|
||||
$this->assertArrayHasKey('grade', $result['grade']);
|
||||
$this->assertEquals($formattedvalue, $result['grade']['grade']);
|
||||
$this->assertEquals(grade_floatval(unformat_float(4)), $result['grade']['grade']);
|
||||
|
||||
$this->assertIsInt($result['grade']['timecreated']);
|
||||
$this->assertArrayHasKey('timemodified', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals($formattedvalue, $result['grade']['usergrade']);
|
||||
$this->assertEquals('4.00 / 5.00', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -269,7 +268,7 @@ class store_test extends advanced_testcase {
|
||||
'itemid' => $storedgradeitem->id,
|
||||
]);
|
||||
|
||||
$this->assertEquals($formattedvalue, $storedgrade->rawgrade);
|
||||
$this->assertEquals(grade_floatval(unformat_float(4)), $storedgrade->rawgrade);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -142,7 +142,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0, $result['grade']['usergrade']);
|
||||
$this->assertEquals('-', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -286,7 +286,7 @@ class fetch_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(2, $result['grade']['usergrade']);
|
||||
$this->assertEquals('B', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
@ -160,7 +160,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(0, $result['grade']['usergrade']);
|
||||
$this->assertEquals('-', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -244,7 +244,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(-1, $result['grade']['usergrade']);
|
||||
$this->assertEquals('-', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
@ -331,7 +331,7 @@ class store_test extends advanced_testcase {
|
||||
$this->assertIsInt($result['grade']['timemodified']);
|
||||
|
||||
$this->assertArrayHasKey('usergrade', $result['grade']);
|
||||
$this->assertEquals(2, $result['grade']['usergrade']);
|
||||
$this->assertEquals('B', $result['grade']['usergrade']);
|
||||
|
||||
$this->assertArrayHasKey('maxgrade', $result['grade']);
|
||||
$this->assertIsInt($result['grade']['maxgrade']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user