Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 43 |
|
0.00% |
0 / 5 |
CRAP | |
0.00% |
0 / 1 |
| StoreConfigPageController | |
0.00% |
0 / 43 |
|
0.00% |
0 / 5 |
156 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 3 |
|
0.00% |
0 / 1 |
2 | |||
| checkAccess | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
30 | |||
| configuration | |
0.00% |
0 / 14 |
|
0.00% |
0 / 1 |
12 | |||
| buildStoreInfo | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| formatStoreAddress | |
0.00% |
0 / 7 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace BuyerKiosk\StoreConfig\Controllers; |
| 4 | |
| 5 | use BuyerKiosk\Core\Store; |
| 6 | |
| 7 | /** |
| 8 | * StoreConfigPageController - Admin Page Rendering |
| 9 | * |
| 10 | * Handles rendering of the Store Configuration admin page where store managers |
| 11 | * can configure store operating hours, per-day hours, and holiday overrides. |
| 12 | * |
| 13 | * Routes: |
| 14 | * - GET /admin/:typeNum/store/configuration - Store Configuration page |
| 15 | * |
| 16 | * @package BuyerKiosk\StoreConfig\Controllers |
| 17 | * @see docs/specs/018-store-configuration/solution-design.md |
| 18 | */ |
| 19 | class StoreConfigPageController |
| 20 | { |
| 21 | /** |
| 22 | * @var object Slim application instance |
| 23 | */ |
| 24 | private $app; |
| 25 | |
| 26 | /** |
| 27 | * @var Store Store object |
| 28 | */ |
| 29 | private Store $store; |
| 30 | |
| 31 | /** |
| 32 | * @var string Store type number |
| 33 | */ |
| 34 | private string $typeNum; |
| 35 | |
| 36 | /** |
| 37 | * Constructor |
| 38 | * |
| 39 | * @param object $app Slim application instance |
| 40 | * @param Store $store Store object (validated) |
| 41 | */ |
| 42 | public function __construct($app, Store $store) |
| 43 | { |
| 44 | $this->app = $app; |
| 45 | $this->store = $store; |
| 46 | $this->typeNum = $store->getTypeNum(); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Check if user has store configuration access |
| 51 | * |
| 52 | * @return bool True if authorized |
| 53 | */ |
| 54 | private function checkAccess(): bool |
| 55 | { |
| 56 | if (!isset($this->app->user) || !$this->app->user) { |
| 57 | $this->app->redirect('/login'); |
| 58 | return false; |
| 59 | } |
| 60 | |
| 61 | if (!$this->app->user->checkAccess('uri_store_settings')) { |
| 62 | $this->app->notAuthorized(); |
| 63 | return false; |
| 64 | } |
| 65 | |
| 66 | if (!$this->app->user->checkStoreGroup($this->typeNum)) { |
| 67 | $this->app->notAuthorized(); |
| 68 | return false; |
| 69 | } |
| 70 | |
| 71 | return true; |
| 72 | } |
| 73 | |
| 74 | /** |
| 75 | * GET /admin/:typeNum/store/configuration |
| 76 | * |
| 77 | * Render the Store Configuration page |
| 78 | * |
| 79 | * This page allows store managers to: |
| 80 | * - View store information (name, typeNum, address, timezone) |
| 81 | * - Configure default store hours |
| 82 | * - Set per-day hour overrides |
| 83 | * - Manage holiday hour overrides |
| 84 | * |
| 85 | * @see PRD/Feature 3: Store Configuration Admin Page |
| 86 | */ |
| 87 | public function configuration(): void |
| 88 | { |
| 89 | if (!$this->checkAccess()) { |
| 90 | return; |
| 91 | } |
| 92 | |
| 93 | $this->app->render('store/configuration.html', [ |
| 94 | 'page' => [ |
| 95 | 'title' => 'Store Configuration', |
| 96 | 'author' => $this->app->site->author ?? '', |
| 97 | 'description' => 'Configure store hours and operating settings' |
| 98 | ], |
| 99 | 'store' => $this->buildStoreInfo(), |
| 100 | 'typeNum' => $this->typeNum, |
| 101 | 'storeName' => $this->store->getCompanyName(), |
| 102 | 'storeTimezone' => $this->store->getTimeZone() ?: 'America/Los_Angeles', |
| 103 | 'storeAddress' => $this->formatStoreAddress(), |
| 104 | ]); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Build store info array for template |
| 109 | * |
| 110 | * This replaces the legacy \getStoreInfo() function to work with BuyerKiosk\Core\Store |
| 111 | * |
| 112 | * @return array Store information for template |
| 113 | */ |
| 114 | private function buildStoreInfo(): array |
| 115 | { |
| 116 | return [ |
| 117 | 'typeNum' => $this->typeNum, |
| 118 | 'companyName' => $this->store->getCompanyName(), |
| 119 | 'timezone' => $this->store->getTimeZone() ?: 'America/Los_Angeles', |
| 120 | 'address' => $this->store->getAddress(), |
| 121 | 'city' => $this->store->getCity(), |
| 122 | 'state' => $this->store->getState(), |
| 123 | 'zipcode' => $this->store->getZipcode(), |
| 124 | ]; |
| 125 | } |
| 126 | |
| 127 | /** |
| 128 | * Format store address for display |
| 129 | * |
| 130 | * @return string Formatted address string |
| 131 | */ |
| 132 | private function formatStoreAddress(): string |
| 133 | { |
| 134 | $parts = array_filter([ |
| 135 | $this->store->getAddress(), |
| 136 | $this->store->getCity(), |
| 137 | $this->store->getState(), |
| 138 | $this->store->getZipcode(), |
| 139 | ]); |
| 140 | |
| 141 | return implode(', ', $parts); |
| 142 | } |
| 143 | } |