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

42 lines
1003 B
PHP

<?php
use MintyPHP\Router;
use MintyPHP\Support\Guard;
use MintyPHP\Service\PermissionService;
Guard::requireLogin();
Guard::requirePermission(PermissionService::PERMISSIONS_VIEW);
if (!isset($_SESSION['user'])) {
http_response_code(401);
Router::json(['data' => [], 'total' => 0]);
}
$limit = (int) ($_GET['limit'] ?? 10);
$offset = (int) ($_GET['offset'] ?? 0);
$search = trim((string) ($_GET['search'] ?? ''));
$order = (string) ($_GET['order'] ?? 'key');
$dir = (string) ($_GET['dir'] ?? 'asc');
$result = PermissionService::listPaged([
'limit' => $limit,
'offset' => $offset,
'search' => $search,
'order' => $order,
'dir' => $dir,
]);
$rows = [];
foreach ($result['data'] ?? [] as $row) {
$rows[] = [
'id' => $row['id'] ?? null,
'key' => $row['key'] ?? '',
'description' => $row['description'] ?? '',
'created' => dt($row['created'] ?? ''),
];
}
Router::json([
'data' => $rows,
'total' => $result['total'] ?? 0,
]);