Complete port of all 163 API endpoints from Lucee/CFML to PHP 8.3. Shared helpers in api/helpers.php (DB, auth, request/response, security). PDO prepared statements throughout. Same JSON response shapes as CFML.
68 lines
2.2 KiB
PHP
68 lines
2.2 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
runAuth();
|
|
|
|
global $businessId;
|
|
|
|
if ($businessId <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'no_business_selected']);
|
|
}
|
|
|
|
$qBiz = queryOne("SELECT BeaconShardID, BeaconMajor FROM Businesses WHERE ID = ? LIMIT 1", [$businessId]);
|
|
|
|
$usesSharding = $qBiz && ((int) ($qBiz['BeaconShardID'] ?? 0)) > 0;
|
|
$assignments = [];
|
|
|
|
if ($usesSharding) {
|
|
$qShard = queryOne("SELECT UUID FROM BeaconShards WHERE ID = ?", [(int) $qBiz['BeaconShardID']]);
|
|
$shardUUID = $qShard ? $qShard['UUID'] : '';
|
|
|
|
$rows = queryTimed("
|
|
SELECT sp.ID AS ServicePointID, sp.BeaconMinor, sp.Name AS ServicePointName
|
|
FROM ServicePoints sp
|
|
WHERE sp.BusinessID = ? AND sp.BeaconMinor IS NOT NULL AND sp.IsActive = 1
|
|
ORDER BY sp.BeaconMinor, sp.Name
|
|
", [$businessId]);
|
|
|
|
foreach ($rows as $r) {
|
|
$assignments[] = [
|
|
'ServicePointID' => (int) $r['ServicePointID'],
|
|
'BeaconID' => 0,
|
|
'BusinessID' => $businessId,
|
|
'BeaconName' => $r['ServicePointName'] . ' (Minor ' . $r['BeaconMinor'] . ')',
|
|
'UUID' => $shardUUID,
|
|
'Major' => (int) $qBiz['BeaconMajor'],
|
|
'Minor' => (int) $r['BeaconMinor'],
|
|
'ServicePointName' => $r['ServicePointName'],
|
|
'IsSharding' => true,
|
|
];
|
|
}
|
|
} else {
|
|
$rows = queryTimed("
|
|
SELECT sp.ID AS ServicePointID, sp.BeaconID, sp.BusinessID,
|
|
b.Name AS BeaconName, b.UUID, sp.Name AS ServicePointName
|
|
FROM ServicePoints sp
|
|
JOIN Beacons b ON b.ID = sp.BeaconID
|
|
WHERE sp.BusinessID = ? AND sp.BeaconID IS NOT NULL
|
|
ORDER BY b.Name, sp.Name
|
|
", [$businessId]);
|
|
|
|
foreach ($rows as $r) {
|
|
$assignments[] = [
|
|
'ServicePointID' => (int) $r['ServicePointID'],
|
|
'BeaconID' => (int) $r['BeaconID'],
|
|
'BusinessID' => (int) $r['BusinessID'],
|
|
'BeaconName' => $r['BeaconName'],
|
|
'UUID' => $r['UUID'],
|
|
'ServicePointName' => $r['ServicePointName'],
|
|
'IsSharding' => false,
|
|
];
|
|
}
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true, 'ERROR' => '',
|
|
'COUNT' => count($assignments),
|
|
'ASSIGNMENTS' => $assignments,
|
|
'USES_SHARDING' => $usesSharding,
|
|
]);
|