MEOBDA nomination seating working.
This commit is contained in:
parent
3f9b467fe5
commit
6ef89c9dfa
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\NominationEnsembles;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\NominationEnsemble;
|
||||
use App\Models\NominationEnsembleEntry;
|
||||
|
||||
class MeobdaNominationSeatingController extends Controller implements NominationSeatingController
|
||||
{
|
||||
|
|
@ -18,12 +19,85 @@ class MeobdaNominationSeatingController extends Controller implements Nomination
|
|||
public function show(NominationEnsemble $ensemble)
|
||||
{
|
||||
$ensembles = NominationEnsemble::all();
|
||||
$nominations = [];
|
||||
|
||||
return view('nomination_ensembles.meobda.admin.seating', compact('ensembles', 'ensemble'));
|
||||
if ($ensemble->data['seated'] ?? false) {
|
||||
$nominations = NominationEnsembleEntry::where('nomination_ensemble_id', $ensemble->id)
|
||||
->orderBy('data->instrument')
|
||||
->orderByRaw('CAST(data->"$.seat" AS UNSIGNED)')
|
||||
->with('student.school')
|
||||
->get();
|
||||
$nominations = $nominations->groupBy(function ($item) {
|
||||
return $item->data['split'];
|
||||
});
|
||||
foreach ($nominations as $split => $splitNoms) {
|
||||
$nominations[$split] = $splitNoms->groupBy(function ($item) {
|
||||
return $item->data['instrument'];
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return view('nomination_ensembles.meobda.admin.seating', compact('ensembles', 'ensemble', 'nominations'));
|
||||
}
|
||||
|
||||
public function seat(NominationEnsemble $ensemble)
|
||||
{
|
||||
// TODO: Implement seat() method.
|
||||
$validData = request()->validate([
|
||||
'action' => 'required|in:seat,clear',
|
||||
]);
|
||||
$action = $validData['action'];
|
||||
$data = $ensemble['data'];
|
||||
$nominations = NominationEnsembleEntry::where('nomination_ensemble_id',
|
||||
$ensemble->id)->inRandomOrder()->get();
|
||||
$groupedNominations = $nominations->groupBy(function ($nom) {
|
||||
return $nom->data['instrument'];
|
||||
});
|
||||
|
||||
if ($action == 'seat') {
|
||||
// If no split names are set, make the name of the ensemble the only split name
|
||||
$splits = $data['split_names'];
|
||||
if (count($splits) < 2 && strlen($splits[0]) < 2) {
|
||||
$splits[0] = $ensemble->name;
|
||||
}
|
||||
$splitOn = 0;
|
||||
|
||||
foreach ($ensemble->data['instruments'] as $instrument) {
|
||||
if (! $groupedNominations->has($instrument['name'])) {
|
||||
continue;
|
||||
}
|
||||
$seatOn = 1;
|
||||
foreach ($groupedNominations[$instrument['name']] as $nomination) {
|
||||
$nomData = $nomination['data'];
|
||||
$nomData['seat'] = $seatOn;
|
||||
$nomData['split'] = $splits[$splitOn];
|
||||
$nomination->data = $nomData;
|
||||
$nomination->save();
|
||||
|
||||
$splitOn++;
|
||||
if ($splitOn >= count($splits)) {
|
||||
$seatOn++;
|
||||
$splitOn = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$data['seated'] = true;
|
||||
|
||||
}
|
||||
|
||||
if ($action == 'clear') {
|
||||
$data['seated'] = false;
|
||||
foreach ($nominations as $nomination) {
|
||||
$nomData = $nomination['data'];
|
||||
unset($nomData['split']);
|
||||
unset($nomData['seat']);
|
||||
$nomination->data = $nomData;
|
||||
$nomination->save();
|
||||
}
|
||||
}
|
||||
$ensemble->data = $data;
|
||||
$ensemble->save();
|
||||
|
||||
return redirect(route('nomination.admin.seating.show', [$ensemble]));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@
|
|||
<x-slot:right_side>
|
||||
<x-form.form action="{{route('nomination.admin.seating.seat',[$ensemble])}}">
|
||||
@if($ensemble->data['seated'] ?? false)
|
||||
<input type="hidden" name="clear" value="clear">
|
||||
<input type="hidden" name="action" value="clear">
|
||||
<x-form.button>Clear Seats</x-form.button>
|
||||
@else
|
||||
<input type="hidden" name="clear" value="seat">
|
||||
<input type="hidden" name="action" value="seat">
|
||||
<x-form.button>Seat</x-form.button>
|
||||
@endif
|
||||
</x-form.form>
|
||||
|
|
@ -36,6 +36,29 @@
|
|||
</x-card.heading>
|
||||
</x-card.card>
|
||||
|
||||
@if($ensemble->data['seated'] ?? false)
|
||||
@foreach($ensemble->data['split_names'] as $split)
|
||||
<x-card.card class="mt-5">
|
||||
<x-card.heading>{{ $split }}</x-card.heading>
|
||||
@foreach ($ensemble->data['instruments'] as $instrument)
|
||||
@continue(! $nominations[$split]->has($instrument['name']))
|
||||
<x-card.heading class="ml-5">
|
||||
{{ $instrument['name'] }}
|
||||
<x-slot:right_side>
|
||||
Count: {{ count($nominations[$split][$instrument['name']]) }}</x-slot:right_side>
|
||||
</x-card.heading>
|
||||
<x-card.list.body>
|
||||
@foreach($nominations[$split][$instrument['name']] as $thisNomination)
|
||||
<x-card.list.row>{{ $thisNomination->data['seat'] }} - {{ $thisNomination->student->full_name() }}, {{ $thisNomination->student->school->name }}</x-card.list.row>
|
||||
|
||||
@endforeach
|
||||
</x-card.list.body>
|
||||
@endforeach
|
||||
</x-card.card>
|
||||
|
||||
@endforeach
|
||||
@endif
|
||||
|
||||
@endif
|
||||
</div>
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue