Skip to content

Commit

Permalink
added entry numbers per role into administration dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Aug 8, 2024
1 parent 942d3cd commit 01ec9bb
Show file tree
Hide file tree
Showing 6 changed files with 96 additions and 26 deletions.
3 changes: 2 additions & 1 deletion src/Participant/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,8 @@ public function showDashboard(
'contingentsPatrolStatistic' => $contingentStatistic,
'istArrivalStatistic' => $istArrivalStatistic,
'foodStatistic' => $foodStatistic,
'entryStatistic' => $this->participantRepository->getEntryStatistic($event),
'entryStatistic' => $this->participantRepository->getEntryStatisticGlobal($event),
'entryStatisticRoles' => $this->participantRepository->getEntryStatisticForAllowedRoles($event),
],
);
}
Expand Down
106 changes: 81 additions & 25 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,7 @@ public function getFoodStatistic(
/**
* @return array<string,int>
*/
public function getEntryStatistic(
public function getEntryStatisticGlobal(
Event $event
): array {
return [
Expand All @@ -328,6 +328,44 @@ public function getEntryStatistic(
];
}

/**
* @return array<string,array<string,int>>
*/
public function getEntryStatisticForAllowedRoles(Event $event): array
{
$entries = [];
if ($event->allowPatrols) {
$entries[ParticipantRole::PatrolLeader->value]
= $this->getEntryStatisticForRole($event, ParticipantRole::PatrolLeader);
}

if ($event->allowTroops) {
$entries[ParticipantRole::TroopLeader->value]
= $this->getEntryStatisticForRole($event, ParticipantRole::TroopLeader);
}

if ($event->allowIsts) {
$entries[ParticipantRole::Ist->value]
= $this->getEntryStatisticForRole($event, ParticipantRole::Ist);
}

return $entries;
}

/**
* @return array<string,int>
*/
public function getEntryStatisticForRole(
Event $event,
ParticipantRole $participantRole,
): array {
return [
'coming' => $this->countEntryComing($event, $participantRole),
'arrived' => $this->countEntryArrived($event, $participantRole),
'leave' => $this->countEntryLeave($event, $participantRole),
];
}

public function getStatistic(
Event $event,
ParticipantRole $role,
Expand Down Expand Up @@ -606,84 +644,102 @@ private function getAllPaidPatrolLeaders(Event $event): array
return $patrolLeaders;
}

private function countEntryComing(Event $event): int
{
$qb = $this->getQueryBuilderCountForPaidParticipants($event);
$qb = $qb->where('participant.entry_date IS NULL');
$qb = $qb->where('participant.leave_date IS NULL');
private function countEntryComing(
Event $event,
?ParticipantRole $participantRole = null,
): int {
$qb = $this->getQueryBuilderCountForPaidParticipants($event, $participantRole);
$qb->where('participant.entry_date IS NULL');
$qb->where('participant.leave_date IS NULL');

/** @var string $countParticipants */
$countParticipants = $qb->fetchSingle();

// count patrol participants and merge
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event);
$qb = $qb->where('participant.entry_date IS NULL');
$qb = $qb->where('participant.leave_date IS NULL');
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event, $participantRole);
$qb->where('participant.entry_date IS NULL');
$qb->where('participant.leave_date IS NULL');

/** @var string $countPatrolParticipants */
$countPatrolParticipants = $qb->fetchSingle();

return (int)$countParticipants + (int)$countPatrolParticipants;
}

private function countEntryArrived(Event $event): int
{
$qb = $this->getQueryBuilderCountForPaidParticipants($event);
private function countEntryArrived(
Event $event,
?ParticipantRole $participantRole = null,
): int {
$qb = $this->getQueryBuilderCountForPaidParticipants($event, $participantRole);
$qb = $qb->where('participant.entry_date IS NOT NULL');
$qb = $qb->where('participant.leave_date IS NULL');

/** @var string $countParticipants */
$countParticipants = $qb->fetchSingle();

// count patrol participants and merge
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event);
$qb = $qb->where('participant.entry_date IS NOT NULL');
$qb = $qb->where('participant.leave_date IS NULL');
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event, $participantRole);
$qb->where('participant.entry_date IS NOT NULL');
$qb->where('participant.leave_date IS NULL');

/** @var string $countPatrolParticipants */
$countPatrolParticipants = $qb->fetchSingle();

return (int)$countParticipants + (int)$countPatrolParticipants;
}

private function countEntryLeave(Event $event): int
{
$qb = $this->getQueryBuilderCountForPaidParticipants($event);
$qb = $qb->where('participant.leave_date IS NOT NULL');
private function countEntryLeave(
Event $event,
?ParticipantRole $participantRole = null,
): int {
$qb = $this->getQueryBuilderCountForPaidParticipants($event, $participantRole);
$qb->where('participant.leave_date IS NOT NULL');

/** @var string $countParticipants */
$countParticipants = $qb->fetchSingle();

// count patrol participants and merge
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event);
$qb = $qb->where('participant.leave_date IS NOT NULL');
$qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event, $participantRole);
$qb->where('participant.leave_date IS NOT NULL');

/** @var string $countPatrolParticipants */
$countPatrolParticipants = $qb->fetchSingle();

return (int)$countParticipants + (int)$countPatrolParticipants;
}

