Skip to content

Commit

Permalink
fixed admin food counting for patrol participants
Browse files Browse the repository at this point in the history
  • Loading branch information
Lung committed Jul 3, 2024
1 parent 5966573 commit 3cd18aa
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions src/Participant/ParticipantRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,30 @@ public function getFoodStatistic(
/** @var array<string,int> $rows */
$rows = $qb->fetchPairs('f', 'count');

// count patrol participants and merge
$qb = $this->connection->select('participant.food_preferences as f, COUNT(*)')->from($this->getTable());
$qb->join('participant')->as('pl')->on('pl.id = participant.patrol_leader_id');
$qb->join('user')->as('u')->on('u.id = pl.user_id');

$qb->where('u.role = %s', UserRole::Participant);
$qb->where('u.status = %s', UserStatus::Paid);
$qb->where('u.event_id = %i', $event->id);

$qb->groupBy('participant.food_preferences');
$qb->orderBy('participant.food_preferences');

/** @var array<string,int> $rows */
$rowsPp = $qb->fetchPairs('f', 'count');

// merge patrol participants into rest
foreach($rowsPp as $foodKey => $count) {
if (array_key_exists($foodKey, $rows) === false) {
$rows[$foodKey] = 0;
}

$rows[$foodKey] += $count;
}

return $rows;
}

Expand Down

0 comments on commit 3cd18aa

Please sign in to comment.