Skip to content

Commit

Permalink
Merge branch 'refs/heads/staging'
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Aug 6, 2024
2 parents 6ffc968 + a7d11a4 commit 27652bb
Show file tree
Hide file tree
Showing 6 changed files with 122 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/Participant/Admin/AdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ public function showDashboard(
'contingentsPatrolStatistic' => $contingentStatistic,
'istArrivalStatistic' => $istArrivalStatistic,
'foodStatistic' => $foodStatistic,
'entryStatistic' => $this->participantRepository->getEntryStatistic($event),
],
);
}
Expand Down
97 changes: 97 additions & 0 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,19 @@ public function getFoodStatistic(
return $rows;
}

/**
* @return array<string,int>
*/
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,
Expand Down Expand Up @@ -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;
}
}
4 changes: 4 additions & 0 deletions src/Templates/cs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/Templates/en.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
4 changes: 4 additions & 0 deletions src/Templates/sk.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
18 changes: 12 additions & 6 deletions src/Templates/translatable/admin/dashboard-admin.twig
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,13 @@
<p>{% trans %}dashboard-admin.approvedTp{% endtrans %}: {{ troopParticipants.approvedCount }}</p>
<p>{% trans %}dashboard-admin.paidTp{% endtrans %}: {{ troopParticipants.paidCount }}</p>
{% endif %}
<br>
{% 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>
<div>
{% if event.allowIsts %}
Expand All @@ -58,6 +65,11 @@
<p>{% trans %}dashboard-admin.approvedGuest{% endtrans %}: {{ guests.approvedCount }}</p>
<p>{% trans %}dashboard-admin.paidGuest{% endtrans %}: {{ guests.paidCount }}</p>
{% endif %}
<br>
<h3>{% trans %}dashboard-admin.entryCount{% endtrans %}</h3>
<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>
</div>
</div>
{% if event.eventType.showContingentPatrolStats %}
Expand Down Expand Up @@ -93,12 +105,6 @@
<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 27652bb

Please sign in to comment.