123 lines
2.6 KiB
PHP
123 lines
2.6 KiB
PHP
<?php
|
|
|
|
namespace adrienpayet\comments;
|
|
|
|
class BaseComment {
|
|
protected $href;
|
|
protected $location;
|
|
protected $position;
|
|
protected $replies;
|
|
protected $text;
|
|
protected $author;
|
|
protected $date;
|
|
protected $id;
|
|
protected $type;
|
|
protected $isRead;
|
|
|
|
public function __construct($data) {
|
|
$page = $data['page'];
|
|
$project = $page->template() == 'project' ? $page : $page->parent();
|
|
$file = $data['file'];
|
|
$position = $data['position'];
|
|
$replies = $data['replies'] ?? [];
|
|
$text = $data['text'];
|
|
$author = $data['author'];
|
|
$date = $data['date'];
|
|
$id = $data['id'];
|
|
$type = $data['type'] ?? 'comment';
|
|
|
|
$this->location = [
|
|
'page' => [
|
|
'uri' => (string) $page->uri(),
|
|
'title' => (string) $page->title(),
|
|
],
|
|
'href' => (string) $data['href'],
|
|
'project' => [
|
|
'title' => (string) $project->title(),
|
|
'uri' => (string) $project->uri(),
|
|
],
|
|
'file' => $file ? [
|
|
'uuid' => (string) $file->uuid(),
|
|
'url' => (string) $file->uuid()
|
|
] : false,
|
|
];
|
|
|
|
$this->replies = $replies ?? [];
|
|
$this->text = $text;
|
|
$this->author = [
|
|
'name' => (string) $author->name(),
|
|
'email' => (string) $author->email(),
|
|
'uuid' => (string) $author->uuid(),
|
|
'role' => (string) $author->role(),
|
|
];
|
|
$this->date = $date;
|
|
$this->id = $id;
|
|
$this->type = $type;
|
|
$this->isRead = false;
|
|
$this->position = $position;
|
|
}
|
|
|
|
public function location() {
|
|
return $this->location;
|
|
}
|
|
|
|
public function file() {
|
|
return $this->location['file'];
|
|
}
|
|
|
|
public function replies() {
|
|
return $this->replies;
|
|
}
|
|
|
|
public function text() {
|
|
return $this->text;
|
|
}
|
|
|
|
public function author() {
|
|
return $this->author;
|
|
}
|
|
|
|
public function date() {
|
|
return $this->date;
|
|
}
|
|
|
|
public function id() {
|
|
return $this->id;
|
|
}
|
|
|
|
public function type() {
|
|
return $this->type;
|
|
}
|
|
|
|
public function isRead() {
|
|
return $this->isRead;
|
|
}
|
|
|
|
public function read() {
|
|
$this->isRead = true;
|
|
return $this->isRead;
|
|
}
|
|
|
|
public function unread() {
|
|
$this->isRead = false;
|
|
return $this->isRead;
|
|
}
|
|
|
|
public function pageIndex() {
|
|
$this->position['pageIndex'];
|
|
}
|
|
|
|
public function toArray() {
|
|
return [
|
|
'location' => $this->location,
|
|
'position' => $this->position,
|
|
'replies' => $this->replies,
|
|
'text' => $this->text,
|
|
'author' => $this->author,
|
|
'date' => $this->date,
|
|
'id' => $this->id,
|
|
'type' => $this->type,
|
|
'isRead' => $this->isRead
|
|
];
|
|
}
|
|
}
|