create comment classes

This commit is contained in:
isUnknown 2024-10-30 09:49:16 +01:00
parent cd1f065962
commit f5ffe312e2
8 changed files with 246 additions and 63 deletions

View 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,
];
}
}