mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-08-25 17:13:49 +00:00
proxy: do not show calendar events when they are present in database
This commit is contained in:
@@ -17,6 +17,7 @@ use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\MapCalendarToUser;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserHttpClient;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\OnBehalfOfUserTokenStorage;
|
||||
use Chill\CalendarBundle\RemoteCalendar\Connector\MSGraph\RemoteEventConverter;
|
||||
use Chill\CalendarBundle\Repository\CalendarRangeRepository;
|
||||
use Chill\MainBundle\Entity\User;
|
||||
use DateTimeImmutable;
|
||||
use Psr\Log\LoggerInterface;
|
||||
@@ -27,6 +28,8 @@ use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
|
||||
|
||||
class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
{
|
||||
private CalendarRangeRepository $calendarRangeRepository;
|
||||
|
||||
private LoggerInterface $logger;
|
||||
|
||||
private MachineHttpClient $machineHttpClient;
|
||||
@@ -42,6 +45,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
private OnBehalfOfUserHttpClient $userHttpClient;
|
||||
|
||||
public function __construct(
|
||||
CalendarRangeRepository $calendarRangeRepository,
|
||||
MachineHttpClient $machineHttpClient,
|
||||
MapCalendarToUser $mapCalendarToUser,
|
||||
LoggerInterface $logger,
|
||||
@@ -50,6 +54,7 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
RemoteEventConverter $remoteEventConverter,
|
||||
UrlGeneratorInterface $urlGenerator
|
||||
) {
|
||||
$this->calendarRangeRepository = $calendarRangeRepository;
|
||||
$this->machineHttpClient = $machineHttpClient;
|
||||
$this->mapCalendarToUser = $mapCalendarToUser;
|
||||
$this->logger = $logger;
|
||||
@@ -91,7 +96,21 @@ class MSGraphRemoteCalendarConnector implements RemoteCalendarConnectorInterface
|
||||
]
|
||||
)->toArray();
|
||||
|
||||
return array_map(function ($item) { return $this->remoteEventConverter->convertToRemote($item); }, $bareEvents['value']);
|
||||
$ids = array_map(function ($item) { return $item['id']; }, $bareEvents['value']);
|
||||
$existingIdsInRange = $this->calendarRangeRepository->findRemoteIdsPresent($ids);
|
||||
|
||||
return array_map(
|
||||
function ($item) {
|
||||
return $this->remoteEventConverter->convertToRemote($item);
|
||||
},
|
||||
// filter all event to keep only the one not in range
|
||||
array_filter(
|
||||
$bareEvents['value'],
|
||||
function ($item) use ($existingIdsInRange) {
|
||||
return (!$existingIdsInRange[$item['id']]) ?? true;
|
||||
}
|
||||
)
|
||||
);
|
||||
} catch (ClientExceptionInterface $e) {
|
||||
if (403 === $e->getResponse()->getStatusCode()) {
|
||||
return $this->getScheduleTimesForUser($user, $startDate, $endDate);
|
||||
|
Reference in New Issue
Block a user