2026-06-14 21:32:07 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
|
|
namespace App\Http\Requests\Bo\Slides;
|
|
|
|
|
|
2026-11-10 14:28:00 +01:00
|
|
|
use App\Cqs\Actions\Slides\CreateSlideInput;
|
2026-11-14 16:06:34 +01:00
|
|
|
use App\Rules\FileExtensionMatchesMimeType;
|
2026-11-16 01:58:43 +01:00
|
|
|
use App\Traits\Requests\ConvertsClientDatesToUtc;
|
2026-10-01 11:25:05 +02:00
|
|
|
use Domain\Models\ValueObjects\DatePeriod;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Foundation\Http\FormRequest;
|
2026-11-14 16:06:34 +01:00
|
|
|
use Illuminate\Support\Stringable;
|
|
|
|
|
use Illuminate\Validation\Rule;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
|
|
|
|
|
|
class StoreSlideRequest extends FormRequest
|
|
|
|
|
{
|
2026-11-16 01:58:43 +01:00
|
|
|
use ConvertsClientDatesToUtc;
|
|
|
|
|
|
2026-11-14 16:06:34 +01:00
|
|
|
public const int MAX_FILE_SIZE_KB = 5120;
|
|
|
|
|
|
|
|
|
|
public const int PICTURE_WIDTH = 1440;
|
|
|
|
|
|
|
|
|
|
public const int PICTURE_HEIGHT = 960;
|
|
|
|
|
|
|
|
|
|
/** @var list<string> */
|
|
|
|
|
public const array ALLOWED_EXTENSIONS = ['jpg', 'jpeg', 'png'];
|
|
|
|
|
|
|
|
|
|
/** @var list<string> */
|
|
|
|
|
public const array ALLOWED_MIME_TYPES = ['image/jpeg', 'image/png'];
|
2026-06-14 21:32:07 +02:00
|
|
|
|
|
|
|
|
public function __construct(
|
2026-11-14 16:06:34 +01:00
|
|
|
private readonly AppAdminAuthService $authService,
|
2026-06-14 21:32:07 +02:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->authService->check();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
public function toDatePeriod(): DatePeriod
|
|
|
|
|
{
|
|
|
|
|
return new DatePeriod(
|
|
|
|
|
start: $this->filled('date_start') ? new \DateTimeImmutable($this->string('date_start')->value()) : null,
|
|
|
|
|
end: $this->filled('date_end') ? new \DateTimeImmutable($this->string('date_end')->value()) : null,
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toCreateSlideInput(): CreateSlideInput
|
|
|
|
|
{
|
|
|
|
|
return new CreateSlideInput(
|
|
|
|
|
title: $this->string('title')->value(),
|
|
|
|
|
text: $this->filled('text') ? $this->string('text')->value() : null,
|
2026-11-14 16:06:34 +01:00
|
|
|
picture: $this->hasFile('picture') ? $this->file('picture') : null,
|
2026-10-01 11:25:05 +02:00
|
|
|
pictureAlt: $this->filled('picture_alt') ? $this->string('picture_alt')->value() : null,
|
|
|
|
|
pictureTitle: $this->filled('picture_title') ? $this->string('picture_title')->value() : null,
|
|
|
|
|
link: $this->filled('link') ? $this->string('link')->value() : null,
|
|
|
|
|
linkLabel: $this->filled('link_label') ? $this->string('link_label')->value() : null,
|
|
|
|
|
linkNewTab: $this->boolean('link_new_tab'),
|
|
|
|
|
connected: $this->boolean('connected'),
|
|
|
|
|
period: $this->toDatePeriod(),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
#[\Override]
|
|
|
|
|
protected function prepareForValidation(): void
|
|
|
|
|
{
|
2026-11-14 16:06:34 +01:00
|
|
|
$text = $this->string('text')->value();
|
|
|
|
|
$trimmedText = $this->string('text')
|
|
|
|
|
->pipe(fn (Stringable $text) => html_entity_decode(strip_tags((string) $text), ENT_QUOTES | ENT_HTML5, 'UTF-8'))
|
|
|
|
|
->trim()
|
|
|
|
|
->toString();
|
|
|
|
|
if ($trimmedText === '') {
|
2026-10-02 19:52:09 +02:00
|
|
|
$text = null;
|
|
|
|
|
}
|
|
|
|
|
|
2026-06-14 21:32:07 +02:00
|
|
|
$this->merge([
|
2026-10-02 19:52:09 +02:00
|
|
|
'text' => $text,
|
2026-06-14 21:32:07 +02:00
|
|
|
'connected' => $this->boolean('connected'),
|
|
|
|
|
'link_new_tab' => $this->boolean('link_new_tab'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
2026-11-14 16:06:34 +01:00
|
|
|
/** @return array<string, \Illuminate\Validation\Rule|array<mixed>|string> */
|
2026-06-14 21:32:07 +02:00
|
|
|
public function rules(): array
|
|
|
|
|
{
|
2026-11-14 16:06:34 +01:00
|
|
|
return [
|
|
|
|
|
'title' => ['required', 'string', 'min:4', 'max:75'],
|
|
|
|
|
'picture_alt' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
|
|
|
|
'picture_title' => ['required_with:picture', 'string', 'min:4', 'max:75'],
|
|
|
|
|
'picture' => [
|
|
|
|
|
Rule::imageFile()
|
|
|
|
|
->extensions(self::ALLOWED_EXTENSIONS)
|
|
|
|
|
->rules([
|
|
|
|
|
'mimetypes:' . implode(',', self::ALLOWED_MIME_TYPES),
|
|
|
|
|
new FileExtensionMatchesMimeType(),
|
|
|
|
|
])
|
|
|
|
|
->max(self::MAX_FILE_SIZE_KB)
|
|
|
|
|
->dimensions(
|
|
|
|
|
Rule::dimensions()
|
|
|
|
|
->width(static::PICTURE_WIDTH)
|
|
|
|
|
->height(static::PICTURE_HEIGHT)
|
|
|
|
|
),
|
2026-06-14 21:32:07 +02:00
|
|
|
],
|
2026-11-14 16:06:34 +01:00
|
|
|
'text' => ['nullable', 'required_without:picture', 'string', 'min:4'],
|
|
|
|
|
'link' => ['nullable', 'url:https', 'max:255'],
|
|
|
|
|
'link_label' => ['nullable', 'string', 'min:5', 'max:255'],
|
|
|
|
|
'link_new_tab' => ['present', 'boolean:strict'],
|
|
|
|
|
'connected' => ['present', 'boolean:strict'],
|
|
|
|
|
'date_start' => ['nullable', 'date_format:Y-m-d\TH:i'],
|
|
|
|
|
'date_end' => ['nullable', 'date_format:Y-m-d\TH:i', 'after:date_start'],
|
|
|
|
|
'client_timezone' => ['required', 'timezone'],
|
|
|
|
|
];
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
2026-11-14 16:06:34 +01:00
|
|
|
protected function passedValidation(): void
|
2026-06-14 21:32:07 +02:00
|
|
|
{
|
2026-11-16 01:58:43 +01:00
|
|
|
$this->mergeLocalDatetimeAsUtc('date_start');
|
|
|
|
|
$this->mergeLocalDatetimeAsUtc('date_end');
|
2026-06-14 21:32:07 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
public function attributes(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'title' => trans('validation.attributes.title'),
|
|
|
|
|
'text' => trans('validation.attributes.text'),
|
|
|
|
|
'date_start' => trans('validation.custom.attributes.date_start_show'),
|
|
|
|
|
'date_end' => trans('validation.custom.attributes.date_end_show'),
|
|
|
|
|
'connected' => trans('validation.custom.attributes.connected'),
|
|
|
|
|
'link' => trans('validation.custom.attributes.link'),
|
|
|
|
|
'link_label' => trans('validation.custom.attributes.link_label'),
|
|
|
|
|
'link_new_tab' => trans('validation.custom.attributes.link_new_tab'),
|
|
|
|
|
'picture' => trans('validation.attributes.image'),
|
|
|
|
|
'picture_alt' => trans('validation.custom.attributes.picture_alt'),
|
|
|
|
|
'picture_title' => trans('validation.custom.attributes.picture_title'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|