]> Raphaël G. Git Repositories - airbundle/commitdiff
Rename SessionEditType in SessionType
authorRaphaël Gertz <git@rapsys.eu>
Tue, 23 Feb 2021 23:58:33 +0000 (00:58 +0100)
committerRaphaël Gertz <git@rapsys.eu>
Tue, 23 Feb 2021 23:59:03 +0000 (00:59 +0100)
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

Controller/OrganizerController.php [deleted file]
Form/SessionEditType.php [deleted file]
Resources/config/doctrine/Civility.orm.yml [moved from Resources/config/doctrine/Title.orm.yml with 100% similarity]
Resources/config/doctrine/Vote.orm.yml [deleted file]
Resources/views/default/_location.html.twig [new file with mode: 0644]
Resources/views/form/_session.html.twig [moved from Resources/views/form/_session_edit.html.twig with 100% similarity]
Resources/views/user/index.html.twig [moved from Resources/views/organizer/index.html.twig with 100% similarity]
Resources/views/user/view.html.twig [moved from Resources/views/organizer/view.html.twig with 100% similarity]

diff --git a/Controller/OrganizerController.php b/Controller/OrganizerController.php
deleted file mode 100644 (file)
index 7bb7e98..0000000
+++ /dev/null
@@ -1,232 +0,0 @@
-<?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);
-       }
-}
diff --git a/Form/SessionEditType.php b/Form/SessionEditType.php
deleted file mode 100644 (file)
index 7841e70..0000000
+++ /dev/null
@@ -1,115 +0,0 @@
-<?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';
-       }
-}
diff --git a/Resources/config/doctrine/Vote.orm.yml b/Resources/config/doctrine/Vote.orm.yml
deleted file mode 100644 (file)
index ee8e2ea..0000000
+++ /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 (file)
index 0000000..32e9b70
--- /dev/null
@@ -0,0 +1,48 @@
+{# Display locations calendar #}
+{% if locations is defined and locations %}
+       <article class="location">
+               <header>
+                       <h2><a href="{{ path('rapsys_air_location') }}">{% trans %}Locations{% endtrans %}</a></h2>
+                       {% if forms.snippets is defined %}
+                               <p>{% trans %}Organizer's snippet by dance space{% endtrans %}</p>
+                       {% else %}
+                               <p>{% trans %}Libre Air location list{% endtrans %}</p>
+                       {% endif %}
+               </header>
+               <div class="panel">
+                       <div class="grid four">
+                               {% for id, title in locations %}
+                                       <article class="cell">
+                                               <h3><a href="{{ path('rapsys_air_location_view', {'id': id}) }}">{{ title }}</a></h3>
+                                               {% if forms.snippets is defined and forms.snippets[id] is defined and forms.snippets[id] %}
+                                                       {{ form_start(forms.snippets[id]) }}
+                                                               <div>
+                                                                       {{ 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 %}
+                                                               </div>
+
+                                                               {# render csrf token etc .#}
+                                                               <footer style="display:none">{{ form_rest(forms.snippets[id]) }}</footer>
+                                                       {{ form_end(forms.snippets[id]) }}
+                                               {% endif %}
+                                       </article>
+                               {% endfor %}
+                       </div>
+               </div>
+       </article>
+{% endif %}