2024-10-30 09:49:16 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace adrienpayet\comments;
|
|
|
|
|
|
|
|
|
|
class BaseComment {
|
|
|
|
|
protected $page;
|
|
|
|
|
protected $file;
|
|
|
|
|
protected $filePageIndex;
|
|
|
|
|
protected $position;
|
|
|
|
|
protected $replies;
|
|
|
|
|
protected $text;
|
2024-10-30 12:15:28 +01:00
|
|
|
protected $author;
|
2024-10-30 09:49:16 +01:00
|
|
|
protected $date;
|
|
|
|
|
protected $id;
|
|
|
|
|
protected $type;
|
2024-10-30 10:56:11 +01:00
|
|
|
protected $isRead;
|
2024-10-30 09:49:16 +01:00
|
|
|
|
|
|
|
|
public function __construct($data) {
|
|
|
|
|
$page = $data['page'];
|
|
|
|
|
$file = $data['file'];
|
|
|
|
|
$filePageIndex = $data['filePageIndex'];
|
|
|
|
|
$replies = $data['replies'] ?? [];
|
|
|
|
|
$text = $data['text'];
|
2024-10-30 12:15:28 +01:00
|
|
|
$author = $data['author'];
|
2024-10-30 09:49:16 +01:00
|
|
|
$date = $data['date'];
|
|
|
|
|
$id = $data['id'];
|
|
|
|
|
$type = $data['type'] ?? 'comment';
|
|
|
|
|
|
|
|
|
|
$this->page = [
|
2024-10-30 11:29:08 +01:00
|
|
|
'uri' => (string) $page->parent()->uri(),
|
|
|
|
|
'title' => (string) $page->parent()->title(),
|
2024-10-30 09:49:16 +01:00
|
|
|
];
|
|
|
|
|
$this->file = [
|
|
|
|
|
'uuid' => (string) $file->uuid(),
|
|
|
|
|
'pageIndex' => $filePageIndex,
|
|
|
|
|
];
|
|
|
|
|
$this->replies = $replies ?? [];
|
|
|
|
|
$this->text = $text;
|
2024-10-30 12:15:28 +01:00
|
|
|
$this->author = [
|
|
|
|
|
'name' => (string) $author->name(),
|
|
|
|
|
'email' => (string) $author->email(),
|
|
|
|
|
'uuid' => (string) $author->uuid(),
|
|
|
|
|
'role' => (string) $author->role(),
|
2024-10-30 09:49:16 +01:00
|
|
|
];
|
|
|
|
|
$this->date = $date;
|
|
|
|
|
$this->id = $id;
|
|
|
|
|
$this->type = $type;
|
2024-10-30 10:56:11 +01:00
|
|
|
$this->isRead = false;
|
2024-10-30 09:49:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function page() {
|
|
|
|
|
return $this->page;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function file() {
|
|
|
|
|
return $this->file;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function replies() {
|
|
|
|
|
return $this->replies;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function text() {
|
|
|
|
|
return $this->text;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 12:15:28 +01:00
|
|
|
public function author() {
|
|
|
|
|
return $this->author;
|
2024-10-30 09:49:16 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function date() {
|
|
|
|
|
return $this->date;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function id() {
|
|
|
|
|
return $this->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function type() {
|
|
|
|
|
return $this->type;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 10:56:11 +01:00
|
|
|
public function isRead() {
|
|
|
|
|
return $this->isRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function read() {
|
|
|
|
|
$this->isRead = true;
|
|
|
|
|
return $this->isRead;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function unread() {
|
|
|
|
|
$this->isRead = false;
|
|
|
|
|
return $this->isRead;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-30 09:49:16 +01:00
|
|
|
public function toArray() {
|
|
|
|
|
return [
|
|
|
|
|
'page' => $this->page,
|
|
|
|
|
'file' => $this->file,
|
|
|
|
|
'replies' => $this->replies,
|
|
|
|
|
'text' => $this->text,
|
2024-10-30 12:15:28 +01:00
|
|
|
'author' => $this->author,
|
2024-10-30 09:49:16 +01:00
|
|
|
'date' => $this->date,
|
|
|
|
|
'id' => $this->id,
|
|
|
|
|
'type' => $this->type,
|
2024-10-30 10:56:11 +01:00
|
|
|
'isRead' => $this->isRead
|
2024-10-30 09:49:16 +01:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|