Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 74 |
|
0.00% |
0 / 11 |
CRAP | |
0.00% |
0 / 1 |
| ServiceQueueItem | |
0.00% |
0 / 74 |
|
0.00% |
0 / 11 |
240 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| create | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
2 | |||
| getById | |
0.00% |
0 / 19 |
|
0.00% |
0 / 1 |
6 | |||
| getActiveQueue | |
0.00% |
0 / 5 |
|
0.00% |
0 / 1 |
2 | |||
| update | |
0.00% |
0 / 13 |
|
0.00% |
0 / 1 |
20 | |||
| delete | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| startService | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
2 | |||
| completeService | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| saveNotes | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| getTextMe | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getCustomerId | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\ServiceQueue; |
| 4 | |
| 5 | class ServiceQueueItem { |
| 6 | private $id; |
| 7 | private $dailyNum; |
| 8 | private $customerID; |
| 9 | private $timeEntered; |
| 10 | private $timeStarted; |
| 11 | private $timeCompleted; |
| 12 | private $employeeID; |
| 13 | private $textMe; |
| 14 | private $numItems; |
| 15 | private $textSent; |
| 16 | private $isFinished; |
| 17 | private $notes; |
| 18 | private $store; |
| 19 | private $storeDB; |
| 20 | |
| 21 | public function __construct(\Store $store) { |
| 22 | $this->store = $store; |
| 23 | $this->storeDB = dbConnectByName($store->getDbName()); |
| 24 | } |
| 25 | |
| 26 | // CREATE |
| 27 | public function create($data) { |
| 28 | $sql = "INSERT INTO serviceQueue |
| 29 | (dailyNum, customerID, employeeID, textMe, numItems, notes) |
| 30 | VALUES (:dailyNum, :customerID, :employeeID, :textMe, :numItems, :notes)"; |
| 31 | |
| 32 | $stmt = $this->storeDB->prepare($sql); |
| 33 | $stmt->execute([ |
| 34 | ':dailyNum' => $data['dailyNum'], |
| 35 | ':customerID' => $data['customerID'], |
| 36 | ':employeeID' => $data['employeeID'] ?? null, |
| 37 | ':textMe' => $data['textMe'] ?? 0, |
| 38 | ':numItems' => $data['numItems'] ?? 0, |
| 39 | ':notes' => $data['notes'] ?? null |
| 40 | ]); |
| 41 | return $this->storeDB->lastInsertId(); |
| 42 | } |
| 43 | |
| 44 | // READ: load the ServiceQueue row by ID and set local properties |
| 45 | public function getById($id) { |
| 46 | $sql = "SELECT * FROM serviceQueue WHERE id = :id"; |
| 47 | $stmt = $this->storeDB->prepare($sql); |
| 48 | $stmt->execute([':id' => $id]); |
| 49 | $row = $stmt->fetch(\PDO::FETCH_ASSOC); |
| 50 | if ($row) { |
| 51 | // Assign each fetched column to this object's properties |
| 52 | $this->id = $row['id']; |
| 53 | $this->dailyNum = $row['dailyNum']; |
| 54 | $this->customerID = $row['customerID']; |
| 55 | $this->timeEntered = $row['timeEntered']; |
| 56 | $this->timeStarted = $row['timeStarted']; |
| 57 | $this->timeCompleted = $row['timeCompleted']; |
| 58 | $this->employeeID = $row['employeeID']; |
| 59 | $this->textMe = $row['textMe']; |
| 60 | $this->numItems = $row['numItems']; |
| 61 | $this->textSent = $row['textSent']; |
| 62 | $this->isFinished = $row['isFinished']; |
| 63 | $this->notes = $row['notes']; |
| 64 | return true; // or return $row if you want to return the row data |
| 65 | } |
| 66 | |
| 67 | return false; |
| 68 | } |
| 69 | |
| 70 | // Return active (unfinished) queue items |
| 71 | public function getActiveQueue() { |
| 72 | $sql = "SELECT * FROM serviceQueue |
| 73 | WHERE isFinished = 0 |
| 74 | ORDER BY timeEntered ASC"; |
| 75 | $stmt = $this->storeDB->prepare($sql); |
| 76 | $stmt->execute(); |
| 77 | return $stmt->fetchAll(\PDO::FETCH_ASSOC); |
| 78 | } |
| 79 | |
| 80 | // UPDATE |
| 81 | public function update($id, $data) { |
| 82 | $updates = []; |
| 83 | $params = [':id' => $id]; |
| 84 | |
| 85 | foreach ($data as $key => $value) { |
| 86 | // Only set columns that correspond to properties on $this |
| 87 | if (property_exists($this, $key)) { |
| 88 | $updates[] = "`$key` = :$key"; |
| 89 | $params[":$key"] = $value; |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (!count($updates)) { |
| 94 | return false; // no valid fields to update |
| 95 | } |
| 96 | |
| 97 | $sql = "UPDATE serviceQueue |
| 98 | SET " . implode(', ', $updates) . " |
| 99 | WHERE id = :id"; |
| 100 | $stmt = $this->storeDB->prepare($sql); |
| 101 | return $stmt->execute($params); |
| 102 | } |
| 103 | |
| 104 | public function delete($id) { |
| 105 | $sql = "DELETE FROM serviceQueue WHERE id = :id"; |
| 106 | $stmt = $this->storeDB->prepare($sql); |
| 107 | return $stmt->execute([':id' => $id]); |
| 108 | } |
| 109 | |
| 110 | // Additional helper methods |
| 111 | public function startService($id, $employeeID) { |
| 112 | // Get store's timezone |
| 113 | $storeTimezone = $this->store->getTimeZone(); |
| 114 | |
| 115 | // Create DateTime object in store's timezone |
| 116 | $localTime = new \DateTime('now', new \DateTimeZone($storeTimezone)); |
| 117 | |
| 118 | // Convert to UTC |
| 119 | $localTime->setTimezone(new \DateTimeZone('UTC')); |
| 120 | |
| 121 | return $this->update($id, [ |
| 122 | 'timeStarted' => $localTime->format('Y-m-d H:i:s'), |
| 123 | 'employeeID' => $employeeID, |
| 124 | 'isFinished' => 0 |
| 125 | ]); |
| 126 | } |
| 127 | |
| 128 | public function completeService($id) { |
| 129 | // Get store's timezone |
| 130 | $storeTimezone = $this->store->getTimeZone(); |
| 131 | |
| 132 | // Create DateTime object in store's timezone |
| 133 | $localTime = new \DateTime('now', new \DateTimeZone($storeTimezone)); |
| 134 | |
| 135 | // Convert to UTC |
| 136 | $localTime->setTimezone(new \DateTimeZone('UTC')); |
| 137 | |
| 138 | return $this->update($id, [ |
| 139 | 'timeCompleted' => $localTime->format('Y-m-d H:i:s'), |
| 140 | 'isFinished' => 1 |
| 141 | ]); |
| 142 | } |
| 143 | |
| 144 | // Save/update notes for a queue item |
| 145 | public function saveNotes($id, $notes) { |
| 146 | return $this->update($id, [ |
| 147 | 'notes' => $notes |
| 148 | ]); |
| 149 | } |
| 150 | |
| 151 | // Accessors as needed |
| 152 | public function getTextMe() { |
| 153 | return $this->textMe; |
| 154 | } |
| 155 | |
| 156 | public function getCustomerId() { |
| 157 | return $this->customerID; |
| 158 | } |
| 159 | } |