diff --git a/app/Http/Controllers/Admin/AuditionController.php b/app/Http/Controllers/Admin/AuditionController.php index 9025bf0..9bd8fec 100644 --- a/app/Http/Controllers/Admin/AuditionController.php +++ b/app/Http/Controllers/Admin/AuditionController.php @@ -181,37 +181,4 @@ class AuditionController extends Controller return to_route('admin.auditions.index')->with('success', 'Audition deleted successfully'); } - - public function prepareDraw() - { - if (! Auth::user()->is_admin) { - abort(403); - } - $allAuditions = Audition::with('entries')->orderBy('score_order')->get(); - $nodraw_auditions = $allAuditions->filter(function ($audition) { - return $audition->has_no_draw(); - }); - $drawn_auditions = $allAuditions->filter(function ($audition) { - return $audition->has_complete_draw(); - }); - $partial_draw_auditions = $allAuditions->filter(function ($audition) { - return $audition->has_partial_draw(); - }); - - return view('admin.entries.prepare_draw', - compact('nodraw_auditions', 'drawn_auditions', 'partial_draw_auditions')); - } - - public function runDraw(Request $request) - { - if (! Auth::user()->is_admin) { - abort(403); - } - $draw_auditions = Audition::with('entries')->find(array_keys($request->input('auditions'))); - foreach ($draw_auditions as $audition) { - $audition->runDraw(); - } - - return redirect(' / admin / auditions / run_draw'); - } } diff --git a/app/Models/Audition.php b/app/Models/Audition.php index 175c053..d33b721 100644 --- a/app/Models/Audition.php +++ b/app/Models/Audition.php @@ -16,14 +16,6 @@ class Audition extends Model protected $guarded = []; - protected $rankedEntries = null; - - protected static $completeAuditions = null; - - protected $fully_scored; // Set by TabulationService - - protected $scored_entries_count; //Set by TabulationService - public function event(): BelongsTo { return $this->belongsTo(Event::class); @@ -49,84 +41,6 @@ class Audition extends Model return '$'.number_format($this->entry_fee / 100, 2); } - public function has_no_draw(): bool - { - // return true if all of my entries have a null draw_number - //return $this->entries->every(fn($entry) => is_null($entry->draw_number)); - // return $this->entries()->whereNotNull('draw_number')->doesntExist(); - if ($this->entries->count() == 0) { - return false; - } - if ($this->relationLoaded('entries')) { - return $this->entries->every(function ($entry) { - return is_null($entry->draw_number); - }); - } else { - return $this->entries()->whereNotNull('draw_number')->doesntExist(); - } - - } - - public function has_complete_draw(): bool - { - // return true if all of my entries have a draw_number - // return $this->entries->every(fn($entry) => !is_null($entry->draw_number)); - // return $this->entries()->whereNull('draw_number')->doesntExist(); - if ($this->entries->count() == 0) { - return false; - } - if ($this->relationLoaded('entries')) { - return $this->entries->every(function ($entry) { - return ! is_null($entry->draw_number); - }); - } else { - return $this->entries()->whereNull('draw_number')->doesntExist(); - } - } - - public function has_partial_draw(): bool - { - if ($this->entries->count() == 0) { - return false; - } - // return true I have at least one entry with a null draw number AND at least one entry with a non-null draw number - //return $this->entries->contains(fn($entry) => is_null($entry->draw_number)) && $this->entries->contains(fn($entry) => !is_null($entry->draw_number)); - - //$hasNull = $this->entries()->whereNull('draw_number')->exists(); - //$hasNotNull = $this->entries()->whereNotNull('draw_number')->exists(); - //return $hasNull && $hasNotNull; - - if ($this->relationLoaded('entries')) { - $hasNull = $this->entries->contains(function ($entry) { - return is_null($entry->draw_number); - }); - - $hasNotNull = $this->entries->contains(function ($entry) { - return ! is_null($entry->draw_number); - }); - - return $hasNull && $hasNotNull; - } else { - $hasNull = $this->entries()->whereNull('draw_number')->exists(); - $hasNotNull = $this->entries()->whereNotNull('draw_number')->exists(); - - return $hasNull && $hasNotNull; - } - } - - public function runDraw(): null - { - $entries = $this->entries->shuffle(); - - foreach ($entries as $index => $entry) { - $entry->update(['draw_number' => $index + 1]); - $entry->save(); - } - - return null; - // TODO move all draw functions to a DrawService - } - /** * @return BelongsToMany|User[] */