diff --git a/sources/Afup/Forum/Inscriptions.php b/sources/Afup/Forum/Inscriptions.php deleted file mode 100644 index 611f6dcf9..000000000 --- a/sources/Afup/Forum/Inscriptions.php +++ /dev/null @@ -1,99 +0,0 @@ -_bdd); - if (null === $idForumPrecedent) { - $idForumPrecedent = $forum->obtenirForumPrecedent($idForum); - } - - $now = new \DateTime(); - $dateForum = new \DateTimeImmutable('@' . $forum->obtenir($idForum)['date_fin_vente']); - - $daysToEndOfSales = 0; - if ($dateForum >= $now) { - $daysToEndOfSales = $dateForum->diff($now)->format('%r%a'); - } - - $requete = ' - SELECT SUM(nombre) as nombre, jour, id_forum - FROM ( - SELECT - COUNT(*) as nombre, - DATEDIFF(FROM_UNIXTIME(date, \'%Y-%m-%d\'), FROM_UNIXTIME(af.date_fin_vente, \'%Y-%m-%d\')) as jour, - id_forum - FROM - afup_inscription_forum i - RIGHT JOIN afup_forum_tarif aft ON (aft.id = i.type_inscription AND aft.default_price > 0) - LEFT JOIN afup_forum af ON af.id = i.id_forum - WHERE - i.id_forum IN (' . (int) $idForum . ', ' . (int) $idForumPrecedent . ') - AND - etat <> 1 - GROUP BY jour, i.id_forum - HAVING jour < 0 - UNION ALL - SELECT - SUM(max_invitations) as nombre, - DATEDIFF(created_on, FROM_UNIXTIME(af.date_fin_vente, \'%Y-%m-%d\')) as jour, - id_forum - FROM afup_forum_sponsors_tickets st - LEFT JOIN afup_forum af ON af.id = st.id_forum - WHERE - st.id_forum IN (' . (int) $idForum . ', ' . (int) $idForumPrecedent . ') - GROUP BY jour, st.id_forum - HAVING jour < 0 - ORDER BY jour ASC - ) all_data - GROUP BY jour, id_forum - '; - $nombre_par_date = $this->_bdd->obtenirTous($requete); - - if ([] === $nombre_par_date) { - $nombre_par_date = [['jour' => 1]]; - } - - $suivis = []; - - for ($i = $nombre_par_date[0]['jour']; $i <= 0; $i++) { - $infoForum = array_sum(array_map(function (array $info) use ($i, $idForum) { - if ($info['id_forum'] == $idForum && $info['jour'] <= $i) { - return $info['nombre']; - } - return 0; - }, $nombre_par_date)); - $infoN1 = array_sum(array_map(function (array $info) use ($i, $idForumPrecedent) { - if ($info['id_forum'] == $idForumPrecedent && $info['jour'] <= $i) { - return $info['nombre']; - } - return 0; - }, $nombre_par_date)); - $suivis[$i] = [ - 'jour' => $i, - 'n' => $daysToEndOfSales >= $i ? $infoForum : null, - 'n_1' => $infoN1, - ]; - } - - return [ - 'suivi' => $suivis, - 'min' => $nombre_par_date[0]['jour'], - 'max' => $i, - 'daysToEndOfSales' => $daysToEndOfSales, - ]; - } -} diff --git a/sources/AppBundle/Controller/Admin/Event/StatsAction.php b/sources/AppBundle/Controller/Admin/Event/StatsAction.php index 452879a66..2b42938a8 100644 --- a/sources/AppBundle/Controller/Admin/Event/StatsAction.php +++ b/sources/AppBundle/Controller/Admin/Event/StatsAction.php @@ -4,7 +4,6 @@ namespace AppBundle\Controller\Admin\Event; -use Afup\Site\Forum\Inscriptions; use AppBundle\Controller\Event\EventActionHelper; use AppBundle\Event\Form\EventCompareSelectType; use AppBundle\Event\Model\Repository\EventRepository; @@ -21,7 +20,6 @@ public function __construct( private readonly TicketTypeRepository $ticketTypeRepository, private readonly EventStatsRepository $eventStatsRepository, private readonly EventRepository $eventRepository, - private readonly Inscriptions $inscriptions, ) {} public function __invoke(Request $request): Response @@ -40,7 +38,7 @@ public function __invoke(Request $request): Response 'events' => $this->eventRepository->getAll(), ]); - $stats = $this->inscriptions->obtenirSuivi($event->getId(), $comparedEvent->getId()); + $stats = $this->eventStatsRepository->getRegistrationTracking($event->getId(), $comparedEvent->getId()); $ticketTypes = []; $chart = [ diff --git a/sources/AppBundle/Event/Model/Repository/EventRepository.php b/sources/AppBundle/Event/Model/Repository/EventRepository.php index 9c18a1696..8a7e35cfc 100644 --- a/sources/AppBundle/Event/Model/Repository/EventRepository.php +++ b/sources/AppBundle/Event/Model/Repository/EventRepository.php @@ -296,6 +296,13 @@ public function getAllSortedByTitre(): CollectionInterface return $query->query($this->getCollection(new HydratorSingleObject())); } + public function getPreviousForum(int $eventId): ?int + { + $query = $this->getQuery('SELECT MAX(id) as id FROM afup_forum WHERE id < :id AND titre LIKE "%Forum%"'); + + return $query->setParams(['id' => $eventId])->query($this->getCollection(new HydratorArray()))->first()['id']; + } + public static function initMetadata(SerializerFactoryInterface $serializerFactory, array $options = []) { $metadata = new Metadata($serializerFactory); diff --git a/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php b/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php index f9dc475fd..1cb0320dc 100644 --- a/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php +++ b/sources/AppBundle/Event/Model/Repository/EventStatsRepository.php @@ -13,6 +13,7 @@ use Doctrine\DBAL\ArrayParameterType; use Doctrine\DBAL\Connection; use Webmozart\Assert\Assert; +use DateTimeImmutable; class EventStatsRepository { @@ -24,6 +25,7 @@ public function __construct( private readonly Connection $connection, private readonly TalkRepository $talkRepository, private readonly TalkToSpeakersRepository $talkToSpeakersRepository, + private readonly EventRepository $eventRepository, ) {} public function getStats(int $eventId, Datetime $from = null): EventStats @@ -127,6 +129,93 @@ private function getStatsForDay(int $eventId, string $day, ?Datetime $from = nul return new DailyStats($registered, $confirmed, $pending, $paid); } + public function getRegistrationTracking(int $eventId, ?int $previousEventId = null): array + { + if ($previousEventId === null) { + $previousEventId = $this->eventRepository->getPreviousForum($eventId) ?? 0; + } + + $event = $this->eventRepository->get($eventId); + + $now = new \DateTime(); + $dateForum = DateTimeImmutable::createFromInterface($event->getDateEndSales()); + + $daysToEndOfSales = 0; + if ($dateForum >= $now) { + $daysToEndOfSales = (int) $dateForum->diff($now)->format('%r%a'); + } + + $sql = " + SELECT SUM(nombre) as nombre, jour, id_forum + FROM ( + SELECT + COUNT(*) as nombre, + DATEDIFF(FROM_UNIXTIME(date, '%Y-%m-%d'), FROM_UNIXTIME(af.date_fin_vente, '%Y-%m-%d')) as jour, + id_forum + FROM + afup_inscription_forum i + RIGHT JOIN afup_forum_tarif aft ON (aft.id = i.type_inscription AND aft.default_price > 0) + LEFT JOIN afup_forum af ON af.id = i.id_forum + WHERE + i.id_forum IN (:eventId, :previousEventId) + AND + etat <> 1 + GROUP BY jour, i.id_forum + HAVING jour < 0 + UNION ALL + SELECT + SUM(max_invitations) as nombre, + DATEDIFF(created_on, FROM_UNIXTIME(af.date_fin_vente, '%Y-%m-%d')) as jour, + id_forum + FROM afup_forum_sponsors_tickets st + LEFT JOIN afup_forum af ON af.id = st.id_forum + WHERE + st.id_forum IN (:eventId, :previousEventId) + GROUP BY jour, st.id_forum + HAVING jour < 0 + ORDER BY jour ASC + ) all_data + GROUP BY jour, id_forum + "; + + $nombreParDate = $this->connection->executeQuery( + $sql, + ['eventId' => $eventId, 'previousEventId' => $previousEventId], + )->fetchAllAssociative(); + + if ($nombreParDate === []) { + $nombreParDate = [['jour' => 1]]; + } + + $suivis = []; + for ($i = $nombreParDate[0]['jour']; $i <= 0; $i++) { + $infoForum = array_sum(array_map(function (array $info) use ($i, $eventId) { + if ((int) $info['id_forum'] === $eventId && $info['jour'] <= $i) { + return $info['nombre']; + } + return 0; + }, $nombreParDate)); + $infoN1 = array_sum(array_map(function (array $info) use ($i, $previousEventId) { + if ((int) $info['id_forum'] === $previousEventId && $info['jour'] <= $i) { + return $info['nombre']; + } + return 0; + }, $nombreParDate)); + $suivis[$i] = [ + 'jour' => $i, + 'n' => $daysToEndOfSales >= $i ? $infoForum : null, + 'n_1' => $infoN1, + ]; + } + + return [ + 'suivi' => $suivis, + 'min' => $nombreParDate[0]['jour'], + 'max' => $i, + 'daysToEndOfSales' => $daysToEndOfSales, + ]; + } + public function getCFPStats(int $eventId): CFPStats { return new CFPStats(