diff --git a/app/Http/Controllers/Tabulation/DoublerDecisionController.php b/app/Http/Controllers/Tabulation/DoublerDecisionController.php index 73141e5..2e79bf5 100644 --- a/app/Http/Controllers/Tabulation/DoublerDecisionController.php +++ b/app/Http/Controllers/Tabulation/DoublerDecisionController.php @@ -21,22 +21,15 @@ class DoublerDecisionController extends Controller public function accept(Entry $entry) { - $doublerInfo = $this->doublerService->getDoublerInfo($entry->student_id); - foreach ($doublerInfo as $info) { - $this->entryService->clearEntryCacheForAudition($info['auditionID']); - if ($info['entryID'] != $entry->id) { - try { - EntryFlag::create([ - 'entry_id' => $info['entryID'], - 'flag_name' => 'declined', - ]); - } catch (\Exception $e) { - session()->flash('error', 'Entry ID'.$info['entryID'].' has already been declined.'); - } - + $doublerInfo = $this->doublerService->simpleDoubleInfo($entry); + foreach ($doublerInfo as $doublerEntry) { + /** @var Entry $doublerEntry */ + if ($doublerEntry->id !== $entry->id) { + $doublerEntry->addFlag('declined'); } } + $returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name; return redirect()->back()->with('success', $returnMessage); diff --git a/app/Models/Entry.php b/app/Models/Entry.php index 0acd0cd..bd3ad71 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -10,8 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; use Illuminate\Database\Eloquent\Relations\HasMany; use Illuminate\Database\Eloquent\Relations\HasOne; use Illuminate\Database\Eloquent\Relations\HasOneThrough; -use Staudenmeir\BelongsToThrough; -use App\Models\ScoreSheet; +use Illuminate\Support\Facades\Cache; class Entry extends Model { @@ -39,7 +38,6 @@ class Entry extends Model return $this->belongsTo(Audition::class); } - public function school(): HasOneThrough { return $this->hasOneThrough( diff --git a/app/Services/DoublerService.php b/app/Services/DoublerService.php index bc97006..b58b547 100644 --- a/app/Services/DoublerService.php +++ b/app/Services/DoublerService.php @@ -45,8 +45,8 @@ class DoublerService 'seating' => $entries->filter(fn ($entry) => $entry->for_seating === 1), 'advancement' => $entries->filter(fn ($entry) => $entry->for_advance === 1), }; - $entries->load('student.school'); - $entries->load('audition'); + #$entries->load('student.school'); + #$entries->load('audition'); $grouped = $entries->groupBy('student_id'); // Filter out student groups with only one entry in the event $grouped = $grouped->filter(fn ($s) => $s->count() > 1); @@ -61,6 +61,14 @@ class DoublerService return $doubler_array; } + public function simpleDoubleInfo(Entry $primaryEntry) + { + if (! isset($this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id])) { + return false; + } + return $this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id]['entries']; + } + public function entryDoublerData(Entry $primaryEntry) { if (! isset($this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id])) {