1 | <?php |
||
17 | class CalendarController extends JsonController |
||
18 | { |
||
19 | /** |
||
20 | * @Route("/schedule/events") |
||
21 | * @Method("GET") |
||
22 | * |
||
23 | * @return JsonResponse |
||
24 | */ |
||
25 | public function eventsListAction() |
||
33 | |||
34 | /** |
||
35 | * @param Request $request |
||
36 | * @Route("/schedule/event/new") |
||
37 | * @Method("POST") |
||
38 | * |
||
39 | * @return JsonResponse |
||
40 | */ |
||
41 | public function newEventAction(Request $request) |
||
65 | |||
66 | /** |
||
67 | * @param $id |
||
68 | * @Route("/schedule/event/{id}") |
||
69 | * @Method("GET") |
||
70 | * |
||
71 | * @return JsonResponse |
||
72 | */ |
||
73 | public function singleEventAction($id) |
||
83 | |||
84 | /** |
||
85 | * @Route("/api/schedule/event/user") |
||
86 | * @Method("GET") |
||
87 | * |
||
88 | * @return JsonResponse |
||
89 | */ |
||
90 | public function currentUserEventsAction() |
||
111 | |||
112 | /** |
||
113 | * @Route("/schedule/event/user/{id}") |
||
114 | * @Method("GET") |
||
115 | * |
||
116 | * @return JsonResponse |
||
117 | */ |
||
118 | public function userEventsAction(User $user) |
||
119 | { |
||
120 | $events = $user->getEvents(); |
||
121 | |||
122 | $googleEvents = []; |
||
123 | |||
124 | $calendar = $this->get('app.google_calendar'); |
||
125 | foreach ($events as $event) { |
||
126 | $googleEvents[] = $calendar |
||
127 | ->getEventById($event->getGoogleId()); |
||
128 | } |
||
129 | if (!$googleEvents) { |
||
130 | return $this->json(['error' => 'Events not found'], 404); |
||
131 | } |
||
132 | |||
133 | $user = $this->get('serializer')->normalize($user, null, ['groups' => ['Short']]); |
||
134 | |||
135 | $response = ['user' => $user, 'events' => $googleEvents]; |
||
136 | |||
137 | return new JsonResponse($response); |
||
138 | } |
||
139 | |||
140 | /** |
||
141 | * @param $id |
||
142 | * @Route("/schedule/event/{id}") |
||
143 | * @Method("DELETE") |
||
144 | * @return JsonResponse |
||
145 | */ |
||
146 | public function removeEventAction($id) |
||
153 | |||
154 | /** |
||
155 | * @param Request $request |
||
156 | * @Method("PATCH") |
||
157 | * @Route("/schedule/event/{id}") |
||
158 | * |
||
159 | * @return JsonResponse |
||
160 | */ |
||
161 | public function editEventAction(Request $request, $id) |
||
162 | { |
||
163 | $dtoEvent = new DtoEvent(); |
||
164 | $form = $this->createForm(EventType::class, $dtoEvent); |
||
165 | $this->handleJsonForm($form, $request); |
||
166 | $this->get('app.google_calendar') |
||
167 | ->editEvent($dtoEvent, $id); |
||
168 | |||
169 | return $this->json(['success' => 'Event edited']); |
||
170 | } |
||
171 | |||
172 | /** |
||
173 | * FOR DEV ONLY. |
||
174 | * |
||
175 | * @Route("/schedule/clear") |
||
176 | */ |
||
177 | public function clearAction() |
||
183 | } |
||
184 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)
or! empty(...)
instead.