auditionadmin/app/Http/Controllers/Tabulation/DoublerDecisionController.php

64 lines
1.9 KiB
PHP

<?php
namespace App\Http\Controllers\Tabulation;
use App\Http\Controllers\Controller;
use App\Models\Entry;
use App\Models\EntryFlag;
use App\Services\DoublerService;
use App\Services\EntryCacheService;
class DoublerDecisionController extends Controller
{
protected $doublerService;
protected $entryService;
public function __construct(DoublerService $doublerService, EntryCacheService $entryService)
{
$this->doublerService = $doublerService;
$this->entryService = $entryService;
}
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.');
}
}
}
$this->doublerService->refreshDoublerCache();
$returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name;
return redirect()->back()->with('success', $returnMessage);
}
public function decline(Entry $entry)
{
if ($entry->hasFlag('declined')) {
return redirect()->back()->with('caution', 'Entry is already declined');
}
EntryFlag::create([
'entry_id' => $entry->id,
'flag_name' => 'declined',
]);
$this->doublerService->refreshDoublerCache();
$returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name;
return redirect()->back()->with('success', $returnMessage);
}
}