1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
declare(strict_types=1); |
4
|
|
|
|
5
|
|
|
namespace CalendarBundle\Controller; |
6
|
|
|
|
7
|
|
|
use CalendarBundle\CalendarEvents; |
8
|
|
|
use CalendarBundle\Event\CalendarEvent; |
9
|
|
|
use CalendarBundle\Serializer\SerializerInterface; |
10
|
|
|
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController; |
11
|
|
|
use Symfony\Component\EventDispatcher\EventDispatcherInterface; |
12
|
|
|
use Symfony\Component\HttpFoundation\Request; |
13
|
|
|
use Symfony\Component\HttpFoundation\Response; |
14
|
|
|
|
15
|
|
|
class CalendarController extends AbstractController |
16
|
|
|
{ |
17
|
|
|
/** |
18
|
|
|
* @var SerializerInterface |
19
|
|
|
*/ |
20
|
|
|
protected $serializer; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @var EventDispatcherInterface |
24
|
|
|
*/ |
25
|
|
|
protected $eventDispatcher; |
26
|
|
|
|
27
|
|
|
public function __construct( |
28
|
|
|
EventDispatcherInterface $eventDispatcher, |
29
|
|
|
SerializerInterface $serializer |
30
|
|
|
) { |
31
|
|
|
$this->eventDispatcher = $eventDispatcher; |
32
|
|
|
$this->serializer = $serializer; |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
public function loadAction(Request $request): Response |
36
|
|
|
{ |
37
|
|
|
$start = new \DateTime($request->get('start')); |
38
|
|
|
$end = new \DateTime($request->get('end')); |
39
|
|
|
$filters = $request->get('filters', '{}'); |
40
|
|
|
$filters = \is_array($filters) ? $filters : json_decode($filters, true); |
41
|
|
|
$timezone = $request->get('timeZone'); |
42
|
|
|
|
43
|
|
|
$event = $this->eventDispatcher->dispatch( |
44
|
|
|
CalendarEvents::SET_DATA, |
|
|
|
|
45
|
|
|
new CalendarEvent($start, $end, $filters, $timezone) |
|
|
|
|
46
|
|
|
); |
47
|
|
|
$content = $this->serializer->serialize($event->getEvents()); |
48
|
|
|
|
49
|
|
|
$response = new Response(); |
50
|
|
|
$response->headers->set('Content-Type', 'application/json'); |
51
|
|
|
$response->setContent($content); |
52
|
|
|
$response->setStatusCode(empty($content) ? Response::HTTP_NO_CONTENT : Response::HTTP_OK); |
53
|
|
|
|
54
|
|
|
return $response; |
55
|
|
|
} |
56
|
|
|
} |
57
|
|
|
|