Files
gorilla/app/Service/Entities/Inspection.php
2026-01-12 12:37:16 +01:00

58 lines
1.5 KiB
PHP

<?php
namespace App\Service\Entities;
use App\Service\Enums\Status;
use App\Service\Enums\Type;
use DateTimeImmutable;
class Inspection extends BaseReport implements EntityInterface
{
public ?int $serviceWeek = null;
public Type $type = Type::INSPECTION;
public function __construct(InputEntity $entity)
{
$this->createdAt = new DateTimeImmutable();
$this->fromData($entity);
}
public static function isValid(InputEntity $entity): bool
{
return preg_match('/przegląd/mi', $entity->description);
}
public function __toArray(): array
{
return [
'description' => $this->description,
'type' => $this->type->value,
'inspectionDate' => $this->serviceDate?->format('Y-m-d') ?? '',
'weekOfInspection' => $this->serviceWeek ?? '',
'status' => $this->status->value,
'recommendations' => $this->serviceNotes ?? '',
'contactPhone' => $this->contactPhone ?? '',
'createdAt' => $this->createdAt->format('Y-m-d')
];
}
private function fromData(InputEntity $entity): void
{
$this->description = $entity->description;
$this->contactPhone = $entity->phone;
$this->serviceDate = $entity->date;
$this->checkWeek();
$this->status = $this->serviceDate ? Status::PLANED : Status::NEW;
}
private function checkWeek(): void
{
if($this->serviceDate) {
$this->serviceWeek = $this->serviceDate->isoWeek();
}
}
}