From e6ea2e72f4363274b2c334f4e1041ff70ac1146a Mon Sep 17 00:00:00 2001 From: Mark Nelson Date: Tue, 17 Aug 2021 20:13:34 +0800 Subject: [PATCH] MDL-49202 core_grades: perform same action on categories in form When you click on 'Edit' then 'Hide' on a grade item like a course category that contains many grade items, the course and the grade items are set to hidden. However, if you use the 'hidden' option on the 'Edit settings' page it only hides that item and none of the items (assignment etc) under that course category. We want them to be consistent. --- grade/edit/tree/lib.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/grade/edit/tree/lib.php b/grade/edit/tree/lib.php index bcc79b43822..8e1be55d653 100644 --- a/grade/edit/tree/lib.php +++ b/grade/edit/tree/lib.php @@ -683,11 +683,15 @@ class grade_edit_tree { $gradeitem->grademin, $gradeitem->grademax, 'gradebook'); } - // Update hiding flag. - if ($hiddenuntil) { - $gradeitem->set_hidden($hiddenuntil, false); - } else { - $gradeitem->set_hidden($hidden, false); + // Only update the category's 'hidden' status if it has changed. Leaving a category as 'unhidden' (checkbox left + // unmarked) and submitting the form without this conditional check will result in displaying any grade items that + // are in the category, including those that were previously 'hidden'. + if (($gradecategory->get_hidden() != $hiddenuntil) || ($gradecategory->get_hidden() != $hidden)) { + if ($hiddenuntil) { + $gradecategory->set_hidden($hiddenuntil, true); + } else { + $gradecategory->set_hidden($hidden, true); + } } $gradeitem->set_locktime($locktime); // Locktime first - it might be removed when unlocking.