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-06-14 21:32:07 +02:00
|
|
|
use App\Traits\Requests\HasPicture;
|
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-10-01 11:25:05 +02:00
|
|
|
use Illuminate\Http\UploadedFile;
|
2026-06-14 21:32:07 +02:00
|
|
|
use Illuminate\Support\Facades\Date;
|
|
|
|
|
use Infrastructure\Adapters\Services\AppAdminAuthService;
|
|
|
|
|
|
|
|
|
|
class StoreSlideRequest extends FormRequest
|
|
|
|
|
{
|
|
|
|
|
use HasPicture;
|
|
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
|
private readonly AppAdminAuthService $authService
|
|
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function authorize(): bool
|
|
|
|
|
{
|
|
|
|
|
return $this->authService->check();
|
|
|
|
|
}
|
|
|
|
|
|
2026-10-01 11:25:05 +02:00
|
|
|
public function resolvePicture(): UploadedFile | string | null
|
|
|
|
|
{
|
|
|
|
|
$file = $this->file('picture');
|
|
|
|
|
if ($file instanceof UploadedFile) {
|
|
|
|
|
return $file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $this->has('picture') && is_string($this->input('picture'))
|
|
|
|
|
? $this->input('picture')
|
|
|
|
|
: null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
|
picture: $this->resolvePicture(),
|
|
|
|
|
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-10-02 19:52:09 +02:00
|
|
|
$text = $this->input('text');
|
|
|
|
|
if (is_string($text) && trim(html_entity_decode(strip_tags($text), ENT_QUOTES | ENT_HTML5, 'UTF-8')) === '') {
|
|
|
|
|
$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'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/** @return array<string,mixed> */
|
|
|
|
|
public function rules(): array
|
|
|
|
|
{
|
|
|
|
|
$maxWidth = 1440;
|
|
|
|
|
$maxHeight = 960;
|
|
|
|
|
|
|
|
|
|
return array_merge(
|
|
|
|
|
[
|
|
|
|
|
'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'],
|
2026-10-02 19:52:09 +02:00
|
|
|
'text' => ['nullable', 'required_without:picture', 'string', 'min:4'],
|
2026-06-14 21:32:07 +02:00
|
|
|
'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'],
|
|
|
|
|
],
|
|
|
|
|
$this->pictureRules(
|
|
|
|
|
'picture',
|
|
|
|
|
$maxWidth,
|
|
|
|
|
$maxHeight,
|
|
|
|
|
$maxWidth,
|
|
|
|
|
$maxHeight,
|
|
|
|
|
true
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\Override]
|
|
|
|
|
protected function passedValidation()
|
|
|
|
|
{
|
|
|
|
|
if ($this->filled('date_start')) {
|
|
|
|
|
$inputValue = Date::createFromFormat(
|
|
|
|
|
'Y-m-d\TH:i',
|
|
|
|
|
$this->string('date_start')->value(),
|
|
|
|
|
$this->string('client_timezone')->value()
|
|
|
|
|
)?->setTimezone('UTC');
|
|
|
|
|
|
|
|
|
|
$this->merge([
|
|
|
|
|
'date_start' => $inputValue?->format('Y-m-d H:i:s'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
if ($this->filled('date_end')) {
|
|
|
|
|
$inputValue = Date::createFromFormat(
|
|
|
|
|
'Y-m-d\TH:i',
|
|
|
|
|
$this->string('date_end')->value(),
|
|
|
|
|
$this->string('client_timezone')->value()
|
|
|
|
|
)?->setTimezone('UTC');
|
|
|
|
|
|
|
|
|
|
$this->merge([
|
|
|
|
|
'date_end' => $inputValue?->format('Y-m-d H:i:s'),
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#[\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'),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|