diff --git a/author.php b/author.php
new file mode 100644
index 0000000..44b9bba
--- /dev/null
+++ b/author.php
@@ -0,0 +1,53 @@
+Неверный запрос";
+ include 'views/footer.php';
+ exit;
+}
+
+$stmt = $pdo->prepare("SELECT id, username, display_name FROM users WHERE id = ?");
+$stmt->execute([$author_id]);
+$author = $stmt->fetch(PDO::FETCH_ASSOC);
+
+if (!$author) {
+ http_response_code(404);
+ echo "
У этого автора пока нет опубликованных книг.
+
+
diff --git a/models/Book.php b/models/Book.php
index f3e1d54..1de36d0 100755
--- a/models/Book.php
+++ b/models/Book.php
@@ -20,27 +20,31 @@ class Book {
return $stmt->fetch(PDO::FETCH_ASSOC);
}
- public function findByUser($user_id) {
- $stmt = $this->pdo->prepare("
- SELECT b.*,
- COUNT(c.id) as chapter_count,
- COALESCE(SUM(c.word_count), 0) as total_words
- FROM books b
- LEFT JOIN chapters c ON b.id = c.book_id
- WHERE b.user_id = ?
- GROUP BY b.id
- ORDER BY b.created_at DESC
- ");
+ public function findByUser($user_id, $only_published = false) {
+ $sql = "
+ SELECT b.*,
+ COUNT(c.id) as chapter_count,
+ COALESCE(SUM(c.word_count), 0) as total_words
+ FROM books b
+ LEFT JOIN chapters c ON b.id = c.book_id
+ WHERE b.user_id = ?
+ ";
+ if ($only_published) {
+ $sql .= " AND b.published = 1 ";
+ }
+ $sql .= " GROUP BY b.id ORDER BY b.created_at DESC ";
+ $stmt = $this->pdo->prepare($sql);
$stmt->execute([$user_id]);
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
public function create($data) {
$share_token = bin2hex(random_bytes(16));
-
+ $published = isset($data['published']) ? (int)$data['published'] : 0;
+
$stmt = $this->pdo->prepare("
- INSERT INTO books (title, description, genre, user_id, series_id, sort_order_in_series, share_token)
- VALUES (?, ?, ?, ?, ?, ?, ?)
+ INSERT INTO books (title, description, genre, user_id, series_id, sort_order_in_series, share_token, published)
+ VALUES (?, ?, ?, ?, ?, ?, ?, ?)
");
return $stmt->execute([
$data['title'],
@@ -49,14 +53,17 @@ class Book {
$data['user_id'],
$data['series_id'] ?? null,
$data['sort_order_in_series'] ?? null,
- $share_token
+ $share_token,
+ $published
]);
}
public function update($id, $data) {
+ $published = isset($data['published']) ? (int)$data['published'] : 0;
+
$stmt = $this->pdo->prepare("
- UPDATE books
- SET title = ?, description = ?, genre = ?, series_id = ?, sort_order_in_series = ?
+ UPDATE books
+ SET title = ?, description = ?, genre = ?, series_id = ?, sort_order_in_series = ?, published = ?
WHERE id = ? AND user_id = ?
");
return $stmt->execute([
@@ -65,6 +72,7 @@ class Book {
$data['genre'] ?? null,
$data['series_id'] ?? null,
$data['sort_order_in_series'] ?? null,
+ $published,
$id,
$data['user_id']
]);
diff --git a/profile.php b/profile.php
index 9efc637..008133e 100755
--- a/profile.php
+++ b/profile.php
@@ -78,6 +78,7 @@ include 'views/header.php';
Информация об аккаунте
+ Моя публичная страница
Дата регистрации: = date('d.m.Y H:i', strtotime($user['created_at'])) ?>
Последний вход: = date('d.m.Y H:i', strtotime($user['last_login'])) ?>