cccc2872cd
API CI/CD / Validate (composer + pint) (push) Successful in 3m9s
API CI/CD / Test (PHPUnit) (push) Failing after 2m0s
API CI/CD / Build frontend assets (push) Failing after 1m55s
API CI/CD / Security audit (push) Failing after 55s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
60 lines
1.8 KiB
PHP
60 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Web;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Services\Settings\SchoolCalendar\SchoolCalendarContextService;
|
|
use App\Services\Settings\SchoolCalendar\SchoolCalendarQueryService;
|
|
use Illuminate\Contracts\View\View;
|
|
use Illuminate\Http\Request;
|
|
|
|
class AdminCalendarPageController extends Controller
|
|
{
|
|
public function __construct(
|
|
private SchoolCalendarContextService $contextService,
|
|
private SchoolCalendarQueryService $queryService,
|
|
) {}
|
|
|
|
public function show(Request $request): View
|
|
{
|
|
$schoolYear = trim((string) $request->query('school_year', ''));
|
|
if ($schoolYear === '') {
|
|
$schoolYear = $this->contextService->defaultSchoolYear();
|
|
}
|
|
|
|
$semester = trim((string) $request->query('semester', ''));
|
|
$filters = ['school_year' => $schoolYear];
|
|
if ($semester !== '') {
|
|
$filters['semester'] = $semester;
|
|
}
|
|
|
|
$events = $this->queryService->listEvents($filters);
|
|
|
|
return view('admin.calendar', [
|
|
'events' => $events,
|
|
'schoolYear' => $schoolYear,
|
|
'semester' => $semester,
|
|
'defaultSemester' => $semester !== '' ? $semester : $this->contextService->defaultSemester(),
|
|
'schoolYears' => $this->schoolYearOptions($schoolYear),
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* @return list<string>
|
|
*/
|
|
private function schoolYearOptions(string $selectedSchoolYear): array
|
|
{
|
|
$currentYear = (int) date('Y') + 1;
|
|
$years = [];
|
|
for ($year = $currentYear; $year >= 2023; $year--) {
|
|
$years[] = ($year - 1).'-'.$year;
|
|
}
|
|
|
|
if ($selectedSchoolYear !== '' && ! in_array($selectedSchoolYear, $years, true)) {
|
|
array_unshift($years, $selectedSchoolYear);
|
|
}
|
|
|
|
return array_values(array_unique($years));
|
|
}
|
|
}
|