Now able to manage split score definitions
This commit is contained in:
parent
797d4910c5
commit
c60f1714c1
|
|
@ -0,0 +1,78 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Admin;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Http\Requests\EditSplitScoreDefinitionRequest;
|
||||
use App\Models\Audition;
|
||||
use App\Models\SplitScoreDefinition;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class SplitScoreDefinitionController extends Controller
|
||||
{
|
||||
public function index()
|
||||
{
|
||||
$splitScores = SplitScoreDefinition::all();
|
||||
|
||||
return view('admin.split_score_definitions.index', compact('splitScores'));
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
$availableAuditions = Audition::doesntHave('splitScoreDefinition')->get();
|
||||
|
||||
return view('admin.split_score_definitions.create', compact('availableAuditions'));
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'audition_id' => 'required|exists:auditions,id|unique:split_score_definitions,audition_id',
|
||||
]);
|
||||
$newSplit = SplitScoreDefinition::create([
|
||||
'audition_id' => $validated['audition_id'],
|
||||
'splits' => [],
|
||||
]);
|
||||
|
||||
return redirect()->route('admin.split_score_definitions.edit', $newSplit)->with('success',
|
||||
'Split score definition created');
|
||||
}
|
||||
|
||||
public function edit(SplitScoreDefinition $splitScoreDefinition)
|
||||
{
|
||||
$subscores = $splitScoreDefinition->audition->scoringGuide->subscores;
|
||||
$judges = $splitScoreDefinition->audition->room->judges;
|
||||
|
||||
return view('admin.split_score_definitions.edit', compact('splitScoreDefinition', 'subscores', 'judges'));
|
||||
}
|
||||
|
||||
public function update(EditSplitScoreDefinitionRequest $request, SplitScoreDefinition $splitScoreDefinition)
|
||||
{
|
||||
$savedSplits = $splitScoreDefinition->splits;
|
||||
if ($request->validated()['split'] ?? false) {
|
||||
$newSplit = [];
|
||||
$submittedSplitData = $request->validated()['split'];
|
||||
foreach ($submittedSplitData as $splitName => $splitData) {
|
||||
$name = $splitName;
|
||||
$judges = array_values($splitData['judges'] ?? []);
|
||||
$subscores = array_values($splitData['subscores'] ?? []);
|
||||
$newSplit[$name] = ['judges' => $judges, 'subscores' => $subscores];
|
||||
}
|
||||
$splitScoreDefinition->splits = $newSplit;
|
||||
$splitScoreDefinition->save();
|
||||
|
||||
}
|
||||
if ($request->validated()['new_split'] ?? false) {
|
||||
$savedSplits[$request->validated()['new_split']] = ['judges' => [], 'subscores' => []];
|
||||
$splitScoreDefinition->splits = $savedSplits;
|
||||
$splitScoreDefinition->save();
|
||||
}
|
||||
|
||||
return redirect()->route('admin.split_score_definitions.edit', $splitScoreDefinition);
|
||||
}
|
||||
|
||||
public function destroy(SplitScoreDefinition $scoreDefinition)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,53 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Validation\Validator;
|
||||
|
||||
class EditSplitScoreDefinitionRequest extends FormRequest
|
||||
{
|
||||
/**
|
||||
* Determine if the user is authorized to make this request.
|
||||
*/
|
||||
public function authorize(): bool
|
||||
{
|
||||
return auth()->user()->is_admin;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
|
||||
*/
|
||||
public function rules(): array
|
||||
{
|
||||
|
||||
return [
|
||||
'new_split' => 'sometimes|string|max:255|min:1',
|
||||
'split' => 'sometimes|array',
|
||||
];
|
||||
}
|
||||
|
||||
public function after(): array
|
||||
{
|
||||
$splitScoreDefinition = $this->route('splitScoreDefinition');
|
||||
|
||||
return [
|
||||
function (Validator $validator) use ($splitScoreDefinition) {
|
||||
if ($this->has('new_split')) {
|
||||
$existingSplitNames = collect($splitScoreDefinition->splits)
|
||||
->pluck('name')
|
||||
->toArray();
|
||||
|
||||
if (in_array($this->new_split, $existingSplitNames)) {
|
||||
$validator->errors()->add(
|
||||
'new_split',
|
||||
'This split name already exists in this definition.'
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -125,6 +125,11 @@ class Audition extends Model
|
|||
return $this->attributes['judges_count'];
|
||||
}
|
||||
|
||||
public function splitScoreDefinition(): HasOne
|
||||
{
|
||||
return $this->hasOne(SplitScoreDefinition::class);
|
||||
}
|
||||
|
||||
public function flags(): HasMany
|
||||
{
|
||||
return $this->hasMany(AuditionFlag::class);
|
||||
|
|
|
|||
|
|
@ -14,4 +14,9 @@ class SplitScoreDefinition extends Model
|
|||
protected $casts = [
|
||||
'splits' => 'array',
|
||||
];
|
||||
|
||||
public function audition()
|
||||
{
|
||||
return $this->belongsTo(Audition::class);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ return new class extends Migration
|
|||
{
|
||||
Schema::create('split_score_definitions', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignIdFor(Audition::class)->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
||||
$table->foreignIdFor(Audition::class)->unique()->constrained()->cascadeOnDelete()->cascadeOnUpdate();
|
||||
$table->json('splits')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>Split Score Definition</x-slot:page_title>
|
||||
<x-card.card class="max-w-2xl mx-auto mt-5">
|
||||
<x-card.heading>
|
||||
Create Split Score
|
||||
</x-card.heading>
|
||||
<x-form.form method="POST" action="{{ route('admin.split_score_definitions.store') }}">
|
||||
<x-form.select name="audition_id">
|
||||
<x-slot:label>Audition</x-slot:label>
|
||||
<option value="">Select Audition</option>
|
||||
@foreach ($availableAuditions as $audition)
|
||||
<option value="{{ $audition->id }}">{{ $audition->name }}</option>
|
||||
@endforeach
|
||||
</x-form.select>
|
||||
<x-form.button class="my-3">Create Split Score</x-form.button>
|
||||
</x-form.form>
|
||||
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
|
@ -0,0 +1,50 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>Split Score - {{ $splitScoreDefinition->audition->name }}</x-slot:page_title>
|
||||
<x-card.card class="max-w-md mx-auto">
|
||||
<x-card.heading>Add Split</x-card.heading>
|
||||
<x-form.form class="my-3" action="{{ route('admin.split_score_definitions.update', $splitScoreDefinition) }}"
|
||||
method="PATCH">
|
||||
<x-form.field name="new_split" label_text="New Split Name"/>
|
||||
<x-form.button class="mt-3">Create New Split</x-form.button>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
|
||||
@if(is_array($splitScoreDefinition->splits))
|
||||
<x-form.form method="patch" action="{{ route('admin.split_score_definitions.update', $splitScoreDefinition) }}">
|
||||
@foreach($splitScoreDefinition->splits as $splitName => $splitData)
|
||||
<x-card.card class="mt-3 max-w-2xl mx-auto">
|
||||
<x-card.heading>{{ $splitName }}</x-card.heading>
|
||||
<div class="grid grid-cols-2 gap-4 py-2 px-6">
|
||||
<div>
|
||||
<div class="font-semibold">Subscores</div>
|
||||
<x-card.list.body>
|
||||
@foreach($subscores as $subscore)
|
||||
<x-card.list.row>
|
||||
@php($checked = in_array($subscore->id, $splitScoreDefinition->splits[$splitName]['subscores']) ?? false)
|
||||
<x-form.checkbox name="split[{{$splitName}}][subscores][{{$subscore->id}}]"
|
||||
value="{{$subscore->id}}" :checked="$checked"></x-form.checkbox>
|
||||
{{ $subscore->name }}
|
||||
</x-card.list.row>
|
||||
@endforeach
|
||||
</x-card.list.body>
|
||||
</div>
|
||||
<div>
|
||||
<div class="font-semibold">Judges</div>
|
||||
<x-card.list.body>
|
||||
@foreach($judges as $judge)
|
||||
@php($checked = in_array($judge->id, $splitScoreDefinition->splits[$splitName]['judges']) ?? false)
|
||||
<x-card.list.row>
|
||||
<x-form.checkbox name="split[{{$splitName}}][judges][{{$judge->id}}]"
|
||||
value="{{$judge->id}}" :checked="$checked"></x-form.checkbox>
|
||||
{{ $judge->full_name() }}
|
||||
</x-card.list.row>
|
||||
@endforeach
|
||||
</x-card.list.body>
|
||||
</div>
|
||||
</div>
|
||||
</x-card.card>
|
||||
@endforeach
|
||||
<x-form.button class="max-w-2xl mx-auto mt-4">Submit Changes</x-form.button>
|
||||
</x-form.form>
|
||||
@endif
|
||||
</x-layout.app>
|
||||
|
|
@ -0,0 +1,17 @@
|
|||
<x-layout.app>
|
||||
<x-slot:page_title>Split Scores</x-slot:page_title>
|
||||
<x-slot:title_bar_right>
|
||||
<x-form.button href="{{ route('admin.split_score_definitions.create') }}">Create Split-Score</x-form.button>
|
||||
</x-slot:title_bar_right>
|
||||
<x-card.card class="max-w-md mx-auto">
|
||||
<x-card.list.body>
|
||||
@foreach($splitScores as $splitScore)
|
||||
<x-card.list.row>
|
||||
<a href="{{ route('admin.split_score_definitions.edit', $splitScore) }}">
|
||||
{{ $splitScore->audition->name }}
|
||||
</a>
|
||||
</x-card.list.row>
|
||||
@endforeach
|
||||
</x-card.list.body>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
|
@ -20,6 +20,7 @@ use App\Http\Controllers\Admin\RecapController;
|
|||
use App\Http\Controllers\Admin\RoomController;
|
||||
use App\Http\Controllers\Admin\SchoolController;
|
||||
use App\Http\Controllers\Admin\ScoringGuideController;
|
||||
use App\Http\Controllers\Admin\SplitScoreDefinitionController;
|
||||
use App\Http\Controllers\Admin\StudentController;
|
||||
use App\Http\Controllers\Admin\UserController;
|
||||
use App\Http\Controllers\Admin\YearEndResetController;
|
||||
|
|
@ -219,4 +220,14 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::patch('/{prelimDefinition}', 'update')->name('admin.prelim_definitions.update');
|
||||
Route::delete('/{prelimDefinition}', 'destroy')->name('admin.prelim_definitions.destroy');
|
||||
});
|
||||
|
||||
// SplitScoreDefinition Routes
|
||||
Route::prefix('split_score_definitions')->controller(SplitScoreDefinitionController::class)->group(function () {
|
||||
Route::get('/', 'index')->name('admin.split_score_definitions.index');
|
||||
Route::get('/new', 'create')->name('admin.split_score_definitions.create');
|
||||
Route::post('/', 'store')->name('admin.split_score_definitions.store');
|
||||
Route::get('/{splitScoreDefinition}', 'edit')->name('admin.split_score_definitions.edit');
|
||||
Route::patch('/{splitScoreDefinition}', 'update')->name('admin.split_score_definitions.update');
|
||||
Route::delete('/{splitScoreDefinition}', 'destroy')->name('admin.split_score_definitions.destroy');
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Reference in New Issue