115 lines
2.6 KiB
PHP
115 lines
2.6 KiB
PHP
<?php
|
|
|
|
/**
|
|
* Repräsentiert einen Kommentar unter einem Beitrag.
|
|
*
|
|
* Ein Kommentar kann entweder ein Hauptkommentar sein
|
|
* oder eine Antwort auf einen anderen Kommentar.
|
|
*
|
|
* @author Caroline Schulte
|
|
*/
|
|
class Comment
|
|
{
|
|
private int $id;
|
|
private int $articleId;
|
|
private ?int $parentCommentId;
|
|
private string $author;
|
|
private string $content;
|
|
private string $created;
|
|
|
|
/**
|
|
* Erstellt einen neuen Kommentar.
|
|
*
|
|
* @param int $id Eindeutige ID des Kommentars
|
|
* @param int $articleId ID des zugehörigen Beitrags
|
|
* @param int|null $parentCommentId ID des Eltern-Kommentars oder null
|
|
* @param string $author Autor des Kommentars
|
|
* @param string $content Inhalt des Kommentars
|
|
* @param string $created Erstellungsdatum des Kommentars
|
|
*/
|
|
public function __construct(
|
|
int $id,
|
|
int $articleId,
|
|
?int $parentCommentId,
|
|
string $author,
|
|
string $content,
|
|
string $created
|
|
) {
|
|
$this->id = $id;
|
|
$this->articleId = $articleId;
|
|
$this->parentCommentId = $parentCommentId;
|
|
$this->author = $author;
|
|
$this->content = $content;
|
|
$this->created = $created;
|
|
}
|
|
|
|
/**
|
|
* Gibt die ID des Kommentars zurück.
|
|
*
|
|
* @return int Kommentar-ID
|
|
*/
|
|
public function getId(): int
|
|
{
|
|
return $this->id;
|
|
}
|
|
|
|
/**
|
|
* Gibt die ID des zugehörigen Beitrags zurück.
|
|
*
|
|
* @return int Beitrags-ID
|
|
*/
|
|
public function getArticleId(): int
|
|
{
|
|
return $this->articleId;
|
|
}
|
|
|
|
/**
|
|
* Gibt die ID des Eltern-Kommentars zurück.
|
|
*
|
|
* @return int|null ID des Eltern-Kommentars oder null
|
|
*/
|
|
public function getParentCommentId(): ?int
|
|
{
|
|
return $this->parentCommentId;
|
|
}
|
|
|
|
/**
|
|
* Gibt zurück, ob der Kommentar eine Antwort ist.
|
|
*
|
|
* @return bool true wenn der Kommentar eine Antwort ist, sonst false
|
|
*/
|
|
public function isReply(): bool
|
|
{
|
|
return $this->parentCommentId !== null;
|
|
}
|
|
|
|
/**
|
|
* Gibt den Autor des Kommentars zurück.
|
|
*
|
|
* @return string Autor
|
|
*/
|
|
public function getAuthor(): string
|
|
{
|
|
return $this->author;
|
|
}
|
|
|
|
/**
|
|
* Gibt den Inhalt des Kommentars zurück.
|
|
*
|
|
* @return string Kommentarinhalt
|
|
*/
|
|
public function getContent(): string
|
|
{
|
|
return $this->content;
|
|
}
|
|
|
|
/**
|
|
* Gibt das Erstellungsdatum des Kommentars zurück.
|
|
*
|
|
* @return string Erstellungsdatum
|
|
*/
|
|
public function getCreated(): string
|
|
{
|
|
return $this->created;
|
|
}
|
|
} |