Skip to content

Commit

Permalink
Merge branch 'MDL-34931-23' of git://github.com/FMCorz/moodle into MO…
Browse files Browse the repository at this point in the history
…ODLE_23_STABLE
  • Loading branch information
stronk7 committed Oct 1, 2012
2 parents aa63be7 + 7765e94 commit 50e8e4d
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 14 deletions.
24 changes: 13 additions & 11 deletions grade/report/user/lib.php
Expand Up @@ -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').']';
Expand Down
20 changes: 17 additions & 3 deletions lib/modinfolib.php
Expand Up @@ -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;
}

/**
Expand Down

0 comments on commit 50e8e4d

Please sign in to comment.