2024-12-18 13:56:21 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace adrienpayet\notifications;
|
2024-12-18 15:05:42 +01:00
|
|
|
use adrienpayet\D2P\data\location\Location;
|
|
|
|
|
use adrienpayet\D2P\data\Author;
|
2024-12-18 13:56:21 +01:00
|
|
|
|
|
|
|
|
class Notification
|
|
|
|
|
{
|
|
|
|
|
protected string $type;
|
|
|
|
|
protected Location $location;
|
|
|
|
|
protected string $text;
|
|
|
|
|
protected Author $author;
|
|
|
|
|
protected string $date;
|
|
|
|
|
protected string $id;
|
|
|
|
|
protected string $isRead;
|
|
|
|
|
|
|
|
|
|
protected ?Position $position = null;
|
|
|
|
|
|
|
|
|
|
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"];
|
2024-12-18 15:05:42 +01:00
|
|
|
$this->isRead = "false";
|
2024-12-18 13:56:21 +01:00
|
|
|
|
|
|
|
|
if ($data["type"] === "comment") {
|
|
|
|
|
$this->position = new Position($data["position"]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray() {
|
|
|
|
|
$array = [
|
|
|
|
|
"type" => $this->type,
|
|
|
|
|
"location" => $this->location->toArray(),
|
|
|
|
|
"text" => $this->text,
|
|
|
|
|
"author" => $this->author->toArray(),
|
|
|
|
|
"date" => $this->date,
|
|
|
|
|
"id" => $this->id,
|
|
|
|
|
"isRead" => $this->isRead,
|
|
|
|
|
];
|
|
|
|
|
if ($this->type === "comment") {
|
|
|
|
|
$array["position"] = $this->position->toArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $array;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|