Skip to content

Commit

Permalink
added food statistics for admins
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Mar 27, 2024
1 parent c19429b commit 9d73c07
Show file tree
Hide file tree
Showing 8 changed files with 53 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/Event/EventType/EventType.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,11 @@ public function showContingentPatrolStats(): bool
return false;
}

public function showFoodStats(): bool
{
return true;
}

public function showIstImport(): bool
{
return false;
Expand Down
12 changes: 12 additions & 0 deletions src/Event/EventType/Korbo/EventTypeKorbo.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class EventTypeKorbo extends EventType
{
private const int SCARF_PRICE = 100;

#[\Override]
protected function getPrice(Participant $participant): int
{
$price = 600;
Expand All @@ -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();
Expand All @@ -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;
}
}
6 changes: 6 additions & 0 deletions src/Participant/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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,
],
);
}
Expand Down
21 changes: 21 additions & 0 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,27 @@ public function getIstArrivalStatistic(
return $rows;
}

/**
* @return array<string,int>
*/
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<string,int> $rows */
$rows = $qb->fetchPairs('f', 'count');

return $rows;
}

public function getStatistic(
Event $event,
ParticipantRole $role,
Expand Down
1 change: 1 addition & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
1 change: 1 addition & 0 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
6 changes: 6 additions & 0 deletions src/Templates/translatable/admin/dashboard-admin.twig
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@
<p>{{ date|date('d. m. Y') }}: <b>{{ count }}</b></p>
{% endfor %}
{% endif %}
{% if event.eventType.showFoodStats() %}
<h3>{% trans %}dashboard-admin.foodCount{% endtrans %}</h3>
{% for food, count in foodStatistic %}
<p>{{ food|trans }}: <b>{{ count }}</b></p>
{% endfor %}
{% endif %}
</div>
<br>
<div class="card paid-theme">
Expand Down

0 comments on commit 9d73c07

Please sign in to comment.