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
|
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);
|
$req->bindValue(':id', $id, PDO::PARAM_INT);
|
||||||
if (!$req->execute()) {
|
if (!$req->execute()) {
|
||||||
return [];
|
return [];
|
||||||
@@ -76,6 +76,16 @@ class CommentGateway
|
|||||||
|
|
||||||
private function createComment(array $data): Comment
|
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 DateTime $publicationDate;
|
||||||
private string $content;
|
private string $content;
|
||||||
private int $authorId;
|
private int $authorId;
|
||||||
|
private string $authorLogin;
|
||||||
|
|
||||||
public function __construct(int $idComment, int $newsId, DateTime $publicationDate, string $content, int $authorId)
|
public function __construct(int $idComment, int $newsId, DateTime $publicationDate, string $content, int $authorId)
|
||||||
{
|
{
|
||||||
@@ -48,8 +49,18 @@ class Comment
|
|||||||
return $this->authorId;
|
return $this->authorId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAuthorLogin(): string
|
||||||
|
{
|
||||||
|
return $this->authorLogin;
|
||||||
|
}
|
||||||
|
|
||||||
public function setId(int $id): void
|
public function setId(int $id): void
|
||||||
{
|
{
|
||||||
$this->idComment = $id;
|
$this->idComment = $id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function setAuthorLogin(string $authorLogin): void
|
||||||
|
{
|
||||||
|
$this->authorLogin = $authorLogin;
|
||||||
|
}
|
||||||
}
|
}
|
@@ -17,7 +17,7 @@
|
|||||||
<?php foreach ($params['comments'] as $comment) : ?>
|
<?php foreach ($params['comments'] as $comment) : ?>
|
||||||
<article class="message">
|
<article class="message">
|
||||||
<header class="message-header">
|
<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>
|
</header>
|
||||||
<div class="message-body">
|
<div class="message-body">
|
||||||
<?= $comment->getContent() ?>
|
<?= $comment->getContent() ?>
|
||||||
|
Reference in New Issue
Block a user