]> Raphaël G. Git Repositories - airbundle/blobdiff - Controller/UserController.php
Add preUpdate doctrine lifecycle callbacks
[airbundle] / Controller / UserController.php
index dcd448bfa6b4aaa53a23559920c01c1ed51a764a..3ed64c79e50e7da3a77a905ff30c27a726879074 100644 (file)
@@ -6,11 +6,13 @@ use Symfony\Component\HttpFoundation\Request;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
 use Symfony\Component\HttpFoundation\Response;
 use Symfony\Component\Routing\RequestContext;
 use Symfony\Component\Security\Core\Authentication\Token\UsernamePasswordToken;
-use Rapsys\AirBundle\Entity\Slot;
-use Rapsys\AirBundle\Entity\Session;
+
+use Rapsys\AirBundle\Entity\Civility;
 use Rapsys\AirBundle\Entity\Location;
 use Rapsys\AirBundle\Entity\Location;
-use Rapsys\AirBundle\Entity\User;
+use Rapsys\AirBundle\Entity\Session;
+use Rapsys\AirBundle\Entity\Slot;
 use Rapsys\AirBundle\Entity\Snippet;
 use Rapsys\AirBundle\Entity\Snippet;
+use Rapsys\AirBundle\Entity\User;
 
 class UserController extends DefaultController {
        /**
 
 class UserController extends DefaultController {
        /**
@@ -26,11 +28,21 @@ class UserController extends DefaultController {
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
                //Fetch doctrine
                $doctrine = $this->getDoctrine();
 
-               //Set section
-               $section = $this->translator->trans('Libre Air users');
+               //With admin role
+               if ($this->isGranted('ROLE_ADMIN')) {
+                       //Set section
+                       $section = $this->translator->trans('Libre Air users');
 
 
-               //Set description
-               $this->context['description'] = $this->translator->trans('Libre Air user list');
+                       //Set description
+                       $this->context['description'] = $this->translator->trans('Libre Air user list');
+               //Without admin role
+               } else {
+                       //Set section
+                       $section = $this->translator->trans('Libre Air organizers');
+
+                       //Set description
+                       $this->context['description'] = $this->translator->trans('Libre Air organizers list');
+               }
 
                //Set keywords
                $this->context['keywords'] = [
 
                //Set keywords
                $this->context['keywords'] = [
@@ -58,10 +70,14 @@ class UserController extends DefaultController {
                        )
                );
 
                        )
                );
 
+               //With admin role
+               if ($this->isGranted('ROLE_ADMIN')) {
+                       //Display all users
+                       $this->context['groups'] = $users;
                //Without admin role
                //Without admin role
-               if (!$this->isGranted('ROLE_ADMIN')) {
-                       //Remove users
-                       unset($users[$this->translator->trans('User')]);
+               } else {
+                       //Only display senior organizers
+                       $this->context['users'] = $users[$this->translator->trans('Senior')];
                }
 
                //Fetch locations
                }
 
                //Fetch locations
@@ -69,7 +85,7 @@ class UserController extends DefaultController {
                $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period);
 
                //Render the view
                $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period);
 
                //Render the view
-               return $this->render('@RapsysAir/user/index.html.twig', ['title' => $title, 'section' => $section, 'users' => $users, 'locations' => $locations]+$this->context);
+               return $this->render('@RapsysAir/user/index.html.twig', ['title' => $title, 'section' => $section, 'locations' => $locations]+$this->context);
        }
 
        /**
        }
 
        /**
@@ -133,7 +149,7 @@ class UserController extends DefaultController {
 
                //Fetch calendar
                //TODO: highlight with current session route parameter
 
                //Fetch calendar
                //TODO: highlight with current session route parameter
-               $calendar = $doctrine->getRepository(Session::class)->fetchUserCalendarByDatePeriod($this->translator, $period, $isGuest?$id:null, $request->get('session'));
+               $calendar = $doctrine->getRepository(Session::class)->fetchUserCalendarByDatePeriod($this->translator, $period, $isGuest?$id:null, $request->get('session'), $request->getLocale());
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
 
                //Fetch locations
                //XXX: we want to display all active locations anyway
@@ -147,6 +163,8 @@ class UserController extends DefaultController {
                                'action' => $this->generateUrl('rapsys_air_user_view', ['id' => $id]),
                                //Set the form attribute
                                'attr' => [ 'class' => 'col' ],
                                'action' => $this->generateUrl('rapsys_air_user_view', ['id' => $id]),
                                //Set the form attribute
                                'attr' => [ 'class' => 'col' ],
+                               //Set civility class
+                               'civility_class' => Civility::class,
                                //Disable mail
                                'mail' => $this->isGranted('ROLE_ADMIN'),
                                //Disable password
                                //Disable mail
                                'mail' => $this->isGranted('ROLE_ADMIN'),
                                //Disable password
@@ -275,23 +293,15 @@ class UserController extends DefaultController {
                                }
 
                                //Create SnippetType form
                                }
 
                                //Create SnippetType form
-                               #$form = $this->createForm('Rapsys\AirBundle\Form\SnippetType', $snippet, [
                                $form = $this->container->get('form.factory')->createNamed('snipped_'.$request->getLocale().'_'.$locationId, 'Rapsys\AirBundle\Form\SnippetType', $snippet, [
                                        //Set the action
                                $form = $this->container->get('form.factory')->createNamed('snipped_'.$request->getLocale().'_'.$locationId, 'Rapsys\AirBundle\Form\SnippetType', $snippet, [
                                        //Set the action
-                                       //TODO: voir si on peut pas faire sauter ça ici
                                        'action' =>
                                                !empty($snippet->getId()) ?
                                                $this->generateUrl('rapsys_air_snippet_edit', ['id' => $snippet->getId()]) :
                                                $this->generateUrl('rapsys_air_snippet_add', ['location' => $locationId]),
                                        'action' =>
                                                !empty($snippet->getId()) ?
                                                $this->generateUrl('rapsys_air_snippet_edit', ['id' => $snippet->getId()]) :
                                                $this->generateUrl('rapsys_air_snippet_add', ['location' => $locationId]),
-                                       #'action' => $this->generateUrl('rapsys_air_snippet_add'),
                                        //Set the form attribute
                                        //Set the form attribute
-                                       'attr' => [],
-                                       //Set csrf_token_id
-                                       //TODO: would maybe need a signature field
-                                       //'csrf_token_id' => $request->getLocale().'_'.$id.'_'.$locationId
+                                       'attr' => []
                                ]);
                                ]);
-                               #return $this->container->get('form.factory')->create($type, $data, $options);
-                               #public function createNamed($name, $type = 'Symfony\Component\Form\Extension\Core\Type\FormType', $data = null, array $options = []);
 
                                //Add form to context
                                $this->context['forms']['snippets'][$locationId] = $form->createView();
 
                                //Add form to context
                                $this->context['forms']['snippets'][$locationId] = $form->createView();