Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 68 |
|
0.00% |
0 / 12 |
CRAP | |
0.00% |
0 / 1 |
| QueueModalController | |
0.00% |
0 / 68 |
|
0.00% |
0 / 12 |
420 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| startBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| processBuy | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| startSort | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| endSort | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| deleteBuy | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| clearFlags | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| viewFlags | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
6 | |||
| checkIn | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| customerInfo | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| renderBuyerSelectionModal | |
0.00% |
0 / 16 |
|
0.00% |
0 / 1 |
20 | |||
| renderError | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | /** |
| 3 | * QueueModalController |
| 4 | * |
| 5 | * Handles rendering of queue action modals for the workspace. |
| 6 | * Modals include: startBuy, processBuy, startSort, endSort, deleteBuy, |
| 7 | * clearFlags, viewFlags, checkIn, and customerInfo. |
| 8 | * |
| 9 | * @package BuyerKiosk\Queue\Controllers |
| 10 | */ |
| 11 | |
| 12 | namespace BuyerKiosk\Queue\Controllers; |
| 13 | |
| 14 | use BuyerKiosk\Queue\QueueModalService; |
| 15 | use Store; |
| 16 | |
| 17 | class QueueModalController |
| 18 | { |
| 19 | /** |
| 20 | * @var \Slim\Slim Slim application instance |
| 21 | */ |
| 22 | private $app; |
| 23 | |
| 24 | /** |
| 25 | * @var Store Store object |
| 26 | */ |
| 27 | private $store; |
| 28 | |
| 29 | /** |
| 30 | * @var QueueModalService Modal service for business logic |
| 31 | */ |
| 32 | private $service; |
| 33 | |
| 34 | /** |
| 35 | * Constructor |
| 36 | * |
| 37 | * @param \Slim\Slim $app Slim application instance |
| 38 | * @param Store $store Store object |
| 39 | */ |
| 40 | public function __construct($app, Store $store) |
| 41 | { |
| 42 | $this->app = $app; |
| 43 | $this->store = $store; |
| 44 | $this->service = new QueueModalService($app, $store); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Render Start Buy modal |
| 49 | * |
| 50 | * Allows selecting a buyer to start processing a buy. |
| 51 | * GET /:typeNum/modal/:buyId/startBuy |
| 52 | * |
| 53 | * @param int|string $buyId The buy ID |
| 54 | */ |
| 55 | public function startBuy($buyId): void |
| 56 | { |
| 57 | $this->renderBuyerSelectionModal('queue/modals/start-buy.html', $buyId); |
| 58 | } |
| 59 | |
| 60 | /** |
| 61 | * Render Process Buy modal |
| 62 | * |
| 63 | * Allows selecting a buyer to complete processing. |
| 64 | * GET /:typeNum/modal/:buyId/processBuy |
| 65 | * |
| 66 | * @param int|string $buyId The buy ID |
| 67 | */ |
| 68 | public function processBuy($buyId): void |
| 69 | { |
| 70 | $this->renderBuyerSelectionModal('queue/modals/process-buy.html', $buyId); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * Render Start Sort modal |
| 75 | * |
| 76 | * Allows selecting a sorter to start sorting items. |
| 77 | * GET /:typeNum/modal/:buyId/startSort |
| 78 | * |
| 79 | * @param int|string $buyId The buy ID |
| 80 | */ |
| 81 | public function startSort($buyId): void |
| 82 | { |
| 83 | $this->renderBuyerSelectionModal('queue/modals/start-sort.html', $buyId); |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * Render End Sort modal |
| 88 | * |
| 89 | * Allows selecting bins remaining and sorter to complete sort. |
| 90 | * GET /:typeNum/modal/:buyId/endSort |
| 91 | * |
| 92 | * @param int|string $buyId The buy ID |
| 93 | */ |
| 94 | public function endSort($buyId): void |
| 95 | { |
| 96 | $this->renderBuyerSelectionModal('queue/modals/end-sort.html', $buyId); |
| 97 | } |
| 98 | |
| 99 | /** |
| 100 | * Render Delete Buy modal |
| 101 | * |
| 102 | * Confirmation dialog to delete a buy from the queue. |
| 103 | * GET /:typeNum/modal/:buyId/deleteBuy |
| 104 | * |
| 105 | * @param int|string $buyId The buy ID |
| 106 | */ |
| 107 | public function deleteBuy($buyId): void |
| 108 | { |
| 109 | $queueItem = $this->service->getQueueItem($buyId); |
| 110 | |
| 111 | if (!$queueItem) { |
| 112 | $this->renderError('Queue item not found'); |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | $this->app->render('queue/modals/delete-buy.html', [ |
| 117 | 'item' => $queueItem, |
| 118 | 'typeNum' => $this->store->getTypeNum() |
| 119 | ]); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Render Clear Flags modal |
| 124 | * |
| 125 | * Shows flags that need to be cleared for a customer. |
| 126 | * GET /:typeNum/modal/:buyId/clearFlags |
| 127 | * |
| 128 | * @param int|string $buyId The buy ID |
| 129 | */ |
| 130 | public function clearFlags($buyId): void |
| 131 | { |
| 132 | $queueItem = $this->service->getQueueItemFromBuyQueue($buyId); |
| 133 | |
| 134 | if (!$queueItem) { |
| 135 | $this->renderError('Queue item not found'); |
| 136 | return; |
| 137 | } |
| 138 | |
| 139 | $this->app->render('queue/modals/clear-flags.html', [ |
| 140 | 'item' => $queueItem, |
| 141 | 'typeNum' => $this->store->getTypeNum() |
| 142 | ]); |
| 143 | } |
| 144 | |
| 145 | /** |
| 146 | * Render View Flags modal |
| 147 | * |
| 148 | * Shows historical flags for a customer. |
| 149 | * GET /:typeNum/modal/:buyId/viewFlags |
| 150 | * |
| 151 | * @param int|string $buyId The buy ID |
| 152 | */ |
| 153 | public function viewFlags($buyId): void |
| 154 | { |
| 155 | $queueItem = $this->service->getQueueItemFromBuyQueue($buyId); |
| 156 | |
| 157 | if (!$queueItem) { |
| 158 | $this->renderError('Queue item not found'); |
| 159 | return; |
| 160 | } |
| 161 | |
| 162 | $this->app->render('queue/modals/view-flags.html', [ |
| 163 | 'item' => $queueItem, |
| 164 | 'typeNum' => $this->store->getTypeNum() |
| 165 | ]); |
| 166 | } |
| 167 | |
| 168 | /** |
| 169 | * Render Check-In modal |
| 170 | * |
| 171 | * Confirms customer check-in for remote buys. |
| 172 | * GET /:typeNum/modal/:buyId/checkIn |
| 173 | * |
| 174 | * @param int|string $buyId The buy ID |
| 175 | */ |
| 176 | public function checkIn($buyId): void |
| 177 | { |
| 178 | $queueItem = $this->service->getQueueItemFromBuyQueue($buyId); |
| 179 | |
| 180 | if (!$queueItem) { |
| 181 | $this->renderError('Queue item not found'); |
| 182 | return; |
| 183 | } |
| 184 | |
| 185 | $this->app->render('queue/modals/check-in.html', [ |
| 186 | 'item' => $queueItem, |
| 187 | 'store' => $this->service->getStoreInfo(), |
| 188 | 'typeNum' => $this->store->getTypeNum() |
| 189 | ]); |
| 190 | } |
| 191 | |
| 192 | /** |
| 193 | * Render Customer Info modal |
| 194 | * |
| 195 | * Shows detailed customer information and buy history. |
| 196 | * GET /:typeNum/modal/:buyId/customerInfo |
| 197 | * |
| 198 | * @param int|string $buyId The buy ID |
| 199 | */ |
| 200 | public function customerInfo($buyId): void |
| 201 | { |
| 202 | $queueItem = $this->service->getQueueItemFromBuyQueue($buyId); |
| 203 | |
| 204 | if (!$queueItem) { |
| 205 | $this->renderError('Queue item not found'); |
| 206 | return; |
| 207 | } |
| 208 | |
| 209 | $this->app->render('queue/modals/customer-info.html', [ |
| 210 | 'item' => $queueItem, |
| 211 | 'store' => $this->service->getStoreInfo(), |
| 212 | 'typeNum' => $this->store->getTypeNum() |
| 213 | ]); |
| 214 | } |
| 215 | |
| 216 | /** |
| 217 | * Helper method to render buyer selection modals |
| 218 | * |
| 219 | * Many modals share the same structure: show list of buyers/employees |
| 220 | * and the queue item data. When WhenIWork is enabled, provides both |
| 221 | * clocked-in employees (shown by default) and all employees (via toggle). |
| 222 | * |
| 223 | * @param string $template Template path |
| 224 | * @param int|string $buyId The buy ID |
| 225 | */ |
| 226 | private function renderBuyerSelectionModal(string $template, $buyId): void |
| 227 | { |
| 228 | $buyerData = $this->service->getBuyersWithClockStatus(); |
| 229 | $queueItem = $this->service->getQueueItem($buyId); |
| 230 | |
| 231 | if (!$queueItem) { |
| 232 | $this->renderError('Queue item not found'); |
| 233 | return; |
| 234 | } |
| 235 | |
| 236 | // For backward compatibility, keep 'buyers' as the list to display by default |
| 237 | // When WIW is enabled, show clocked-in first; otherwise show all |
| 238 | $buyers = $buyerData['wiwEnabled'] && !empty($buyerData['clockedIn']) |
| 239 | ? $buyerData['clockedIn'] |
| 240 | : $buyerData['allEmployees']; |
| 241 | |
| 242 | $this->app->render($template, [ |
| 243 | 'buyers' => $buyers, |
| 244 | 'allBuyers' => $buyerData['allEmployees'], |
| 245 | 'clockedInBuyers' => $buyerData['clockedIn'], |
| 246 | 'wiwEnabled' => $buyerData['wiwEnabled'], |
| 247 | 'item' => $queueItem, |
| 248 | 'typeNum' => $this->store->getTypeNum() |
| 249 | ]); |
| 250 | } |
| 251 | |
| 252 | /** |
| 253 | * Render an error modal |
| 254 | * |
| 255 | * @param string $message Error message |
| 256 | */ |
| 257 | private function renderError(string $message): void |
| 258 | { |
| 259 | $this->app->render('queue/modals/error.html', [ |
| 260 | 'message' => $message |
| 261 | ]); |
| 262 | } |
| 263 | } |