Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
23 / 23 |
|
100.00% |
13 / 13 |
CRAP | |
100.00% |
1 / 1 |
| PlaceService | |
100.00% |
22 / 22 |
|
100.00% |
13 / 13 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| runAction | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
2 | |||
| create | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| multiplepos | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| sessionusers | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| exndnfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| invoicelst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ticketlst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ticketnfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| productlst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| productnfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| qrcodes | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| ticketlog | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace UppServices; |
| 6 | |
| 7 | require_once __DIR__ . '/legacy/ddbb/conx.php'; |
| 8 | |
| 9 | /** |
| 10 | * Place-related actions: creation, multiple POS, session users, license info, invoices, tickets, products, QR codes, ticket log. |
| 11 | * Delegates to action files in App/Services/place/. Each action receives ConxHelper and $logger. |
| 12 | */ |
| 13 | class PlaceService |
| 14 | { |
| 15 | private const PLACE_ACTIONS_DIR = __DIR__.'/place'; |
| 16 | |
| 17 | private readonly SessionService $sessionService; |
| 18 | private readonly LoggerFactory $loggerFactory; |
| 19 | |
| 20 | /** @var array<string, callable> cache of loaded action callables */ |
| 21 | private static array $actionCache = []; |
| 22 | |
| 23 | public function __construct( |
| 24 | SessionService $sessionService, |
| 25 | LoggerFactory $loggerFactory, |
| 26 | ) { |
| 27 | $this->sessionService = $sessionService; |
| 28 | $this->loggerFactory = $loggerFactory; |
| 29 | } |
| 30 | |
| 31 | /** |
| 32 | * Load and run a place action. Creates ConxHelper; caller releases in finally. |
| 33 | * |
| 34 | * @param string $actionName Action file name (without .php). |
| 35 | * @param string $body Request body (for POST). |
| 36 | * @param array<string, mixed> $query Query params. |
| 37 | * @return array{output: string, contentType: string} |
| 38 | */ |
| 39 | private function runAction(string $actionName, string $body, array $query): array |
| 40 | { |
| 41 | $conx = new \ConxHelper(__FILE__); |
| 42 | if (!isset(self::$actionCache[$actionName])) { |
| 43 | $path = self::PLACE_ACTIONS_DIR.'/'.$actionName.'.php'; |
| 44 | self::$actionCache[$actionName] = require $path; |
| 45 | } |
| 46 | $action = self::$actionCache[$actionName]; |
| 47 | $logger = $this->loggerFactory->for(__FILE__); |
| 48 | try { |
| 49 | return $action($body, $query, $conx, $logger, $this->sessionService); |
| 50 | } finally { |
| 51 | $conx->release(); |
| 52 | } |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Create a new place: insert in central DB with status PA and create the place database. |
| 57 | * Delegates to CreatePlace action. |
| 58 | * |
| 59 | * @param array<string, mixed> $query Query params (device, session). |
| 60 | * @param array<string, mixed> $body JSON body; only _uuid is used if present. |
| 61 | * @return array{errorcode: int, objid?: int} JSON response payload (objid only on success). |
| 62 | */ |
| 63 | public function create(array $query, array $body): array |
| 64 | { |
| 65 | $result = $this->runAction('CreatePlace', json_encode($body), $query); |
| 66 | return json_decode($result['output'], true); |
| 67 | } |
| 68 | |
| 69 | /** GET /place/multiplepos - enable/disable multiple POS for place */ |
| 70 | public function multiplepos(array $query): array |
| 71 | { |
| 72 | return $this->runAction('Multiplepos', '', $query); |
| 73 | } |
| 74 | |
| 75 | /** POST /place/sessionusers - get usernames for session list */ |
| 76 | public function sessionusers(string $body, array $query): array |
| 77 | { |
| 78 | return $this->runAction('Sessionusers', $body, $query); |
| 79 | } |
| 80 | |
| 81 | /** GET /place/exndnfo - license extended period info */ |
| 82 | public function exndnfo(array $query): array |
| 83 | { |
| 84 | return $this->runAction('Exndnfo', '', $query); |
| 85 | } |
| 86 | |
| 87 | /** GET /place/invoicelst - invoice list for date range */ |
| 88 | public function invoicelst(array $query): array |
| 89 | { |
| 90 | return $this->runAction('Invoicelst', '', $query); |
| 91 | } |
| 92 | |
| 93 | /** GET /place/ticketlst - ticket list for date range */ |
| 94 | public function ticketlst(array $query): array |
| 95 | { |
| 96 | return $this->runAction('Ticketlst', '', $query); |
| 97 | } |
| 98 | |
| 99 | /** POST /place/ticketnfo - load ticket details by objids */ |
| 100 | public function ticketnfo(string $body, array $query): array |
| 101 | { |
| 102 | return $this->runAction('Ticketnfo', $body, $query); |
| 103 | } |
| 104 | |
| 105 | /** GET /place/productlst - product list for date range */ |
| 106 | public function productlst(array $query): array |
| 107 | { |
| 108 | return $this->runAction('Productlst', '', $query); |
| 109 | } |
| 110 | |
| 111 | /** POST /place/productnfo - load product details by objids */ |
| 112 | public function productnfo(string $body, array $query): array |
| 113 | { |
| 114 | return $this->runAction('Productnfo', $body, $query); |
| 115 | } |
| 116 | |
| 117 | /** GET /place/qrcodes - generate QR sticker PDF */ |
| 118 | public function qrcodes(array $query): array |
| 119 | { |
| 120 | return $this->runAction('Qrcodes', '', $query); |
| 121 | } |
| 122 | |
| 123 | /** GET /place/ticketlog - ticket activity log */ |
| 124 | public function ticketlog(array $query): array |
| 125 | { |
| 126 | return $this->runAction('Ticketlog', '', $query); |
| 127 | } |
| 128 | } |