diff --git a/src/Participant/Admin/AdminController.php b/src/Participant/Admin/AdminController.php index e538b4e..a3e7320 100755 --- a/src/Participant/Admin/AdminController.php +++ b/src/Participant/Admin/AdminController.php @@ -80,6 +80,7 @@ public function showDashboard( 'contingentsPatrolStatistic' => $contingentStatistic, 'istArrivalStatistic' => $istArrivalStatistic, 'foodStatistic' => $foodStatistic, + 'entryStatistic' => $this->participantRepository->getEntryStatistic($event), ], ); } diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index cc7c6a2..03c6d04 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -285,6 +285,19 @@ public function getFoodStatistic( return $rows; } + /** + * @return array + */ + public function getEntryStatistic( + Event $event + ): array { + return [ + 'coming' => $this->countEntryComing($event), + 'arrived' => $this->countEntryArrived($event), + 'leave' => $this->countEntryLeave($event), + ]; + } + public function getStatistic( Event $event, ParticipantRole $role, @@ -562,4 +575,88 @@ 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'); + + /** @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'); + + /** @var string $countPatrolParticipants */ + $countPatrolParticipants = $qb->fetchSingle(); + + return (int)$countParticipants + (int)$countPatrolParticipants; + } + + private function countEntryArrived(Event $event): int + { + $qb = $this->getQueryBuilderCountForPaidParticipants($event); + $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'); + + /** @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'); + + /** @var string $countParticipants */ + $countParticipants = $qb->fetchSingle(); + + // count patrol participants and merge + $qb = $this->getQueryBuilderCountForPaidPatrolParticipants($event); + $qb = $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 + { + $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); + return $qb; + } + + /** + * @param Event $event + * @return Fluent + * @throws \LeanMapper\Exception\InvalidStateException + */ + private function getQueryBuilderCountForPaidPatrolParticipants(Event $event): 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 = participant.user_id'); + + $qb->where('u.status = %s', UserStatus::Paid); + $qb->where('u.event_id = %i', $event->id); + return $qb; + } } diff --git a/src/Templates/cs.yaml b/src/Templates/cs.yaml index 529e938..99dfdb0 100755 --- a/src/Templates/cs.yaml +++ b/src/Templates/cs.yaml @@ -351,6 +351,10 @@ dashboard-admin: paidTroop: "zaplacené skupiny" paidTp: "zaplacení účastníci" paidGuest: "potvrzení hosté (nemuseli platit)" + entryCount: "Počty příjezdů" + entryComing: "Na cestě" + entryArrived: "Dorazili" + entryLeave: "Odjeli" adminActions: "Akce administrátora" showPaid: "Zaplacení účastníci" open: "Neuzamčení účastníci" diff --git a/src/Templates/en.yaml b/src/Templates/en.yaml index e19c34d..d76505b 100755 --- a/src/Templates/en.yaml +++ b/src/Templates/en.yaml @@ -351,6 +351,10 @@ dashboard-admin: paidTroop: "Paid Troops" paidTp: "Paid Participants" paidGuest: "Paid Guests" + entryCount: "Entry count" + entryComing: "On their way" + entryArrived: "Arrived" + entryLeave: "Left" adminActions: "Administator actions" showPaid: "Paid participants" open: "Unlocked participants" diff --git a/src/Templates/sk.yaml b/src/Templates/sk.yaml index 09919a0..c80da22 100755 --- a/src/Templates/sk.yaml +++ b/src/Templates/sk.yaml @@ -351,6 +351,10 @@ dashboard-admin: paidTroop: "zaplacené skupiny" paidTp: "zaplacení účastníci" paidGuest: "potvrzení hosté (nemuseli platit)" + entryCount: "Počty příjezdů" + entryComing: "Na cestě" + entryArrived: "Dorazili" + entryLeave: "Odjeli" adminActions: "Akce administrátora" showPaid: "Zaplacení účastníci" open: "Neuzamčení účastníci" diff --git a/src/Templates/translatable/admin/dashboard-admin.twig b/src/Templates/translatable/admin/dashboard-admin.twig index 686d544..f8536a2 100755 --- a/src/Templates/translatable/admin/dashboard-admin.twig +++ b/src/Templates/translatable/admin/dashboard-admin.twig @@ -38,6 +38,13 @@

{% trans %}dashboard-admin.approvedTp{% endtrans %}: {{ troopParticipants.approvedCount }}

{% trans %}dashboard-admin.paidTp{% endtrans %}: {{ troopParticipants.paidCount }}

{% endif %} +
+ {% if event.eventType.showFoodStats() %} +

{% trans %}dashboard-admin.foodCount{% endtrans %}

+ {% for food, count in foodStatistic %} +

{{ food|trans }}: {{ count }}

+ {% endfor %} + {% endif %}
{% if event.allowIsts %} @@ -58,6 +65,11 @@

{% trans %}dashboard-admin.approvedGuest{% endtrans %}: {{ guests.approvedCount }}

{% trans %}dashboard-admin.paidGuest{% endtrans %}: {{ guests.paidCount }}

{% endif %} +
+

{% trans %}dashboard-admin.entryCount{% endtrans %}

+

{% trans %}dashboard-admin.entryComing{% endtrans %}: {{ entryStatistic.coming }}

+

{% trans %}dashboard-admin.entryArrived{% endtrans %}: {{ entryStatistic.arrived }}

+

{% trans %}dashboard-admin.entryLeave{% endtrans %}: {{ entryStatistic.leave }}

{% if event.eventType.showContingentPatrolStats %} @@ -93,12 +105,6 @@

{{ date|date('d. m. Y') }}: {{ count }}

{% endfor %} {% endif %} - {% if event.eventType.showFoodStats() %} -

{% trans %}dashboard-admin.foodCount{% endtrans %}

- {% for food, count in foodStatistic %} -

{{ food|trans }}: {{ count }}

- {% endfor %} - {% endif %}