mirror of
https://github.com/moodle/moodle.git
synced 2025-01-31 12:45:04 +01:00
MDL-78082 core_grades: lock/unlock all option for grade categories
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.
This commit is contained in:
parent
b208ea26d1
commit
09ef2d0aa5
@ -2380,8 +2380,24 @@ class grade_structure {
|
||||
$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();
|
||||
@ -2504,7 +2520,6 @@ class grade_structure {
|
||||
|
||||
$context = [
|
||||
'hidden' => $element['object']->is_hidden(),
|
||||
'locked' => $element['object']->is_locked(),
|
||||
];
|
||||
|
||||
if ($element['object'] instanceof grade_grade) {
|
||||
@ -2514,19 +2529,32 @@ class grade_structure {
|
||||
$context['feedback'] = !empty($grade->feedback) && $grade->load_grade_item()->gradetype != GRADE_TYPE_TEXT;
|
||||
}
|
||||
|
||||
// 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')) {
|
||||
if ($element['object'] instanceof grade_category) {
|
||||
$context['classes'] = 'category_grade_icons';
|
||||
$context['locked'] = false;
|
||||
|
||||
$children = $element['object']->get_children(true);
|
||||
$alllocked = true;
|
||||
foreach ($children as $child) {
|
||||
if (!$child['object']->is_locked()) {
|
||||
$alllocked = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if ($alllocked) {
|
||||
$context['locked'] = true;
|
||||
}
|
||||
} else {
|
||||
$context['locked'] = $element['object']->is_locked();
|
||||
}
|
||||
|
||||
return $OUTPUT->render_from_template('core_grades/status_icons', $context);
|
||||
// Don't even attempt rendering if there is no status to show.
|
||||
if (in_array(true, $context)) {
|
||||
return $OUTPUT->render_from_template('core_grades/status_icons', $context);
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2655,6 +2683,7 @@ class grade_structure {
|
||||
}
|
||||
$context->editurl = $this->get_edit_link($element, $gpr);
|
||||
$context->hideurl = $this->get_hiding_link($element, $gpr);
|
||||
$context->lockurl = $this->get_locking_link($element, $gpr);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user