]> Raphaƫl G. Git Repositories - airbundle/blobdiff - Controller/SessionController.php
Add link feature
[airbundle] / Controller / SessionController.php
index ce15032104c34c704b451fd35bc7206c7b292a82..6359f6a7febaa29242d6e14e1b048c865c77b37e 100644 (file)
@@ -10,6 +10,7 @@ use Rapsys\AirBundle\Entity\Application;
 use Rapsys\AirBundle\Entity\User;
 use Rapsys\AirBundle\Entity\Slot;
 use Rapsys\AirBundle\Entity\Session;
+use Rapsys\AirBundle\Entity\Link;
 use Rapsys\AirBundle\Entity\Location;
 
 class SessionController extends DefaultController {
@@ -37,7 +38,7 @@ class SessionController extends DefaultController {
                $doctrine = $this->getDoctrine();
 
                //Fetch session
-               $session = $doctrine->getRepository(Session::class)->fetchOneById($id);
+               $session = $doctrine->getRepository(Session::class)->fetchOneById($id, $request->getLocale());
 
                //Check if
                if (
@@ -299,7 +300,7 @@ class SessionController extends DefaultController {
                                $this->addFlash('notice', $this->translator->trans('Session %id% auto attributed', ['%id%' => $id]));
                        //No application
                        } else {
-                               //Add notice in flash message
+                               //Add warning in flash message
                                $this->addFlash('warning', $this->translator->trans('Session %id% not auto attributed', ['%id%' => $id]));
                        }
                //With lock
@@ -367,7 +368,7 @@ class SessionController extends DefaultController {
                        $this->addFlash('notice', $this->translator->trans('Session %id% updated', ['%id%' => $id]));
                //Unknown action
                } else {
-                       //Add notice in flash message
+                       //Add warning in flash message
                        $this->addFlash('warning', $this->translator->trans('Session %id% not updated', ['%id%' => $id]));
                }
 
@@ -434,15 +435,26 @@ class SessionController extends DefaultController {
         *
         * @return Response The rendered view
         */
-       public function index(Request $request = null) {
+       public function index(Request $request) {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Set section
                $section = $this->translator->trans('Sessions');
 
+               //Set description
+               $this->context['description'] = $this->translator->trans('Libre Air session list');
+
+               //Set keywords
+               $this->context['keywords'] = [
+                       $this->translator->trans('sessions'),
+                       $this->translator->trans('session list'),
+                       $this->translator->trans('listing'),
+                       $this->translator->trans('Libre Air')
+               ];
+
                //Set title
-               $title = $section.' - '.$this->translator->trans($this->config['site']['title']);
+               $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
 
                //Init context
                $context = [];
@@ -487,7 +499,9 @@ class SessionController extends DefaultController {
                        //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 + 4 week':'Monday this week + 2 week'
+                       )
                );
 
                //Fetch calendar
@@ -496,7 +510,7 @@ class SessionController extends DefaultController {
 
                //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
                return $this->render('@RapsysAir/session/index.html.twig', ['title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$context+$this->context);
@@ -517,13 +531,31 @@ class SessionController extends DefaultController {
                $doctrine = $this->getDoctrine();
 
                //Fetch session
-               $session = $doctrine->getRepository(Session::class)->fetchOneById($id);
+               if (empty($session = $doctrine->getRepository(Session::class)->fetchOneById($id, $request->getLocale()))) {
+                       throw $this->createNotFoundException($this->translator->trans('Unable to find session: %id%', ['%id%' => $id]));
+               }
 
                //Set section
                $section = $this->translator->trans($session['l_title']);
 
+               //Set localization date formater
+               $intl = new \IntlDateFormatter($request->getLocale(), \IntlDateFormatter::GREGORIAN, \IntlDateFormatter::SHORT);
+
+               //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('Session %id%', ['%id%' => $id]).' - '.$section.' - '.$this->translator->trans($this->config['site']['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']]);
 
                //Init context
                $context = [];
@@ -632,15 +664,77 @@ class SessionController extends DefaultController {
                                'id' => $session['t_id'],
                                'title' => $this->translator->trans($session['t_title'])
                        ],
+                       'snippet' => [
+                               'id' => $session['p_id'],
+                               'description' => $session['p_description']
+                       ],
                        'applications' => null
                ];
 
                //With application
                if (!empty($session['a_id'])) {
+                       //Init links
+                       $links = null;
+
+                       //Merge array
+                       if (!empty($session['i_type']) && !empty($session['i_url'])) {
+                               //Extract links type
+                               $session['i_type'] = explode("\n", $session['i_type']);
+
+                               //Extract links url
+                               $session['i_url'] = explode("\n", $session['i_url']);
+
+                               //Set links array
+                               $links = [];
+
+                               //Iterate on links type
+                               foreach($session['i_type'] as $i => $type) {
+                                       //Type is contact, donate or link
+                                       if (in_array($type, [Link::TYPE_CONTACT, Link::TYPE_DONATE, Link::TYPE_LINK])) {
+                                               //Set title
+                                               $linkTitle = $this->translator->trans(ucfirst($type));
+                                       }
+
+                                       //Type is contact
+                                       if ($type == Link::TYPE_CONTACT) {
+                                               //Set description
+                                               $description = $this->translator->trans('Send a message to %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]);
+                                       //Type is donate
+                                       } elseif ($type == Link::TYPE_DONATE) {
+                                               //Set description
+                                               $description = $this->translator->trans('Donate to %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]);
+                                       //Type is link
+                                       } elseif ($type == Link::TYPE_LINK) {
+                                               //Set description
+                                               $description = $this->translator->trans('Link to %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]);
+                                       //Type is social
+                                       } elseif ($type == Link::TYPE_SOCIAL) {
+                                               //Set description
+                                               $description = $this->translator->trans('Consult %pseudonym% social profile', [ '%pseudonym%' => $session['au_pseudonym'] ]);
+
+                                               //Set title
+                                               $linkTitle = $this->translator->trans('Social network');
+                                       //Unknown type
+                                       } else {
+                                               //Throw explode
+                                               throw new \InvalidArgumentException('Invalid type');
+                                       }
+
+                                       //Set link entry
+                                       $links[$i] = [
+                                               'description' => $description,
+                                               'title' => $linkTitle,
+                                               'type' => $type,
+                                               'url' => $session['i_url'][$i]
+                                       ];
+                               }
+                       }
                        $context['session']['application'] = [
                                'user' => [
                                        'id' => $session['au_id'],
-                                       'title' => $session['au_pseudonym']
+                                       'by' => $this->translator->trans('by %pseudonym%', [ '%pseudonym%' => $session['au_pseudonym'] ]),
+                                       'title' => $session['au_pseudonym'],
+                                       'links' => $links
                                ],
                                'id' => $session['a_id'],
                                'title' => $this->translator->trans('Application %id%', [ '%id%' => $session['a_id'] ]),
@@ -686,7 +780,23 @@ class SessionController extends DefaultController {
                        }
                }
 
+               //Compute period
+               $period = new \DatePeriod(
+                       //Start from first monday of week
+                       new \DateTime('Monday this week'),
+                       //Iterate on each day
+                       new \DateInterval('P1D'),
+                       //End with next sunday and 4 weeks
+                       new \DateTime(
+                               $this->isGranted('IS_AUTHENTICATED_REMEMBERED')?'Monday this week + 4 week':'Monday this week + 2 week'
+                       )
+               );
+
+               //Fetch locations
+               //XXX: we want to display all active locations anyway
+               $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period, $session['au_id']);
+
                //Render the view
-               return $this->render('@RapsysAir/session/view.html.twig', ['title' => $title, 'section' => $section]+$context+$this->context);
+               return $this->render('@RapsysAir/session/view.html.twig', ['title' => $title, 'section' => $section, 'locations' => $locations]+$context+$this->context);
        }
 }