Fix portal news when saving career/promotion see BT#16262

pull/3092/head
Julio 6 years ago
parent 7bb1e6b646
commit a270bbdf12
  1. 39
      main/inc/lib/system_announcements.lib.php
  2. 4
      main/inc/lib/userportal.lib.php

@ -184,7 +184,7 @@ class SystemAnnouncementManager
*/
public static function count_nb_announcement($start = 0, $user_id = '')
{
$start = intval($start);
$start = (int) $start;
$user_selected_language = api_get_interface_language();
$db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
$sql = 'SELECT id FROM '.$db_table.'
@ -830,12 +830,47 @@ class SystemAnnouncementManager
$sql .= " AND access_url_id IN ('1', '$current_url_id') ";
}
$checkCareers = api_get_configuration_value('allow_careers_in_global_announcements') === true;
$userId = api_get_user_id();
$promotion = new Promotion();
$sql .= ' ORDER BY date_start DESC';
$result = Database::query($sql);
$announcements = [];
if (Database::num_rows($result) > 0) {
while ($announcement = Database::fetch_object($result)) {
if ($checkCareers && !empty($announcement->career_id)) {
if (!empty($announcement->promotion_id)) {
$promotionList[] = $announcement->promotion_id;
} else {
$promotionList = $promotion->get_all_promotions_by_career_id($announcement->career_id);
if (!empty($promotionList)) {
$promotionList = array_column($promotionList, 'id');
}
}
$show = false;
foreach ($promotionList as $promotionId) {
$sessionList = SessionManager::get_all_sessions_by_promotion($promotionId);
foreach ($sessionList as $session) {
$status = (int) SessionManager::getUserStatusInSession($userId, $session['id']);
if ($visible === self::VISIBLE_TEACHER && $status === 2) {
$show = true;
break 2;
}
if ($visible === self::VISIBLE_STUDENT && $status === 1) {
$show = true;
break 2;
}
}
}
if (false === $show) {
continue;
}
}
$announcementData = [
'id' => $announcement->id,
'title' => $announcement->title,

@ -109,11 +109,11 @@ class IndexManager
{
$hideAnnouncements = api_get_setting('hide_global_announcements_when_not_connected');
$currentUserId = api_get_user_id();
if ($hideAnnouncements == 'true' && empty($currentUserId)) {
if ($hideAnnouncements === 'true' && empty($currentUserId)) {
return null;
}
$announcement = isset($_GET['announcement']) ? $_GET['announcement'] : null;
$announcement = intval($announcement);
$announcement = (int) $announcement;
if (!api_is_anonymous() && $this->user_id) {
$visibility = SystemAnnouncementManager::getCurrentUserVisibility();

Loading…
Cancel
Save