comments / notifications : improve abstraction
This commit is contained in:
parent
f467012241
commit
32c026acfe
11 changed files with 92 additions and 65 deletions
|
|
@ -3,8 +3,8 @@
|
|||
namespace adrienpayet\comments;
|
||||
|
||||
class BaseComment {
|
||||
protected $page;
|
||||
protected $file;
|
||||
protected $href;
|
||||
protected $location;
|
||||
protected $position;
|
||||
protected $replies;
|
||||
protected $text;
|
||||
|
|
@ -16,6 +16,7 @@ class BaseComment {
|
|||
|
||||
public function __construct($data) {
|
||||
$page = $data['page'];
|
||||
$project = $page->template() == 'project' ? $page : $page->parent();
|
||||
$file = $data['file'];
|
||||
$position = $data['position'];
|
||||
$replies = $data['replies'] ?? [];
|
||||
|
|
@ -25,13 +26,22 @@ class BaseComment {
|
|||
$id = $data['id'];
|
||||
$type = $data['type'] ?? 'comment';
|
||||
|
||||
$this->page = [
|
||||
'uri' => (string) $page->parent()->uri(),
|
||||
'title' => (string) $page->parent()->title(),
|
||||
];
|
||||
$this->file = [
|
||||
$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 = [
|
||||
|
|
@ -47,12 +57,12 @@ class BaseComment {
|
|||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function page() {
|
||||
return $this->page;
|
||||
public function location() {
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function file() {
|
||||
return $this->file;
|
||||
return $this->location['file'];
|
||||
}
|
||||
|
||||
public function replies() {
|
||||
|
|
@ -99,12 +109,11 @@ class BaseComment {
|
|||
|
||||
public function toArray() {
|
||||
return [
|
||||
'page' => $this->page,
|
||||
'file' => $this->file,
|
||||
'location' => $this->location,
|
||||
'position' => $this->position,
|
||||
'replies' => $this->replies,
|
||||
'text' => $this->text,
|
||||
'author' => $this->author,
|
||||
'position' => $this->position,
|
||||
'date' => $this->date,
|
||||
'id' => $this->id,
|
||||
'type' => $this->type,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue