62 lines
1.8 KiB
PHP
62 lines
1.8 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\EntryService;
|
|
|
|
class DoublerDecisionController extends Controller
|
|
{
|
|
protected $doublerService;
|
|
protected $entryService;
|
|
|
|
public function __construct(DoublerService $doublerService, EntryService $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');
|
|
}
|
|
|
|
$entry->addFlag('declined');
|
|
|
|
$this->doublerService->refreshDoublerCache();
|
|
|
|
$returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name;
|
|
|
|
return redirect()->back()->with('success', $returnMessage);
|
|
}
|
|
}
|