#68 - finish notification class. Content notification on validate brief working
This commit is contained in:
parent
3fb043210e
commit
fa36c9ef4a
12 changed files with 246 additions and 24 deletions
50
public/site/plugins/notifications/src/Notification.php
Normal file
50
public/site/plugins/notifications/src/Notification.php
Normal file
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications;
|
||||
use adrienpayet\notifications\location\Location;
|
||||
use adrienpayet\Author;
|
||||
|
||||
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"];
|
||||
$this->isRead = $data["isRead"];
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
}
|
||||
25
public/site/plugins/notifications/src/Position.php
Normal file
25
public/site/plugins/notifications/src/Position.php
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications;
|
||||
|
||||
class Position
|
||||
{
|
||||
public int $pageIndex;
|
||||
public float $x;
|
||||
public float $y;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->pageIndex = $data['pageIndex'];
|
||||
$this->x = (float) $data['x'];
|
||||
$this->y = (float) $data['y'];
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"pageIndex" => $this->pageIndex,
|
||||
"x" => $this->x,
|
||||
"y" => $this->y,
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
|
||||
class FileDetails
|
||||
{
|
||||
public string $uuid;
|
||||
public string $url;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->uuid = (string) $data->uuid();
|
||||
$this->url = (string) $data->url();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"uuid" => $this->uuid,
|
||||
"url" => $this->url
|
||||
];
|
||||
}
|
||||
}
|
||||
36
public/site/plugins/notifications/src/location/Location.php
Normal file
36
public/site/plugins/notifications/src/location/Location.php
Normal file
|
|
@ -0,0 +1,36 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
|
||||
class Location
|
||||
{
|
||||
protected PageDetails $page;
|
||||
protected ?string $dialogUri = null;
|
||||
protected ProjectDetails $project;
|
||||
protected ?FileDetails $file = null;
|
||||
|
||||
public function __construct(array $data)
|
||||
{
|
||||
$this->page = new PageDetails($data["page"]);
|
||||
$this->dialogUri = $data["dialogUri"];
|
||||
$this->project = new ProjectDetails($data["project"]);
|
||||
|
||||
if (isset($data['file'])) {
|
||||
$this->file = new FileDetails($data["file"]);
|
||||
}
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
$array = [
|
||||
"page" => $this->page->toArray(),
|
||||
"project" => $this->project->toArray(),
|
||||
];
|
||||
|
||||
if ($this->dialogUri) {
|
||||
$array["dialogUri"] = $this->dialogUri;
|
||||
$array["file"] = $this->file;
|
||||
}
|
||||
|
||||
return $array;
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
use Kirby\Cms\Page;
|
||||
|
||||
class PageDetails
|
||||
{
|
||||
protected Page $page;
|
||||
|
||||
public function __construct(Page $page)
|
||||
{
|
||||
$this->page = $page;
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"uri" => (string) $this->page->uri(),
|
||||
"title" => (string) $this->page->title(),
|
||||
];
|
||||
}
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
use Kirby;
|
||||
|
||||
class ProjectDetails
|
||||
{
|
||||
public string $title;
|
||||
public string $uri;
|
||||
|
||||
public function __construct(Kirby\Cms\Page $page)
|
||||
{
|
||||
$this->title = (string) $page->title();
|
||||
$this->uri = (string) $page->uri();
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
"title" => $this->title,
|
||||
"uri" => $this->uri
|
||||
];
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue