Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-34931 core_grade: Fixed grades hidden when activity is hidden

  • Loading branch information...
commit 7765e94f5edb3e305c7e9aedad54ca43e9cc3a9f 1 parent 9273bd1
Frédéric Massart FMCorz authored
Showing with 30 additions and 14 deletions.
  1. +13 −11 grade/report/user/lib.php
  2. +17 −3 lib/modinfolib.php
24 grade/report/user/lib.php
View
@@ -341,23 +341,25 @@ private function fill_table_recursive(&$element) {
$hidden = ' hidden';
}
+ $hide = false;
// If this is a hidden grade item, hide it completely from the user.
if ($grade_grade->is_hidden() && !$this->canviewhidden && (
$this->showhiddenitems == GRADE_REPORT_USER_HIDE_HIDDEN ||
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
- // return false;
- } else {
- // The grade object can be marked visible but still be hidden
- // if "enablegroupmembersonly" is on and its an activity assigned to a grouping the user is not in
- if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
- $instances = $this->gtree->modinfo->get_instances();
- if (!empty($instances[$grade_object->itemmodule][$grade_object->iteminstance])) {
- $cm = $instances[$grade_object->itemmodule][$grade_object->iteminstance];
- if (!$cm->uservisible) {
- return false;
- }
+ $hide = true;
+ } else if (!empty($grade_object->itemmodule) && !empty($grade_object->iteminstance)) {
+ // The grade object can be marked visible but still be hidden if "enablegroupmembersonly"
+ // is on and it's an activity assigned to a grouping the user is not in.
+ $instances = $this->gtree->modinfo->get_instances_of($grade_object->itemmodule);
+ if (!empty($instances[$grade_object->iteminstance])) {
+ $cm = $instances[$grade_object->iteminstance];
+ if ($cm->is_user_access_restricted_by_group()) {
+ $hide = true;
}
}
+ }
+
+ if (!$hide) {
/// Excluded Item
if ($grade_grade->is_excluded()) {
$fullname .= ' ['.get_string('excluded', 'grades').']';
20 lib/modinfolib.php
View
@@ -1095,17 +1095,31 @@ private function update_user_visible() {
}
// Check group membership. The grouping option makes the activity
// completely invisible as it does not apply to the user at all.
+ if ($this->is_user_access_restricted_by_group()) {
+ $this->uservisible = false;
+ // Ensure activity is completely hidden from user.
+ $this->showavailability = 0;
+ }
+ }
+
+ /**
+ * Checks whether the module group settings restrict the user access.
+ * @return bool true if the user access is restricted
+ */
+ public function is_user_access_restricted_by_group() {
+ global $CFG;
+ $modcontext = context_module::instance($this->id);
+ $userid = $this->modinfo->get_user_id();
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly)
and !has_capability('moodle/site:accessallgroups', $modcontext, $userid)) {
// If the activity has 'group members only' and you don't have accessallgroups...
$groups = $this->modinfo->get_groups($this->groupingid);
if (empty($groups)) {
// ...and you don't belong to a group, then set it so you can't see/access it
- $this->uservisible = false;
- // Ensure activity is completely hidden from user.
- $this->showavailability = 0;
+ return true;
}
}
+ return false;
}
/**
Please sign in to comment.
Something went wrong with that request. Please try again.