Accept/Decline buttons are working
This commit is contained in:
parent
a1f5191a19
commit
e1aa852142
|
|
@ -21,22 +21,15 @@ class DoublerDecisionController extends Controller
|
||||||
|
|
||||||
public function accept(Entry $entry)
|
public function accept(Entry $entry)
|
||||||
{
|
{
|
||||||
$doublerInfo = $this->doublerService->getDoublerInfo($entry->student_id);
|
$doublerInfo = $this->doublerService->simpleDoubleInfo($entry);
|
||||||
foreach ($doublerInfo as $info) {
|
foreach ($doublerInfo as $doublerEntry) {
|
||||||
$this->entryService->clearEntryCacheForAudition($info['auditionID']);
|
/** @var Entry $doublerEntry */
|
||||||
if ($info['entryID'] != $entry->id) {
|
if ($doublerEntry->id !== $entry->id) {
|
||||||
try {
|
$doublerEntry->addFlag('declined');
|
||||||
EntryFlag::create([
|
|
||||||
'entry_id' => $info['entryID'],
|
|
||||||
'flag_name' => 'declined',
|
|
||||||
]);
|
|
||||||
} catch (\Exception $e) {
|
|
||||||
session()->flash('error', 'Entry ID'.$info['entryID'].' has already been declined.');
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name;
|
$returnMessage = $entry->student->full_name().' accepted seating in '.$entry->audition->name;
|
||||||
|
|
||||||
return redirect()->back()->with('success', $returnMessage);
|
return redirect()->back()->with('success', $returnMessage);
|
||||||
|
|
|
||||||
|
|
@ -10,8 +10,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||||
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
use Illuminate\Database\Eloquent\Relations\HasOneThrough;
|
||||||
use Staudenmeir\BelongsToThrough;
|
use Illuminate\Support\Facades\Cache;
|
||||||
use App\Models\ScoreSheet;
|
|
||||||
|
|
||||||
class Entry extends Model
|
class Entry extends Model
|
||||||
{
|
{
|
||||||
|
|
@ -39,7 +38,6 @@ class Entry extends Model
|
||||||
return $this->belongsTo(Audition::class);
|
return $this->belongsTo(Audition::class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function school(): HasOneThrough
|
public function school(): HasOneThrough
|
||||||
{
|
{
|
||||||
return $this->hasOneThrough(
|
return $this->hasOneThrough(
|
||||||
|
|
|
||||||
|
|
@ -45,8 +45,8 @@ class DoublerService
|
||||||
'seating' => $entries->filter(fn ($entry) => $entry->for_seating === 1),
|
'seating' => $entries->filter(fn ($entry) => $entry->for_seating === 1),
|
||||||
'advancement' => $entries->filter(fn ($entry) => $entry->for_advance === 1),
|
'advancement' => $entries->filter(fn ($entry) => $entry->for_advance === 1),
|
||||||
};
|
};
|
||||||
$entries->load('student.school');
|
#$entries->load('student.school');
|
||||||
$entries->load('audition');
|
#$entries->load('audition');
|
||||||
$grouped = $entries->groupBy('student_id');
|
$grouped = $entries->groupBy('student_id');
|
||||||
// Filter out student groups with only one entry in the event
|
// Filter out student groups with only one entry in the event
|
||||||
$grouped = $grouped->filter(fn ($s) => $s->count() > 1);
|
$grouped = $grouped->filter(fn ($s) => $s->count() > 1);
|
||||||
|
|
@ -61,6 +61,14 @@ class DoublerService
|
||||||
return $doubler_array;
|
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)
|
public function entryDoublerData(Entry $primaryEntry)
|
||||||
{
|
{
|
||||||
if (! isset($this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id])) {
|
if (! isset($this->findDoublersForEvent($primaryEntry->audition->event)[$primaryEntry->student_id])) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue