Restructure the festival hierarchy end-to-end: Seeder: Remove duplicate festival-level VOLUNTEER time slots, keep only CREW operational slots. Rename sub-events to "Dag 1/2/3 — ..." pattern. Change Nachtsecurity to Security (cross_event). EHBO/Security shifts now use sub-event time slots via cross_event exception. Add flat event "Braderie Dorpstown 2026". API: Add ?include_children=true to TimeSlotController for festivals, returning all sub-event time slots with source and event_name fields. Update StoreShiftRequest and UpdateShiftRequest to accept child time slots for cross_event sections. Frontend: Create useTimeSlotDropdown composable with 4-scenario dropdown logic. Replace AppSelect with VAutocomplete in CreateShiftDialog with grouped items, dimmed festival slots, and info tooltips. Add InfoTooltip reusable component. Show festival context labels on cross_event sections in sub-event section lists. Add read-only festival time slots on sub-event time-slots page. Add cross_event context banner with "Bekijk alle diensten" link. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
122 lines
4.7 KiB
PHP
122 lines
4.7 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Http\Controllers\Api\V1;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Controllers\Api\V1\Traits\VerifiesOrganisationEvent;
|
|
use App\Http\Requests\Api\V1\StoreTimeSlotRequest;
|
|
use App\Http\Requests\Api\V1\UpdateTimeSlotRequest;
|
|
use App\Http\Resources\Api\V1\TimeSlotResource;
|
|
use App\Models\Event;
|
|
use App\Models\Organisation;
|
|
use App\Models\TimeSlot;
|
|
use Illuminate\Http\JsonResponse;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Support\Facades\Gate;
|
|
|
|
final class TimeSlotController extends Controller
|
|
{
|
|
use VerifiesOrganisationEvent;
|
|
|
|
public function index(Organisation $organisation, Event $event): AnonymousResourceCollection
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('viewAny', [TimeSlot::class, $event]);
|
|
|
|
$timeSlots = $event->timeSlots()
|
|
->withCount('shifts')
|
|
->with(['shifts' => fn ($q) => $q->withCount([
|
|
'shiftAssignments as assignments_count' => fn ($q) => $q->where('status', 'approved'),
|
|
])])
|
|
->orderBy('date')
|
|
->orderBy('start_time')
|
|
->get();
|
|
|
|
// For sub-events: include parent festival time slots
|
|
if ($event->isSubEvent() && request()->boolean('include_parent') && $event->parent_event_id) {
|
|
$parentTimeSlots = TimeSlot::where('event_id', $event->parent_event_id)
|
|
->withCount('shifts')
|
|
->with([
|
|
'event',
|
|
'shifts' => fn ($q) => $q->withCount([
|
|
'shiftAssignments as assignments_count' => fn ($q) => $q->where('status', 'approved'),
|
|
]),
|
|
])
|
|
->orderBy('date')
|
|
->orderBy('start_time')
|
|
->get();
|
|
|
|
$timeSlots->load('event');
|
|
$timeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'sub_event'));
|
|
$parentTimeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'festival'));
|
|
|
|
$timeSlots = $timeSlots->merge($parentTimeSlots)
|
|
->sortBy([['date', 'asc'], ['start_time', 'asc']])
|
|
->values();
|
|
}
|
|
|
|
// For festivals: include all sub-event time slots (for cross_event section shift dialogs)
|
|
if (!$event->isSubEvent() && request()->boolean('include_children')) {
|
|
$childEventIds = Event::where('parent_event_id', $event->id)->pluck('id');
|
|
|
|
if ($childEventIds->isNotEmpty()) {
|
|
$childTimeSlots = TimeSlot::whereIn('event_id', $childEventIds)
|
|
->withCount('shifts')
|
|
->with([
|
|
'event',
|
|
'shifts' => fn ($q) => $q->withCount([
|
|
'shiftAssignments as assignments_count' => fn ($q) => $q->where('status', 'approved'),
|
|
]),
|
|
])
|
|
->orderBy('date')
|
|
->orderBy('start_time')
|
|
->get();
|
|
|
|
$timeSlots->load('event');
|
|
$timeSlots->each(fn (TimeSlot $ts) => $ts->setAttribute('source', 'own'));
|
|
$childTimeSlots->each(function (TimeSlot $ts) use ($event) {
|
|
$ts->setAttribute('source', $ts->event_id);
|
|
});
|
|
|
|
$timeSlots = $timeSlots->merge($childTimeSlots)
|
|
->sortBy([['date', 'asc'], ['start_time', 'asc']])
|
|
->values();
|
|
}
|
|
}
|
|
|
|
return TimeSlotResource::collection($timeSlots);
|
|
}
|
|
|
|
public function store(StoreTimeSlotRequest $request, Organisation $organisation, Event $event): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('create', [TimeSlot::class, $event]);
|
|
|
|
$timeSlot = $event->timeSlots()->create($request->validated());
|
|
|
|
return $this->created(new TimeSlotResource($timeSlot));
|
|
}
|
|
|
|
public function update(UpdateTimeSlotRequest $request, Organisation $organisation, Event $event, TimeSlot $timeSlot): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('update', [$timeSlot, $event]);
|
|
|
|
$timeSlot->update($request->validated());
|
|
|
|
return $this->success(new TimeSlotResource($timeSlot->fresh()));
|
|
}
|
|
|
|
public function destroy(Organisation $organisation, Event $event, TimeSlot $timeSlot): JsonResponse
|
|
{
|
|
$this->verifyEventBelongsToOrganisation($organisation, $event);
|
|
Gate::authorize('delete', [$timeSlot, $event]);
|
|
|
|
$timeSlot->delete();
|
|
|
|
return response()->json(null, 204);
|
|
}
|
|
}
|