This commit is contained in:
Lizandro Guarnizo
2026-02-03 21:30:55 -05:00
parent 44423adb32
commit 1aae148396
89 changed files with 8581 additions and 7687 deletions
+41 -5
View File
@@ -24,8 +24,30 @@ header('Access-Control-Allow-Headers: Content-Type');
try {
$db = Database::getInstance();
$users = $db->fetchAll(
"SELECT
// Parámetros de paginación
$page = isset($_GET['page']) ? max(1, intval($_GET['page'])) : 1;
$limit = isset($_GET['limit']) ? max(1, min(100, intval($_GET['limit']))) : 20;
$offset = ($page - 1) * $limit;
// Búsqueda opcional
$search = isset($_GET['search']) ? trim($_GET['search']) : '';
$whereClause = '';
$params = [];
if (!empty($search)) {
$whereClause = "WHERE u.phone_number LIKE ? OR u.name LIKE ? OR u.email LIKE ?";
$searchParam = "%{$search}%";
$params = [$searchParam, $searchParam, $searchParam];
}
// Contar total de registros
$countQuery = "SELECT COUNT(*) as total FROM users u {$whereClause}";
$totalResult = $db->fetch($countQuery, $params);
$total = $totalResult['total'];
$totalPages = ceil($total / $limit);
// Obtener usuarios paginados
$query = "SELECT
u.id,
u.phone_number,
u.name,
@@ -38,12 +60,26 @@ try {
m.name as current_menu
FROM users u
LEFT JOIN menus m ON u.current_menu_id = m.id
ORDER BY u.created_at DESC"
);
{$whereClause}
ORDER BY u.created_at DESC
LIMIT ? OFFSET ?";
$params[] = $limit;
$params[] = $offset;
$users = $db->fetchAll($query, $params);
echo json_encode([
'success' => true,
'data' => $users
'data' => $users,
'pagination' => [
'page' => $page,
'limit' => $limit,
'total' => $total,
'totalPages' => $totalPages,
'hasNext' => $page < $totalPages,
'hasPrev' => $page > 1
]
]);
} catch (Exception $e) {