From 2018c3e634925071c4999d69e31e5fc96b5b1b5a Mon Sep 17 00:00:00 2001 From: Julie Date: Tue, 21 Nov 2023 19:21:42 +0100 Subject: [PATCH] FIX ULTIM --- src/Controller/ProfilController.php | 4 +++- src/Model/ArticleManager.php | 14 ++++++++++++-- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/src/Controller/ProfilController.php b/src/Controller/ProfilController.php index af5e48a..fe41c3d 100644 --- a/src/Controller/ProfilController.php +++ b/src/Controller/ProfilController.php @@ -19,7 +19,7 @@ public function profil() // Récupère les articles de l'utilisateur $articleManager = new ArticleManager(); - $articles = $articleManager->getAllArticles(); + $articles = $articleManager->getArticlesByUserId($userId); $articles = array_map(function ($article) { if (isset($article['categories'])) { @@ -38,6 +38,8 @@ public function profil() } } + + public function login() { if ($_SERVER['REQUEST_METHOD'] === 'POST') { diff --git a/src/Model/ArticleManager.php b/src/Model/ArticleManager.php index 39cb7c4..928a0d1 100644 --- a/src/Model/ArticleManager.php +++ b/src/Model/ArticleManager.php @@ -59,14 +59,24 @@ public function deleteArticle(int $articleId) public function getArticlesByUserId(int $userId) { - $query = 'SELECT * FROM ' . static::TABLE . ' WHERE blog_user_id = :user_id'; + $query = "SELECT A.*, BU.name AS author_name, C.id AS comment_id, C.content AS comment_content, + CAT.name AS category_name + FROM article A + INNER JOIN blog_user BU ON A.blog_user_id = BU.id + LEFT JOIN commentary C ON A.id = C.article_id + LEFT JOIN article_category AC ON A.id = AC.article_id + LEFT JOIN category CAT ON AC.category_id = CAT.id + WHERE A.blog_user_id = :user_id + ORDER BY A.date DESC"; + $statement = $this->pdo->prepare($query); - $statement->bindValue(':user_id', $userId, \PDO::PARAM_INT); + $statement->bindValue(':user_id', $userId, PDO::PARAM_INT); $statement->execute(); return $statement->fetchAll(); } + public function getAllArticles() { $query = "SELECT A.*, BU.name AS author_name, COUNT(C.id) AS comment_count,