3 namespace Rapsys\AirBundle\Controller
; 
   5 use Symfony\Component\HttpFoundation\Request
; 
   7 use Rapsys\AirBundle\Entity\Slot
; 
   8 use Rapsys\AirBundle\Entity\Session
; 
   9 use Rapsys\AirBundle\Entity\Location
; 
  10 use Rapsys\AirBundle\Entity\User
; 
  11 use Rapsys\AirBundle\Entity\Snippet
; 
  13 class OrganizerController 
extends DefaultController 
{ 
  17          * @desc Display all user with a group listed as organizers 
  19          * @param Request $request The request instance 
  20          * @param int $id The user id 
  22          * @return Response The rendered view 
  24         public function index(Request 
$request) { 
  26                 $doctrine = $this->getDoctrine(); 
  29                 $section = $this->translator
->trans('Argentine Tango organizers'); 
  32                 $this->context
['description'] = $this->translator
->trans('Outdoor Argentine Tango organizer list'); 
  35                 $this->context
['keywords'] = [ 
  36                         $this->translator
->trans('Argentine Tango'), 
  37                         $this->translator
->trans('outdoor'), 
  38                         $this->translator
->trans('organizer'), 
  39                         $this->translator
->trans('Libre Air') 
  43                 $title = $this->translator
->trans($this->config
['site']['title']).' - '.$section; 
  48                 //Create application form for role_guest 
  49                 if ($this->isGranted('ROLE_GUEST')) { 
  50                         //Create ApplicationType form 
  51                         $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
  53                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
  54                                 //Set the form attribute 
  55                                 'attr' => [ 'class' => 'col' ], 
  57                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
  58                                 //Set default user to current 
  59                                 'user' => $this->getUser()->getId(), 
  60                                 //Set default slot to evening 
  61                                 //XXX: default to Evening (3) 
  62                                 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3) 
  66                         $context['application'] = $application->createView(); 
  67                 //Create login form for anonymous 
  68                 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
  69                         //Create ApplicationType form 
  70                         $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [ 
  72                                 'action' => $this->generateUrl('rapsys_user_login'), 
  73                                 //Set the form attribute 
  74                                 'attr' => [ 'class' => 'col' ] 
  78                         $context['login'] = $login->createView(); 
  82                 $organizers = $doctrine->getRepository(User
::class)->findOrganizerGroupedByGroup($this->translator
); 
  85                 $period = new \
DatePeriod( 
  86                         //Start from first monday of week 
  87                         new \
DateTime('Monday this week'), 
  89                         new \
DateInterval('P1D'), 
  90                         //End with next sunday and 4 weeks 
  91                         new \
DateTime('Monday this week + 5 week') 
  95                 //XXX: we want to display all active locations anyway 
  96                 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period); 
  99                 return $this->render('@RapsysAir/organizer/index.html.twig', ['title' => $title, 'section' => $section, 'organizers' => $organizers, 'locations' => $locations]+
$context+
$this->context
); 
 103          * List all sessions for the organizer 
 105          * @desc Display all sessions for the user with an application or login form 
 107          * @param Request $request The request instance 
 108          * @param int $id The user id 
 110          * @return Response The rendered view 
 112         public function view(Request 
$request, $id) { 
 114                 $doctrine = $this->getDoctrine(); 
 117                 if (empty($user = $doctrine->getRepository(User
::class)->findOneById($id))) { 
 118                         throw $this->createNotFoundException($this->translator
->trans('Unable to find organizer: %id%', ['%id%' => $id])); 
 122                 $section = $user->getPseudonym(); 
 125                 $title = $this->translator
->trans($this->config
['site']['title']).' - '.$section; 
 130                 //Create application form for role_guest 
 131                 if ($this->isGranted('ROLE_GUEST')) { 
 132                         //Create ApplicationType form 
 133                         $application = $this->createForm('Rapsys\AirBundle\Form\ApplicationType', null, [ 
 135                                 'action' => $this->generateUrl('rapsys_air_application_add'), 
 136                                 //Set the form attribute 
 137                                 'attr' => [ 'class' => 'col' ], 
 139                                 'admin' => $this->isGranted('ROLE_ADMIN'), 
 140                                 //Set default user to current 
 141                                 'user' => $this->getUser()->getId(), 
 142                                 //Set default slot to evening 
 143                                 //XXX: default to Evening (3) 
 144                                 'slot' => $doctrine->getRepository(Slot
::class)->findOneById(3) 
 147                         //Add form to context 
 148                         $context['application'] = $application->createView(); 
 149                 //Create login form for anonymous 
 150                 } elseif (!$this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { 
 151                         //Create ApplicationType form 
 152                         $login = $this->createForm('Rapsys\UserBundle\Form\LoginType', null, [ 
 154                                 'action' => $this->generateUrl('rapsys_user_login'), 
 155                                 //Set the form attribute 
 156                                 'attr' => [ 'class' => 'col' ] 
 159                         //Add form to context 
 160                         $context['login'] = $login->createView(); 
 164                 $period = new \
DatePeriod( 
 165                         //Start from first monday of week 
 166                         new \
DateTime('Monday this week'), 
 167                         //Iterate on each day 
 168                         new \
DateInterval('P1D'), 
 169                         //End with next sunday and 4 weeks 
 170                         new \
DateTime('Monday this week + 5 week') 
 174                 //TODO: highlight with current session route parameter 
 175                 $calendar = $doctrine->getRepository(Session
::class)->fetchUserCalendarByDatePeriod($this->translator
, $period, $id, $request->get('session')); 
 178                 //XXX: we want to display all active locations anyway 
 179                 $locations = $doctrine->getRepository(Location
::class)->findTranslatedSortedByPeriod($this->translator
, $period, $id); 
 181                 //Create snippet forms for role_guest 
 182                 if ($this->isGranted('ROLE_GUEST')) { 
 183                         //Fetch all user snippet 
 184                         $snippets = $doctrine->getRepository(Snippet
::class)->findByLocaleUserId($request->getLocale(), $id); 
 186                         //Rekey by location id 
 187                         $snippets = array_reduce($snippets, function($carry, $item){$carry
[$item
->getLocation()->getId()] = $item
; return $carry
;}, []); 
 189                         //Init snippets to context 
 190                         $context['snippets'] = []; 
 192                         //Iterate on locations 
 193                         foreach($locations as $locationId => $location) { 
 195                                 $snippet = new Snippet(); 
 198                                 $snippet->setLocale($request->getLocale()); 
 201                                 $snippet->setUser($user); 
 203                                 //Set default location 
 204                                 $snippet->setLocation($doctrine->getRepository(Location
::class)->findOneById($locationId)); 
 207                                 if (!empty($snippets[$locationId])) { 
 208                                         $snippet = $snippets[$locationId]; 
 211                                 //Create SnippetType form 
 212                                 $form = $this->createForm('Rapsys\AirBundle\Form\SnippetType', $snippet, [ 
 214                                         //TODO: voir si on peut pas faire sauter ça ici 
 215                                         'action' => !empty($snippet->getId())?$this->generateUrl('rapsys_air_snippet_edit', ['id' => $snippet->getId()]):$this->generateUrl('rapsys_air_snippet_add'), 
 216                                         #'action' => $this->generateUrl('rapsys_air_snippet_add'), 
 217                                         //Set the form attribute 
 220                                         //TODO: would maybe need a signature field 
 221                                         //'csrf_token_id' => $request->getLocale().'_'.$id.'_'.$locationId 
 224                                 //Add form to context 
 225                                 $context['snippets'][$locationId] = $form->createView(); 
 230                 return $this->render('@RapsysAir/organizer/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+
$context+
$this->context
);