1 | <?php |
||
20 | class PerformanceEventsController extends Controller |
||
21 | { |
||
22 | const MAX_DAYS_PER_GET = 367; |
||
23 | |||
24 | /** |
||
25 | * @Get("/performanceevents") |
||
26 | * @QueryParam( |
||
27 | * name="fromDate", |
||
28 | * default="today", |
||
29 | * requirements="\d{2}-\d{2}-\d{4}|today" , |
||
30 | * description="Find entries from this date, fromat=dd-mm-yyyy" |
||
31 | * ) |
||
32 | * @QueryParam( |
||
33 | * name="toDate", |
||
34 | * default="+1 Year", |
||
35 | * requirements="\d{2}-\d{2}-\d{4}|\+1 Year", |
||
36 | * description="Find entries to this date, fromat=dd-mm-yyyy" |
||
37 | * ) |
||
38 | * @QueryParam(name="limit", description="Count of entities in collection") |
||
39 | * @QueryParam(name="performance", description="Performance slug") |
||
40 | * @QueryParam( |
||
41 | * name="locale", |
||
42 | * requirements="uk|en", |
||
43 | * default="uk", |
||
44 | * description="Selects language of data you want to receive" |
||
45 | * ) |
||
46 | * |
||
47 | * @RestView |
||
48 | */ |
||
49 | 5 | public function cgetAction(ParamFetcher $paramFetcher) |
|
50 | { |
||
51 | 5 | $em = $this->getDoctrine()->getManager(); |
|
52 | |||
53 | 5 | $dateDiff = strtotime($paramFetcher->get('toDate')) - strtotime($paramFetcher->get('fromDate')); |
|
54 | |||
55 | 5 | if (self::MAX_DAYS_PER_GET < abs(floor($dateDiff/(60*60*24)))) { |
|
56 | throw new BadRequestHttpException(sprintf('You can\'t get more than "%s" days', self::MAX_DAYS_PER_GET)); |
||
57 | } |
||
58 | |||
59 | 5 | $performanceEvents = $em->getRepository('AppBundle:PerformanceEvent') |
|
60 | 5 | ->findByDateRangeAndSlug( |
|
61 | 5 | new \DateTime($paramFetcher->get('fromDate')), |
|
62 | 5 | new \DateTime($paramFetcher->get('toDate')), |
|
63 | 5 | $paramFetcher->get('limit'), |
|
64 | 5 | $paramFetcher->get('performance') |
|
65 | ) |
||
66 | ; |
||
67 | |||
68 | 5 | $performanceEventsTranslated = []; |
|
69 | |||
70 | 5 | foreach ($performanceEvents as $performanceEvent) { |
|
71 | |||
72 | /** @var PerformanceEvent $performanceEvent */ |
||
73 | 5 | $performanceEvent->setLocale($paramFetcher->get('locale')); |
|
74 | 5 | $em->refresh($performanceEvent); |
|
75 | |||
76 | 5 | $performanceEvent->getPerformance()->setLocale($paramFetcher->get('locale')); |
|
77 | 5 | $em->refresh($performanceEvent->getPerformance()); |
|
78 | |||
79 | 5 | $performanceEvent->getVenue()->setLocale($paramFetcher->get('locale')); |
|
80 | 5 | $em->refresh($performanceEvent->getVenue()); |
|
81 | |||
82 | 5 | if ($performanceEvent->getTranslations()) { |
|
83 | 5 | $performanceEvent->unsetTranslations(); |
|
84 | } |
||
85 | |||
86 | 5 | if ($performanceEvent->getPerformance()->getTranslations()) { |
|
87 | 5 | $performanceEvent->getPerformance()->unsetTranslations(); |
|
88 | } |
||
89 | |||
90 | 5 | if ($performanceEvent->getVenue()->getTranslations()) { |
|
91 | 5 | $performanceEvent->getVenue()->unsetTranslations(); |
|
92 | } |
||
93 | 5 | $performanceEventsTranslated[] = $performanceEvent; |
|
94 | } |
||
95 | |||
96 | 5 | $performanceEvents = $performanceEventsTranslated; |
|
97 | |||
98 | 5 | $performanceEventsResponse = new PerformanceEventsResponse(); |
|
99 | 5 | $performanceEventsResponse->setPerformanceEvents($performanceEvents); |
|
100 | |||
101 | 5 | return $performanceEventsResponse; |
|
102 | } |
||
103 | |||
104 | /** |
||
105 | * @Get("/performanceevents/{id}", requirements={"id" = "\d+"}) |
||
106 | * @ParamConverter("performanceEvent", class="AppBundle:PerformanceEvent") |
||
107 | * @QueryParam( |
||
108 | * name="locale", |
||
109 | * requirements="uk|en", |
||
110 | * default="uk", |
||
111 | * description="Selects language of data you want to receive" |
||
112 | * ) |
||
113 | * @QueryParam( |
||
114 | * name="id", |
||
115 | * requirements="\d+", |
||
116 | * description="PerformanceEvent ID" |
||
117 | * ) |
||
118 | * @RestView |
||
119 | */ |
||
120 | 1 | public function getAction(ParamFetcher $paramFetcher, PerformanceEvent $performanceEvent) |
|
147 | |||
148 | /** |
||
149 | * @Get("/performanceevents/{id}/tickets", requirements={"id" = "\d+"}) |
||
150 | * @RestView(serializerGroups={"get_ticket"}) |
||
151 | * @ParamConverter("performanceEvent", class="AppBundle:PerformanceEvent") |
||
152 | */ |
||
153 | 1 | public function cgetTicketsAction(PerformanceEvent $performanceEvent) |
|
162 | |||
163 | |||
164 | /** |
||
165 | * @Get("/performanceevents/{id}/pricecategories", requirements={"id" = "\d+"}) |
||
166 | * @RestView |
||
167 | * @ParamConverter("performanceEvent", class="AppBundle:PerformanceEvent") |
||
168 | * @QueryParam( |
||
169 | * name="locale", |
||
170 | * requirements="uk|en", |
||
171 | * default="uk", |
||
172 | * description="Selects language of data you want to receive" |
||
173 | * ) |
||
174 | * @QueryParam( |
||
175 | * name="id", |
||
176 | * requirements="\d+", |
||
177 | * description="PerformanceEvent ID" |
||
178 | * ) |
||
179 | */ |
||
180 | 1 | public function getPriceCategoriesAction(ParamFetcher $paramFetcher, PerformanceEvent $performanceEvent) |
|
196 | } |
||
197 |