Post Create/Edit

This commit is contained in:
2024-07-27 16:42:03 +02:00
parent 74fd55084f
commit 08731f8559
29 changed files with 632 additions and 161 deletions
+15 -2
View File
@@ -58,7 +58,7 @@ class Post implements JsonSerializable
return new Post($data["id"], $user, null, null, $data["beitrag"], $data["zeitstempel"]);
}
public static function create(User $user, string $content): Post
public static function create(User $user, string $content, int $limit): array
{
$content = substr(trim($content), 0, 250);
@@ -73,8 +73,21 @@ class Post implements JsonSerializable
$stmt->bindValue(":CON", nl2br(htmlspecialchars($content)));
$stmt->execute();
$lastId = $db->lastInsertId();
return Post::getByID($db->lastInsertId());
$stmt = $db->prepare(
"SELECT
COUNT(*)
FROM
egb_gaestebuch"
);
$stmt->execute();
$count = $stmt->fetch(PDO::FETCH_COLUMN, 0);
return [
"pages" => intdiv($count, $limit + 1) + 1,
"post" => Post::getByID($lastId)
];
}
public static function list(int $page, int $limit, bool $authed = false): array