id.'-'.$mode.'-'.$sort; return Cache::remember($cacheKey, 300, function () use ($audition, $mode, $sort) { $this->validateAudition($audition); $this->validateMode($mode); $this->validateSort($sort); $sortColumn = match ($sort) { 'tiebreak' => 'tiebreak_order', 'display' => 'display_order', }; $modeColumn = match ($mode) { 'seating' => 'for_seating', 'advancement' => 'for_advance', 'all' => null, }; $audition->load('scoringGuide.subscores'); if ($mode == 'all') { return $audition->scoringGuide->subscores->sortBy($sortColumn); } return $audition->scoringGuide->subscores->where($modeColumn, true)->sortBy($sortColumn); }); } public function getJudgesOLD(Audition $audition) { $cacheKey = 'auditionJudges-'.$audition->id; return Cache::remember($cacheKey, 10, function () use ($audition) { $this->validateAudition($audition); return $audition->judges; }); } public function getJudges(Audition $audition) { $cacheKey = 'auditionJudgeAssignments'; $assignments = Cache::remember($cacheKey, 60, function () { $allAuditions = Audition::with('judges')->get(); $return = []; foreach ($allAuditions as $audition) { $return[$audition->id] = $audition->judges; } return $return; }); return $assignments[$audition->id]; } public function getSeatingLimits(Audition $audition) { $cacheKey = 'auditionSeatingLimits'; $allLimits = Cache::remember($cacheKey, 300, function () { $lims = []; $auditions = Audition::all(); $ensembles = Ensemble::orderBy('rank')->get(); foreach ($auditions as $audition) { foreach ($ensembles as $ensemble) { if ($ensemble->event_id !== $audition->event_id) { continue; } $lims[$audition->id][$ensemble->id] = [ 'ensemble' => $ensemble, 'limit' => 0, ]; } } $limits = SeatingLimit::all(); foreach ($limits as $limit) { $lims[$limit->audition_id][$limit->ensemble_id] = [ 'ensemble' => $ensembles->find($limit->ensemble_id), 'limit' => $limit->maximum_accepted, ]; } return $lims; }); return $allLimits[$audition->id] ?? []; } protected function validateAudition($audition) { if (! $audition->exists()) { throw new AuditionServiceException('Invalid audition provided'); } } protected function validateMode($mode) { if ($mode !== 'seating' && $mode !== 'advancement' && $mode !== 'all') { throw new AuditionServiceException('Invalid mode requested. Mode must be seating or advancement'); } } protected function validateSort($sort) { if ($sort !== 'tiebreak' && $sort !== 'display') { throw new AuditionServiceException('Invalid sort requested. Sort must be tiebreak or weight'); } } }