{{-- Training required at a home, in three steps: 1. Service-specific e-learning (opt-in, course_service) 2. Mandatory e-learning (per-home opt-out, service_course_exclusions) 3. Required face-to-face trainings (service_training_names) Used by the admin service form and the SM / RM "Manage Training" page. Needs: $selectableCourses, $requiredCourseIds, $mandatoryCourses, $excludedMandatoryIds; optional $sessionNames, $requiredSessionIds. Each card has live search, "show selected" filter, select/clear all and a live selected count; the summary strip at the top updates as you tick. --}} @php $reqIds = array_map('intval', old('required_course_ids', $requiredCourseIds)); $mandIds = array_map('intval', old('required_mandatory_ids', $mandatoryCourses->pluck('id')->diff($excludedMandatoryIds)->all())); $sessIds = array_map('intval', old('required_session_ids', $requiredSessionIds ?? [])); $hasSessions = isset($sessionNames); $cards = [ [ 'key' => 'specific', 'step' => 1, 'icon' => 'add_task', 'name' => 'required_course_ids[]', 'title' => 'Service-specific e-learning', 'help' => 'Extra online courses this home needs on top of the mandatory ones (e.g. Epilepsy, Bed Rails). Tick a course to assign it to every care worker here and the Service Manager.', 'items' => $selectableCourses->map(fn ($c) => [ 'id' => $c->id, 'title' => $c->title, 'sub' => ucwords(str_replace('_', ' ', $c->category)).($c->refresh_cycle ? ' · renew '.$c->refresh_cycle : ''), 'on' => in_array($c->id, $reqIds, true), ]), 'empty' => 'No service-specific courses available.', 'noun' => 'course', ], [ 'key' => 'mandatory', 'step' => 2, 'icon' => 'verified', 'name' => 'required_mandatory_ids[]', 'title' => 'Mandatory e-learning', 'help' => 'Organisation-wide courses — all ticked by default. Only untick a course this home genuinely doesn’t need: it won’t be assigned here, won’t count toward compliance, and shows as N/A on the matrix. Completed records are kept.', 'items' => $mandatoryCourses->map(fn ($c) => [ 'id' => $c->id, 'title' => $c->title, 'sub' => 'Mandatory', 'on' => in_array($c->id, $mandIds, true), ]), 'empty' => 'No mandatory courses defined.', 'noun' => 'course', 'marker' => 'mandatory_section', ], ]; if ($hasSessions) { $cards[] = [ 'key' => 'sessions', 'step' => 3, 'icon' => 'groups', 'name' => 'required_session_ids[]', 'title' => 'Required Face to Face Trainings', 'help' => 'Classroom / trainer-led sessions staff here must attend (the session names trainers use on the calendar). Each ticked training shows on this home’s session matrix, and anyone who hasn’t attended it counts as overdue in compliance.', // Insulin / PEG / Dysphagia observations first, next to the compulsory competency tile. 'items' => $sessionNames->sortBy(fn ($t) => \App\Models\ObservationRecord::typeForTitle($t->name) ? 0 : 1)->values()->map(fn ($t) => [ 'id' => $t->id, 'title' => $t->name, 'sub' => ($obsType = \App\Models\ObservationRecord::typeForTitle($t->name)) ? 'Observation · PDF upload · renewed '.\App\Models\ObservationRecord::renewalLabel($obsType).(isset(\App\Models\ObservationRecord::PREREQUISITES[$obsType]) ? ' · also requires '.\App\Models\ObservationRecord::PREREQUISITES[$obsType] : '') : ($t->training_code ? 'Face to face · '.$t->training_code : 'Face to face'), 'on' => in_array($t->id, $sessIds, true), ]), 'empty' => 'No face-to-face trainings exist yet — trainers add these when scheduling on the calendar.', 'noun' => 'training', 'marker' => 'sessions_section', ]; } @endphp {{-- At-a-glance summary (updates live) --}}
What staff at this home must complete
{!! $card['help'] !!}
@if($card['key'] === 'sessions' && ($sessionsPrefilled ?? false) && ! old('sessions_section'))Mandatory at every service
Service-specific
@endif @endif @if($card['items']->isEmpty()){{ $card['empty'] }}
@else {{-- Toolbar: search · show filter · bulk actions --}}Nothing matches.