Files
breadcrumb-the-shire/pages/admin/tenants/data().php
2026-02-11 19:28:12 +01:00

50 lines
1.6 KiB
PHP

<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\Tenant\TenantService;
use MintyPHP\Service\Settings\SettingService;
use MintyPHP\Service\Access\PermissionService;
Guard::requireLogin();
Guard::requirePermissionOrForbidden(PermissionService::TENANTS_VIEW);
$limit = (int) ($_GET['limit'] ?? 10);
$offset = (int) ($_GET['offset'] ?? 0);
$search = trim((string) ($_GET['search'] ?? ''));
$order = (string) ($_GET['order'] ?? 'description');
$dir = (string) ($_GET['dir'] ?? 'asc');
$result = TenantService::listPaged([
'limit' => $limit,
'offset' => $offset,
'search' => $search,
'order' => $order,
'dir' => $dir,
]);
$defaultTenantId = SettingService::getDefaultTenantId();
$defaultPrimaryColor = SettingService::getAppPrimaryColor() ?? '#2fa4a4';
$rows = [];
foreach ($result['rows'] as $row) {
$tenantId = (int) ($row['id'] ?? 0);
$primaryColor = (string) ($row['primary_color'] ?? '');
$useDefaultColor = $primaryColor === '';
$rows[] = [
'id' => $row['id'] ?? null,
'uuid' => $row['uuid'] ?? '',
'is_default' => $tenantId > 0 && $defaultTenantId === $tenantId,
'description' => $row['description'] ?? '',
'status' => $row['status'] ?? 'active',
'primary_color' => $useDefaultColor ? $defaultPrimaryColor : $primaryColor,
'primary_color_is_default' => $useDefaultColor ? 1 : 0,
'created' => dt($row['created'] ?? ''),
'modified' => dt($row['modified'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);