Skip to content

Commit

Permalink
MDL-71439 core_grades: return a blank mustache template for letters
Browse files Browse the repository at this point in the history
  • Loading branch information
mdjnelson committed Oct 27, 2021
1 parent 6070bbb commit 53a4d06
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
25 changes: 20 additions & 5 deletions grade/classes/grades/grader/gradingpanel/point/external/fetch.php
Expand Up @@ -137,31 +137,46 @@ public static function execute(string $component, int $contextid, string $itemna

$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);
}

/**
* Get the data to be fetched.
*
* @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,
Expand Down
Expand Up @@ -175,7 +175,7 @@ public static function execute(string $component, int $contextid, string $itemna
$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);
}

/**
Expand Down
28 changes: 28 additions & 0 deletions grade/templates/grades/grader/gradingpanel/point_blank.mustache
@@ -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):
{
}
}}

0 comments on commit 53a4d06

Please sign in to comment.