Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 90 |
|
0.00% |
0 / 25 |
CRAP | |
0.00% |
0 / 1 |
| EventAlert | |
0.00% |
0 / 90 |
|
0.00% |
0 / 25 |
992 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
20 | |||
| getById | |
0.00% |
0 / 17 |
|
0.00% |
0 / 1 |
12 | |||
| getByEventId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| getUnacknowledged | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| getUnacknowledgedByEventId | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| acknowledge | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| delete | |
0.00% |
0 / 4 |
|
0.00% |
0 / 1 |
2 | |||
| toArray | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
2 | |||
| getId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getEventId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setEventId | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAlertType | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAlertType | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getMessage | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setMessage | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getBinCount | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setBinCount | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAcknowledged | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAcknowledged | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| getAcknowledgedBy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| setAcknowledgedBy | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| getAcknowledgedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCreatedAt | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\Backstock; |
| 4 | |
| 5 | class EventAlert extends Backstock |
| 6 | { |
| 7 | public $id; |
| 8 | public $eventId; |
| 9 | public $alertType; |
| 10 | public $message; |
| 11 | public $binCount; |
| 12 | public $acknowledged; |
| 13 | public $acknowledgedBy; |
| 14 | public $acknowledgedAt; |
| 15 | public $createdAt; |
| 16 | |
| 17 | public function __construct(\Store $store) |
| 18 | { |
| 19 | parent::__construct($store); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * Create a new alert |
| 24 | * @return $this |
| 25 | */ |
| 26 | public function create() |
| 27 | { |
| 28 | $stmt = $this->storeDB->prepare(" |
| 29 | INSERT INTO bsEvent_Alerts ( |
| 30 | eventId, alertType, message, binCount, |
| 31 | acknowledged, acknowledgedBy, acknowledgedAt, created_at |
| 32 | ) VALUES ( |
| 33 | :eventId, :alertType, :message, :binCount, |
| 34 | :acknowledged, :acknowledgedBy, :acknowledgedAt, NOW() |
| 35 | ) |
| 36 | "); |
| 37 | |
| 38 | $stmt->bindValue(":eventId", $this->eventId, \PDO::PARAM_INT); |
| 39 | $stmt->bindValue(":alertType", $this->alertType); |
| 40 | $stmt->bindValue(":message", $this->message); |
| 41 | $stmt->bindValue(":binCount", $this->binCount, $this->binCount === null ? \PDO::PARAM_NULL : \PDO::PARAM_INT); |
| 42 | $stmt->bindValue(":acknowledged", $this->acknowledged ?? 0, \PDO::PARAM_INT); |
| 43 | $stmt->bindValue(":acknowledgedBy", $this->acknowledgedBy, $this->acknowledgedBy === null ? \PDO::PARAM_NULL : \PDO::PARAM_INT); |
| 44 | $stmt->bindValue(":acknowledgedAt", $this->acknowledgedAt, $this->acknowledgedAt === null ? \PDO::PARAM_NULL : \PDO::PARAM_STR); |
| 45 | |
| 46 | $stmt->execute(); |
| 47 | $this->id = $this->storeDB->lastInsertId(); |
| 48 | return $this; |
| 49 | } |
| 50 | |
| 51 | /** |
| 52 | * Load alert by ID |
| 53 | * @param int $id |
| 54 | * @return $this|null |
| 55 | */ |
| 56 | public function getById($id) |
| 57 | { |
| 58 | $stmt = $this->storeDB->prepare(" |
| 59 | SELECT eventId, alertType, message, binCount, |
| 60 | acknowledged, acknowledgedBy, acknowledgedAt, created_at |
| 61 | FROM bsEvent_Alerts |
| 62 | WHERE id = :id |
| 63 | "); |
| 64 | $stmt->bindValue(":id", $id, \PDO::PARAM_INT); |
| 65 | |
| 66 | if ($stmt->execute()) { |
| 67 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 68 | if ($row) { |
| 69 | $this->id = $id; |
| 70 | $this->eventId = $row['eventId']; |
| 71 | $this->alertType = $row['alertType']; |
| 72 | $this->message = $row['message']; |
| 73 | $this->binCount = $row['binCount']; |
| 74 | $this->acknowledged = $row['acknowledged']; |
| 75 | $this->acknowledgedBy = $row['acknowledgedBy']; |
| 76 | $this->acknowledgedAt = $row['acknowledgedAt']; |
| 77 | $this->createdAt = $row['created_at']; |
| 78 | return $this; |
| 79 | } |
| 80 | } |
| 81 | return null; |
| 82 | } |
| 83 | |
| 84 | /** |
| 85 | * Get all alerts for an event |
| 86 | * @param int $eventId |
| 87 | * @return array |
| 88 | */ |
| 89 | public function getByEventId($eventId) |
| 90 | { |
| 91 | $stmt = $this->storeDB->prepare(" |
| 92 | SELECT id, alertType, message, binCount, |
| 93 | acknowledged, acknowledgedBy, acknowledgedAt, created_at |
| 94 | FROM bsEvent_Alerts |
| 95 | WHERE eventId = :eventId |
| 96 | ORDER BY created_at DESC |
| 97 | "); |
| 98 | $stmt->bindValue(":eventId", $eventId, \PDO::PARAM_INT); |
| 99 | $stmt->execute(); |
| 100 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 101 | } |
| 102 | |
| 103 | /** |
| 104 | * Get all unacknowledged alerts across all events |
| 105 | * @return array |
| 106 | */ |
| 107 | public function getUnacknowledged() |
| 108 | { |
| 109 | $stmt = $this->storeDB->prepare(" |
| 110 | SELECT a.id, a.eventId, a.alertType, a.message, a.binCount, |
| 111 | a.acknowledged, a.acknowledgedBy, a.acknowledgedAt, a.created_at, |
| 112 | e.name as event_name, e.startDate, e.endDate |
| 113 | FROM bsEvent_Alerts a |
| 114 | JOIN bsEvents e ON a.eventId = e.id |
| 115 | WHERE a.acknowledged = 0 |
| 116 | ORDER BY a.created_at DESC |
| 117 | "); |
| 118 | $stmt->execute(); |
| 119 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Get unacknowledged alerts for a specific event |
| 124 | * @param int $eventId |
| 125 | * @return array |
| 126 | */ |
| 127 | public function getUnacknowledgedByEventId($eventId) |
| 128 | { |
| 129 | $stmt = $this->storeDB->prepare(" |
| 130 | SELECT id, alertType, message, binCount, |
| 131 | acknowledged, acknowledgedBy, acknowledgedAt, created_at |
| 132 | FROM bsEvent_Alerts |
| 133 | WHERE eventId = :eventId AND acknowledged = 0 |
| 134 | ORDER BY created_at DESC |
| 135 | "); |
| 136 | $stmt->bindValue(":eventId", $eventId, \PDO::PARAM_INT); |
| 137 | $stmt->execute(); |
| 138 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 139 | } |
| 140 | |
| 141 | /** |
| 142 | * Mark alert as acknowledged |
| 143 | * @param int $employeeId |
| 144 | * @return $this |
| 145 | */ |
| 146 | public function acknowledge($employeeId) |
| 147 | { |
| 148 | $stmt = $this->storeDB->prepare(" |
| 149 | UPDATE bsEvent_Alerts SET |
| 150 | acknowledged = 1, |
| 151 | acknowledgedBy = :employee_id, |
| 152 | acknowledgedAt = NOW() |
| 153 | WHERE id = :id |
| 154 | "); |
| 155 | |
| 156 | $stmt->bindValue(":employee_id", $employeeId, \PDO::PARAM_INT); |
| 157 | $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT); |
| 158 | $stmt->execute(); |
| 159 | |
| 160 | $this->acknowledged = 1; |
| 161 | $this->acknowledgedBy = $employeeId; |
| 162 | return $this; |
| 163 | } |
| 164 | |
| 165 | /** |
| 166 | * Delete alert |
| 167 | * @return $this |
| 168 | */ |
| 169 | public function delete() |
| 170 | { |
| 171 | $stmt = $this->storeDB->prepare("DELETE FROM bsEvent_Alerts WHERE id = :id"); |
| 172 | $stmt->bindValue(":id", $this->id, \PDO::PARAM_INT); |
| 173 | $stmt->execute(); |
| 174 | return $this; |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Convert to array for JSON serialization |
| 179 | * @return array |
| 180 | */ |
| 181 | public function toArray() |
| 182 | { |
| 183 | return [ |
| 184 | 'id' => $this->id, |
| 185 | 'eventId' => $this->eventId, |
| 186 | 'alertType' => $this->alertType, |
| 187 | 'message' => $this->message, |
| 188 | 'binCount' => $this->binCount, |
| 189 | 'acknowledged' => (bool)$this->acknowledged, |
| 190 | 'acknowledgedBy' => $this->acknowledgedBy, |
| 191 | 'acknowledgedAt' => $this->acknowledgedAt, |
| 192 | 'createdAt' => $this->createdAt |
| 193 | ]; |
| 194 | } |
| 195 | |
| 196 | /** |
| 197 | * @return int |
| 198 | */ |
| 199 | public function getId() |
| 200 | { |
| 201 | return $this->id; |
| 202 | } |
| 203 | |
| 204 | /** |
| 205 | * @param int $id |
| 206 | * @return $this |
| 207 | */ |
| 208 | public function setId($id) |
| 209 | { |
| 210 | $this->id = $id; |
| 211 | return $this; |
| 212 | } |
| 213 | |
| 214 | /** |
| 215 | * @return int |
| 216 | */ |
| 217 | public function getEventId() |
| 218 | { |
| 219 | return $this->eventId; |
| 220 | } |
| 221 | |
| 222 | /** |
| 223 | * @param int $eventId |
| 224 | * @return $this |
| 225 | */ |
| 226 | public function setEventId($eventId) |
| 227 | { |
| 228 | $this->eventId = $eventId; |
| 229 | return $this; |
| 230 | } |
| 231 | |
| 232 | /** |
| 233 | * @return string |
| 234 | */ |
| 235 | public function getAlertType() |
| 236 | { |
| 237 | return $this->alertType; |
| 238 | } |
| 239 | |
| 240 | /** |
| 241 | * @param string $alertType |
| 242 | * @return $this |
| 243 | */ |
| 244 | public function setAlertType($alertType) |
| 245 | { |
| 246 | $this->alertType = $alertType; |
| 247 | return $this; |
| 248 | } |
| 249 | |
| 250 | /** |
| 251 | * @return string |
| 252 | */ |
| 253 | public function getMessage() |
| 254 | { |
| 255 | return $this->message; |
| 256 | } |
| 257 | |
| 258 | /** |
| 259 | * @param string $message |
| 260 | * @return $this |
| 261 | */ |
| 262 | public function setMessage($message) |
| 263 | { |
| 264 | $this->message = $message; |
| 265 | return $this; |
| 266 | } |
| 267 | |
| 268 | /** |
| 269 | * @return int|null |
| 270 | */ |
| 271 | public function getBinCount() |
| 272 | { |
| 273 | return $this->binCount; |
| 274 | } |
| 275 | |
| 276 | /** |
| 277 | * @param int|null $binCount |
| 278 | * @return $this |
| 279 | */ |
| 280 | public function setBinCount($binCount) |
| 281 | { |
| 282 | $this->binCount = $binCount; |
| 283 | return $this; |
| 284 | } |
| 285 | |
| 286 | /** |
| 287 | * @return bool |
| 288 | */ |
| 289 | public function getAcknowledged() |
| 290 | { |
| 291 | return (bool)$this->acknowledged; |
| 292 | } |
| 293 | |
| 294 | /** |
| 295 | * @param bool $acknowledged |
| 296 | * @return $this |
| 297 | */ |
| 298 | public function setAcknowledged($acknowledged) |
| 299 | { |
| 300 | $this->acknowledged = $acknowledged ? 1 : 0; |
| 301 | return $this; |
| 302 | } |
| 303 | |
| 304 | /** |
| 305 | * @return int|null |
| 306 | */ |
| 307 | public function getAcknowledgedBy() |
| 308 | { |
| 309 | return $this->acknowledgedBy; |
| 310 | } |
| 311 | |
| 312 | /** |
| 313 | * @param int|null $acknowledgedBy |
| 314 | * @return $this |
| 315 | */ |
| 316 | public function setAcknowledgedBy($acknowledgedBy) |
| 317 | { |
| 318 | $this->acknowledgedBy = $acknowledgedBy; |
| 319 | return $this; |
| 320 | } |
| 321 | |
| 322 | /** |
| 323 | * @return string|null |
| 324 | */ |
| 325 | public function getAcknowledgedAt() |
| 326 | { |
| 327 | return $this->acknowledgedAt; |
| 328 | } |
| 329 | |
| 330 | /** |
| 331 | * @return string |
| 332 | */ |
| 333 | public function getCreatedAt() |
| 334 | { |
| 335 | return $this->createdAt; |
| 336 | } |
| 337 | } |