Skip to content

Commit

Permalink
feat(events): add a selector for easier event comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceAmstoutz committed Dec 28, 2024
1 parent 12c0ec8 commit c628ff0
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 4 deletions.
12 changes: 12 additions & 0 deletions app/Resources/views/admin/event/compare_event.html.twig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<div class="ui violet segment">
{{ form_start(form) }}
<div class="ui form">
<div class="inline fields">
<div class="field">
{{ form_label(form.id, 'Comparer à') }}
{{ form_widget(form.id, {attr: {onchange:'this.name="id"; this.form.submit(); return false;'}}) }}
</div>
</div>
</div>
{{ form_end(form) }}
</div>
2 changes: 1 addition & 1 deletion app/Resources/views/admin/event/stats.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
{% include 'admin/event/change_event.html.twig' with {form: event_select_form} only %}

{% if event == null %}

<div class="ui placeholder segment">
<div class="ui icon header">
<i class="meh outline icon"></i>
Expand All @@ -15,6 +14,7 @@
{% else %}
<div class="ui segment">
<h2 class="ui header">Évolution des inscriptions</h2>
{% include 'admin/event/compare_event.html.twig' with {form: event_compare_form} only %}
<div class="ui clearing divider"></div>
<div id="container"></div>
</div>
Expand Down
4 changes: 4 additions & 0 deletions app/config/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions sources/AppBundle/Controller/Admin/Event/StatsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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(),
]));
}
}
46 changes: 46 additions & 0 deletions sources/AppBundle/Event/Form/EventCompareSelectType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php


namespace AppBundle\Event\Form;

use AppBundle\Event\Model\Event;
use AppBundle\Event\Model\Repository\EventRepository;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\OptionsResolver\OptionsResolver;

class EventCompareSelectType extends AbstractType
{
/** @var EventRepository */
private $eventRepository;

public function __construct(EventRepository $eventRepository)
{
$this->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
]);
}
}
18 changes: 15 additions & 3 deletions sources/AppBundle/Event/Model/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down

0 comments on commit c628ff0

Please sign in to comment.