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 if (empty($location = $doctrine->getRepository(Location
::class)->findOneById($id))) {
27 throw $this->createNotFoundException($this->translator
->trans('Unable to find location: %id%', ['%id%' => $id]));
31 $section = $this->translator
->trans('Argentine Tango at '.$location);
34 $title = $this->translator
->trans($this->config
['site']['title']).' - '.$section;
39 //Create application form for role_guest
40 if ($this->isGranted('ROLE_GUEST')) {
41 //Create ApplicationType form
42 $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
44 'action' => $this->generateUrl('rapsys_air_application_add'),
45 //Set the form attribute
46 'attr' => [ 'class' => 'col' ],
48 'admin' => $this->isGranted('ROLE_ADMIN'),
49 //Set default user to current
50 'user' => $this->getUser()->getId(),
51 //Set default slot to evening
52 //XXX: default to Evening (3)
53 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3),
54 //Set default location to current one
55 'location' => $location
59 $context['application'] = $application->createView();
60 //Create login form for anonymous
61 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
62 //Create ApplicationType form
63 $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
65 'action' => $this->generateUrl('rapsys_user_login'),
66 //Set the form attribute
67 'attr' => [ 'class' => 'col' ]
71 $context['login'] = $login->createView();
75 $period = new \
DatePeriod(
76 //Start from first monday of week
77 new \
DateTime('Monday this week'),
79 new \
DateInterval('P1D'),
80 //End with next sunday and 4 weeks
81 new \
DateTime('Monday this week + 5 week')
85 $calendar = $doctrine->getRepository(Session
::class)->fetchCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session'), !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'));
88 //XXX: we want to display all active locations anyway
89 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period);
92 return $this->render('@RapsysAir/location/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+
$context+
$this->context
);