]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Controller/SessionController.php
Reduce connected period from 4 weeks to 3 weeks.
[airbundle] / Controller / SessionController.php
index c3104a3039dc7717b5394c09cb1f64fa7b883725..30a0a730bd786e587dd58d8e7de4ccb18d8166ac 100644 (file)
@@ -3,6 +3,7 @@
 namespace Rapsys\AirBundle\Controller;
 
 use Symfony\Component\HttpFoundation\Request;
 namespace Rapsys\AirBundle\Controller;
 
 use Symfony\Component\HttpFoundation\Request;
+use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Routing\Exception\MethodNotAllowedException;
 use Symfony\Component\Routing\Exception\ResourceNotFoundException;
@@ -24,7 +25,7 @@ class SessionController extends DefaultController {
         *
         * @throws \RuntimeException When user has not at least guest role
         */
         *
         * @throws \RuntimeException When user has not at least guest role
         */
-       public function edit(Request $request, $id) {
+       public function edit(Request $request, $id): Response {
                //Prevent non-guest to access here
                $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator->trans('Guest')]));
 
                //Prevent non-guest to access here
                $this->denyAccessUnlessGranted('ROLE_GUEST', null, $this->translator->trans('Unable to access this page without role %role%!', ['%role%' => $this->translator->trans('Guest')]));
 
@@ -55,8 +56,8 @@ class SessionController extends DefaultController {
                //Set now
                $now = new \DateTime('now');
 
                //Set now
                $now = new \DateTime('now');
 
-               //Create SessionEditType form
-               $form = $this->createForm('Rapsys\AirBundle\Form\SessionEditType', null, [
+               //Create SessionType form
+               $form = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
                        //Set the action
                        'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                        //Set the form attribute
                        //Set the action
                        'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                        //Set the form attribute
@@ -434,51 +435,26 @@ class SessionController extends DefaultController {
         *
         * @return Response The rendered view
         */
         *
         * @return Response The rendered view
         */
-       public function index(Request $request) {
+       public function index(Request $request): Response {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Set section
                $section = $this->translator->trans('Sessions');
 
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Set section
                $section = $this->translator->trans('Sessions');
 
-               //Set title
-               $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
-
-               //Init context
-               $context = [];
+               //Set description
+               $this->context['description'] = $this->translator->trans('Libre Air session list');
 
 
-               //Create application form for role_guest
-               if ($this->isGranted('ROLE_GUEST')) {
-                       //Create ApplicationType form
-                       $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_air_application_add'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ],
-                               //Set admin
-                               'admin' => $this->isGranted('ROLE_ADMIN'),
-                               //Set default user to current
-                               'user' => $this->getUser()->getId(),
-                               //Set default slot to evening
-                               //XXX: default to Evening (3)
-                               'slot' => $doctrine->getRepository(Slot::class)->findOneById(3)
-                       ]);
-
-                       //Add form to context
-                       $context['application'] = $application->createView();
-               //Create login form for anonymous
-               } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
-                       //Create ApplicationType form
-                       $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_user_login'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ]
-                       ]);
+               //Set keywords
+               $this->context['keywords'] = [
+                       $this->translator->trans('sessions'),
+                       $this->translator->trans('session list'),
+                       $this->translator->trans('listing'),
+                       $this->translator->trans('Libre Air')
+               ];
 
 
-                       //Add form to context
-                       $context['login'] = $login->createView();
-               }
+               //Set title
+               $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
 
                //Compute period
                $period = new \DatePeriod(
 
                //Compute period
                $period = new \DatePeriod(
@@ -487,7 +463,9 @@ class SessionController extends DefaultController {
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
-                       new \DateTime('Monday this week + 5 week')
+                       new \DateTime(
+                               $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
+                       )
                );
 
                //Fetch calendar
                );
 
                //Fetch calendar
@@ -496,10 +474,10 @@ class SessionController extends DefaultController {
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
-               $locations = $doctrine->getRepository(Location::class)->fetchTranslatedLocationByDatePeriod($this->translator, $period/*, !$this->isGranted('IS_AUTHENTICATED_REMEMBERED')*/);
+               $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period);
 
                //Render the view
 
                //Render the view
-               return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$context+$this->context);
+               return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$this->context);
        }
 
        /**
        }
 
        /**
@@ -512,7 +490,7 @@ class SessionController extends DefaultController {
         *
         * @return Response The rendered view
         */
         *
         * @return Response The rendered view
         */
