Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): add a selector for easier event comparison #1575

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.compared_event_id, 'Comparer à') }}
{{ form_widget(form.compared_event_id, {attr: {onchange:'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
6 changes: 1 addition & 5 deletions sources/Afup/Forum/Inscriptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,13 +88,9 @@ public function getRegistrationsByReference($reference)
*
* @return array
*/
function obtenirSuivi($idForum, $idForumPrecedent = null)
function obtenirSuivi($idForum, $idForumPrecedent)
{
$forum = new Forum($this->_bdd);
if (null === $idForumPrecedent) {
$idForumPrecedent = $forum->obtenirForumPrecedent($idForum);
}

$now = new \DateTime();
$dateForum = \DateTime::createFromFormat('U', $forum->obtenir($idForum)['date_fin_vente']);

Expand Down
30 changes: 29 additions & 1 deletion sources/AppBundle/Controller/Admin/Event/StatsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@

namespace AppBundle\Controller\Admin\Event;

use Afup\Site\Forum\Forum;
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 @@ -32,13 +34,19 @@
/** @var Environment */
private $twig;

/**
* @var Forum
*/
private $forum;

public function __construct(
EventActionHelper $eventActionHelper,
LegacyModelFactory $legacyModelFactory,
TicketRepository $ticketRepository,
TicketTypeRepository $ticketTypeRepository,
EventStatsRepository $eventStatsRepository,
FormFactoryInterface $formFactory,
Forum $forum,
Environment $twig
) {
$this->eventActionHelper = $eventActionHelper;
Expand All @@ -47,6 +55,7 @@
$this->ticketTypeRepository = $ticketTypeRepository;
$this->eventStatsRepository = $eventStatsRepository;
$this->formFactory = $formFactory;
$this->forum = $forum;
$this->twig = $twig;
}

Expand All @@ -55,16 +64,34 @@
$id = $request->query->get('id');
$comparedEventId = $request->query->get('compared_event_id');

if(!$id && !$comparedEventId) {
$compareData = $request->query->get('compare_event');
$id = $compareData['id'];
$comparedEventId = $compareData['compared_event_id'];
}

dump($id, $comparedEventId);

Check failure on line 73 in sources/AppBundle/Controller/Admin/Event/StatsAction.php

View workflow job for this annotation

GitHub Actions / PHPStan

Function dump not found.

$event = $this->eventActionHelper->getEventById($id);

$legacyInscriptions = $this->legacyModelFactory->createObject(Inscriptions::class);

$comparedSerieName = 'n-1';
if ($comparedEventId) {
$comparedEvent = $this->eventActionHelper->getEventById($comparedEventId, false);
$comparedSerieName = $comparedEvent->getTitle();
} elseif($id !== null) {
$comparedEventId = $this->forum->obtenirForumPrecedent($id);
$comparedEvent = $this->eventActionHelper->getEventById($comparedEventId, false);
$comparedSerieName = $comparedEvent->getTitle();
} else {
$comparedSerieName = 'n-1';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ici on pourrait se passer de ce elseif, et ne jamais afficher le "n-1", ça permettrais d'être plus lisible en étant toujours explicite et affichant toujours le nom de l'événement comparé (ce qui est maintenant possible vu qu'on a remonté l'appel à $this->forum->obtenirForumPrecedent($id)

}

$comparedEventForm = $this->formFactory->create(EventCompareSelectType::class, [
'id' => $id,
'compared_event_id' => $comparedEventId,
])->createView();

$stats = $legacyInscriptions->obtenirSuivi($event->getId(), $comparedEventId);
$ticketsDayOne = $this->ticketRepository->getPublicSoldTicketsByDay(Ticket::DAY_ONE, $event);
$ticketsDayTwo = $this->ticketRepository->getPublicSoldTicketsByDay(Ticket::DAY_TWO, $event);
Expand Down Expand Up @@ -167,6 +194,7 @@
'two' => $ticketsDayTwo,
],
'event_select_form' => $this->formFactory->create(EventSelectType::class, $event)->createView(),
'event_compare_form' => $comparedEventForm,
]));
}
}
66 changes: 66 additions & 0 deletions sources/AppBundle/Event/Form/EventCompareSelectType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<?php


namespace AppBundle\Event\Form;

use AppBundle\Event\Model\Repository\EventRepository;
use CCMBenchmark\Ting\Exception;
use CCMBenchmark\Ting\Query\QueryException;
use Symfony\Component\Form\AbstractType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
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;
}

/**
* @throws QueryException
* @throws Exception
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{

$eventId = $builder->getData()['id'] ?? null;
$excludedEventId = $builder->getData()['compared_event_id'] ?? null;
$events = $this->eventRepository->getAllEventsExcept($eventId);

dump($events->first());

Check failure on line 37 in sources/AppBundle/Event/Form/EventCompareSelectType.php

View workflow job for this annotation

GitHub Actions / PHPStan

Function dump not found.

$builder
->add('compared_event_id', ChoiceType::class,
[
'choice_label' => 'title',
'choice_value' => 'id',
'data' => "2",
'choices' => $events,
]
)
->setMethod(Request::METHOD_GET)
->add('id', HiddenType::class, [
'data' => $eventId,
])
;
}

public function configureOptions(OptionsResolver $resolver)
{
$resolver->setDefaults([
'csrf_protection' => false
]);
}

public function getBlockPrefix(): string
{
return 'compare_event';
}
}
19 changes: 19 additions & 0 deletions sources/AppBundle/Event/Model/Repository/EventRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use AppBundle\Event\Model\GithubUser;
use AppBundle\Event\Model\Ticket;
use CCMBenchmark\Ting\Driver\Mysqli\Serializer\Boolean;
use CCMBenchmark\Ting\Exception;
use CCMBenchmark\Ting\Query\QueryException;
use CCMBenchmark\Ting\Repository\CollectionInterface;
use CCMBenchmark\Ting\Repository\HydratorArray;
use CCMBenchmark\Ting\Repository\HydratorSingleObject;
Expand Down Expand Up @@ -174,6 +176,23 @@ public function getPreviousEvents($eventCount)
return $query->query($this->getCollection(new HydratorSingleObject()));
}

/**
* @param ?int $excludedEventId
*
* @throws QueryException
* @throws Exception
*/
public function getAllEventsExcept(int $excludedEventId = null): CollectionInterface
{
if($excludedEventId === null) {
return $this->getAll();
}

return $this->getQuery('SELECT * FROM afup_forum WHERE id <> :id ORDER BY date_debut DESC')
->setParams(['id' => $excludedEventId])
->query($this->getCollection(new HydratorSingleObject()));
}

/**
* @param $path
*
Expand Down
Loading