private function getQueryBuilderCountForPaidParticipants(Event $event): Fluent
{
private function getQueryBuilderCountForPaidParticipants(
Event $event,
?ParticipantRole $participantRole = null
): Fluent {
$qb = $this->connection->select('COUNT(participant.id)')->from($this->getTable());
$qb->join('user')->as('u')->on('u.id = participant.user_id');

$qb->where('u.status = %s', UserStatus::Paid);
$qb->where('u.event_id = %i', $event->id);

if ($participantRole !== null) {
$qb->where('participant.role = %s', $participantRole);
}

return $qb;
}

private function getQueryBuilderCountForPaidPatrolParticipants(Event $event): Fluent
{
private function getQueryBuilderCountForPaidPatrolParticipants(
Event $event,
?ParticipantRole $participantRole = null,
): Fluent {
$qb = $this->connection->select('COUNT(participant.id)')->from($this->getTable());
$qb->join('participant')->as('pl')->on('pl.id = participant.patrol_leader_id');
$qb->join('user')->as('u')->on('u.id = pl.user_id');

$qb->where('u.status = %s', UserStatus::Paid);
$qb->where('u.event_id = %i', $event->id);

if ($participantRole !== null) {
$qb->where('participant.role = %s', $participantRole);
}

return $qb;
}
}
1 change: 1 addition & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ dashboard-admin:
paidTp: "zaplacení účastníci"
paidGuest: "potvrzení hosté (nemuseli platit)"
entryCount: "Počty příjezdů"
entryCountPerRole: "Počty příjezdů podle rolí"
entryComing: "Na cestě"
entryArrived: "Dorazili"
entryLeave: "Odjeli"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ dashboard-admin:
paidTp: "Paid Participants"
paidGuest: "Paid Guests"
entryCount: "Entry count"
entryCountPerRole: "Entry count per role"
entryComing: "On their way"
entryArrived: "Arrived"
entryLeave: "Left"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ dashboard-admin:
paidTp: "zaplacení účastníci"
paidGuest: "potvrzení hosté (nemuseli platit)"
entryCount: "Počty příjezdů"
entryCountPerRole: "Počty příjezdů podle rolí"
entryComing: "Na cestě"
entryArrived: "Dorazili"
entryLeave: "Odjeli"
Expand Down
10 changes: 10 additions & 0 deletions src/Templates/translatable/admin/dashboard-admin.twig
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,16 @@
<p>{% trans %}dashboard-admin.entryComing{% endtrans %}: {{ entryStatistic.coming }}</p>
<p>{% trans %}dashboard-admin.entryArrived{% endtrans %}: {{ entryStatistic.arrived }}</p>
<p>{% trans %}dashboard-admin.entryLeave{% endtrans %}: {{ entryStatistic.leave }}</p>

<h3>{% trans %}dashboard-admin.entryCountPerRole{% endtrans %}</h3>
{% for role, entryData in entryStatisticRoles %}
<p>
<b>{{ ('role.'~role)|trans }}</b>:
{% trans %}dashboard-admin.entryComing{% endtrans %}: {{ entryData.coming }},
{% trans %}dashboard-admin.entryArrived{% endtrans %}: {{ entryData.arrived }},
{% trans %}dashboard-admin.entryLeave{% endtrans %}: {{ entryData.leave }}
</p>
{% endfor %}
</div>
<div>
{% if event.eventType.showFoodStats() %}
Expand Down

0 comments on commit 01ec9bb

Please sign in to comment.