Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

MDL-35762 core_grade: altered the code that determines whether an act…

…ivity is visible on the user report
  • Loading branch information...
commit 47ae6d3fc9f440e42af0829b0776e23e5feabeae 1 parent d46929e
@andyjdavis andyjdavis authored stronk7 committed
Showing with 68 additions and 23 deletions.
  1. +8 −4 grade/report/user/lib.php
  2. +60 −19 lib/modinfolib.php
View
12 grade/report/user/lib.php
@@ -346,13 +346,17 @@ private function fill_table_recursive(&$element) {
($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;
+ }
}
}
}
View
79 lib/modinfolib.php
@@ -985,8 +985,12 @@ public function obtain_dynamic_data() {
}
/**
- * 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,39 +998,76 @@ private function update_user_visible() {
$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;
+
+ 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 (!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 (has_capability('moodle/course:viewhiddenactivities', $modcontext, $userid)) {
+ return false;
}
+
+ // Is the module hidden due to unmet conditions?
+ if (!$this->available) {
+ return true;
+ }
+
return false;
}
Please sign in to comment.
Something went wrong with that request. Please try again.