Skip to content

Commit 3cd18aa

Browse files
author
Lung
committed
fixed admin food counting for patrol participants
1 parent 5966573 commit 3cd18aa

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/Participant/ParticipantRepository.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,30 @@ public function getFoodStatistic(
254254
/** @var array<string,int> $rows */
255255
$rows = $qb->fetchPairs('f', 'count');
256256

257+
// count patrol participants and merge
258+
$qb = $this->connection->select('participant.food_preferences as f, COUNT(*)')->from($this->getTable());
259+
$qb->join('participant')->as('pl')->on('pl.id = participant.patrol_leader_id');
260+
$qb->join('user')->as('u')->on('u.id = pl.user_id');
261+
262+
$qb->where('u.role = %s', UserRole::Participant);
263+
$qb->where('u.status = %s', UserStatus::Paid);
264+
$qb->where('u.event_id = %i', $event->id);
265+
266+
$qb->groupBy('participant.food_preferences');
267+
$qb->orderBy('participant.food_preferences');
268+
269+
/** @var array<string,int> $rows */
270+
$rowsPp = $qb->fetchPairs('f', 'count');
271+
272+
// merge patrol participants into rest
273+
foreach($rowsPp as $foodKey => $count) {
274+
if (array_key_exists($foodKey, $rows) === false) {
275+
$rows[$foodKey] = 0;
276+
}
277+
278+
$rows[$foodKey] += $count;
279+
}
280+
257281
return $rows;
258282
}
259283

0 commit comments

Comments
 (0)