Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
84.62% |
44 / 52 |
n/a |
0 / 0 |
CRAP | n/a |
0 / 0 |
||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * @file |
| 5 | * Place action: load ticket details by objids (ticketnfo). |
| 6 | */ |
| 7 | |
| 8 | declare(strict_types=1); |
| 9 | |
| 10 | require_once __DIR__.'/../../Legacy/common/session.php'; |
| 11 | require_once __DIR__.'/../../Legacy/model/synchloader.php'; |
| 12 | |
| 13 | $datamodel = json_decode('{ |
| 14 | "data": { |
| 15 | "TICKET": [ |
| 16 | { "direction": ">", "target": "SESSION", "by": "session", "reason": null }, |
| 17 | { "direction": ">", "target": "SESSION", "by": "paidby", "reason": null }, |
| 18 | { "direction": "<", "target": "TICKETPRODUCT", "by": "ticket", "reason": "products" }, |
| 19 | { "direction": "<", "target": "TICKETOFFER", "by": "ticket", "reason": "offers" }, |
| 20 | { "direction": "<", "target": "TICKETDISCOUNT", "by": "ticket", "reason": "discounts" }, |
| 21 | { "direction": "<", "target": "TICKETEXTRA", "by": "ticket", "reason": "extras" }, |
| 22 | { "direction": "<", "target": "TICKETMIXEDPAY", "by": "ticket", "reason": "mixed" }, |
| 23 | { "direction": "<", "target": "TICKETINVOICE", "by": "ticket", "reason": "invoice" }, |
| 24 | { "direction": "<", "target": "TICKETAUDIT", "by": "ticket", "reason": "audit" }, |
| 25 | { "direction": ">", "target": "PAYACCOUNT", "by": "account", "reason": null }, |
| 26 | { "direction": "<", "target": "TICKETCHANGE", "by": "ticket", "reason": "changes" }, |
| 27 | { "direction": ">", "target": "ACCOUNTINVOICE", "by": "invceac", "reason": null } |
| 28 | ], |
| 29 | "TICKETCHANGE": [ |
| 30 | { "direction": ">", "target": "SESSION", "by": "session", "reason": null }, |
| 31 | { "direction": "<", "target": "TICKETBAI", "by": "tckchg", "reason": "ticketbai" } |
| 32 | ], |
| 33 | "TICKETPRODUCT": [ |
| 34 | { "direction": ">", "target": "PRODUCT", "by": "product", "reason": null }, |
| 35 | { "direction": "<", "target": "TICKETOPTION", "by": "product", "reason": "options" } |
| 36 | ], |
| 37 | "TICKETOPTION": [ |
| 38 | { "direction": ">", "target": "TICKETPRODUCT", "by": "product", "reason": null }, |
| 39 | { "direction": ">", "target": "PRODUCTOPT", "by": "prodopt", "reason": null } |
| 40 | ], |
| 41 | "TICKETOFFER": [ |
| 42 | { "direction": ">", "target": "OFFER", "by": "offer", "reason": null } |
| 43 | ], |
| 44 | "TICKETDISCOUNT": [ |
| 45 | { "direction": ">", "target": "DISCOUNT", "by": "discount", "reason": null } |
| 46 | ], |
| 47 | "TICKETAUDIT": [ |
| 48 | { "direction": ">", "target": "AUDIT", "by": "audit", "reason": null } |
| 49 | ], |
| 50 | "TICKETEXTRA": [ |
| 51 | { "direction": ">", "target": "EXTRA", "by": "extra", "reason": null } |
| 52 | ], |
| 53 | "TICKETINVOICE": [ |
| 54 | { "direction": ">", "target": "INVOICEBUSINESS", "by": "client", "reason": "client" } |
| 55 | ], |
| 56 | "PAYACCOUNT": [ |
| 57 | { "direction": ">", "target": "INVOICEBUSINESS", "by": "client", "reason": "client" }, |
| 58 | { "direction": "<", "target": "ACCOUNTINVOICE", "by": "account", "reason": "invoice" } |
| 59 | ] |
| 60 | } |
| 61 | }', true); |
| 62 | |
| 63 | /** |
| 64 | * Action callable: load ticket details by objids (POST body). |
| 65 | * |
| 66 | * @param string $body JSON array of ticket objids. |
| 67 | * @param array<string, mixed> $query Query params: device, session, place. |
| 68 | * @param \ConxHelper $conx Connection helper. |
| 69 | * @param \Psr\Log\LoggerInterface $logger Logger. |
| 70 | * @param \UppServices\SessionService $sessionService Session service for check. |
| 71 | * @return array{output: string, contentType: string} |
| 72 | */ |
| 73 | return function (string $body, array $query, \ConxHelper $conx, \Psr\Log\LoggerInterface $logger, \UppServices\SessionService $sessionService): array { |
| 74 | $retval = \ApplicationError::Success; |
| 75 | $updates = []; |
| 76 | |
| 77 | if (!$body) { |
| 78 | $logger->error("No post data provided."); |
| 79 | $retval = \ApplicationError::Parameters; |
| 80 | } |
| 81 | |
| 82 | if (\success($retval)) { |
| 83 | $tickets = json_decode($body, true); |
| 84 | $logger->debug("DUMP OF POST DATA:".PHP_EOL.print_r($tickets, true).PHP_EOL); |
| 85 | if ($tickets === false) { |
| 86 | $logger->error("Invalid JSON format in post request data"); |
| 87 | $retval = \ApplicationError::Parameters; |
| 88 | } else { |
| 89 | $_objids = implode(', ', array_map('intval', $tickets)); |
| 90 | } |
| 91 | } |
| 92 | |
| 93 | if (\success($retval)) { |
| 94 | $device = $query['device'] ?? null; |
| 95 | if (!$device) { |
| 96 | $logger->error("No device provided on URL. Operation cancelled."); |
| 97 | $retval = \ApplicationError::Parameters; |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | if (\success($retval)) { |
| 102 | $session = $query['session'] ?? null; |
| 103 | if (!$session) { |
| 104 | $logger->error("No session provided on URL. Operation cancelled."); |
| 105 | $retval = \ApplicationError::Parameters; |
| 106 | } else { |
| 107 | $userid = null; |
| 108 | $sessionObjid = null; |
| 109 | $retval = $sessionService->checkSession($conx, (string) $session, (string) $device, $userid, $sessionObjid); |
| 110 | } |
| 111 | } |
| 112 | |
| 113 | if (\success($retval)) { |
| 114 | $place = $query['place'] ?? null; |
| 115 | if ($place === null || $place === '') { |
| 116 | $logger->error("Mandatory argument 'place' not provided in url parameters."); |
| 117 | $retval = \ApplicationError::Parameters; |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | if (\success($retval)) { |
| 122 | $conx->tenant = $place; |
| 123 | } |
| 124 | |
| 125 | if (\success($retval) && $conx->tenant === null) { |
| 126 | $logger->error("Connection to place database failed."); |
| 127 | $retval = \ApplicationError::Database; |
| 128 | } |
| 129 | |
| 130 | if (\success($retval)) { |
| 131 | $GLOBALS['session'] = $session; |
| 132 | $datamodelData = $datamodel['data'] ?? null; |
| 133 | if ($datamodelData) { |
| 134 | $logger->info("(".$session.") Loading tickets for objids: [".$_objids."]"); |
| 135 | $retval = \load_updates($conx, $datamodelData, 'TICKET', $tickets, 0, $updates); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | $result = [ |
| 140 | "errorcode" => $retval, |
| 141 | "updates" => \success($retval) ? $updates : null, |
| 142 | ]; |
| 143 | return ['output' => json_encode($result), 'contentType' => 'application/json; charset=utf-8']; |
| 144 | }; |