File tree Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Expand file tree Collapse file tree 1 file changed +24
-0
lines changed Original file line number Diff line number Diff line change @@ -254,6 +254,30 @@ public function getFoodStatistic(
254
254
/** @var array<string,int> $rows */
255
255
$ rows = $ qb ->fetchPairs ('f ' , 'count ' );
256
256
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
+
257
281
return $ rows ;
258
282
}
259
283
You can’t perform that action at this time.
0 commit comments