Files
breadcrumb-the-shire/pages/admin/tenants/data().php
2026-02-04 23:31:53 +01:00

44 lines
1.2 KiB
PHP

<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\TenantService;
use MintyPHP\Service\SettingService;
use MintyPHP\Service\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();
$rows = [];
foreach ($result['rows'] as $row) {
$tenantId = (int) ($row['id'] ?? 0);
$rows[] = [
'id' => $row['id'] ?? null,
'uuid' => $row['uuid'] ?? '',
'is_default' => $tenantId > 0 && $defaultTenantId === $tenantId,
'description' => $row['description'] ?? '',
'created' => dt($row['created'] ?? ''),
'modified' => dt($row['modified'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);