From: Raphaël Gertz Date: Tue, 23 Feb 2021 23:58:33 +0000 (+0100) Subject: Rename SessionEditType in SessionType X-Git-Tag: 0.2.1~38 X-Git-Url: https://git.rapsys.eu/.gitweb.cgi/airbundle/commitdiff_plain/5eaefbbc2e975fc4aee4e9897c39a7939046f22c?hp=24f36b713eff5d897518b317bc11b9a40371f9a0 Rename SessionEditType in SessionType Rename organizer in user controller Rename Title in Civility Remove Vote entity Add twig location shared template Rename twig template session_edit in session Rename template for organizer in user --- diff --git a/Controller/OrganizerController.php b/Controller/OrganizerController.php deleted file mode 100644 index 7bb7e98..0000000 --- a/Controller/OrganizerController.php +++ /dev/null @@ -1,232 +0,0 @@ -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); - } -} diff --git a/Form/SessionEditType.php b/Form/SessionEditType.php deleted file mode 100644 index 7841e70..0000000 --- a/Form/SessionEditType.php +++ /dev/null @@ -1,115 +0,0 @@ -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'; - } -} diff --git a/Resources/config/doctrine/Title.orm.yml b/Resources/config/doctrine/Civility.orm.yml similarity index 100% rename from Resources/config/doctrine/Title.orm.yml rename to Resources/config/doctrine/Civility.orm.yml diff --git a/Resources/config/doctrine/Vote.orm.yml b/Resources/config/doctrine/Vote.orm.yml deleted file mode 100644 index ee8e2ea..0000000 --- a/Resources/config/doctrine/Vote.orm.yml +++ /dev/null @@ -1,23 +0,0 @@ -Rapsys\AirBundle\Entity\Vote: - type: entity - #repositoryClass: Rapsys\AirBundle\Repository\VoteRepository - table: votes - id: - id: - type: integer - generator: - strategy: AUTO - options: - unsigned: true - fields: - created: - type: datetime - updated: - type: datetime - manyToOne: - application: - targetEntity: Rapsys\AirBundle\Entity\Application - inversedBy: votes - user: - targetEntity: Rapsys\AirBundle\Entity\User - inversedBy: votes diff --git a/Resources/views/default/_location.html.twig b/Resources/views/default/_location.html.twig new file mode 100644 index 0000000..32e9b70 --- /dev/null +++ b/Resources/views/default/_location.html.twig @@ -0,0 +1,48 @@ +{# Display locations calendar #} +{% if locations is defined and locations %} +
+
+

{% trans %}Locations{% endtrans %}

+ {% if forms.snippets is defined %} +

{% trans %}Organizer's snippet by dance space{% endtrans %}

+ {% else %} +

{% trans %}Libre Air location list{% endtrans %}

+ {% endif %} +
+
+
+ {% for id, title in locations %} +
+

{{ title }}

+ {% if forms.snippets is defined and forms.snippets[id] is defined and forms.snippets[id] %} + {{ form_start(forms.snippets[id]) }} +
+ {{ form_row(forms.snippets[id].description) }} + + {{ form_row(forms.snippets[id].class) }} + + {{ form_row(forms.snippets[id].contact) }} + + {{ form_row(forms.snippets[id].donate) }} + + {{ form_row(forms.snippets[id].link) }} + + {{ form_row(forms.snippets[id].profile) }} + + {{ form_row(forms.snippets[id].submit) }} + + {% if forms.snippets[id].delete is defined %} + {{ form_row(forms.snippets[id].delete) }} + {% endif %} +
+ + {# render csrf token etc .#} + + {{ form_end(forms.snippets[id]) }} + {% endif %} +
+ {% endfor %} +
+
+
+{% endif %} diff --git a/Resources/views/form/_session_edit.html.twig b/Resources/views/form/_session.html.twig similarity index 100% rename from Resources/views/form/_session_edit.html.twig rename to Resources/views/form/_session.html.twig diff --git a/Resources/views/organizer/index.html.twig b/Resources/views/user/index.html.twig similarity index 100% rename from Resources/views/organizer/index.html.twig rename to Resources/views/user/index.html.twig diff --git a/Resources/views/organizer/view.html.twig b/Resources/views/user/view.html.twig similarity index 100% rename from Resources/views/organizer/view.html.twig rename to Resources/views/user/view.html.twig