#68 - create comment create working (notification to adapt)

This commit is contained in:
isUnknown 2024-12-18 16:26:55 +01:00
parent 3d4ddc12fc
commit cf83edc1e6
11 changed files with 106 additions and 158 deletions

View file

@ -1,40 +1,32 @@
<?php
namespace adrienpayet\comments;
use adrienpayet\D2P\data\location\Location;
use adrienpayet\D2P\data\Author;
class BaseComment {
protected $href;
protected $location;
protected $position;
protected $replies;
protected $text;
protected $author;
protected $date;
protected $id;
protected $type;
protected $isRead;
protected string $type;
protected Location $location;
protected string $text;
protected Author $author;
protected string $date;
protected string $id;
public function __construct($data) {
$this->type = $data["type"];
$this->location = new Location($data["location"]);
$this->text = $data["text"];
$this->author = new Author($data["author"]);
$this->date = $data["date"];
$this->id = $data["id"];
$this->isRead = "false";
}
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
"location" => $this->location->toArray(),
"text" => $this->text,
"author" => $this->author->toArray(),
"date" => $this->date,
"id" => $this->id,
];
}
}

View file

@ -1,23 +1,26 @@
<?php
namespace adrienpayet\comments;
use adrienpayet\D2P\data\Position;
class Comment extends BaseComment
{
protected $position;
protected ?Position $position = null;
protected string $type = "comment";
protected array $replies = [];
public function __construct($data) {
parent::__construct($data);
$this->position = $data['position'] ?? null;
}
public function position() {
return $this->position;
if (isset($data["position"])) {
$this->position = new Position($data['position']);
}
}
public function toArray() {
$array = parent::toArray();
$array['position'] = $this->position;
$array['type'] = $this->type;
$array['replies'] = $this->replies;
return $array;
}