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.
89 lines
2.9 KiB
PHP
89 lines
2.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/../helpers.php';
|
|
require_once __DIR__ . '/../grants/_grantUtils.php';
|
|
runAuth();
|
|
|
|
global $businessId;
|
|
|
|
$data = readJsonBody();
|
|
$bizId = $businessId;
|
|
if ($bizId <= 0) $bizId = (int) ($data['BusinessID'] ?? 0);
|
|
if ($bizId <= 0) {
|
|
apiAbort(['OK' => false, 'ERROR' => 'missing_businessid']);
|
|
}
|
|
|
|
$onlyActive = true;
|
|
if (isset($data['onlyActive'])) {
|
|
$v = $data['onlyActive'];
|
|
if (is_bool($v)) $onlyActive = $v;
|
|
elseif (is_numeric($v)) $onlyActive = ((int) $v === 1);
|
|
elseif (is_string($v)) $onlyActive = (strtolower(trim($v)) === 'true');
|
|
}
|
|
|
|
$sql = "
|
|
SELECT ID, Name, TypeID, Code, Description, SortOrder, IsActive, BeaconMinor
|
|
FROM ServicePoints WHERE BusinessID = ?
|
|
";
|
|
$params = [$bizId];
|
|
if ($onlyActive) $sql .= " AND IsActive = 1";
|
|
$sql .= " ORDER BY SortOrder, Name";
|
|
|
|
$rows = queryTimed($sql, $params);
|
|
|
|
$servicePoints = [];
|
|
foreach ($rows as $r) {
|
|
$servicePoints[] = [
|
|
'ServicePointID' => (int) $r['ID'],
|
|
'Name' => $r['Name'],
|
|
'TypeID' => (int) $r['TypeID'],
|
|
'Code' => $r['Code'] ?? '',
|
|
'Description' => $r['Description'] ?? '',
|
|
'SortOrder' => (int) $r['SortOrder'],
|
|
'IsActive' => (int) $r['IsActive'],
|
|
'BeaconMinor' => (int) ($r['BeaconMinor'] ?? 0),
|
|
];
|
|
}
|
|
|
|
// Granted service points (SP-SM)
|
|
$qGranted = queryTimed("
|
|
SELECT sp.ID, sp.Name, sp.TypeID, sp.Code, sp.Description, sp.SortOrder, sp.IsActive,
|
|
g.ID AS GrantID, g.OwnerBusinessID, g.EconomicsType, g.EconomicsValue,
|
|
g.EligibilityScope, g.TimePolicyType, g.TimePolicyData,
|
|
ob.Name AS OwnerBusinessName
|
|
FROM ServicePointGrants g
|
|
JOIN ServicePoints sp ON sp.ID = g.ServicePointID
|
|
JOIN Businesses ob ON ob.ID = g.OwnerBusinessID
|
|
WHERE g.GuestBusinessID = ? AND g.StatusID = 1 AND sp.IsActive = 1
|
|
", [$bizId]);
|
|
|
|
$grantedServicePoints = [];
|
|
foreach ($qGranted as $r) {
|
|
if (isGrantTimeActive($r['TimePolicyType'] ?? 'always', $r['TimePolicyData'] ?? '')) {
|
|
$grantedServicePoints[] = [
|
|
'ServicePointID' => (int) $r['ID'],
|
|
'Name' => $r['Name'],
|
|
'TypeID' => (int) $r['TypeID'],
|
|
'Code' => $r['Code'] ?? '',
|
|
'Description' => $r['Description'] ?? '',
|
|
'SortOrder' => (int) $r['SortOrder'],
|
|
'IsActive' => (int) $r['IsActive'],
|
|
'IsGranted' => true,
|
|
'GrantID' => (int) $r['GrantID'],
|
|
'OwnerBusinessID' => (int) $r['OwnerBusinessID'],
|
|
'OwnerBusinessName' => $r['OwnerBusinessName'],
|
|
'EconomicsType' => $r['EconomicsType'],
|
|
'EconomicsValue' => (float) $r['EconomicsValue'],
|
|
'EligibilityScope' => $r['EligibilityScope'],
|
|
];
|
|
}
|
|
}
|
|
|
|
jsonResponse([
|
|
'OK' => true,
|
|
'ERROR' => '',
|
|
'BusinessID' => $bizId,
|
|
'COUNT' => count($servicePoints),
|
|
'SERVICEPOINTS' => $servicePoints,
|
|
'GRANTED_COUNT' => count($grantedServicePoints),
|
|
'GRANTED_SERVICEPOINTS' => $grantedServicePoints,
|
|
]);
|