From c628ff0c1baf8f7e4327ae53664b17dbd2541fdb Mon Sep 17 00:00:00 2001 From: Vincent Amstoutz Date: Sat, 28 Dec 2024 18:10:41 +0100 Subject: [PATCH] feat(events): add a selector for easier event comparison --- .../views/admin/event/compare_event.html.twig | 12 +++++ .../views/admin/event/stats.html.twig | 2 +- app/config/services.yml | 4 ++ .../Controller/Admin/Event/StatsAction.php | 2 + .../Event/Form/EventCompareSelectType.php | 46 +++++++++++++++++++ .../Model/Repository/EventRepository.php | 18 ++++++-- 6 files changed, 80 insertions(+), 4 deletions(-) create mode 100644 app/Resources/views/admin/event/compare_event.html.twig create mode 100644 sources/AppBundle/Event/Form/EventCompareSelectType.php diff --git a/app/Resources/views/admin/event/compare_event.html.twig b/app/Resources/views/admin/event/compare_event.html.twig new file mode 100644 index 000000000..01d24884e --- /dev/null +++ b/app/Resources/views/admin/event/compare_event.html.twig @@ -0,0 +1,12 @@ +
+ {{ form_start(form) }} +
+
+
+ {{ form_label(form.id, 'Comparer à') }} + {{ form_widget(form.id, {attr: {onchange:'this.name="id"; this.form.submit(); return false;'}}) }} +
+
+
+ {{ form_end(form) }} +
diff --git a/app/Resources/views/admin/event/stats.html.twig b/app/Resources/views/admin/event/stats.html.twig index 6300bfef5..6c42e8afd 100644 --- a/app/Resources/views/admin/event/stats.html.twig +++ b/app/Resources/views/admin/event/stats.html.twig @@ -5,7 +5,6 @@ {% include 'admin/event/change_event.html.twig' with {form: event_select_form} only %} {% if event == null %} -
@@ -15,6 +14,7 @@ {% else %}

Évolution des inscriptions

+ {% include 'admin/event/compare_event.html.twig' with {form: event_compare_form} only %}
diff --git a/app/config/services.yml b/app/config/services.yml index d8e9366ea..64d4da691 100644 --- a/app/config/services.yml +++ b/app/config/services.yml @@ -132,6 +132,10 @@ services: autowire: true autoconfigure: true + AppBundle\Event\Form\EventCompareSelectType: + autowire: true + autoconfigure: true + AppBundle\Event\Form\SpeakerType: autowire: true autoconfigure: true diff --git a/sources/AppBundle/Controller/Admin/Event/StatsAction.php b/sources/AppBundle/Controller/Admin/Event/StatsAction.php index bdb63695f..b2aef81d4 100644 --- a/sources/AppBundle/Controller/Admin/Event/StatsAction.php +++ b/sources/AppBundle/Controller/Admin/Event/StatsAction.php @@ -4,6 +4,7 @@ use Afup\Site\Forum\Inscriptions; use AppBundle\Controller\Event\EventActionHelper; +use AppBundle\Event\Form\EventCompareSelectType; use AppBundle\Event\Form\EventSelectType; use AppBundle\Event\Model\Repository\EventStatsRepository; use AppBundle\Event\Model\Repository\TicketRepository; @@ -167,6 +168,7 @@ public function __invoke(Request $request) 'two' => $ticketsDayTwo, ], 'event_select_form' => $this->formFactory->create(EventSelectType::class, $event)->createView(), + 'event_compare_form' => $this->formFactory->create(EventCompareSelectType::class, $event)->createView(), ])); } } diff --git a/sources/AppBundle/Event/Form/EventCompareSelectType.php b/sources/AppBundle/Event/Form/EventCompareSelectType.php new file mode 100644 index 000000000..21d9e40d0 --- /dev/null +++ b/sources/AppBundle/Event/Form/EventCompareSelectType.php @@ -0,0 +1,46 @@ +eventRepository = $eventRepository; + } + + public function buildForm(FormBuilderInterface $builder, array $options) + { + $builder + ->add('id', ChoiceType::class, + [ + 'choice_label' => 'title', + 'choice_value' => 'id', + 'data' => $options['data'] ?? null, + 'choices' => $this->eventRepository->getPreviousEvents(), + ] + ) + ->setMethod(Request::METHOD_GET) + ; + } + + public function configureOptions(OptionsResolver $resolver) + { + $resolver->setDefaults([ + 'data_class' => Event::class, + 'csrf_protection' => false + ]); + } +} diff --git a/sources/AppBundle/Event/Model/Repository/EventRepository.php b/sources/AppBundle/Event/Model/Repository/EventRepository.php index b624a8a67..0ed62ba12 100644 --- a/sources/AppBundle/Event/Model/Repository/EventRepository.php +++ b/sources/AppBundle/Event/Model/Repository/EventRepository.php @@ -162,18 +162,30 @@ public function getCurrentEvent() } /** - * @param int $eventCount + * @param int|null $eventCount * * @return \CCMBenchmark\Ting\Repository\CollectionInterface */ - public function getPreviousEvents($eventCount) + public function getPreviousEvents($eventCount = null) { - $query = $this->getQuery('SELECT * FROM afup_forum WHERE date_debut < NOW() ORDER BY date_debut DESC LIMIT :limit'); + $baseQuery = 'SELECT * FROM afup_forum WHERE date_debut < NOW() ORDER BY date_debut DESC'; + + if ($eventCount === null) { + return $this->getQuery($baseQuery) + ->query( + $this->getCollection(new HydratorSingleObject()) + ); + + } + + $baseQuery .= ' LIMIT :limit'; + $query = $this->getQuery($baseQuery); $query->setParams(['limit' => $eventCount]); return $query->query($this->getCollection(new HydratorSingleObject())); } + /** * @param $path *