MDL-77447 core_grades: Create grade statuses template.
This commit is contained in:
+18
-34
@@ -2463,51 +2463,35 @@ class grade_structure {
|
||||
* Sets status icons for the grade.
|
||||
*
|
||||
* @param array $element array with grade item info
|
||||
* @return string status icons container HTML
|
||||
* @return string|null status icons container HTML
|
||||
*/
|
||||
public function set_grade_status_icons(array $element): string {
|
||||
public function set_grade_status_icons(array $element): ?string {
|
||||
global $OUTPUT;
|
||||
|
||||
$attributes = ['class' => 'text-muted'];
|
||||
|
||||
$statusicons = '';
|
||||
if ($element['object']->is_hidden()) {
|
||||
$statusicons .= $OUTPUT->pix_icon('i/show', grade_helper::get_lang_string('hidden', 'grades'),
|
||||
'moodle', $attributes);
|
||||
}
|
||||
|
||||
if ($element['object']->is_locked()) {
|
||||
$statusicons .= $OUTPUT->pix_icon('i/lock', grade_helper::get_lang_string('locked', 'grades'),
|
||||
'moodle', $attributes);
|
||||
}
|
||||
$context = [
|
||||
'hidden' => $element['object']->is_hidden(),
|
||||
'locked' => $element['object']->is_locked(),
|
||||
];
|
||||
|
||||
if ($element['object'] instanceof grade_grade) {
|
||||
$grade = $element['object'];
|
||||
if ($grade->is_overridden()) {
|
||||
$statusicons .= $OUTPUT->pix_icon('i/overriden_grade',
|
||||
grade_helper::get_lang_string('overridden', 'grades'), 'moodle', $attributes);
|
||||
}
|
||||
|
||||
if ($grade->is_excluded()) {
|
||||
$statusicons .= $OUTPUT->pix_icon('i/excluded', grade_helper::get_lang_string('excluded', 'grades'),
|
||||
'moodle', $attributes);
|
||||
}
|
||||
$context['overridden'] = $grade->is_overridden();
|
||||
$context['excluded'] = $grade->is_excluded();
|
||||
$context['feedback'] = !empty($grade->feedback) && $grade->load_grade_item()->gradetype != GRADE_TYPE_TEXT;
|
||||
}
|
||||
|
||||
$class = 'grade_icons data-collapse_gradeicons';
|
||||
// Early return if there aren't any statuses that we need to show.
|
||||
if (!in_array(true, $context)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$context['classes'] = 'grade_icons data-collapse_gradeicons';
|
||||
|
||||
if (isset($element['type']) && ($element['type'] == 'category')) {
|
||||
$class = 'category_grade_icons';
|
||||
$context['classes'] = 'category_grade_icons';
|
||||
}
|
||||
|
||||
if (!empty($grade->feedback) && $grade->load_grade_item()->gradetype != GRADE_TYPE_TEXT) {
|
||||
$statusicons .= $OUTPUT->pix_icon('i/asterisk', grade_helper::get_lang_string('feedbackprovided', 'grades'),
|
||||
'moodle', $attributes);
|
||||
}
|
||||
|
||||
if ($statusicons) {
|
||||
$statusicons = $OUTPUT->container($statusicons, $class);
|
||||
}
|
||||
return $statusicons;
|
||||
return $OUTPUT->render_from_template('core_grades/status_icons', $context);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -0,0 +1,35 @@
|
||||
{{!
|
||||
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/status_icons
|
||||
|
||||
Template for the grade status icons.
|
||||
|
||||
Example context (json):
|
||||
{
|
||||
"classes": "gradestatus",
|
||||
"hidden": true,
|
||||
"locked": true,
|
||||
"overridden": false,
|
||||
"excluded": false,
|
||||
"feedback": false
|
||||
}
|
||||
}}
|
||||
<div class="text-muted {{classes}}">
|
||||
{{#hidden}}{{#pix}}i/show, moodle, {{#str}} hidden, grades {{/str}}{{/pix}}{{/hidden}}
|
||||
{{#locked}}{{#pix}}i/lock, moodle, {{#str}} locked, grades {{/str}}{{/pix}}{{/locked}}
|
||||
{{#overridden}}{{#pix}}i/overriden_grade, moodle, {{#str}} overridden, grades {{/str}}{{/pix}}{{/overridden}}
|
||||
{{#excluded}}{{#pix}}i/excluded, moodle, {{#str}} excluded, grades {{/str}}{{/pix}}{{/excluded}}
|
||||
{{#feedback}}{{#pix}}i/asterisk, moodle, {{#str}} feedbackprovided, grades {{/str}}{{/pix}}{{/feedback}}
|
||||
</div>
|
||||
Reference in New Issue
Block a user