80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
namespace App\Data;
|
|
|
|
use Carbon\Carbon;
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
readonly class PointOfInterest implements Arrayable
|
|
{
|
|
private readonly array $info;
|
|
function __construct
|
|
(
|
|
public int $id,
|
|
public ?int $poiNumber,
|
|
public ?int $poiNumberWinter,
|
|
public string $category,
|
|
public array $tags,
|
|
public string $area,
|
|
public array $seasons,
|
|
public string $title,
|
|
public ?string $description,
|
|
public array $entrance,
|
|
public ?string $titleImage,
|
|
)
|
|
{
|
|
|
|
}
|
|
|
|
public function setInfo(array $info): void
|
|
{
|
|
$this->info = $info;
|
|
}
|
|
|
|
public function queueTime(): int
|
|
{
|
|
return $this?->info['waitTime'] ?? 0;
|
|
}
|
|
|
|
public function isOpen(): bool
|
|
{
|
|
$now = now()->setTimezone('Europe/Berlin');
|
|
$inOpeningHours = $now->between($this->opensAt(), $this->closesAt());
|
|
|
|
$rideOpen = $this->info['open'];
|
|
|
|
if(!$rideOpen) {
|
|
return false;
|
|
}
|
|
|
|
return $inOpeningHours;
|
|
}
|
|
|
|
public function closesAt(): Carbon
|
|
{
|
|
return Carbon::parse($this->info['closing'], 'Europe/Berlin');
|
|
}
|
|
|
|
public function opensAt(): Carbon
|
|
{
|
|
return Carbon::parse($this->info['opening'], 'Europe/Berlin');
|
|
}
|
|
|
|
public function toArray()
|
|
{
|
|
return [
|
|
'id' => $this->id,
|
|
'poiNumber' => $this->poiNumber,
|
|
'poiNumberWinter' => $this->poiNumberWinter,
|
|
'category' => $this->category,
|
|
'tags' => $this->tags,
|
|
'area' => $this->area,
|
|
'seasons' => $this->seasons,
|
|
'title' => $this->title,
|
|
'description' => $this->description,
|
|
'entrance' => $this->entrance,
|
|
'titleImage' => $this->titleImage,
|
|
];
|
|
}
|
|
}
|