- //Fetch sessions
- $sessions = $doctrine->getRepository(Session::class)->findAllByDatePeriod($period);
-
- //Init calendar
- $calendar = [];
-
- //Init month
- $month = null;
-
- //Iterate on each day
- foreach($period as $date) {
- //Init day in calendar
- $calendar[$Ymd = $date->format('Ymd')] = [
- 'title' => $date->format('d'),
- 'class' => [],
- 'sessions' => []
- ];
- //Append month for first day of month
- if ($month != $date->format('m')) {
- $month = $date->format('m');
- $calendar[$Ymd]['title'] .= '/'.$month;
- }
- //Deal with today
- if ($date->format('U') == ($today = strtotime('today'))) {
- $calendar[$Ymd]['title'] .= '/'.$month;
- $calendar[$Ymd]['current'] = true;
- $calendar[$Ymd]['class'][] = 'current';
- }
- //Disable passed days
- if ($date->format('U') < $today) {
- $calendar[$Ymd]['disabled'] = true;
- $calendar[$Ymd]['class'][] = 'disabled';
- }
- //Set next month days
- if ($date->format('m') > date('m')) {
- $calendar[$Ymd]['next'] = true;
- $calendar[$Ymd]['class'][] = 'next';
- }
- //Iterate on each session to find the one of the day
- foreach($sessions as $session) {
- if (($sessionYmd = $session->getDate()->format('Ymd')) == $Ymd) {
- //Count number of application
- $count = count($session->getApplications());
-
- //Compute classes
- $class = [];
- if ($session->getApplication()) {
- $class[] = 'granted';
- } elseif ($count == 0) {
- $class[] = 'orphaned';
- } elseif ($count > 1) {
- $class[] = 'disputed';
- } else {
- $class[] = 'pending';
- }
-
- //Add the session
- $calendar[$Ymd]['sessions'][$session->getSlot()->getId().$session->getLocation()->getId()] = [
- 'id' => $session->getId(),
- 'title' => ($count > 1?'['.$count.'] ':'').$session->getSlot()->getTitle().' '.$session->getLocation()->getTitle(),
- 'class' => $class
- ];
- }
+ //Create location forms for role_admin
+ if ($this->isGranted('ROLE_ADMIN')) {
+ //Fetch all locations
+ $locations = $doctrine->getRepository(Location::class)->findAll();
+
+ //Rekey by id
+ $locations = array_reduce($locations, function($carry, $item){$carry[$item->getId()] = $item; return $carry;}, []);
+
+ //Init locations to context
+ $this->context['forms']['locations'] = [];
+
+ //Iterate on locations
+ foreach($locations as $locationId => $location) {
+ //Create LocationType form
+ $form = $this->createForm('Rapsys\AirBundle\Form\LocationType', $location, [
+ //Set the action
+ 'action' => $this->generateUrl('rapsys_air_location_edit', ['id' => $location->getId()]),
+ //Set the form attribute
+ 'attr' => [],
+ //Set block prefix
+ //TODO: make this shit works to prevent label collision
+ //XXX: see https://stackoverflow.com/questions/8703016/adding-a-prefix-to-a-form-label-for-translation
+ 'label_prefix' => 'location_'.$locationId
+ ]);
+
+ //Add form to context
+ $this->context['forms']['locations'][$locationId] = $form->createView();