diff --git a/public/main/forum/index.php b/public/main/forum/index.php index a60cee1d84..f3d0ef0d57 100644 --- a/public/main/forum/index.php +++ b/public/main/forum/index.php @@ -247,7 +247,10 @@ if (!empty($allCourseForums)) { $actions = Display::toolbarAction('toolbar-forum', [$actionLeft]); $languages = api_get_language_list_for_flag(); -$defaultUserLanguage = $user->getLocale(); +$defaultUserLanguage = 'en'; +if (null !== $user) { + $defaultUserLanguage = $user->getLocale(); +} $extraFieldValues = new ExtraFieldValue('user'); $value = $extraFieldValues->get_values_by_handler_and_field_variable(api_get_user_id(), 'langue_cible'); diff --git a/public/main/inc/lib/AnnouncementManager.php b/public/main/inc/lib/AnnouncementManager.php index f175a63385..8b4370371e 100644 --- a/public/main/inc/lib/AnnouncementManager.php +++ b/public/main/inc/lib/AnnouncementManager.php @@ -1386,264 +1386,14 @@ class AnnouncementManager if (api_is_allowed_to_edit(false, true)) { $qb = $repo->getResourcesByCourse($course, $session, $group); } else { - $qb = $repo->getResourcesByCourseLinkedToUser(api_get_user_entity(), $course, $session, $group); - } - - $announcements = $qb->getQuery()->getResult(); - - /* - $allowUserEditSetting = api_get_course_setting('allow_user_edit_announcement'); - - $select = ' DISTINCT - announcement.*, - ip.visibility, - ip.to_group_id, - ip.insert_user_id, - ip.insert_date, - ip.lastedit_date'; - $groupBy = ' GROUP BY announcement.iid'; - if ($getCount) { - $groupBy = ''; - $select = ' COUNT(DISTINCT announcement.iid) count'; - } - - $searchCondition = ''; - if (!empty($titleToSearch)) { - $titleToSearch = Database::escape_string($titleToSearch); - $searchCondition .= " AND (title LIKE '%$titleToSearch%')"; - } - - if (!empty($userIdToSearch)) { - $userIdToSearch = (int) $userIdToSearch; - $searchCondition .= " AND (ip.insert_user_id = $userIdToSearch)"; - } - - $allowOnlyGroup = api_get_configuration_value('hide_base_course_announcements_in_group'); - $extraGroupCondition = ''; - if ($allowOnlyGroup) { - $extraGroupCondition = " AND ip.to_group_id = $group_id "; - } - - $allowDrhAccess = api_get_configuration_value('allow_drh_access_announcement'); - - if ($allowDrhAccess && api_is_drh()) { - // DRH only can see visible - $searchCondition .= ' AND (ip.visibility = 1)'; - } - - if (api_is_allowed_to_edit(false, true) || - ($allowUserEditSetting && !api_is_anonymous()) || - ($allowDrhAccess && api_is_drh()) - ) { - // A.1. you are a course admin with a USER filter - // => see only the messages of this specific user + the messages of the group (s)he is member of. - //if (!empty($user_id)) { - if (0) { - if (is_array($group_memberships) && - count($group_memberships) > 0 - ) { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND ip.c_id = announcement.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool = 'announcement' AND - ( - ip.to_user_id = $user_id OR - ip.to_group_id IS NULL OR - ip.to_group_id IN (0, ".implode(", ", $group_memberships).") - ) AND - ip.visibility IN ('1', '0') - $condition_session - $searchCondition - ORDER BY display_order DESC"; - } else { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND ip.c_id = announcement.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool ='announcement' AND - (ip.to_user_id = $user_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) AND - ip.visibility IN ('1', '0') - $condition_session - $searchCondition - ORDER BY display_order DESC"; - } - } elseif ($group_id != 0) { - // A.2. you are a course admin with a GROUP filter - // => see only the messages of this specific group - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool='announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.visibility<>'2' AND - (ip.to_group_id = $group_id OR ip.to_group_id='0' OR ip.to_group_id IS NULL) - $condition_session - $searchCondition - $extraGroupCondition - $groupBy - ORDER BY display_order DESC"; - } else { - // A.3 you are a course admin without any group or user filter - // A.3.a you are a course admin without user or group filter but WITH studentview - // => see all the messages of all the users and groups without editing possibilities - if (isset($isStudentView) && $isStudentView == 'true') { - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool='announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.visibility='1' - $condition_session - $searchCondition - $groupBy - ORDER BY display_order DESC"; - } else { - // A.3.a you are a course admin without user or group filter and WTIHOUT studentview (= the normal course admin view) - // => see all the messages of all the users and groups with editing possibilities - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - ip.tool = 'announcement' AND - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - (ip.visibility='0' OR ip.visibility='1') - $condition_session - $searchCondition - $groupBy - ORDER BY display_order DESC"; - } - } - } else { - // STUDENT - if (is_array($group_memberships) && count($group_memberships) > 0) { - if ($allowUserEditSetting && !api_is_anonymous()) { - if ($group_id == 0) { - // No group - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) OR - (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) - ) - ) "; - } else { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.") - )"; - $cond_user_id .= $extraGroupCondition; - } - } else { - if ($group_id == 0) { - $cond_user_id = " AND ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND - (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".implode(", ", $group_memberships).")) - ) "; - } else { - $cond_user_id = " AND ( - (ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND - (ip.to_group_id IS NULL OR ip.to_group_id IN (0, ".$group_id.")) - )"; - $cond_user_id .= $extraGroupCondition; - } - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement INNER JOIN - $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition AND - ip.visibility='1' - $groupBy - ORDER BY display_order DESC"; - } else { - if ($user_id) { - if ($allowUserEditSetting && !api_is_anonymous()) { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".api_get_user_id()."' OR - ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND - (ip.to_group_id='0' OR ip.to_group_id IS NULL) - ) - ) "; - } else { - $cond_user_id = " AND ((ip.to_user_id='$user_id' OR ip.to_user_id IS NULL) AND - (ip.to_group_id='0' OR ip.to_group_id IS NULL) ) "; - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition - AND ip.visibility='1' - AND announcement.session_id IN(0, ".$session_id.") - $groupBy - ORDER BY display_order DESC"; - } else { - if (($allowUserEditSetting && !api_is_anonymous())) { - $cond_user_id = " AND ( - ip.lastedit_user_id = '".$user_id."' OR ip.to_group_id='0' OR ip.to_group_id IS NULL - )"; - } else { - $cond_user_id = " AND ip.to_group_id='0' OR ip.to_group_id IS NULL "; - } - - $sql = "SELECT $select - FROM $tbl_announcement announcement - INNER JOIN $tbl_item_property ip - ON (announcement.id = ip.ref AND announcement.c_id = ip.c_id) - WHERE - announcement.c_id = $courseId AND - ip.c_id = $courseId AND - ip.tool='announcement' - $cond_user_id - $condition_session - $searchCondition AND - ip.visibility='1' AND - announcement.session_id IN ( 0,".api_get_session_id().") - $groupBy - "; - } + $user = api_get_user_entity(); + if (null === $user) { + return []; } + $qb = $repo->getResourcesByCourseLinkedToUser($user, $course, $session, $group); } - if (!is_null($start) && !is_null($limit)) { - $start = (int) $start; - $limit = (int) $limit; - $sql .= " LIMIT $start, $limit"; - } - - $result = Database::query($sql); - if ($getCount) { - $result = Database::fetch_array($result, 'ASSOC'); - - return $result['count']; - }*/ + $announcements = $qb->getQuery()->getResult(); $iterator = 1; $bottomAnnouncement = $announcement_number;