Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 48 |
|
0.00% |
0 / 17 |
CRAP | |
0.00% |
0 / 1 |
| Position | |
0.00% |
0 / 48 |
|
0.00% |
0 / 17 |
462 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| fromRow | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
| getPositionId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getColor | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getSortOrder | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isActive | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedByUserId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUpdatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setPositionId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setName | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setColor | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setSortOrder | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| setIsActive | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| toDbArray | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
6 | |||
| jsonSerialize | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Scheduling\Models; |
| 4 | |
| 5 | use DateTime; |
| 6 | use DateTimeInterface; |
| 7 | use JsonSerializable; |
| 8 | |
| 9 | /** |
| 10 | * Position Entity Model |
| 11 | * |
| 12 | * Represents a store position from the schedulePositions table. |
| 13 | * |
| 14 | * @package BuyerKiosk\Scheduling\Models |
| 15 | */ |
| 16 | class Position implements JsonSerializable |
| 17 | { |
| 18 | private ?int $positionId = null; |
| 19 | private string $name; |
| 20 | private string $color; |
| 21 | private int $sortOrder = 0; |
| 22 | private bool $isActive = true; |
| 23 | private int $createdByUserId; |
| 24 | private ?DateTime $createdAt = null; |
| 25 | private ?DateTime $updatedAt = null; |
| 26 | |
| 27 | /** |
| 28 | * Create a new Position instance |
| 29 | * |
| 30 | * @param string $name Position name |
| 31 | * @param string $color Position color (hex code) |
| 32 | * @param int $createdByUserId User ID who created the position |
| 33 | */ |
| 34 | public function __construct( |
| 35 | string $name, |
| 36 | string $color, |
| 37 | int $createdByUserId |
| 38 | ) { |
| 39 | $this->name = $name; |
| 40 | $this->color = $color; |
| 41 | $this->createdByUserId = $createdByUserId; |
| 42 | } |
| 43 | |
| 44 | /** |
| 45 | * Create Position from database row |
| 46 | * |
| 47 | * @param array $row Database row |
| 48 | * @return self |
| 49 | */ |
| 50 | public static function fromRow(array $row): self |
| 51 | { |
| 52 | $position = new self( |
| 53 | $row['name'], |
| 54 | $row['color'], |
| 55 | (int)$row['createdByUserId'] |
| 56 | ); |
| 57 | |
| 58 | $position->positionId = isset($row['positionId']) ? (int)$row['positionId'] : null; |
| 59 | $position->sortOrder = (int)($row['sortOrder'] ?? 0); |
| 60 | $position->isActive = (bool)($row['isActive'] ?? true); |
| 61 | |
| 62 | if (isset($row['created_at'])) { |
| 63 | $position->createdAt = new DateTime($row['created_at']); |
| 64 | } |
| 65 | if (isset($row['updated_at'])) { |
| 66 | $position->updatedAt = new DateTime($row['updated_at']); |
| 67 | } |
| 68 | |
| 69 | return $position; |
| 70 | } |
| 71 | |
| 72 | // Getters |
| 73 | |
| 74 | public function getPositionId(): ?int |
| 75 | { |
| 76 | return $this->positionId; |
| 77 | } |
| 78 | |
| 79 | public function getName(): string |
| 80 | { |
| 81 | return $this->name; |
| 82 | } |
| 83 | |
| 84 | public function getColor(): string |
| 85 | { |
| 86 | return $this->color; |
| 87 | } |
| 88 | |
| 89 | public function getSortOrder(): int |
| 90 | { |
| 91 | return $this->sortOrder; |
| 92 | } |
| 93 | |
| 94 | public function isActive(): bool |
| 95 | { |
| 96 | return $this->isActive; |
| 97 | } |
| 98 | |
| 99 | public function getCreatedByUserId(): int |
| 100 | { |
| 101 | return $this->createdByUserId; |
| 102 | } |
| 103 | |
| 104 | public function getCreatedAt(): ?DateTime |
| 105 | { |
| 106 | return $this->createdAt; |
| 107 | } |
| 108 | |
| 109 | public function getUpdatedAt(): ?DateTime |
| 110 | { |
| 111 | return $this->updatedAt; |
| 112 | } |
| 113 | |
| 114 | // Setters |
| 115 | |
| 116 | public function setPositionId(int $positionId): self |
| 117 | { |
| 118 | $this->positionId = $positionId; |
| 119 | return $this; |
| 120 | } |
| 121 | |
| 122 | public function setName(string $name): self |
| 123 | { |
| 124 | $this->name = $name; |
| 125 | return $this; |
| 126 | } |
| 127 | |
| 128 | public function setColor(string $color): self |
| 129 | { |
| 130 | $this->color = $color; |
| 131 | return $this; |
| 132 | } |
| 133 | |
| 134 | public function setSortOrder(int $sortOrder): self |
| 135 | { |
| 136 | $this->sortOrder = $sortOrder; |
| 137 | return $this; |
| 138 | } |
| 139 | |
| 140 | public function setIsActive(bool $isActive): self |
| 141 | { |
| 142 | $this->isActive = $isActive; |
| 143 | return $this; |
| 144 | } |
| 145 | |
| 146 | /** |
| 147 | * Convert to array for database insert/update |
| 148 | * |
| 149 | * @return array |
| 150 | */ |
| 151 | public function toDbArray(): array |
| 152 | { |
| 153 | return [ |
| 154 | 'name' => $this->name, |
| 155 | 'color' => $this->color, |
| 156 | 'sortOrder' => $this->sortOrder, |
| 157 | 'isActive' => $this->isActive ? 1 : 0, |
| 158 | 'createdByUserId' => $this->createdByUserId, |
| 159 | ]; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * JSON serialization for API responses |
| 164 | * |
| 165 | * @return array |
| 166 | */ |
| 167 | public function jsonSerialize(): array |
| 168 | { |
| 169 | return [ |
| 170 | 'positionId' => $this->positionId, |
| 171 | 'name' => $this->name, |
| 172 | 'color' => $this->color, |
| 173 | 'isActive' => $this->isActive, |
| 174 | 'sortOrder' => $this->sortOrder, |
| 175 | ]; |
| 176 | } |
| 177 | } |