110 lines
2.9 KiB
PHP
110 lines
2.9 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Dto;
|
|
|
|
use App\Models\Slide;
|
|
use Illuminate\Contracts\Routing\UrlRoutable;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
use Illuminate\Support\Carbon;
|
|
|
|
/**
|
|
* @implements Arrayable<string, mixed>
|
|
*/
|
|
final readonly class SlideDto implements Arrayable, UrlRoutable
|
|
{
|
|
public function __construct(
|
|
public int $id,
|
|
public string $title,
|
|
public ?string $text,
|
|
public ?string $picture,
|
|
public ?string $picture_alt,
|
|
public ?string $picture_title,
|
|
public ?string $link,
|
|
public ?string $link_label,
|
|
public bool $link_new_tab,
|
|
public bool $connected,
|
|
public ?Carbon $date_start,
|
|
public ?Carbon $date_end,
|
|
public int $order,
|
|
public bool $status,
|
|
public bool $isVisible = false,
|
|
) {
|
|
}
|
|
|
|
public static function fromModel(Slide $slide): self
|
|
{
|
|
return new self(
|
|
id: $slide->id,
|
|
title: $slide->title,
|
|
text: $slide->text,
|
|
picture: is_string($slide->picture) ? $slide->picture : null,
|
|
picture_alt: $slide->picture_alt,
|
|
picture_title: $slide->picture_title,
|
|
link: $slide->link,
|
|
link_label: $slide->link_label,
|
|
link_new_tab: $slide->link_new_tab,
|
|
connected: $slide->connected,
|
|
date_start: $slide->date_start,
|
|
date_end: $slide->date_end,
|
|
order: $slide->order,
|
|
status: $slide->status,
|
|
isVisible: $slide->isVisible(),
|
|
);
|
|
}
|
|
|
|
public function isVisible(): bool
|
|
{
|
|
return $this->isVisible;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKey(): mixed
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
#[\Override]
|
|
public function getRouteKeyName(): string
|
|
{
|
|
return 'id';
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveRouteBinding($value, $field = null): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
#[\Override]
|
|
public function resolveChildRouteBinding($childType, $value, $field): mixed
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* @return array<string, mixed>
|
|
*/
|
|
#[\Override]
|
|
public function toArray(): array
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'title' => $this->title,
|
|
'text' => $this->text,
|
|
'picture' => $this->picture,
|
|
'picture_alt' => $this->picture_alt,
|
|
'picture_title' => $this->picture_title,
|
|
'link' => $this->link,
|
|
'link_label' => $this->link_label,
|
|
'link_new_tab' => $this->link_new_tab,
|
|
'connected' => $this->connected,
|
|
'date_start' => $this->date_start,
|
|
'date_end' => $this->date_end,
|
|
'order' => $this->order,
|
|
'status' => $this->status,
|
|
'is_visible' => $this->isVisible,
|
|
];
|
|
}
|
|
}
|