Skip to content

Commit

Permalink
Merge branch 'MDL-28557-21' of git://github.com/bostelm/moodle into M…
Browse files Browse the repository at this point in the history
…OODLE_21_STABLE
  • Loading branch information
danpoltawski committed May 25, 2012
2 parents b108e75 + a2ec78a commit 4972888
Showing 1 changed file with 32 additions and 19 deletions.
51 changes: 32 additions & 19 deletions calendar/lib.php
Expand Up @@ -1237,6 +1237,10 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {
$user = false;
$group = false;

// capabilities that allow seeing group events from all groups
// TODO: rewrite so that moodle/calendar:manageentries is not necessary here
$allgroupscaps = array('moodle/site:accessallgroups', 'moodle/calendar:manageentries');

$isloggedin = isloggedin();

if ($ignorefilters || calendar_show_event_type(CALENDAR_EVENT_COURSE)) {
Expand All @@ -1262,26 +1266,35 @@ function calendar_set_filters(array $courseeventsfrom, $ignorefilters = false) {

if (!empty($courseeventsfrom) && (calendar_show_event_type(CALENDAR_EVENT_GROUP) || $ignorefilters)) {

if (!empty($CFG->calendar_adminseesall) && has_capability('moodle/calendar:manageentries', get_system_context())) {
$group = true;
} else if ($isloggedin) {
$groupids = array();

// We already have the courses to examine in $courses
// For each course...
foreach ($courseeventsfrom as $courseid => $course) {
// If the user is an editing teacher in there,
if (!empty($USER->groupmember[$course->id])) {
// We've already cached the users groups for this course so we can just use that
$groupids = array_merge($groupids, $USER->groupmember[$course->id]);
} else if (($course->groupmode != NOGROUPS || !$course->groupmodeforce) && has_capability('moodle/calendar:manageentries', get_context_instance(CONTEXT_COURSE, $course->id))) {
// If this course has groups, show events from all of them
$coursegroups = groups_get_user_groups($course->id, $USER->id);
$groupids = array_merge($groupids, $coursegroups['0']);
}
if (count($courseeventsfrom)==1) {
$course = reset($courseeventsfrom);
if (has_any_capability($allgroupscaps, get_context_instance(CONTEXT_COURSE, $course->id))) {
$coursegroups = groups_get_all_groups($course->id, 0, 0, 'g.id');
$group = array_keys($coursegroups);
}
if (!empty($groupids)) {
$group = $groupids;
}
if ($group === false) {
if (!empty($CFG->calendar_adminseesall) && has_any_capability($allgroupscaps, get_system_context())) {
$group = true;
} else if ($isloggedin) {
$groupids = array();

// We already have the courses to examine in $courses
// For each course...
foreach ($courseeventsfrom as $courseid => $course) {
// If the user is an editing teacher in there,
if (!empty($USER->groupmember[$course->id])) {
// We've already cached the users groups for this course so we can just use that
$groupids = array_merge($groupids, $USER->groupmember[$course->id]);
} else if ($course->groupmode != NOGROUPS || !$course->groupmodeforce) {
// If this course has groups, show events from all of those related to the current user
$coursegroups = groups_get_user_groups($course->id, $USER->id);
$groupids = array_merge($groupids, $coursegroups['0']);
}
}
if (!empty($groupids)) {
$group = $groupids;
}
}
}
}
Expand Down

0 comments on commit 4972888

Please sign in to comment.