Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 45 |
|
0.00% |
0 / 15 |
CRAP | |
0.00% |
0 / 1 |
| EmployeeInvitation | |
0.00% |
0 / 45 |
|
0.00% |
0 / 15 |
342 | |
0.00% |
0 / 1 |
| fromRow | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getTypeNum | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEmployeeId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getEmail | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getToken | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getInvitedBy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getExpiresAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getUsedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getDefaultGroupsArray | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
12 | |||
| isValid | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
6 | |||
| isUsed | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| isExpired | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 15 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\UserEmployee; |
| 4 | |
| 5 | /** |
| 6 | * Entity representing an invitation for an employee to create a user account |
| 7 | * |
| 8 | * This class represents a single invitation sent to an employee to complete |
| 9 | * self-registration and create their uf_user account. |
| 10 | */ |
| 11 | class EmployeeInvitation |
| 12 | { |
| 13 | private int $id; |
| 14 | private string $typeNum; |
| 15 | private int $employeeId; |
| 16 | private string $email; |
| 17 | private string $token; |
| 18 | private int $invitedBy; |
| 19 | private ?string $defaultGroups; |
| 20 | private string $expiresAt; |
| 21 | private ?string $usedAt; |
| 22 | private string $createdAt; |
| 23 | |
| 24 | /** |
| 25 | * Create EmployeeInvitation from database row |
| 26 | * |
| 27 | * @param array $row Associative array from database query |
| 28 | * @return self New EmployeeInvitation instance |
| 29 | */ |
| 30 | public static function fromRow(array $row): self |
| 31 | { |
| 32 | $invitation = new self(); |
| 33 | $invitation->id = (int) $row['id']; |
| 34 | $invitation->typeNum = $row['typeNum']; |
| 35 | $invitation->employeeId = (int) $row['employeeId']; |
| 36 | $invitation->email = $row['email']; |
| 37 | $invitation->token = $row['token']; |
| 38 | $invitation->invitedBy = (int) $row['invitedBy']; |
| 39 | $invitation->defaultGroups = $row['defaultGroups'] ?? null; |
| 40 | $invitation->expiresAt = $row['expiresAt']; |
| 41 | $invitation->usedAt = $row['usedAt'] ?? null; |
| 42 | $invitation->createdAt = $row['createdAt']; |
| 43 | return $invitation; |
| 44 | } |
| 45 | |
| 46 | /** |
| 47 | * Get invitation ID |
| 48 | * @return int |
| 49 | */ |
| 50 | public function getId(): int |
| 51 | { |
| 52 | return $this->id; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Get store typeNum |
| 57 | * @return string |
| 58 | */ |
| 59 | public function getTypeNum(): string |
| 60 | { |
| 61 | return $this->typeNum; |
| 62 | } |
| 63 | |
| 64 | /** |
| 65 | * Get employee ID |
| 66 | * @return int |
| 67 | */ |
| 68 | public function getEmployeeId(): int |
| 69 | { |
| 70 | return $this->employeeId; |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Get email address |
| 75 | * @return string |
| 76 | */ |
| 77 | public function getEmail(): string |
| 78 | { |
| 79 | return $this->email; |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Get invitation token |
| 84 | * @return string |
| 85 | */ |
| 86 | public function getToken(): string |
| 87 | { |
| 88 | return $this->token; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Get ID of user who sent invitation |
| 93 | * @return int |
| 94 | */ |
| 95 | public function getInvitedBy(): int |
| 96 | { |
| 97 | return $this->invitedBy; |
| 98 | } |
| 99 | |
| 100 | /** |
| 101 | * Get expiration timestamp |
| 102 | * @return string |
| 103 | */ |
| 104 | public function getExpiresAt(): string |
| 105 | { |
| 106 | return $this->expiresAt; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * Get timestamp when invitation was used (null if not used) |
| 111 | * @return string|null |
| 112 | */ |
| 113 | public function getUsedAt(): ?string |
| 114 | { |
| 115 | return $this->usedAt; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Get creation timestamp |
| 120 | * @return string |
| 121 | */ |
| 122 | public function getCreatedAt(): string |
| 123 | { |
| 124 | return $this->createdAt; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Get default groups as array |
| 129 | * |
| 130 | * @return array Array of group IDs |
| 131 | */ |
| 132 | public function getDefaultGroupsArray(): array |
| 133 | { |
| 134 | if ($this->defaultGroups === null) { |
| 135 | return []; |
| 136 | } |
| 137 | |
| 138 | $decoded = json_decode($this->defaultGroups, true); |
| 139 | return is_array($decoded) ? $decoded : []; |
| 140 | } |
| 141 | |
| 142 | /** |
| 143 | * Check if invitation is still valid (not expired and not used) |
| 144 | * |
| 145 | * @return bool True if invitation can still be used |
| 146 | */ |
| 147 | public function isValid(): bool |
| 148 | { |
| 149 | return !$this->isUsed() && !$this->isExpired(); |
| 150 | } |
| 151 | |
| 152 | /** |
| 153 | * Check if invitation has been used |
| 154 | * |
| 155 | * @return bool True if usedAt is not null |
| 156 | */ |
| 157 | public function isUsed(): bool |
| 158 | { |
| 159 | return $this->usedAt !== null; |
| 160 | } |
| 161 | |
| 162 | /** |
| 163 | * Check if invitation has expired |
| 164 | * |
| 165 | * @return bool True if current time is past expiresAt |
| 166 | */ |
| 167 | public function isExpired(): bool |
| 168 | { |
| 169 | $now = new \DateTime(); |
| 170 | $expires = new \DateTime($this->expiresAt); |
| 171 | return $now > $expires; |
| 172 | } |
| 173 | |
| 174 | /** |
| 175 | * Convert to array for API responses |
| 176 | * |
| 177 | * @return array Associative array of all invitation data |
| 178 | */ |
| 179 | public function toArray(): array |
| 180 | { |
| 181 | return [ |
| 182 | 'id' => $this->id, |
| 183 | 'typeNum' => $this->typeNum, |
| 184 | 'employeeId' => $this->employeeId, |
| 185 | 'email' => $this->email, |
| 186 | 'token' => $this->token, |
| 187 | 'invitedBy' => $this->invitedBy, |
| 188 | 'defaultGroups' => $this->getDefaultGroupsArray(), |
| 189 | 'expiresAt' => $this->expiresAt, |
| 190 | 'usedAt' => $this->usedAt, |
| 191 | 'createdAt' => $this->createdAt, |
| 192 | 'isValid' => $this->isValid(), |
| 193 | 'isUsed' => $this->isUsed(), |
| 194 | 'isExpired' => $this->isExpired(), |
| 195 | ]; |
| 196 | } |
| 197 | } |