From 8a8ae44617e148358713c7cc6317806ac5b9b6a5 Mon Sep 17 00:00:00 2001 From: Matt Young Date: Tue, 5 Nov 2024 07:12:19 -0600 Subject: [PATCH] If an entry is flagged as a no show at the time of the draw, put them at the end. --- app/Services/DrawService.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/app/Services/DrawService.php b/app/Services/DrawService.php index 53d162c..f604d39 100644 --- a/app/Services/DrawService.php +++ b/app/Services/DrawService.php @@ -21,6 +21,15 @@ class DrawService DB::table('entries')->where('audition_id', $audition->id)->update(['draw_number' => null]); $randomizedEntries = $audition->entries->shuffle(); + + // Move entries flagged as no show to the end + [$noShowEntries, $otherEntries] = $randomizedEntries->partition(function ($entry) { + return $entry->hasFlag('no_show'); + }); + + // Merge the entries, placing the 'no_show' entries at the end + $randomizedEntries = $otherEntries->merge($noShowEntries); + foreach ($randomizedEntries as $index => $entry) { $entry->draw_number = $index + 1; $entry->save();