From 8827e573db796b22dea6e21229a420bdac9b8690 Mon Sep 17 00:00:00 2001 From: Mathew May Date: Wed, 6 Nov 2019 09:15:35 +0800 Subject: [PATCH] MDL-66958 core_grade: Add hasgrade to all external fetch webservices --- .../grades/grader/gradingpanel/point/external/fetch.php | 8 ++++++-- .../grades/grader/gradingpanel/point/external/store.php | 2 +- .../grades/grader/gradingpanel/scale/external/fetch.php | 3 +++ .../classes/grades/grader/gradingpanel/external/fetch.php | 3 +++ .../classes/grades/grader/gradingpanel/external/fetch.php | 3 +++ grade/grading/form/rubric/lang/en/gradingform_rubric.php | 1 + 6 files changed, 17 insertions(+), 3 deletions(-) diff --git a/grade/classes/grades/grader/gradingpanel/point/external/fetch.php b/grade/classes/grades/grader/gradingpanel/point/external/fetch.php index b8332e51988..4c86bbd9986 100644 --- a/grade/classes/grades/grader/gradingpanel/point/external/fetch.php +++ b/grade/classes/grades/grader/gradingpanel/point/external/fetch.php @@ -129,20 +129,23 @@ class fetch extends external_api { // Fetch the actual data. $gradeduser = \core_user::get_user($gradeduserid); + $hasgrade = $gradeitem->user_has_grade($gradeduser); $grade = $gradeitem->get_grade_for_user($gradeduser, $USER); - return self::get_fetch_data($grade); + return self::get_fetch_data($grade, $hasgrade); } /** * Get the data to be fetched. * * @param stdClass $grade + * @param bool $hasgrade * @return array */ - public static function get_fetch_data(stdClass $grade): array { + public static function get_fetch_data(stdClass $grade, bool $hasgrade): array { return [ 'templatename' => 'core_grades/grades/grader/gradingpanel/point', + 'hasgrade' => $hasgrade, 'grade' => [ 'grade' => $grade->grade, 'timecreated' => $grade->timecreated, @@ -161,6 +164,7 @@ class fetch extends external_api { public static function execute_returns(): external_single_structure { return new external_single_structure([ 'templatename' => new external_value(PARAM_SAFEPATH, 'The template to use when rendering this data'), + 'hasgrade' => new external_value(PARAM_BOOL, 'Does the user have a grade?'), 'grade' => new external_single_structure([ 'grade' => new external_value(PARAM_FLOAT, 'The numeric grade'), 'timecreated' => new external_value(PARAM_INT, 'The time that the grade was created'), diff --git a/grade/classes/grades/grader/gradingpanel/point/external/store.php b/grade/classes/grades/grader/gradingpanel/point/external/store.php index bc9e989c24d..37f95c6a342 100644 --- a/grade/classes/grades/grader/gradingpanel/point/external/store.php +++ b/grade/classes/grades/grader/gradingpanel/point/external/store.php @@ -152,7 +152,7 @@ class store extends external_api { // Grade. $gradeitem->store_grade_from_formdata($gradeduser, $USER, (object) $data); - $hasgrade = $gradeitem->get_grade_status_for_user($gradeduser); + $hasgrade = $gradeitem->user_has_grade($gradeduser); // Fetch the updated grade back out. $grade = $gradeitem->get_grade_for_user($gradeduser, $USER); diff --git a/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php b/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php index dfd9acd38a9..3e10f5b151f 100644 --- a/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php +++ b/grade/classes/grades/grader/gradingpanel/scale/external/fetch.php @@ -142,6 +142,7 @@ class fetch extends external_api { public static function get_fetch_data(gradeitem $gradeitem, stdClass $gradeduser): array { global $USER; + $hasgrade = $gradeitem->user_has_grade($gradeduser); $grade = $gradeitem->get_grade_for_user($gradeduser, $USER); $currentgrade = (int) unformat_float($grade->grade); @@ -156,6 +157,7 @@ class fetch extends external_api { return [ 'templatename' => 'core_grades/grades/grader/gradingpanel/scale', + 'hasgrade' => $hasgrade, 'grade' => [ 'options' => $values, 'timecreated' => $grade->timecreated, @@ -174,6 +176,7 @@ class fetch extends external_api { public static function execute_returns(): external_single_structure { return new external_single_structure([ 'templatename' => new external_value(PARAM_SAFEPATH, 'The template to use when rendering this data'), + 'hasgrade' => new external_value(PARAM_BOOL, 'Does the user have a grade?'), 'grade' => new external_single_structure([ 'options' => new external_multiple_structure( new external_single_structure([ diff --git a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php index fe341825f37..6225ce3a9ad 100644 --- a/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php +++ b/grade/grading/form/guide/classes/grades/grader/gradingpanel/external/fetch.php @@ -148,6 +148,7 @@ class fetch extends external_api { public static function get_fetch_data(gradeitem $gradeitem, stdClass $gradeduser): array { global $USER; + $hasgrade = $gradeitem->user_has_grade($gradeduser); $grade = $gradeitem->get_grade_for_user($gradeduser, $USER); $instance = $gradeitem->get_advanced_grading_instance($USER, $grade); $controller = $instance->get_controller(); @@ -217,6 +218,7 @@ class fetch extends external_api { return [ 'templatename' => 'gradingform_guide/grades/grader/gradingpanel', + 'hasgrade' => $hasgrade, 'grade' => [ 'instanceid' => $instance->get_id(), 'criterion' => $criterion, @@ -238,6 +240,7 @@ class fetch extends external_api { public static function execute_returns(): external_single_structure { return new external_single_structure([ 'templatename' => new external_value(PARAM_SAFEPATH, 'The template to use when rendering this data'), + 'hasgrade' => new external_value(PARAM_BOOL, 'Does the user have a grade?'), 'grade' => new external_single_structure([ 'instanceid' => new external_value(PARAM_INT, 'The id of the current grading instance'), 'criterion' => new external_multiple_structure( diff --git a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php index 6cf05b73f89..18d01de9c8b 100644 --- a/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php +++ b/grade/grading/form/rubric/classes/grades/grader/gradingpanel/external/fetch.php @@ -140,6 +140,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); $instance = $gradeitem->get_advanced_grading_instance($USER, $grade); $controller = $instance->get_controller(); @@ -229,6 +230,7 @@ class fetch extends external_api { return [ 'templatename' => 'gradingform_rubric/grades/grader/gradingpanel', + 'hasgrade' => $hasgrade, 'grade' => [ 'instanceid' => $instance->get_id(), 'criteria' => $criterion, @@ -251,6 +253,7 @@ class fetch extends external_api { public static function execute_returns(): external_single_structure { return new external_single_structure([ 'templatename' => new external_value(PARAM_SAFEPATH, 'The template to use when rendering this data'), + 'hasgrade' => new external_value(PARAM_BOOL, 'Does the user have a grade?'), 'grade' => new external_single_structure([ 'instanceid' => new external_value(PARAM_INT, 'The id of the current grading instance'), 'rubricmode' => new external_value(PARAM_RAW, 'The mode i.e. evaluate editable'), diff --git a/grade/grading/form/rubric/lang/en/gradingform_rubric.php b/grade/grading/form/rubric/lang/en/gradingform_rubric.php index 85f3c6bc8e2..655c8143afd 100644 --- a/grade/grading/form/rubric/lang/en/gradingform_rubric.php +++ b/grade/grading/form/rubric/lang/en/gradingform_rubric.php @@ -25,6 +25,7 @@ defined('MOODLE_INTERNAL') || die(); $string['addcriterion'] = 'Add criterion'; +$string['additionalfeedback'] = 'Additional feedback'; $string['alwaysshowdefinition'] = 'Allow users to preview rubric (otherwise it will only be displayed after grading)'; $string['backtoediting'] = 'Back to editing'; $string['confirmdeletecriterion'] = 'Are you sure you want to delete this criterion?';