MDL-35762 core_grade: altered the code that determines whether an activity is visible on the user report
This commit is contained in:
committed by
Eloy Lafuente (stronk7)
parent
d46929e4e3
commit
47ae6d3fc9
@@ -346,13 +346,17 @@ class grade_report_user extends grade_report {
|
||||
($this->showhiddenitems == GRADE_REPORT_USER_HIDE_UNTIL && !$grade_grade->is_hiddenuntil()))) {
|
||||
$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.
|
||||
// The grade object can be marked visible but still be hidden if...
|
||||
// 1) "enablegroupmembersonly" is on and the activity is assigned to a grouping the user is not in.
|
||||
// 2) the student cannot see the activity due to conditional access and its set to be hidden entirely.
|
||||
$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 (!$cm->uservisible) {
|
||||
// Further checks are required to determine whether the activity is entirely hidden or just greyed out.
|
||||
if ($cm->is_user_access_restricted_by_group() || $cm->is_user_access_restricted_by_conditional_access()) {
|
||||
$hide = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+61
-20
@@ -985,8 +985,12 @@ class cm_info extends stdClass {
|
||||
}
|
||||
|
||||
/**
|
||||
* Works out whether activity is visible *for current user* - if this is false, they
|
||||
* aren't allowed to access it.
|
||||
* Works out whether activity is available to the current user
|
||||
*
|
||||
* If the activity is unavailable, additional checks are required to determine if its hidden or greyed out
|
||||
*
|
||||
* @see is_user_access_restricted_by_group()
|
||||
* @see is_user_access_restricted_by_conditional_access()
|
||||
* @return void
|
||||
*/
|
||||
private function update_user_visible() {
|
||||
@@ -994,42 +998,79 @@ class cm_info extends stdClass {
|
||||
$modcontext = get_context_instance(CONTEXT_MODULE, $this->id);
|
||||
$userid = $this->modinfo->get_user_id();
|
||||
$this->uservisible = true;
|
||||
// Check visibility/availability conditions.
|
||||
|
||||
// If the user cannot access the activity set the uservisible flag to false.
|
||||
// Additional checks are required to determine whether the activity is entirely hidden or just greyed out.
|
||||
if ((!$this->visible or !$this->available) and
|
||||
!has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
|
||||
// If the activity is hidden or unavailable, and you don't have viewhiddenactivities,
|
||||
// set it so that user can't see or access it.
|
||||
|
||||
$this->uservisible = false;
|
||||
}
|
||||
// Check group membership. The grouping option makes the activity
|
||||
// completely invisible as it does not apply to the user at all.
|
||||
|
||||
// Check group membership.
|
||||
if ($this->is_user_access_restricted_by_group()) {
|
||||
$this->uservisible = false;
|
||||
// Ensure activity is completely hidden from user.
|
||||
|
||||
$this->uservisible = false;
|
||||
// Ensure activity is completely hidden from the user.
|
||||
$this->showavailability = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the module group settings restrict the user access.
|
||||
* @return bool true if the user access is restricted
|
||||
* Checks whether the module's group settings restrict the current user's 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
|
||||
return true;
|
||||
|
||||
if (!empty($CFG->enablegroupmembersonly) and !empty($this->groupmembersonly)) {
|
||||
$modcontext = context_module::instance($this->id);
|
||||
$userid = $this->modinfo->get_user_id();
|
||||
if (!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
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks whether the module's conditional access settings mean that the user cannot see the activity at all
|
||||
*
|
||||
* @return bool True if the user cannot see the module. False if the activity is either available or should be greyed out.
|
||||
*/
|
||||
public function is_user_access_restricted_by_conditional_access() {
|
||||
global $CFG, $USER;
|
||||
|
||||
if (empty($CFG->enableavailability)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// If module will always be visible anyway (but greyed out), don't bother checking anything else
|
||||
if ($this->showavailability == CONDITION_STUDENTVIEW_SHOW) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Can the user see hidden modules?
|
||||
$modcontext = context_module::instance($this->id);
|
||||
$userid = $this->modinfo->get_user_id();
|
||||
if (has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Is the module hidden due to unmet conditions?
|
||||
if (!$this->available) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Calls a module function (if exists), passing in one parameter: this object.
|
||||
* @param string $type Name of function e.g. if this is 'grooblezorb' and the modname is
|
||||
|
||||
Reference in New Issue
Block a user