Skip to content

Commit

Permalink
MDL-78082 core_grades: lock/unlock all option for grade categories
Browse files Browse the repository at this point in the history
A lock/unlock option is added to the context menu of the grade
categories again. But it is only used as an auxiliary tool to lock or
unlock all the grade items within the category.
  • Loading branch information
rezaies committed Sep 6, 2023
1 parent d2d8d16 commit 3693a22
Showing 1 changed file with 37 additions and 9 deletions.
46 changes: 37 additions & 9 deletions grade/lib.php
Expand Up @@ -2353,8 +2353,24 @@ public function get_locking_link(array $element, object $gpr): ?string {
$url = $gpr->add_url_params($url);

if ($element['type'] == 'category') {
// Grade categories themselves cannot be locked.
return null;
// Grade categories themselves cannot be locked. We lock/unlock their grade items.
$children = $element['object']->get_children(true);
$alllocked = true;
foreach ($children as $child) {
if (!$child['object']->is_locked()) {
$alllocked = false;
break;
}
}
if ($alllocked && has_capability('moodle/grade:unlock', $this->context)) {
$title = get_string('unlock', 'grades');
$url->param('action', 'unlock');
} else if (!$alllocked && has_capability('moodle/grade:lock', $this->context)) {
$title = get_string('lock', 'grades');
$url->param('action', 'lock');
} else {
return null;
}
} else if (($element['type'] == 'grade') && ($element['object']->grade_item->is_locked())) {
// Don't allow an unlocking action for a grade whose grade item is locked: just print a state icon.
$strparamobj = new stdClass();
Expand Down Expand Up @@ -2476,14 +2492,30 @@ public function set_grade_status_icons(array $element): string {
global $OUTPUT;

$attributes = ['class' => 'text-muted'];

$class = 'grade_icons data-collapse_gradeicons';
$statusicons = '';

if ($element['object']->is_hidden()) {
$statusicons .= $OUTPUT->pix_icon('i/show', grade_helper::get_lang_string('hidden', 'grades'),
'moodle', $attributes);
}

if (($element['type'] != 'category') && $element['object']->is_locked()) {
if ($element['object'] instanceof grade_category) {
$class = 'category_grade_icons';

$children = $element['object']->get_children(true);
$alllocked = true;
foreach ($children as $child) {
if (!$child['object']->is_locked()) {
$alllocked = false;
break;
}
}
if ($alllocked) {
$statusicons .= $OUTPUT->pix_icon('i/lock', get_string('locked', 'grades'),
'moodle', $attributes);
}
} else if ($element['object']->is_locked()) {
$statusicons .= $OUTPUT->pix_icon('i/lock', grade_helper::get_lang_string('locked', 'grades'),
'moodle', $attributes);
}
Expand All @@ -2501,11 +2533,6 @@ public function set_grade_status_icons(array $element): string {
}
}

$class = 'grade_icons data-collapse_gradeicons';
if (isset($element['type']) && ($element['type'] == 'category')) {
$class = '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);
Expand Down Expand Up @@ -2643,6 +2670,7 @@ public function get_cell_action_menu(array $element, string $mode, grade_plugin_
}
$context->editurl = $this->get_edit_link($element, $gpr);
$context->hideurl = $this->get_hiding_link($element, $gpr);
$context->lockurl = $this->get_locking_link($element, $gpr);
}
}

Expand Down

0 comments on commit 3693a22

Please sign in to comment.