]> Raphaƫl G. Git Repositories - airbundle/blob - Controller/LocationController.php
Add translated location fetch
[airbundle] / Controller / LocationController.php
1 <?php
2
3 namespace Rapsys\AirBundle\Controller;
4
5 use Symfony\Component\HttpFoundation\Request;
6 use Rapsys\AirBundle\Entity\Slot;
7 use Rapsys\AirBundle\Entity\Session;
8 use Rapsys\AirBundle\Entity\Location;
9
10 class LocationController extends DefaultController {
11 /**
12 * List all sessions for the location
13 *
14 * @desc Display all sessions for the location with an application or login form
15 *
16 * @param Request $request The request instance
17 * @param int $id The location id
18 *
19 * @return Response The rendered view
20 */
21 public function view(Request $request, $id) {
22 //Fetch doctrine
23 $doctrine = $this->getDoctrine();
24
25 //Fetch location
26 $location = $doctrine->getRepository(Location::class)->findOneById($id);
27
28 //Set section
29 $section = $this->translator->trans($location);
30
31 //Set title
32 $title = $section.' - '.$this->translator->trans($this->config['site']['title']);
33
34 //Init context
35 $context = [];
36
37 //Create application form for role_guest
38 if ($this->isGranted('ROLE_GUEST')) {
39 //Create ApplicationType form
40 $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
41 //Set the action
42 'action' => $this->generateUrl('rapsys_air_application_add'),
43 //Set the form attribute
44 'attr' => [ 'class' => 'col' ],
45 //Set admin
46 'admin' => $this->isGranted('ROLE_ADMIN'),
47 //Set default user to current
48 'user' => $this->getUser()->getId(),
49 //Set default slot to evening
50 //XXX: default to Evening (3)
51 'slot' => $doctrine->getRepository(Slot::class)->findOneById(3)
52 ]);
53
54 //Add form to context
55 $context['application'] = $application->createView();
56 //Create login form for anonymous
57 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
58 //Create ApplicationType form
59 $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
60 //Set the action
61 'action' => $this->generateUrl('rapsys_user_login'),
62 //Set the form attribute
63 'attr' => [ 'class' => 'col' ]
64 ]);
65
66 //Add form to context
67 $context['login'] = $login->createView();
68 }
69
70 //Compute period
71 $period = new \DatePeriod(
72 //Start from first monday of week
73 new \DateTime('Monday this week'),
74 //Iterate on each day
75 new \DateInterval('P1D'),
76 //End with next sunday and 4 weeks
77 new \DateTime('Monday this week + 5 week')
78 );
79
80 //Fetch calendar
81 $calendar = $doctrine->getRepository(Session::class)->fetchCalendarByDatePeriod($this->translator, $period, $id, $request->get('session'));
82
83 //Render the view
84 return $this->render('@RapsysAir/location/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar]+$context+$this->context);
85 }
86 }