Calendar: Fix filter for events with careers/promotion - refs BT#19497

pull/4204/head
Angel Fernando Quiroz Campos 3 years ago
parent 7b7819a4d6
commit 3f81b09da2
  1. 17
      main/inc/lib/agenda.lib.php
  2. 98
      main/inc/lib/system_announcements.lib.php

@ -2371,6 +2371,10 @@ class Agenda
$result = Database::query($sql);
$my_events = [];
if (Database::num_rows($result)) {
$allowCareersInGlobalAgenda = api_get_configuration_value('allow_careers_in_global_agenda');
$userId = api_get_user_id();
$userVisibility = SystemAnnouncementManager::getCurrentUserVisibility();
while ($row = Database::fetch_array($result, 'ASSOC')) {
$event = [];
$event['id'] = 'platform_'.$row['id'];
@ -2399,10 +2403,21 @@ class Agenda
$event['has_children'] = 0;
$event['description'] = $row['content'];
if (api_get_configuration_value('allow_careers_in_global_agenda')) {
if ($allowCareersInGlobalAgenda) {
$event['career'] = null;
$event['promotion'] = null;
$eventIsVisibleForUser = SystemAnnouncementManager::isVisibleAnnouncementForUser(
$userId,
$userVisibility,
(int) $row['career_id'],
(int) $row['promotion_id']
);
if (false === $eventIsVisibleForUser) {
continue;
}
if (!empty($row['career_id'])) {
$careerInfo = (new Career())->get($row['career_id']);

@ -866,6 +866,58 @@ class SystemAnnouncementManager
return $data;
}
public static function isVisibleAnnouncementForUser(
int $userId,
string $userVisibility,
int $careerId,
int $promotionId
): bool {
$objPromotion = new Promotion();
$promotionList = [];
if (!empty($promotionId)) {
$promotionList[] = $promotionId;
} else {
$promotionList = $objPromotion->get_all_promotions_by_career_id($careerId);
if (!empty($promotionList)) {
$promotionList = array_column($promotionList, 'id');
}
}
foreach ($promotionList as $promotionId) {
$sessionList = SessionManager::get_all_sessions_by_promotion($promotionId);
foreach ($sessionList as $session) {
$sessionId = $session['id'];
// Check student
if (self::VISIBLE_STUDENT == $userVisibility &&
SessionManager::isUserSubscribedAsStudent($sessionId, $userId)
) {
return true;
}
if (self::VISIBLE_TEACHER == $userVisibility
&& SessionManager::user_is_general_coach($userId, $sessionId)
) {
return true;
}
// Check course coach
$coaches = SessionManager::getCoachesBySession($sessionId);
if (self::VISIBLE_TEACHER == $userVisibility
&& in_array($userId, $coaches)
) {
return true;
}
}
}
return false;
}
/**
* Displays announcements as an slideshow.
*
@ -908,52 +960,18 @@ class SystemAnnouncementManager
$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)) {
$promotionList = [];
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) {
$sessionId = $session['id'];
// Check student
if ($visible === self::VISIBLE_STUDENT &&
SessionManager::isUserSubscribedAsStudent($sessionId, $userId)
) {
$show = true;
break 2;
}
if ($visible === self::VISIBLE_TEACHER &&
SessionManager::user_is_general_coach($userId, $sessionId)
) {
$show = true;
break 2;
}
// Check course coach
$coaches = SessionManager::getCoachesBySession($sessionId);
if ($visible === self::VISIBLE_TEACHER && in_array($userId, $coaches)) {
$show = true;
break 2;
}
}
}
$show = self::isVisibleAnnouncementForUser(
$userId,
$visible,
(int) $announcement->career_id,
(int) $announcement->promotion_id
);
if (false === $show) {
continue;

Loading…
Cancel
Save