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

62 lines
1.8 KiB
PHP

<?php
namespace App\Http\Controllers\Tabulation;
use App\Http\Controllers\Controller;
use App\Models\Entry;
use App\Services\DoublerService;
use App\Services\EntryService;
use Illuminate\Support\Facades\Cache;
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->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;
$this->clearCache($entry);
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');
$returnMessage = $entry->student->full_name().' declined seating in '.$entry->audition->name;
$this->clearCache($entry);
return redirect()->back()->with('success', $returnMessage);
}
protected function clearCache($entry)
{
$cacheKey = 'event'.$entry->audition->event_id.'doublers-seating';
Cache::forget($cacheKey);
$cacheKey = 'event'.$entry->audition->event_id.'doublers-advancement';
Cache::forget($cacheKey);
}
}