Affiche le nom d'utilisateur pour chaque commentaire
This commit is contained in:
@@ -43,7 +43,7 @@ class CommentGateway
|
||||
*/
|
||||
public function getByNewsId(int $id): array
|
||||
{
|
||||
$req = $this->pdo->prepare('SELECT * FROM comment WHERE news_id = :id ORDER BY publication_date DESC');
|
||||
$req = $this->pdo->prepare('SELECT c.*, u.login author_login FROM comment c INNER JOIN registered_user u ON u.id_user = c.author_id WHERE c.news_id = :id ORDER BY c.publication_date ASC');
|
||||
$req->bindValue(':id', $id, PDO::PARAM_INT);
|
||||
if (!$req->execute()) {
|
||||
return [];
|
||||
@@ -76,6 +76,16 @@ class CommentGateway
|
||||
|
||||
private function createComment(array $data): Comment
|
||||
{
|
||||
return new Comment(intval($data['id_comment']),intval($data['news_id']), DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date']), $data['content'], intval($data['author_id']));
|
||||
$comment = new Comment(
|
||||
intval($data['id_comment']),
|
||||
intval($data['news_id']),
|
||||
DateTime::createFromFormat('Y-m-d H:i:s', $data['publication_date']),
|
||||
$data['content'],
|
||||
intval($data['author_id'])
|
||||
);
|
||||
if (isset($data['author_login'])) {
|
||||
$comment->setAuthorLogin($data['author_login']);
|
||||
}
|
||||
return $comment;
|
||||
}
|
||||
}
|
@@ -13,6 +13,7 @@ class Comment
|
||||
private DateTime $publicationDate;
|
||||
private string $content;
|
||||
private int $authorId;
|
||||
private string $authorLogin;
|
||||
|
||||
public function __construct(int $idComment, int $newsId, DateTime $publicationDate, string $content, int $authorId)
|
||||
{
|
||||
@@ -48,8 +49,18 @@ class Comment
|
||||
return $this->authorId;
|
||||
}
|
||||
|
||||
public function getAuthorLogin(): string
|
||||
{
|
||||
return $this->authorLogin;
|
||||
}
|
||||
|
||||
public function setId(int $id): void
|
||||
{
|
||||
$this->idComment = $id;
|
||||
}
|
||||
|
||||
public function setAuthorLogin(string $authorLogin): void
|
||||
{
|
||||
$this->authorLogin = $authorLogin;
|
||||
}
|
||||
}
|
@@ -17,7 +17,7 @@
|
||||
<?php foreach ($params['comments'] as $comment) : ?>
|
||||
<article class="message">
|
||||
<header class="message-header">
|
||||
From <?= $comment->getAuthorId() ?> published on <?= $comment->getPublicationDate()->format('Y-m-d H:i:s') ?>
|
||||
From <?= $comment->getAuthorLogin() ?> published on <?= $comment->getPublicationDate()->format('Y-m-d H:i:s') ?>
|
||||
</header>
|
||||
<div class="message-body">
|
||||
<?= $comment->getContent() ?>
|
||||
|
Reference in New Issue
Block a user