-       public function view(Request $request, $id) {
+       public function view(Request $request, $id): Response {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
@@ -524,16 +502,29 @@ class SessionController extends DefaultController {
                //Set section
                $section = $this->translator->trans($session['l_title']);
 
                //Set section
                $section = $this->translator->trans($session['l_title']);
 
-               //Set title
-               $title = $this->translator->trans($this->config['site']['title']).' - '.$section.' - '.$this->translator->trans('Session %id%', ['%id%' => $id]);
+               //Set localization date formater
+               $intl = new \IntlDateFormatter($request->getLocale(), \IntlDateFormatter::GREGORIAN, \IntlDateFormatter::SHORT);
 
 
-               //Init context
-               $context = [];
+               //Set description
+               $this->context['description'] = $this->translator->trans('Outdoor Argentine Tango session the %date%', [ '%date%' => $intl->format($session['start']) ]);
+
+               //Set keywords
+               $this->context['keywords'] = [
+                       $this->translator->trans('outdoor'),
+                       $this->translator->trans('Argentine Tango'),
+               ];
+
+               //With granted session
+               if (!empty($session['au_id'])) {
+                       $this->context['keywords'][0] = $session['au_pseudonym'];
+               }
+               //Set title
+               $title = $this->translator->trans($this->config['site']['title']).' - '.$section.' - '.$this->translator->trans(!empty($session['au_id'])?'Session %id% by %pseudonym%':'Session %id%', ['%id%' => $id, '%pseudonym%' => $session['au_pseudonym']]);
 
                //Create application form for role_guest
                if ($this->isGranted('ROLE_GUEST')) {
                        //Create ApplicationType form
 
                //Create application form for role_guest
                if ($this->isGranted('ROLE_GUEST')) {
                        //Create ApplicationType form
-                       $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
+                       $applicationForm = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_application_add'),
                                //Set the form attribute
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_application_add'),
                                //Set the form attribute
@@ -549,13 +540,13 @@ class SessionController extends DefaultController {
                        ]);
 
                        //Add form to context
                        ]);
 
                        //Add form to context
-                       $context['application'] = $application->createView();
+                       $this->context['forms']['application'] = $applicationForm->createView();
 
                        //Set now
                        $now = new \DateTime('now');
 
 
                        //Set now
                        $now = new \DateTime('now');
 
-                       //Create SessionEditType form
-                       $session_edit = $this->createForm('Rapsys\AirBundle\Form\SessionEditType', null, [
+                       //Create SessionType form
+                       $sessionForm = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                                //Set the form attribute
                                //Set the action
                                'action' => $this->generateUrl('rapsys_air_session_edit', [ 'id' => $id ]),
                                //Set the form attribute
@@ -583,19 +574,7 @@ class SessionController extends DefaultController {
                        ]);
 
                        //Add form to context
                        ]);
 
                        //Add form to context
-                       $context['session_edit'] = $session_edit->createView();
-               //Create login form for anonymous
-               } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) {
-                       //Create ApplicationType form
-                       $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [
-                               //Set the action
-                               'action' => $this->generateUrl('rapsys_user_login'),
-                               //Set the form attribute
-                               'attr' => [ 'class' => 'col' ]
-                       ]);
-
-                       //Add form to context
-                       $context['login'] = $login->createView();
+                       $this->context['forms']['session'] = $sessionForm->createView();
                }
 
                //Add session in context
                }
 
                //Add session in context
@@ -636,7 +615,12 @@ class SessionController extends DefaultController {
                        ],
                        'snippet' => [
                                'id' => $session['p_id'],
                        ],
                        'snippet' => [
                                'id' => $session['p_id'],
-                               'description' => $session['p_description']
+                               'description' => $session['p_description'],
+                               'class' => $session['p_class'],
+                               'contact' => $session['p_contact'],
+                               'donate' => $session['p_donate'],
+                               'link' => $session['p_link'],
+                               'profile' => $session['p_profile']
                        ],
                        'applications' => null
                ];
                        ],
                        'applications' => null
                ];
@@ -646,11 +630,11 @@ class SessionController extends DefaultController {
                        $context['session']['application'] = [
                                'user' => [
                                        'id' => $session['au_id'],
                        $context['session']['application'] = [
                                'user' => [
                                        'id' => $session['au_id'],
-                                       'title' => $session['au_pseudonym'],
-                                       'donation' => $session['au_donation'],
-                                       'site' => $session['au_site']
+                                       'by' => $this->translator->trans('by %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]),
+                                       'title' => $session['au_pseudonym']
                                ],
                                'id' => $session['a_id'],
                                ],
                                'id' => $session['a_id'],
+                               'canceled' => $session['a_canceled'],
                                'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
                        ];
                }
                                'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
                        ];
                }
@@ -701,7 +685,9 @@ class SessionController extends DefaultController {
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
                        //Iterate on each day
                        new \DateInterval('P1D'),
                        //End with next sunday and 4 weeks
-                       new \DateTime('Monday this week + 5 week')
+                       new \DateTime(
+                               $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 3 week':'Monday this week + 2 week'
+                       )
                );
 
                //Fetch locations
                );
 
                //Fetch locations