Add safety seal support to orders and related logic for wash certificates
- Introduced `safety_seal` column in the `orders` table. - Updated order creation and completion logic to handle safety seal values. - Enhanced order and booking classes to manage safety seal attachment and retrieval. - Added tests to validate safety seal functionality in order processing.
This commit is contained in:
@@ -30,6 +30,26 @@ class subuser_grants_o extends db
|
||||
subusers_permission_node_key::BOOKINGS_DELETE,
|
||||
];
|
||||
|
||||
private static function normalizePermissionsValue(mixed $raw): array
|
||||
{
|
||||
if ($raw === null || $raw === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
if (is_array($raw)) {
|
||||
return array_values(array_filter($raw, static fn ($permission) => is_string($permission) && trim($permission) !== ''));
|
||||
}
|
||||
|
||||
if (is_string($raw)) {
|
||||
$decoded = json_decode($raw, true);
|
||||
if (is_array($decoded)) {
|
||||
return array_values(array_filter($decoded, static fn ($permission) => is_string($permission) && trim($permission) !== ''));
|
||||
}
|
||||
}
|
||||
|
||||
return [];
|
||||
}
|
||||
|
||||
|
||||
public function structure(): void
|
||||
{
|
||||
@@ -62,23 +82,7 @@ class subuser_grants_o extends db
|
||||
'subuser' => (int)$this->subuser->value(),
|
||||
'enabled' => (bool)$this->enabled->value(),
|
||||
'note' => $this->note->value(),
|
||||
'permissions' => (function ($raw) {
|
||||
// Handle different representations from object_property:
|
||||
// - When type is 'json', object_property::value() may already return an array
|
||||
// - In older behavior, it could return a JSON string
|
||||
// Normalize to an array for API output
|
||||
if ($raw === null || $raw === '') {
|
||||
return [];
|
||||
}
|
||||
if (is_array($raw)) {
|
||||
return $raw;
|
||||
}
|
||||
if (is_string($raw)) {
|
||||
$decoded = json_decode($raw, true);
|
||||
return is_array($decoded) ? $decoded : [];
|
||||
}
|
||||
return [];
|
||||
})($this->permissions->value()),
|
||||
'permissions' => self::normalizePermissionsValue($this->permissions->value()),
|
||||
'created_at' => $this->created_at->value(),
|
||||
'updated_at' => $this->updated_at->value(),
|
||||
'deleted_at' => $this->deleted_at->value(),
|
||||
@@ -122,11 +126,33 @@ class subuser_grants_o extends db
|
||||
// Extract permissions from the grants
|
||||
$permissions = [];
|
||||
foreach ($grants as $grant) {
|
||||
$grant_permissions = json_decode($grant['permissions'], true);
|
||||
$grant_permissions = self::normalizePermissionsValue($grant['permissions'] ?? null);
|
||||
if (is_array($grant_permissions)) {
|
||||
$permissions = array_merge($permissions, $grant_permissions);
|
||||
}
|
||||
}
|
||||
return $permissions;
|
||||
return array_values(array_unique($permissions));
|
||||
}
|
||||
}
|
||||
|
||||
public function getGrantForSubuserAndCustomer(int $subuser_id, int $customer_number, bool $includeDisabled = true): ?subuser_grants_o
|
||||
{
|
||||
$grants = self::getFieldsWhere([
|
||||
'billing_customer_number' => $customer_number,
|
||||
'subuser' => $subuser_id,
|
||||
'deleted_at' => null,
|
||||
], ['id', 'enabled']);
|
||||
|
||||
if (!$includeDisabled) {
|
||||
$grants = array_values(array_filter($grants, static fn (array $grant): bool => (int)($grant['enabled'] ?? 0) === 1));
|
||||
}
|
||||
|
||||
if (count($grants) === 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
usort($grants, static fn (array $left, array $right): int => (int)$right['id'] <=> (int)$left['id']);
|
||||
$grant = (new subuser_grants_o())->select((int)$grants[0]['id']);
|
||||
$grant->getObjectProperties();
|
||||
return $grant;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user