|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Chamilo\CoreBundle\State; |
|
6
|
|
|
|
|
7
|
|
|
use ApiPlatform\Doctrine\Orm\State\CollectionProvider; |
|
8
|
|
|
use ApiPlatform\Metadata\CollectionOperationInterface; |
|
9
|
|
|
use ApiPlatform\Metadata\Operation; |
|
10
|
|
|
use ApiPlatform\State\ProviderInterface; |
|
11
|
|
|
use Chamilo\CoreBundle\ApiResource\CalendarEvent; |
|
12
|
|
|
use Chamilo\CoreBundle\Entity\AccessUrl; |
|
13
|
|
|
use Chamilo\CoreBundle\Entity\User; |
|
14
|
|
|
use Chamilo\CoreBundle\Repository\SessionRepository; |
|
15
|
|
|
use Chamilo\CoreBundle\ServiceHelper\AccessUrlHelper; |
|
16
|
|
|
use Chamilo\CoreBundle\Settings\SettingsManager; |
|
17
|
|
|
use Symfony\Bundle\SecurityBundle\Security; |
|
18
|
|
|
use Symfony\Component\HttpFoundation\RequestStack; |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* @template-implements ProviderInterface<CalendarEvent[]> |
|
22
|
|
|
*/ |
|
23
|
|
|
final class CalendarEventStateProvider implements ProviderInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public function __construct( |
|
26
|
|
|
private readonly CollectionProvider $collectionProvider, |
|
27
|
|
|
private readonly Security $security, |
|
28
|
|
|
private readonly AccessUrlHelper $accessUrlService, |
|
29
|
|
|
private readonly SessionRepository $sessionRepository, |
|
30
|
|
|
private readonly RequestStack $requestStack, |
|
31
|
|
|
private readonly SettingsManager $settingsManager, |
|
32
|
|
|
) {} |
|
33
|
|
|
|
|
34
|
|
|
public function provide(Operation $operation, array $uriVariables = [], array $context = []): iterable |
|
35
|
|
|
{ |
|
36
|
|
|
/** @var User|null $user */ |
|
37
|
|
|
$user = $this->security->getUser(); |
|
38
|
|
|
|
|
39
|
|
|
$accessUrl = $this->accessUrlService->getCurrent(); |
|
40
|
|
|
|
|
41
|
|
|
if ($operation instanceof CollectionOperationInterface) { |
|
42
|
|
|
$cCalendarEvents = $this->collectionProvider->provide($operation, $uriVariables, $context); |
|
43
|
|
|
$userSessions = []; |
|
44
|
|
|
|
|
45
|
|
|
$request = $this->requestStack->getMainRequest(); |
|
46
|
|
|
$courseId = $request->query->getInt('cid'); |
|
47
|
|
|
$sessionId = $request->query->getInt('sid'); |
|
48
|
|
|
|
|
49
|
|
|
$inCourseBase = !empty($courseId); |
|
50
|
|
|
$inSession = !empty($sessionId); |
|
51
|
|
|
$inCourseSession = $inCourseBase && $inSession; |
|
52
|
|
|
|
|
53
|
|
|
$inPersonalAgenda = !$inCourseBase && !$inCourseSession; |
|
54
|
|
|
|
|
55
|
|
|
if ($inPersonalAgenda |
|
56
|
|
|
&& 'true' === $this->settingsManager->getSetting('agenda.personal_calendar_show_sessions_occupation') |
|
57
|
|
|
) { |
|
58
|
|
|
$userSessions = $this->getSessionList($user, $accessUrl, $context); |
|
59
|
|
|
} |
|
60
|
|
|
|
|
61
|
|
|
return array_merge($cCalendarEvents, $userSessions); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
return null; |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
private function getSessionList(User $user, AccessUrl $accessUrl, array $context = []): array |
|
68
|
|
|
{ |
|
69
|
|
|
$qb = $this->sessionRepository->getUserFollowedSessionsInAccessUrl($user, $accessUrl); |
|
70
|
|
|
|
|
71
|
|
|
if (!empty($context['filters']['startDate']['before'])) { |
|
72
|
|
|
$qb |
|
73
|
|
|
->andWhere($qb->expr()->lte('s.displayStartDate', ':value_start')) |
|
74
|
|
|
->setParameter('value_start', $context['filters']['startDate']['before']) |
|
75
|
|
|
; |
|
76
|
|
|
} |
|
77
|
|
|
|
|
78
|
|
|
if (!empty($context['filters']['startDate']['after'])) { |
|
79
|
|
|
$qb |
|
80
|
|
|
->andWhere($qb->expr()->gte('s.displayStartDate', ':value_start')) |
|
81
|
|
|
->setParameter('value_start', $context['filters']['startDate']['after']) |
|
82
|
|
|
; |
|
83
|
|
|
} |
|
84
|
|
|
|
|
85
|
|
|
if (!empty($context['filters']['startDate']['strictly_before'])) { |
|
86
|
|
|
$qb |
|
87
|
|
|
->andWhere($qb->expr()->lt('s.displayStartDate', ':value_start')) |
|
88
|
|
|
->setParameter('value_start', $context['filters']['startDate']['strictly_before']) |
|
89
|
|
|
; |
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
if (!empty($context['filters']['startDate']['strictly_after'])) { |
|
93
|
|
|
$qb |
|
94
|
|
|
->andWhere($qb->expr()->gt('s.displayStartDate', ':value_start')) |
|
95
|
|
|
->setParameter('value_start', $context['filters']['startDate']['strictly_after']) |
|
96
|
|
|
; |
|
97
|
|
|
} |
|
98
|
|
|
|
|
99
|
|
|
if (!empty($context['filters']['endDate']['before'])) { |
|
100
|
|
|
$qb |
|
101
|
|
|
->andWhere($qb->expr()->lte('s.displayEndDate', ':value_end')) |
|
102
|
|
|
->setParameter('value_end', $context['filters']['endDate']['before']) |
|
103
|
|
|
; |
|
104
|
|
|
} |
|
105
|
|
|
|
|
106
|
|
|
if (!empty($context['filters']['endDate']['after'])) { |
|
107
|
|
|
$qb |
|
108
|
|
|
->andWhere($qb->expr()->gte('s.displayEndDate', ':value_end')) |
|
109
|
|
|
->setParameter('value_end', $context['filters']['endDate']['after']) |
|
110
|
|
|
; |
|
111
|
|
|
} |
|
112
|
|
|
|
|
113
|
|
|
if (!empty($context['filters']['endDate']['strictly_before'])) { |
|
114
|
|
|
$qb |
|
115
|
|
|
->andWhere($qb->expr()->lt('s.displayEndDate', ':value_end')) |
|
116
|
|
|
->setParameter('value_end', $context['filters']['endDate']['strictly_before']) |
|
117
|
|
|
; |
|
118
|
|
|
} |
|
119
|
|
|
|
|
120
|
|
|
if (!empty($context['filters']['endDate']['strictly_after'])) { |
|
121
|
|
|
$qb |
|
122
|
|
|
->andWhere($qb->expr()->gt('s.displayEndDate', ':value_end')) |
|
123
|
|
|
->setParameter('value_end', $context['filters']['endDate']['strictly_after']) |
|
124
|
|
|
; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
return $qb->getQuery()->getResult(); |
|
128
|
|
|
} |
|
129
|
|
|
} |
|
130
|
|
|
|