+++ /dev/null
-<?php
-
-namespace Rapsys\AirBundle\Controller;
-
-use Symfony\Component\HttpFoundation\Request;
-
-use Rapsys\AirBundle\Entity\Slot;
-use Rapsys\AirBundle\Entity\Session;
-use Rapsys\AirBundle\Entity\Location;
-use Rapsys\AirBundle\Entity\User;
-use Rapsys\AirBundle\Entity\Snippet;
-
-class OrganizerController extends DefaultController {
- /**
- * List all organizers
- *
- * @desc Display all user with a group listed as organizers
- *
- * @param Request $request The request instance
- * @param int $id The user id
- *
- * @return Response The rendered view
- */
- public function index(Request $request) {
- //Fetch doctrine
- $doctrine = $this->getDoctrine();
-
- //Set section
- $section = $this->translator->trans('Argentine Tango organizers');
-
- //Set description
- $this->context['description'] = $this->translator->trans('Outdoor Argentine Tango organizer list');
-
- //Set keywords
- $this->context['keywords'] = [
- $this->translator->trans('Argentine Tango'),
- $this->translator->trans('outdoor'),
- $this->translator->trans('organizer'),
- $this->translator->trans('Libre Air')
- ];
-
- //Set title
- $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
-
- //Init context
- $context = [];
-
- //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' ]
- ]);
-
- //Add form to context
- $context['login'] = $login->createView();
- }
-
- //Fetch organizers
- $organizers = $doctrine->getRepository(User::class)->findOrganizerGroupedByGroup($this->translator);
-
- //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('Monday this week + 5 week')
- );
-
- //Fetch locations
- //XXX: we want to display all active locations anyway
- $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period);
-
- //Render the view
- return $this->render('@RapsysAir/organizer/index.html.twig', ['title' => $title, 'section' => $section, 'organizers' => $organizers, 'locations' => $locations]+$context+$this->context);
- }
-
- /**
- * List all sessions for the organizer
- *
- * @desc Display all sessions for the user with an application or login form
- *
- * @param Request $request The request instance
- * @param int $id The user id
- *
- * @return Response The rendered view
- */
- public function view(Request $request, $id) {
- //Fetch doctrine
- $doctrine = $this->getDoctrine();
-
- //Fetch user
- if (empty($user = $doctrine->getRepository(User::class)->findOneById($id))) {
- throw $this->createNotFoundException($this->translator->trans('Unable to find organizer: %id%', ['%id%' => $id]));
- }
-
- //Set section
- $section = $user->getPseudonym();
-
- //Set title
- $title = $this->translator->trans($this->config['site']['title']).' - '.$section;
-
- //Init context
- $context = [];
-
- //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' ]
- ]);
-
- //Add form to context
- $context['login'] = $login->createView();
- }
-
- //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('Monday this week + 5 week')
- );
-
- //Fetch calendar
- //TODO: highlight with current session route parameter
- $calendar = $doctrine->getRepository(Session::class)->fetchUserCalendarByDatePeriod($this->translator, $period, $id, $request->get('session'));
-
- //Fetch locations
- //XXX: we want to display all active locations anyway
- $locations = $doctrine->getRepository(Location::class)->findTranslatedSortedByPeriod($this->translator, $period, $id);
-
- //Create snippet forms for role_guest
- if ($this->isGranted('ROLE_GUEST')) {
- //Fetch all user snippet
- $snippets = $doctrine->getRepository(Snippet::class)->findByLocaleUserId($request->getLocale(), $id);
-
- //Rekey by location id
- $snippets = array_reduce($snippets, function($carry, $item){$carry[$item->getLocation()->getId()] = $item; return $carry;}, []);
-
- //Init snippets to context
- $context['snippets'] = [];
-
- //Iterate on locations
- foreach($locations as $locationId => $location) {
- //Init snippet
- $snippet = new Snippet();
-
- //Set default locale
- $snippet->setLocale($request->getLocale());
-
- //Set default user
- $snippet->setUser($user);
-
- //Set default location
- $snippet->setLocation($doctrine->getRepository(Location::class)->findOneById($locationId));
-
- //Get snippet
- if (!empty($snippets[$locationId])) {
- $snippet = $snippets[$locationId];
- }
-
- //Create SnippetType form
- $form = $this->createForm('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'),
- #'action' => $this->generateUrl('rapsys_air_snippet_add'),
- //Set the form attribute
- 'attr' => [],
- //Set csrf_token_id
- //TODO: would maybe need a signature field
- //'csrf_token_id' => $request->getLocale().'_'.$id.'_'.$locationId
- ]);
-
- //Add form to context
- $context['snippets'][$locationId] = $form->createView();
- }
- }
-
- //Render the view
- return $this->render('@RapsysAir/organizer/view.html.twig', ['id' => $id, 'title' => $title, 'section' => $section, 'calendar' => $calendar, 'locations' => $locations]+$context+$this->context);
- }
-}
+++ /dev/null
-<?php
-
-namespace Rapsys\AirBundle\Form;
-
-use Symfony\Bridge\Doctrine\RegistryInterface;
-use Symfony\Component\Form\AbstractType;
-use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
-use Symfony\Component\Form\Extension\Core\Type\SubmitType;
-use Symfony\Component\Form\Extension\Core\Type\TimeType;
-use Symfony\Component\Form\FormBuilderInterface;
-use Symfony\Component\OptionsResolver\OptionsResolver;
-use Symfony\Component\Translation\TranslatorInterface;
-use Symfony\Component\Validator\Constraints\NotBlank;
-use Symfony\Component\Validator\Constraints\Time;
-use Rapsys\AirBundle\Entity\User;
-use Rapsys\AirBundle\Entity\Location;
-
-class SessionEditType extends AbstractType {
- //Doctrine instance
- private $doctrine;
-
- /**
- * {@inheritdoc}
- */
- public function __construct(RegistryInterface $doctrine) {
- $this->doctrine = $doctrine;
- }
-
- /**
- * {@inheritdoc}
- */
- public function buildForm(FormBuilderInterface $builder, array $options) {
- //Is admin or user with rainfall >= 2
- if (!empty($options['raincancel'])) {
- //Add raincancel item
- $builder->add('raincancel', SubmitType::class, ['label' => 'Rain cancel', 'attr' => ['class' => 'submit']]);
- //Is admin
- } elseif (!empty($options['admin'])) {
- //Add forcecancel item
- $builder->add('forcecancel', SubmitType::class, ['label' => 'Force cancel', 'attr' => ['class' => 'submit']]);
- }
-
- //Is admin or owner
- if (!empty($options['modify'])) {
- $builder
- //TODO: avertissement + minimum et maximum ???
- ->add('begin', TimeType::class, ['attr' => ['placeholder' => 'Your begin', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['begin'], 'constraints' => [new NotBlank(['message' => 'Please provide your begin']), new Time(['message' => 'Your begin doesn\'t seems to be valid'])]])
- //TODO: avertissement + minimum et maximum ???
- ->add('length', TimeType::class, ['attr' => ['placeholder' => 'Your length', 'class' => 'time'], 'html5' => true, 'input' => 'datetime', 'widget' => 'single_text', 'data' => $options['length'], 'constraints' => [new NotBlank(['message' => 'Please provide your length']), new Time(['message' => 'Your length doesn\'t seems to be valid'])]])
- ->add('modify', SubmitType::class, ['label' => 'Modify', 'attr' => ['class' => 'submit']]);
- }
-
- //Is admin or applicant
- if (!empty($options['cancel'])) {
- $builder->add('cancel', SubmitType::class, ['label' => 'Cancel', 'attr' => ['class' => 'submit']]);
- }
-
- //Is admin or senior owner
- if (!empty($options['move'])) {
- //Load locations
- $locations = $this->doctrine->getRepository(Location::class)->findComplementBySessionId($options['session']);
- $builder
- //TODO: class senior en orange ???
- ->add('location', ChoiceType::class, ['attr' => ['placeholder' => 'Your location'], 'constraints' => [new NotBlank(['message' => 'Please provide your location'])], 'choices' => $locations, 'choice_translation_domain' => true])
- ->add('move', SubmitType::class, ['label' => 'Move', 'attr' => ['class' => 'submit']]);
- }
-
- //Add extra user field
- if (!empty($options['admin'])) {
- //Load users
- $users = $this->doctrine->getRepository(User::class)->findAllApplicantBySession($options['session']);
- //Add admin fields
- $builder
- //TODO: class admin en rouge ???
- ->add('user', ChoiceType::class, ['attr' => ['placeholder' => 'Your user'], 'constraints' => [new NotBlank(['message' => 'Please provide your user'])], 'choices' => $users, 'data' => $options['user'], 'choice_translation_domain' => false])
- ->add('lock', SubmitType::class, ['label' => 'Lock', 'attr' => ['class' => 'submit']]);
-
- //Is admin and locked === null
- if (!empty($options['attribute'])) {
- //Add attribute fields
- $builder
- ->add('attribute', SubmitType::class, ['label' => 'Attribute', 'attr' => ['class' => 'submit']])
- ->add('autoattribute', SubmitType::class, ['label' => 'Auto attribute', 'attr' => ['class' => 'submit']]);
- }
- }
-
- //Return form
- return $builder;
- }
-
- /**
- * {@inheritdoc}
- */
- public function configureOptions(OptionsResolver $resolver) {
- $resolver->setDefaults(['error_bubbling' => true, 'admin' => false, 'begin' => null, 'length' => null, 'cancel' => false, 'raincancel' => false, 'modify' => false, 'move' => false, 'attribute' => false, 'user' => null, 'session' => null]);
- $resolver->setAllowedTypes('admin', 'boolean');
- #TODO: voir si c'est le bon type
- $resolver->setAllowedTypes('begin', 'datetime');
- $resolver->setAllowedTypes('length', 'datetime');
- $resolver->setAllowedTypes('cancel', 'boolean');
- $resolver->setAllowedTypes('raincancel', 'boolean');
- $resolver->setAllowedTypes('modify', 'boolean');
- $resolver->setAllowedTypes('move', 'boolean');
- $resolver->setAllowedTypes('attribute', 'boolean');
- $resolver->setAllowedTypes('user', 'integer');
- $resolver->setAllowedTypes('session', 'integer');
- }
-
- /**
- * {@inheritdoc}
- */
- public function getName() {
- return 'rapsys_air_session_edit';
- }
-}