94 lines
1.9 KiB
PHP
94 lines
1.9 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace adrienpayet\comments;
|
||
|
|
|
||
|
|
class BaseComment {
|
||
|
|
protected $page;
|
||
|
|
protected $file;
|
||
|
|
protected $filePageIndex;
|
||
|
|
protected $position;
|
||
|
|
protected $replies;
|
||
|
|
protected $text;
|
||
|
|
protected $user;
|
||
|
|
protected $date;
|
||
|
|
protected $id;
|
||
|
|
protected $type;
|
||
|
|
|
||
|
|
public function __construct($data) {
|
||
|
|
$page = $data['page'];
|
||
|
|
$file = $data['file'];
|
||
|
|
$filePageIndex = $data['filePageIndex'];
|
||
|
|
$replies = $data['replies'] ?? [];
|
||
|
|
$text = $data['text'];
|
||
|
|
$user = $data['user'];
|
||
|
|
$date = $data['date'];
|
||
|
|
$id = $data['id'];
|
||
|
|
$type = $data['type'] ?? 'comment';
|
||
|
|
|
||
|
|
$this->page = [
|
||
|
|
'uri' => (string) $page->uri(),
|
||
|
|
'title' => (string) $page->title(),
|
||
|
|
];
|
||
|
|
$this->file = [
|
||
|
|
'uuid' => (string) $file->uuid(),
|
||
|
|
'pageIndex' => $filePageIndex,
|
||
|
|
];
|
||
|
|
$this->replies = $replies ?? [];
|
||
|
|
$this->text = $text;
|
||
|
|
$this->user = [
|
||
|
|
'name' => (string) $user->name(),
|
||
|
|
'email' => (string) $user->email(),
|
||
|
|
'uuid' => (string) $user->uuid(),
|
||
|
|
'role' => (string) $user->role(),
|
||
|
|
];
|
||
|
|
$this->date = $date;
|
||
|
|
$this->id = $id;
|
||
|
|
$this->type = $type;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function page() {
|
||
|
|
return $this->page;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function file() {
|
||
|
|
return $this->file;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function replies() {
|
||
|
|
return $this->replies;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function text() {
|
||
|
|
return $this->text;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function user() {
|
||
|
|
return $this->user;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function date() {
|
||
|
|
return $this->date;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function id() {
|
||
|
|
return $this->id;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function type() {
|
||
|
|
return $this->type;
|
||
|
|
}
|
||
|
|
|
||
|
|
public function toArray() {
|
||
|
|
return [
|
||
|
|
'page' => $this->page,
|
||
|
|
'file' => $this->file,
|
||
|
|
'replies' => $this->replies,
|
||
|
|
'text' => $this->text,
|
||
|
|
'user' => $this->user,
|
||
|
|
'date' => $this->date,
|
||
|
|
'id' => $this->id,
|
||
|
|
'type' => $this->type,
|
||
|
|
];
|
||
|
|
}
|
||
|
|
}
|