create comment classes
This commit is contained in:
parent
cd1f065962
commit
f5ffe312e2
8 changed files with 246 additions and 63 deletions
93
public/site/plugins/comments/src/BaseComment.php
Normal file
93
public/site/plugins/comments/src/BaseComment.php
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
<?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,
|
||||
];
|
||||
}
|
||||
}
|
||||
24
public/site/plugins/comments/src/Comment.php
Normal file
24
public/site/plugins/comments/src/Comment.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\comments;
|
||||
|
||||
class Comment extends BaseComment
|
||||
{
|
||||
protected $position;
|
||||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
$this->position = $data['position'] ?? null;
|
||||
}
|
||||
|
||||
public function position() {
|
||||
return $this->position;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = parent::toArray();
|
||||
$array['position'] = $this->position;
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
24
public/site/plugins/comments/src/Reply.php
Normal file
24
public/site/plugins/comments/src/Reply.php
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
<?php
|
||||
namespace adrienpayet\comments;
|
||||
|
||||
class Reply extends BaseComment {
|
||||
|
||||
protected $parentId;
|
||||
|
||||
public function __construct($data) {
|
||||
parent::__construct($data);
|
||||
$this->parentId = $data['parentId'];
|
||||
}
|
||||
|
||||
|
||||
public function parentId() {
|
||||
return $this->parentId;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = parent::toArray();
|
||||
$array['parentId'] = $this->parentId;
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue