Fix agenda event list view, teachers can see all events in group

Depends in filters. See BT#12671
pull/2487/head
jmontoyaa 8 years ago
parent f09483c6e9
commit f4d492c362
  1. 33
      main/inc/lib/agenda.lib.php

@ -1659,6 +1659,7 @@ class Agenda
} }
} }
$group_memberships = [];
if (!empty($groupId)) { if (!empty($groupId)) {
if (!api_is_allowed_to_edit()) { if (!api_is_allowed_to_edit()) {
$user_id = api_get_user_id(); $user_id = api_get_user_id();
@ -1683,12 +1684,14 @@ class Agenda
$user_id $user_id
); );
} else { } else {
if (empty($user_id)) {
// If no group was defined and I am a teacher/admin reviewing // If no group was defined and I am a teacher/admin reviewing
// someone else's agenda, we should fetch this person's groups // someone else's agenda, we should fetch all groups
$group_memberships = GroupManager::get_group_ids( $groupList = GroupManager::get_group_list();
$course_id, if (!empty($groupList)) {
$user_id $group_memberships = array_column($groupList, 'id');
); }
}
} }
} }
@ -1702,28 +1705,16 @@ class Agenda
if (is_array($group_memberships) && count($group_memberships) > 0) { if (is_array($group_memberships) && count($group_memberships) > 0) {
if (api_is_allowed_to_edit()) { if (api_is_allowed_to_edit()) {
if (!empty($groupId)) { if (!empty($groupId)) {
$where_condition = "( ip.to_group_id IN (".implode( $where_condition = "( ip.to_group_id IN (".implode(", ", $group_memberships).") ) ";
", ",
$group_memberships
).") ) ";
} else { } else {
if (!empty($user_id)) { if (!empty($user_id)) {
$where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode( $where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) ";
", ",
$group_memberships
).")) ) ";
} else { } else {
$where_condition = "( ip.to_group_id IN (0, ".implode( $where_condition = "( ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
", ",
$group_memberships
).") ) ";
} }
} }
} else { } else {
$where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode( $where_condition = "( ip.to_user_id = $user_id OR ip.to_user_id IS NULL OR (ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) ) ";
", ",
$group_memberships
).")) ) ";
} }
if (empty($session_id)) { if (empty($session_id)) {

Loading…
Cancel
Save