Skip to content
Open
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
99 changes: 0 additions & 99 deletions sources/Afup/Forum/Inscriptions.php

This file was deleted.

4 changes: 1 addition & 3 deletions sources/AppBundle/Controller/Admin/Event/StatsAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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 = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Doctrine\DBAL\ArrayParameterType;
use Doctrine\DBAL\Connection;
use Webmozart\Assert\Assert;
use DateTimeImmutable;

class EventStatsRepository
{
Expand All @@ -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
Expand Down Expand Up @@ -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(
Expand Down
Loading