Accept/Decline buttons are working

This commit is contained in:
Matt Young 2024-07-13 00:02:11 -05:00
parent a1f5191a19
commit e1aa852142
3 changed files with 17 additions and 18 deletions

View File

@ -21,21 +21,14 @@ 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;

View File

@ -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(

View File

@ -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])) {