From 9d73c07b5f4bffdd61819a1b32035a5dc9f778f3 Mon Sep 17 00:00:00 2001 From: Lung Date: Wed, 27 Mar 2024 20:28:50 +0100 Subject: [PATCH] added food statistics for admins --- src/Event/EventType/EventType.php | 5 +++++ src/Event/EventType/Korbo/EventTypeKorbo.php | 12 +++++++++++ src/Participant/Admin/AdminController.php | 6 ++++++ src/Participant/ParticipantRepository.php | 21 +++++++++++++++++++ src/Templates/cs.yaml | 1 + src/Templates/en.yaml | 1 + src/Templates/sk.yaml | 1 + .../translatable/admin/dashboard-admin.twig | 6 ++++++ 8 files changed, 53 insertions(+) diff --git a/src/Event/EventType/EventType.php b/src/Event/EventType/EventType.php index 2b9d1f9c..cdeee18c 100755 --- a/src/Event/EventType/EventType.php +++ b/src/Event/EventType/EventType.php @@ -158,6 +158,11 @@ public function showContingentPatrolStats(): bool return false; } + public function showFoodStats(): bool + { + return true; + } + public function showIstImport(): bool { return false; diff --git a/src/Event/EventType/Korbo/EventTypeKorbo.php b/src/Event/EventType/Korbo/EventTypeKorbo.php index c6a99e3f..eca2eaea 100755 --- a/src/Event/EventType/Korbo/EventTypeKorbo.php +++ b/src/Event/EventType/Korbo/EventTypeKorbo.php @@ -12,6 +12,7 @@ class EventTypeKorbo extends EventType { private const int SCARF_PRICE = 100; + #[\Override] protected function getPrice(Participant $participant): int { $price = 600; @@ -22,11 +23,13 @@ protected function getPrice(Participant $participant): int return $price; } + #[\Override] public function isUnlockExpiredButtonAllowed(): bool { return true; } + #[\Override] public function getContentArbiterIst(): ContentArbiterIst { $ca = parent::getContentArbiterIst(); @@ -42,20 +45,29 @@ public function getContentArbiterIst(): ContentArbiterIst return $ca; } + #[\Override] public function getTranslationFilePaths(): array { return ["cs" => __DIR__ . "/cs.yaml"]; } + #[\Override] public function getStylesheetNameWithoutLeadingSlash(): string { return 'eventSpecificCss/stylesKorbo.css'; } + #[\Override] public function getLanguages(): array { return [ 'cs' => '🇨🇿 Česky', ]; } + + #[\Override] + public function showFoodStats(): bool + { + return false; + } } diff --git a/src/Participant/Admin/AdminController.php b/src/Participant/Admin/AdminController.php index b8635f48..9c55e753 100755 --- a/src/Participant/Admin/AdminController.php +++ b/src/Participant/Admin/AdminController.php @@ -58,6 +58,11 @@ public function showDashboard(Response $response, Event $event): Response $istArrivalStatistic = $this->participantRepository->getIstArrivalStatistic($event); } + $foodStatistic = []; + if ($eventType->showFoodStats()) { + $foodStatistic = $this->participantRepository->getFoodStatistic($event); + } + return $this->view->render( $response, 'admin/dashboard-admin.twig', @@ -69,6 +74,7 @@ public function showDashboard(Response $response, Event $event): Response 'guests' => $this->participantRepository->getStatistic($event, ParticipantRole::Guest), 'contingentsPatrolStatistic' => $contingentStatistic, 'istArrivalStatistic' => $istArrivalStatistic, + 'foodStatistic' => $foodStatistic, ], ); } diff --git a/src/Participant/ParticipantRepository.php b/src/Participant/ParticipantRepository.php index 751ff090..b8a3e4ef 100755 --- a/src/Participant/ParticipantRepository.php +++ b/src/Participant/ParticipantRepository.php @@ -288,6 +288,27 @@ public function getIstArrivalStatistic( return $rows; } + /** + * @return array + */ + public function getFoodStatistic( + Event $event, + ): array { + $qb = $this->connection->select('participant.food_preferences as f, COUNT(*)')->from($this->getTable()); + $qb->join('user')->as('u')->on('u.id = participant.user_id'); + + $qb->where('u.event_id = %i', $event->id); + $qb->where('u.status = %s', UserStatus::Paid); + + $qb->groupBy('participant.food_preferences'); + $qb->orderBy('participant.food_preferences'); + + /** @var array $rows */ + $rows = $qb->fetchPairs('f', 'count'); + + return $rows; + } + public function getStatistic( Event $event, ParticipantRole $role, diff --git a/src/Templates/cs.yaml b/src/Templates/cs.yaml index cb94bc93..c95f06b2 100755 --- a/src/Templates/cs.yaml +++ b/src/Templates/cs.yaml @@ -323,6 +323,7 @@ dashboard-admin: count: " počty" contingentPatrolStats: "Statistiky kontingentů" istArrivalStats: "Příjezdy" + foodCount: "Počty jídel" limitIst: "limit servisáků" limitPatrol: "limit patrol" limitTroop: "limit skupin" diff --git a/src/Templates/en.yaml b/src/Templates/en.yaml index 0c630a69..31ec3afd 100755 --- a/src/Templates/en.yaml +++ b/src/Templates/en.yaml @@ -323,6 +323,7 @@ dashboard-admin: count: "counts" contingentPatrolStats: "Contingent patrol statistics" istArrivalStats: "Arrivals of" + foodCount: "Food count" limitIst: "Limit for IST" limitPatrol: "Limit for Patrols" limitTroop: "Limit for Troops" diff --git a/src/Templates/sk.yaml b/src/Templates/sk.yaml index 8c16bcd7..30ee5fa6 100755 --- a/src/Templates/sk.yaml +++ b/src/Templates/sk.yaml @@ -323,6 +323,7 @@ dashboard-admin: count: " počty" contingentPatrolStats: "Statistiky kontingentů" istArrivalStats: "Příjezdy" + foodCount: "Počty jídel" limitIst: "limit servisáků" limitPatrol: "limit patrol" limitTroop: "limit skupin" diff --git a/src/Templates/translatable/admin/dashboard-admin.twig b/src/Templates/translatable/admin/dashboard-admin.twig index c81d725d..f06963cb 100755 --- a/src/Templates/translatable/admin/dashboard-admin.twig +++ b/src/Templates/translatable/admin/dashboard-admin.twig @@ -93,6 +93,12 @@

{{ 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 %}