3 namespace Rapsys\AirBundle\Controller
;
5 use Symfony\Component\HttpFoundation\Request
;
6 use Rapsys\AirBundle\Entity\Slot
;
7 use Rapsys\AirBundle\Entity\Session
;
8 use Rapsys\AirBundle\Entity\Location
;
10 class LocationController
extends DefaultController
{
12 * List all sessions for the location
14 * @desc Display all sessions for the location with an application or login form
16 * @param Request $request The request instance
17 * @param int $id The location id
19 * @return Response The rendered view
21 public function view(Request
$request, $id) {
23 $doctrine = $this->getDoctrine();
26 $location = $doctrine->getRepository(Location
::class)->findOneById($id);
29 $section = $this->translator
->trans($location);
32 $title = $section.' - '.$this->translator
->trans($this->config
['site']['title']);
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, [
42 'action' => $this->generateUrl('rapsys_air_application_add'),
43 //Set the form attribute
44 'attr' => [ 'class' => 'col' ],
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)
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, [
61 'action' => $this->generateUrl('rapsys_user_login'),
62 //Set the form attribute
63 'attr' => [ 'class' => 'col' ]
67 $context['login'] = $login->createView();
71 $period = new \
DatePeriod(
72 //Start from first monday of week
73 new \
DateTime('Monday this week'),
75 new \
DateInterval('P1D'),
76 //End with next sunday and 4 weeks
77 new \
DateTime('Monday this week + 5 week')
81 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session'));
84 return $this->render('@RapsysAir/location/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar]+
$context+
$this->context
);