Skip to content

Commit

Permalink
Fix agenda visibility when using groups see BT#11972
Browse files Browse the repository at this point in the history
  • Loading branch information
jmontoyaa committed May 19, 2017
1 parent 12af7e8 commit ee8b908
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 70 deletions.
2 changes: 1 addition & 1 deletion main/calendar/agenda_js.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@
$form = new FormValidator(
'form',
'get',
null,
api_get_self().'?'.api_get_cidreq(),
null,
array('id' => 'add_event_form')
);
Expand Down
95 changes: 26 additions & 69 deletions main/inc/lib/agenda.lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -1662,61 +1662,33 @@ public function getCourseEvents(

$group_memberships = [];
if (!empty($groupId)) {
if (!api_is_allowed_to_edit()) {
$user_id = api_get_user_id();
$group_memberships = GroupManager::get_group_ids(
$course_id,
$user_id
);
$group_memberships = array($groupId);
} else {
if (api_is_allowed_to_edit()) {
// Getting all groups
$groupList = GroupManager::get_group_list(null, $courseInfo['code']);
if (!empty($groupList)) {
$group_memberships = array_column($groupList, 'id');
}
} else {
// get only related groups from user
$group_memberships = GroupManager::get_group_ids(
$course_id,
$user_id
);
}
} else {
// if no group was defined but I am a student reviewing his agenda,
// group events should show, so we should fetch those groups to which
// I belong
if (!api_is_allowed_to_edit()) {
$user_id = api_get_user_id();
$group_memberships = GroupManager::get_group_ids(
$course_id,
$user_id
);
} else {
if (empty($user_id)) {
// If no group was defined and I am a teacher/admin reviewing
// someone else's agenda, we should fetch all groups
$groupList = GroupManager::get_group_list();
if (!empty($groupList)) {
$group_memberships = array_column($groupList, 'id');
}
}
}
}

$tlb_course_agenda = Database::get_course_table(TABLE_AGENDA);
$tbl_property = Database::get_course_table(TABLE_ITEM_PROPERTY);

if (!empty($groupId)) {
$group_memberships = array($groupId);
}

if (is_array($group_memberships) && count($group_memberships) > 0) {
if (api_is_allowed_to_edit()) {
if (!empty($groupId)) {
$where_condition = "( ip.to_group_id IN (".implode(", ", $group_memberships).") ) ";
} else {
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(", ", $group_memberships).")) ) ";
} else {
$where_condition = "( ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
}
}
if (empty($user_id)) {
$where_condition = "( ip.to_group_id IN (0, ".implode(", ", $group_memberships).") ) ";
} else {
$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).")) ) ";
}
//var_dump($where_condition);

if (empty($session_id)) {
$sessionCondition = "
Expand Down Expand Up @@ -1748,22 +1720,21 @@ public function getCourseEvents(
WHERE
$where_condition AND
ip.visibility = '1' AND
agenda.c_id = $course_id AND
ip.c_id = agenda.c_id AND
agenda.c_id = $course_id AND
$sessionCondition
";
} else {
$visibilityCondition = " ip.visibility='1' AND ";

if (api_is_allowed_to_edit()) {
if ($user_id == 0) {
if (empty($user_id)) {
$where_condition = '';
} else {
$where_condition = " (ip.to_user_id = ".$user_id." OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL AND ";
$where_condition = " (ip.to_user_id = ".$user_id.") AND ip.to_group_id IS NULL AND ";
}
$visibilityCondition = " (ip.visibility IN ('1', '0')) AND ";
} else {
$where_condition = " ( (ip.to_user_id = ".api_get_user_id()." OR ip.to_user_id IS NULL) AND ip.to_group_id IS NULL) AND ";
$where_condition = " ( (ip.to_user_id = ".api_get_user_id().") AND ip.to_group_id IS NULL) AND ";
}

if (empty($session_id)) {
Expand Down Expand Up @@ -1799,7 +1770,6 @@ public function getCourseEvents(
}

$dateCondition = null;

if (!empty($start) && !empty($end)) {
$dateCondition .= "AND (
agenda.start_date BETWEEN '".$start."' AND '".$end."' OR
Expand All @@ -1817,10 +1787,7 @@ public function getCourseEvents(

$coachCanEdit = false;
if (!empty($session_id)) {
$coachCanEdit = api_is_coach(
$session_id,
$course_id
) || api_is_platform_admin();
$coachCanEdit = api_is_coach($session_id, $course_id) || api_is_platform_admin();
}

if (Database::num_rows($result)) {
Expand Down Expand Up @@ -2922,19 +2889,15 @@ public function displayActions($view, $filter = 0)
}

$actionsLeft = '';
$actionsLeft .= "<a href='".api_get_path(
WEB_CODE_PATH
)."calendar/agenda_js.php?type={$this->type}&".$courseCondition."'>".
$actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_js.php?type={$this->type}&".$courseCondition."'>".
Display::return_icon(
'calendar.png',
get_lang('Calendar'),
'',
ICON_SIZE_MEDIUM
)."</a>";

$actionsLeft .= "<a href='".api_get_path(
WEB_CODE_PATH
)."calendar/agenda_list.php?type={$this->type}&".$courseCondition."'>".
$actionsLeft .= "<a href='".api_get_path(WEB_CODE_PATH)."calendar/agenda_list.php?type={$this->type}&".$courseCondition."'>".
Display::return_icon(
'week.png',
get_lang('AgendaList'),
Expand All @@ -2947,11 +2910,11 @@ public function displayActions($view, $filter = 0)
(api_get_course_setting('allow_user_edit_agenda') && !api_is_anonymous()) &&
api_is_allowed_to_session_edit(false, true) ||
(GroupManager::user_has_access(
api_get_user_id(),
$groupIid,
GroupManager::GROUP_TOOL_CALENDAR
) &&
GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo))
api_get_user_id(),
$groupIid,
GroupManager::GROUP_TOOL_CALENDAR
) &&
GroupManager::is_tutor_of_group(api_get_user_id(), $groupInfo))
) {
$actionsLeft .= Display::url(
Display::return_icon(
Expand All @@ -2960,10 +2923,7 @@ public function displayActions($view, $filter = 0)
'',
ICON_SIZE_MEDIUM
),
api_get_path(
WEB_CODE_PATH
)."calendar/agenda.php?".api_get_cidreq(
)."&action=add&type=".$this->type
api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=add&type=".$this->type
);

$actionsLeft .= Display::url(
Expand All @@ -2973,10 +2933,7 @@ public function displayActions($view, $filter = 0)
'',
ICON_SIZE_MEDIUM
),
api_get_path(
WEB_CODE_PATH
)."calendar/agenda.php?".api_get_cidreq(
)."&action=importical&type=".$this->type
api_get_path(WEB_CODE_PATH)."calendar/agenda.php?".api_get_cidreq()."&action=importical&type=".$this->type
);

if ($this->type === 'course') {
Expand Down

0 comments on commit ee8b908

Please sign in to comment.