46 lines
1.2 KiB
PHP
Executable File
46 lines
1.2 KiB
PHP
Executable File
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Carbon;
|
|
use Inertia\Inertia;
|
|
use Inertia\Response;
|
|
|
|
class PlannerController extends Controller
|
|
{
|
|
public const YEAR_SPAN = 5;
|
|
|
|
public function index(Request $request): Response
|
|
{
|
|
$currentYear = (int) Carbon::now()->format('Y');
|
|
$minYear = $currentYear - self::YEAR_SPAN;
|
|
$maxYear = $currentYear + self::YEAR_SPAN;
|
|
|
|
$year = (int) $request->query('year', $currentYear);
|
|
|
|
if ($year < $minYear || $year > $maxYear) {
|
|
$year = $currentYear;
|
|
}
|
|
|
|
$user = $request->user();
|
|
|
|
$markers = $user->markers()
|
|
->orderBy('id')
|
|
->get(['id', 'name', 'color']);
|
|
|
|
$periods = $user->vacationPeriods()
|
|
->where('start_date', '<=', Carbon::create($year, 12, 31)->toDateString())
|
|
->where('end_date', '>=', Carbon::create($year, 1, 1)->toDateString())
|
|
->orderBy('start_date')
|
|
->get(['id', 'marker_id', 'start_date', 'end_date']);
|
|
|
|
return Inertia::render('planner', [
|
|
'year' => $year,
|
|
'years' => range($minYear, $maxYear),
|
|
'markers' => $markers,
|
|
'periods' => $periods,
|
|
]);
|
|
}
|
|
}
|