X-Git-Url: https://git.rapsys.eu/airbundle/blobdiff_plain/bf7340106f67f4bd1e22bf1f831b39673257fdec..5bb3e32a5cf76401be2fe4c14195a1baa4c3045b:/Controller/SessionController.php?ds=sidebyside diff --git a/Controller/SessionController.php b/Controller/SessionController.php index db556dc..c755650 100644 --- a/Controller/SessionController.php +++ b/Controller/SessionController.php @@ -47,7 +47,7 @@ class SessionController extends AbstractController { $this->context['cities'] = $this->doctrine->getRepository(Location::class)->findCitiesAsArray($this->period); //Add calendar - $this->context['calendar'] = $this->doctrine->getRepository(Session::class)->findAllByPeriodAsCalendarArray($this->period, !$this->isGranted('IS_AUTHENTICATED_REMEMBERED'), null, null, 1); + $this->context['calendar'] = $this->doctrine->getRepository(Session::class)->findAllByPeriodAsCalendarArray($this->period, !$this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED'), null, null, 1); //Add dances $this->context['dances'] = $this->doctrine->getRepository(Dance::class)->findNamesAsArray(); @@ -59,7 +59,7 @@ class SessionController extends AbstractController { $response = new Response(); //With logged user - if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + if ($this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { //Set last modified $response->setLastModified(new \DateTime('-1 year')); @@ -139,7 +139,7 @@ class SessionController extends AbstractController { $dances = implode($this->translator->trans(' and '), array_filter(array_merge([implode(', ', array_slice($dances, 0, -1))], array_slice($dances, -1)), 'strlen')); //Set title - $this->context['title'] = $this->translator->trans('%dances% %cities% sessions', ['%dances%' => $dances, '%cities%' => $cities]); + $this->context['title']['page'] = $this->translator->trans('%dances% %cities% sessions', ['%dances%' => $dances, '%cities%' => $cities]); //Set description $this->context['description'] = $this->translator->trans('%dances% indoor and outdoor session calendar %cities%', ['%dances%' => $dances, '%cities%' => $cities]); @@ -246,7 +246,7 @@ class SessionController extends AbstractController { $response = new Response(); //With logged user - if ($this->isGranted('IS_AUTHENTICATED_REMEMBERED')) { + if ($this->checker->isGranted('IS_AUTHENTICATED_REMEMBERED')) { //Set last modified $response->setLastModified(new \DateTime('-1 year')); @@ -348,7 +348,7 @@ class SessionController extends AbstractController { //With application if (!empty($this->context['session']['application'])) { //Set title - $this->context['title'] = $this->translator->trans('%dance% %id% by %pseudonym%', ['%id%' => $id, '%dance%' => $this->context['session']['application']['dance']['title'], '%pseudonym%' => $this->context['session']['application']['user']['title']]); + $this->context['title']['page'] = $this->translator->trans('%dance% %id% by %pseudonym%', ['%id%' => $id, '%dance%' => $this->context['session']['application']['dance']['title'], '%pseudonym%' => $this->context['session']['application']['user']['title']]); //Set description $this->context['description'] = ucfirst($this->translator->trans('%dance% %location% %city% %slot% on %date% at %time%', [ @@ -372,7 +372,7 @@ class SessionController extends AbstractController { //Without application } else { //Set title - $this->context['title'] = $this->translator->trans('Session %id%', ['%id%' => $id]); + $this->context['title']['page'] = $this->translator->trans('Session %id%', ['%id%' => $id]); //Set description $this->context['description'] = ucfirst($this->translator->trans('%location% %city% %slot% on %date% at %time%', [ @@ -395,12 +395,12 @@ class SessionController extends AbstractController { $this->context['section'] = $this->context['session']['location']['title']; //Set facebook title - $this->context['facebook']['metas']['og:title'] = $this->context['title'].' '.$this->context['session']['location']['at']; + $this->context['facebook']['og:title'] = $this->context['title']['page'].' '.$this->context['session']['location']['at']; //Set facebook image - $this->context['facebook'] = [ + $this->context['fbimage'] = [ 'texts' => [ - $this->context['session']['application']['user']['title']??$this->context['title'] => [ + $this->context['session']['application']['user']['title']??$this->context['title']['page'] => [ 'font' => 'irishgrover', 'size' => 110 ], @@ -418,21 +418,47 @@ class SessionController extends AbstractController { ]+$this->context['facebook']; //Create application form for role_guest - if ($this->isGranted('ROLE_GUEST')) { + if ($this->checker->isGranted('ROLE_GUEST')) { //Set now $now = new \DateTime('now'); + //Default favorites and dances + $danceFavorites = $dances = []; + //Default dance + $danceDefault = null; + + //With admin + if ($this->checker->isGranted('ROLE_ADMIN')) { + //Get favorites dances + $danceFavorites = $this->doctrine->getRepository(Dance::class)->findByUserId($this->security->getUser()->getId()); + + //Get dances + $dances = $this->doctrine->getRepository(Dance::class)->findAllIndexed(); + + //Set dance default + $danceDefault = !empty($this->context['session']['application'])?$dances[$this->context['session']['application']['dance']['id']]:null; + } + //Create SessionType form //TODO: move to named form ??? - $sessionForm = $this->createForm('Rapsys\AirBundle\Form\SessionType', null, [ + $sessionForm = $this->factory->create('Rapsys\AirBundle\Form\SessionType', null, [ //Set the action 'action' => $this->generateUrl('rapsys_air_session_view', ['id' => $id, 'location' => $this->context['session']['location']['slug'], 'dance' => $this->context['session']['application']['dance']['slug']??null, 'user' => $this->context['session']['application']['user']['slug']??null]), //Set the form attribute 'attr' => [ 'class' => 'col' ], //Set admin - 'admin' => $this->isGranted('ROLE_ADMIN'), + 'admin' => $this->checker->isGranted('ROLE_ADMIN'), + //Set dance choices + 'dance_choices' => $dances, + //Set dance default + 'dance_default' => $danceDefault, + //Set dance favorites + 'dance_favorites' => $danceFavorites, + //Set to session slot or evening by default + //XXX: default to Evening (3) + 'slot_default' => $this->doctrine->getRepository(Slot::class)->findOneById($this->context['session']['slot']['id']??3), //Set default user to current - 'user' => $this->getUser()->getId(), + 'user' => $this->security->getUser()->getId(), //Set date 'date' => $this->context['session']['date'], //Set begin @@ -440,15 +466,15 @@ class SessionController extends AbstractController { //Set length 'length' => $this->context['session']['length'], //Set raincancel - 'raincancel' => ($this->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->getUser()->getId() == $this->context['session']['application']['user']['id']) && $this->context['session']['rainfall'] >= 2, + 'raincancel' => ($this->checker->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->security->getUser()->getId() == $this->context['session']['application']['user']['id']) && $this->context['session']['rainfall'] >= 2, //Set cancel - 'cancel' => $this->isGranted('ROLE_ADMIN') || in_array($this->getUser()->getId(), explode("\n", $this->context['session']['sau_id'])), + 'cancel' => $this->checker->isGranted('ROLE_ADMIN') || in_array($this->security->getUser()->getId(), explode("\n", $this->context['session']['sau_id'])), //Set modify - 'modify' => $this->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->getUser()->getId() == $this->context['session']['application']['user']['id'] && $this->context['session']['stop'] >= $now && $this->isGranted('ROLE_REGULAR'), + 'modify' => $this->checker->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->security->getUser()->getId() == $this->context['session']['application']['user']['id'] && $this->context['session']['stop'] >= $now && $this->checker->isGranted('ROLE_REGULAR'), //Set move - 'move' => $this->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->getUser()->getId() == $this->context['session']['application']['user']['id'] && $this->context['session']['stop'] >= $now && $this->isGranted('ROLE_SENIOR'), + 'move' => $this->checker->isGranted('ROLE_ADMIN') || !empty($this->context['session']['application']['user']['id']) && $this->security->getUser()->getId() == $this->context['session']['application']['user']['id'] && $this->context['session']['stop'] >= $now && $this->checker->isGranted('ROLE_SENIOR'), //Set attribute - 'attribute' => $this->isGranted('ROLE_ADMIN') && $this->context['session']['locked'] === null, + 'attribute' => $this->checker->isGranted('ROLE_ADMIN') && $this->context['session']['locked'] === null, //Set session 'session' => $this->context['session']['id'] ]); @@ -465,10 +491,10 @@ class SessionController extends AbstractController { $sessionObject = $this->doctrine->getRepository(Session::class)->findOneById($id); //Set user - $userObject = $this->getUser(); + $userObject = $this->security->getUser(); //Replace with requested user for admin - if ($this->isGranted('ROLE_ADMIN') && !empty($data['user'])) { + if ($this->checker->isGranted('ROLE_ADMIN') && !empty($data['user'])) { $userObject = $this->doctrine->getRepository(User::class)->findOneById($data['user']); } @@ -491,7 +517,7 @@ class SessionController extends AbstractController { ]; //With raincancel and application and (rainfall or admin) - if ($action['raincancel'] && ($application = $sessionObject->getApplication()) && ($sessionObject->getRainfall() >= 2 || $this->isGranted('ROLE_ADMIN'))) { + if ($action['raincancel'] && ($application = $sessionObject->getApplication()) && ($sessionObject->getRainfall() >= 2 || $this->checker->isGranted('ROLE_ADMIN'))) { //Cancel application at start minus one day $application->setCanceled($canceled); @@ -523,7 +549,19 @@ class SessionController extends AbstractController { //With modify } elseif ($action['modify']) { //With admin - if ($this->isGranted('ROLE_ADMIN')) { + if ($this->checker->isGranted('ROLE_ADMIN')) { + //Get application + $application = $this->doctrine->getRepository(Application::class)->findOneBySessionUser($sessionObject, $userObject); + + //Set dance + $application->setDance($data['dance']); + + //Queue session save + $this->manager->persist($application); + + //Set slot + $sessionObject->setSlot($data['slot']); + //Set date $sessionObject->setDate($data['date']); }