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

48 lines
1.3 KiB
PHP

<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\Access\RoleService;
use MintyPHP\Service\Settings\SettingService;
use MintyPHP\Service\Access\PermissionService;
Guard::requireLogin();
Guard::requirePermission(PermissionService::ROLES_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');
$active = (string) ($_GET['active'] ?? '');
$result = RoleService::listPaged([
'limit' => $limit,
'offset' => $offset,
'search' => $search,
'order' => $order,
'dir' => $dir,
'active' => $active,
]);
$defaultRoleId = SettingService::getDefaultRoleId();
$rows = [];
foreach ($result['rows'] as $row) {
$roleId = (int) ($row['id'] ?? 0);
$rows[] = [
'id' => $row['id'] ?? null,
'uuid' => $row['uuid'] ?? '',
'is_default' => $roleId > 0 && $defaultRoleId === $roleId,
'description' => $row['description'] ?? '',
'code' => $row['code'] ?? '',
'active' => (int) ($row['active'] ?? 1),
'created' => dt($row['created'] ?? ''),
'modified' => dt($row['modified'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);