Skip to content

Commit

Permalink
FIX ULTIM
Browse files Browse the repository at this point in the history
  • Loading branch information
JulieRaymond committed Nov 21, 2023
1 parent ccf431c commit 2018c3e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/Controller/ProfilController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'])) {
Expand All @@ -38,6 +38,8 @@ public function profil()
}
}



public function login()
{
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
Expand Down
14 changes: 12 additions & 2 deletions src/Model/ArticleManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 2018c3e

Please sign in to comment.