| 1 |
<?php |
| 2 |
|
| 3 |
declare(strict_types=1); |
| 4 |
|
| 5 |
namespace Yatra\Models; |
| 6 |
|
| 7 |
/** |
| 8 |
* Destination Model |
| 9 |
* Represents a destination entity |
| 10 |
*/ |
| 11 |
class Destination |
| 12 |
{ |
| 13 |
/** |
| 14 |
* @var int |
| 15 |
*/ |
| 16 |
public int $id; |
| 17 |
|
| 18 |
/** |
| 19 |
* @var string |
| 20 |
*/ |
| 21 |
public string $name; |
| 22 |
|
| 23 |
/** |
| 24 |
* @var string |
| 25 |
*/ |
| 26 |
public string $slug; |
| 27 |
|
| 28 |
/** |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
public string $description; |
| 32 |
|
| 33 |
/** |
| 34 |
* @var array|null Icon data (type and value) |
| 35 |
*/ |
| 36 |
public ?array $icon; |
| 37 |
|
| 38 |
/** |
| 39 |
* @var string |
| 40 |
*/ |
| 41 |
public string $status; |
| 42 |
|
| 43 |
/** |
| 44 |
* @var string |
| 45 |
*/ |
| 46 |
public string $created_at; |
| 47 |
|
| 48 |
/** |
| 49 |
* @var string |
| 50 |
*/ |
| 51 |
public string $updated_at; |
| 52 |
|
| 53 |
/** |
| 54 |
* @var int |
| 55 |
*/ |
| 56 |
public int $created_by; |
| 57 |
|
| 58 |
/** |
| 59 |
* @var int |
| 60 |
*/ |
| 61 |
public int $updated_by; |
| 62 |
|
| 63 |
/** |
| 64 |
* Create from array |
| 65 |
*/ |
| 66 |
public static function fromArray(array $data): self |
| 67 |
{ |
| 68 |
$destination = new self(); |
| 69 |
|
| 70 |
$destination->id = (int) ($data['id'] ?? 0); |
| 71 |
$destination->name = $data['name'] ?? ''; |
| 72 |
$destination->slug = $data['slug'] ?? ''; |
| 73 |
$destination->description = $data['description'] ?? ''; |
| 74 |
$destination->icon = isset($data['icon']) ? (is_array($data['icon']) ? $data['icon'] : maybe_unserialize($data['icon'])) : null; |
| 75 |
$destination->status = $data['status'] ?? 'draft'; |
| 76 |
$destination->created_at = $data['created_at'] ?? ''; |
| 77 |
$destination->updated_at = $data['updated_at'] ?? ''; |
| 78 |
$destination->created_by = (int) ($data['created_by'] ?? 0); |
| 79 |
$destination->updated_by = (int) ($data['updated_by'] ?? 0); |
| 80 |
|
| 81 |
return $destination; |
| 82 |
} |
| 83 |
|
| 84 |
/** |
| 85 |
* Convert to array |
| 86 |
*/ |
| 87 |
public function toArray(): array |
| 88 |
{ |
| 89 |
return [ |
| 90 |
'id' => $this->id, |
| 91 |
'name' => $this->name, |
| 92 |
'slug' => $this->slug, |
| 93 |
'description' => $this->description, |
| 94 |
'icon' => $this->icon, |
| 95 |
'status' => $this->status, |
| 96 |
'created_at' => $this->created_at, |
| 97 |
'updated_at' => $this->updated_at, |
| 98 |
'created_by' => $this->created_by, |
| 99 |
'updated_by' => $this->updated_by, |
| 100 |
]; |
| 101 |
} |
| 102 |
} |
| 103 |
|