MDL-34931 core_grade: Fixed grades hidden when activity is hidden
This commit is contained in:
+13
-11
@@ -339,23 +339,25 @@ class grade_report_user extends grade_report {
|
||||
$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').']';
|
||||
|
||||
+17
-3
@@ -1003,17 +1003,31 @@ class cm_info extends stdClass {
|
||||
}
|
||||
// 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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user