Pagination on the list, optional auth

This commit is contained in:
2024-07-22 16:19:01 +02:00
parent 7ee04b0a4b
commit 5251c43a6b
11 changed files with 499 additions and 119 deletions
+12 -2
View File
@@ -226,9 +226,17 @@ class User implements JsonSerializable
return $stmt->execute();
}
public static function list()
public static function list(int $page, int $limit)
{
$db = Database::getInstance();
$stmt = $db->prepare(
"SELECT
COUNT(*)
FROM
egb_gaestebuch"
);
$stmt->execute();
$count = $stmt->fetch(PDO::FETCH_COLUMN, 0);
$stmt = $db->prepare(
"SELECT
b.id, b.benutzer, b.status, b.email, b.image, b.isadmin, b.zeitstempel,
@@ -239,10 +247,12 @@ class User implements JsonSerializable
$stmt->execute();
$data = $stmt->fetchAll();
return array_map(
$list = array_map(
fn ($item) => new User($item["id"], $item["benutzer"], $item["status"], $item["email"], $item["zeitstempel"], $item["image"], $item["isadmin"] === 1, $item["postCount"]),
$data
);
return ["pages" => intdiv($count, $limit) + 1, "data" => $list];
}
/*