Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
27 / 27 |
|
100.00% |
11 / 11 |
CRAP | |
100.00% |
1 / 1 |
| PlaceService | |
100.00% |
26 / 26 |
|
100.00% |
11 / 11 |
14 | |
100.00% |
1 / 1 |
| __construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
| runAction | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
4 | |||
| create | |
100.00% |
2 / 2 |
|
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 | |||
| productlst | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| productnfo | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| qrcodepdf | |
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, 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 | private readonly Html2PdfService $html2PdfService; |
| 20 | private readonly LicenseService $licenseService; |
| 21 | |
| 22 | /** @var array<string, callable> cache of loaded action callables */ |
| 23 | private static array $actionCache = []; |
| 24 | |
| 25 | public function __construct( |
| 26 | SessionService $sessionService, |
| 27 | LoggerFactory $loggerFactory, |
| 28 | Html2PdfService $html2PdfService, |
| 29 | LicenseService $licenseService, |
| 30 | ) { |
| 31 | $this->sessionService = $sessionService; |
| 32 | $this->loggerFactory = $loggerFactory; |
| 33 | $this->html2PdfService = $html2PdfService; |
| 34 | $this->licenseService = $licenseService; |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Load and run a place action. Creates ConxHelper; caller releases in finally. |
| 39 | * |
| 40 | * @param string $actionName Action file name (without .php). |
| 41 | * @param string $body Request body (for POST). |
| 42 | * @param array<string, mixed> $query Query params. |
| 43 | * @return array{output: string, contentType: string} |
| 44 | */ |
| 45 | private function runAction(string $actionName, string $body, array $query): array |
| 46 | { |
| 47 | $conx = new \ConxHelper(__FILE__); |
| 48 | if (!isset(self::$actionCache[$actionName])) { |
| 49 | $path = self::PLACE_ACTIONS_DIR.'/'.$actionName.'.php'; |
| 50 | self::$actionCache[$actionName] = require $path; |
| 51 | } |
| 52 | $action = self::$actionCache[$actionName]; |
| 53 | $logger = $this->loggerFactory->for(__FILE__); |
| 54 | try { |
| 55 | if ($actionName === 'Qrcodepdf') { |
| 56 | return $action($body, $query, $conx, $logger, $this->sessionService, $this->html2PdfService); |
| 57 | } |
| 58 | if ($actionName === 'Exndnfo') { |
| 59 | return $action($body, $query, $conx, $logger, $this->sessionService, $this->licenseService); |
| 60 | } |
| 61 | return $action($body, $query, $conx, $logger, $this->sessionService); |
| 62 | } finally { |
| 63 | $conx->release(); |
| 64 | } |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Create a new place: insert in central DB with status PA and create the place database. |
| 69 | * Delegates to CreatePlace action. |
| 70 | * |
| 71 | * @param array<string, mixed> $query Query params (device, session). |
| 72 | * @param array<string, mixed> $body JSON body; only _uuid is used if present. |
| 73 | * @return array{errorcode: int, objid?: int} JSON response payload (objid only on success). |
| 74 | */ |
| 75 | public function create(array $query, array $body): array |
| 76 | { |
| 77 | $result = $this->runAction('CreatePlace', json_encode($body), $query); |
| 78 | return json_decode($result['output'], true); |
| 79 | } |
| 80 | |
| 81 | /** POST /place/sessionusers - get usernames for session list */ |
| 82 | public function sessionusers(string $body, array $query): array |
| 83 | { |
| 84 | return $this->runAction('Sessionusers', $body, $query); |
| 85 | } |
| 86 | |
| 87 | /** GET /place/exndnfo - license extended period info */ |
| 88 | public function exndnfo(array $query): array |
| 89 | { |
| 90 | return $this->runAction('Exndnfo', '', $query); |
| 91 | } |
| 92 | |
| 93 | /** GET /place/invoicelst - invoice list for date range */ |
| 94 | public function invoicelst(array $query): array |
| 95 | { |
| 96 | return $this->runAction('Invoicelst', '', $query); |
| 97 | } |
| 98 | |
| 99 | /** GET /place/ticketlst - ticket list for date range */ |
| 100 | public function ticketlst(array $query): array |
| 101 | { |
| 102 | return $this->runAction('Ticketlst', '', $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 | /** POST /place/qrcodepdf - render QR stickers PDF from HTML */ |
| 118 | public function qrcodepdf(string $body, array $query): array |
| 119 | { |
| 120 | return $this->runAction('Qrcodepdf', $body, $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 | } |