MDL-71439 core_grades: return a blank mustache template for letters

This commit is contained in:
Mark Nelson 2021-06-28 16:17:38 +08:00
parent 2621d36782
commit 7bf0b6ab51
3 changed files with 49 additions and 6 deletions

View file

@ -137,12 +137,13 @@ class fetch extends external_api {
$hasgrade = $gradeitem->user_has_grade($gradeduser);
$grade = $gradeitem->get_formatted_grade_for_user($gradeduser, $USER);
$isgrading = $gradeitem->user_can_grade($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;
return self::get_fetch_data($grade, $hasgrade, (int) $grade->maxgrade, $gradername);
return self::get_fetch_data($grade, $hasgrade, $gradeitem, $gradername, $isgrading);
}
/**
@ -150,18 +151,32 @@ class fetch extends external_api {
*
* @param stdClass $grade
* @param bool $hasgrade
* @param int $maxgrade
* @param gradeitem $gradeitem
* @param string|null $gradername
* @param bool $isgrading
* @return array
*/
public static function get_fetch_data(stdClass $grade, bool $hasgrade, int $maxgrade, ?string $gradername): array {
public static function get_fetch_data(stdClass $grade,
bool $hasgrade,
gradeitem $gradeitem,
?string $gradername,
bool $isgrading = false
): array {
$templatename = 'core_grades/grades/grader/gradingpanel/point';
// We do not want to display anything if we are showing the grade as a letter. For example the 'Grade' might
// read 'B-'. We do not want to show the user the actual point they were given. See MDL-71439.
if (($gradeitem->get_grade_item()->get_displaytype() == GRADE_DISPLAY_TYPE_LETTER) && !$isgrading) {
$templatename = 'core_grades/grades/grader/gradingpanel/point_blank';
}
return [
'templatename' => 'core_grades/grades/grader/gradingpanel/point',
'templatename' => $templatename,
'hasgrade' => $hasgrade,
'grade' => [
'grade' => $grade->grade,
'usergrade' => $grade->usergrade,
'maxgrade' => $maxgrade,
'maxgrade' => (int) $grade->maxgrade,
'gradedby' => $gradername,
'timecreated' => $grade->timecreated,
'timemodified' => $grade->timemodified,

View file

@ -175,7 +175,7 @@ class store extends external_api {
$gradegrade = \grade_grade::fetch(['itemid' => $gradeitem->get_grade_item()->id, 'userid' => $gradeduser->id]);
$gradername = $gradegrade ? fullname(\core_user::get_user($gradegrade->usermodified)) : null;
return fetch::get_fetch_data($grade, $hasgrade, (int) $grade->maxgrade, $gradername);
return fetch::get_fetch_data($grade, $hasgrade, $gradeitem, $gradername);
}
/**

View file

@ -0,0 +1,28 @@
{{!
This file is part of Moodle - http://moodle.org/
Moodle is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Moodle is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Moodle. If not, see <http://www.gnu.org/licenses/>.
}}
{{!
@template core_grades/grades/grader/gradingpanel/point_black
Point-based grading template for use in the grading panel.
Context variables required for this template:
Example context (json):
{
}
}}