Skip to content

Commit

Permalink
Merge branch 'MDL-77447-master' of https://github.com/ilyatregubov/mo…
Browse files Browse the repository at this point in the history
  • Loading branch information
junpataleta committed Aug 2, 2023
2 parents 3054d43 + 565dbaa commit b2d3f24
Show file tree
Hide file tree
Showing 17 changed files with 197 additions and 144 deletions.
50 changes: 17 additions & 33 deletions grade/lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -2495,51 +2495,35 @@ public function get_edit_calculation_link(array $element, object $gpr): ?string
* 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';
if (isset($element['type']) && ($element['type'] == 'category')) {
$class = 'category_grade_icons';
// Early return if there aren't any statuses that we need to show.
if (!in_array(true, $context)) {
return null;
}

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);
}
$context['classes'] = 'grade_icons data-collapse_gradeicons';

if ($statusicons) {
$statusicons = $OUTPUT->container($statusicons, $class);
if (isset($element['type']) && ($element['type'] == 'category')) {
$context['classes'] = 'category_grade_icons';
}
return $statusicons;

return $OUTPUT->render_from_template('core_grades/status_icons', $context);
}

/**
Expand Down
25 changes: 11 additions & 14 deletions grade/report/singleview/classes/local/screen/grade.php
Original file line number Diff line number Diff line change
Expand Up @@ -215,24 +215,21 @@ public function format_line($item): array {

$grade = $this->fetch_grade_or_default($this->item, $item->id);

$lockicon = '';
$gradestatus = '';
$context = [
'hidden' => $grade->is_hidden(),
'locked' => $grade->is_locked(),
];

$lockedgrade = $lockedgradeitem = 0;
if (!empty($grade->locked)) {
$lockedgrade = 1;
}
if (!empty($grade->grade_item->locked)) {
$lockedgradeitem = 1;
}
// Check both grade and grade item.
if ( $lockedgrade || $lockedgradeitem ) {
$lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked') . ' ';
if (in_array(true, $context)) {
$context['classes'] = 'gradestatus';
$gradestatus = $OUTPUT->render_from_template('core_grades/status_icons', $context);
}

if (has_capability('moodle/site:viewfullnames', \context_course::instance($this->courseid))) {
$fullname = $lockicon . fullname($item, true);
$fullname = fullname($item, true);
} else {
$fullname = $lockicon . fullname($item);
$fullname = fullname($item);
}

$item->imagealt = $fullname;
Expand All @@ -245,7 +242,7 @@ public function format_line($item): array {
$line = [
html_writer::link($url, $userpic . $fullname),
$this->get_user_action_menu($item),
$formatteddefinition['finalgrade'],
$formatteddefinition['finalgrade'] . $gradestatus,
$this->item_range(),
$formatteddefinition['feedback'],
$formatteddefinition['override'],
Expand Down
24 changes: 11 additions & 13 deletions grade/report/singleview/classes/local/screen/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,18 +169,16 @@ public function format_line($item): array {
global $OUTPUT;

$grade = $this->fetch_grade_or_default($item, $this->item->id);
$lockicon = '';
$gradestatus = '';

$lockeditem = $lockeditemgrade = 0;
if (!empty($grade->locked)) {
$lockeditem = 1;
}
if (!empty($grade->grade_item->locked)) {
$lockeditemgrade = 1;
}
// Check both grade and grade item.
if ($lockeditem || $lockeditemgrade) {
$lockicon = $OUTPUT->pix_icon('t/locked', 'grade is locked', 'moodle', ['class' => 'ml-3']);
$context = [
'hidden' => $grade->is_hidden(),
'locked' => $grade->is_locked(),
];

if (in_array(true, $context)) {
$context['classes'] = 'gradestatus';
$gradestatus = $OUTPUT->render_from_template('core_grades/status_icons', $context);
}

// Create a fake gradetreeitem so we can call get_element_header().
Expand Down Expand Up @@ -210,10 +208,10 @@ public function format_line($item): array {
}

$line = [
html_writer::div($itemicon . $itemcontent . $lockicon, "{$type} d-flex align-items-center"),
html_writer::div($itemicon . $itemcontent, "{$type} d-flex align-items-center"),
$this->get_item_action_menu($item),
$this->category($item),
$formatteddefinition['finalgrade'],
$formatteddefinition['finalgrade'] . $gradestatus,
new range($item),
$formatteddefinition['feedback'],
$formatteddefinition['override'],
Expand Down
2 changes: 0 additions & 2 deletions grade/report/singleview/classes/report/singleview.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,7 @@
namespace gradereport_singleview\report;

use context_course;
use grade_helper;
use grade_report;
use html_writer;
use moodle_url;
use renderer_base;
use stdClass;
Expand Down
35 changes: 22 additions & 13 deletions grade/report/user/classes/report/user.php
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ private function fill_table_recursive(array &$element) {
$gradeobject = $element['object'];
$eid = $gradeobject->id;
$element['userid'] = $this->user->id;
$fullname = $this->gtree->get_element_header($element, true, false, true, true, true);
$fullname = $this->gtree->get_element_header($element, true, false, true, false, true);
$data = [];
$gradeitemdata = [];
$hidden = '';
Expand Down Expand Up @@ -603,6 +603,22 @@ private function fill_table_recursive(array &$element) {
}

if ($this->showgrade) {
$gradestatus = '';
// We only show status icons for a teacher if he views report as himself.
if (isset($this->viewasuser) && !$this->viewasuser) {
$context = [
'hidden' => $gradegrade->is_hidden(),
'locked' => $gradegrade->is_locked(),
'overridden' => $gradegrade->is_overridden(),
'excluded' => $gradegrade->is_excluded()
];

if (in_array(true, $context)) {
$context['classes'] = 'gradestatus';
$gradestatus = $OUTPUT->render_from_template('core_grades/status_icons', $context);
}
}

$gradeitemdata['graderaw'] = null;
$gradeitemdata['gradehiddenbydate'] = false;
$gradeitemdata['gradeneedsupdate'] = $gradegrade->grade_item->needsupdate;
Expand Down Expand Up @@ -633,7 +649,7 @@ private function fill_table_recursive(array &$element) {
userdate(
$gradegrade->get_datesubmitted(),
get_string('strftimedatetimeshort')
)
) . $gradestatus
);
$gradeitemdata['gradehiddenbydate'] = true;
} else if ($gradegrade->is_hidden()) {
Expand All @@ -644,7 +660,7 @@ private function fill_table_recursive(array &$element) {
$gradeitemdata['graderaw'] = $gradeval;
$data['grade']['content'] = grade_format_gradevalue($gradeval,
$gradegrade->grade_item,
true);
true) . $gradestatus;
}
} else {
$gradestatusclass = '';
Expand All @@ -671,7 +687,7 @@ private function fill_table_recursive(array &$element) {

$data['grade']['class'] = "{$class} {$gradestatusclass}";
$data['grade']['content'] = $gradepassicon . grade_format_gradevalue($gradeval,
$gradegrade->grade_item, true);
$gradegrade->grade_item, true) . $gradestatus;
$gradeitemdata['graderaw'] = $gradeval;
}
$data['grade']['headers'] = "$headercat $headerrow grade";
Expand Down Expand Up @@ -814,17 +830,10 @@ private function fill_table_recursive(array &$element) {
);
}

if ($gradegrade->overridden > 0 && ($type == 'categoryitem' || $type == 'courseitem')) {
$data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['content'] = get_string('overridden', 'grades').': ' .
format_text($gradegrade->feedback, $gradegrade->feedbackformat,
['context' => $gradegrade->get_context()]);
$gradeitemdata['feedback'] = $gradegrade->feedback;
} else if (empty($gradegrade->feedback) || (!$this->canviewhidden && $gradegrade->is_hidden())) {
$data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['class'] = $classfeedback.' feedbacktext';
if (empty($gradegrade->feedback) || (!$this->canviewhidden && $gradegrade->is_hidden())) {
$data['feedback']['content'] = ' ';
} else {
$data['feedback']['class'] = $classfeedback.' feedbacktext';
$data['feedback']['content'] = format_text($gradegrade->feedback, $gradegrade->feedbackformat,
['context' => $gradegrade->get_context()]);
$gradeitemdata['feedback'] = $gradegrade->feedback;
Expand Down
4 changes: 0 additions & 4 deletions grade/report/user/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,3 @@
display: none;
}
}

#fitem_id_submitbutton {
padding-right: 2em;
}
35 changes: 35 additions & 0 deletions grade/templates/status_icons.mustache
Original file line number Diff line number Diff line change
@@ -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>
Loading

0 comments on commit b2d3f24

Please sign in to comment.