#68 - refactor some of the notification classes to classes plugin to share them with comments
This commit is contained in:
parent
6ab18b1066
commit
3d4ddc12fc
9 changed files with 22 additions and 105 deletions
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet;
|
||||
namespace adrienpayet\D2P\data;
|
||||
|
||||
class Author
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications;
|
||||
namespace adrienpayet\D2P\data;
|
||||
|
||||
class Position
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
|
||||
class FileDetails
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
|
||||
class Location
|
||||
{
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
use Kirby\Cms\Page;
|
||||
|
||||
class PageDetails
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications\location;
|
||||
namespace adrienpayet\D2P\data\location;
|
||||
use Kirby;
|
||||
|
||||
class ProjectDetails
|
||||
|
|
@ -15,98 +15,15 @@ class BaseComment {
|
|||
protected $isRead;
|
||||
|
||||
public function __construct($data) {
|
||||
$page = $data['page'];
|
||||
$project = $page->template() == 'project' ? $page : $page->parent();
|
||||
$file = $data['file'];
|
||||
$position = $data['position'];
|
||||
$replies = $data['replies'] ?? [];
|
||||
$text = $data['text'];
|
||||
$author = $data['author'];
|
||||
$date = $data['date'];
|
||||
$id = $data['id'];
|
||||
$type = $data['type'] ?? 'comment';
|
||||
|
||||
$this->location = [
|
||||
'page' => [
|
||||
'uri' => (string) $page->uri(),
|
||||
'title' => (string) $page->title(),
|
||||
],
|
||||
'href' => (string) $data['href'],
|
||||
'project' => [
|
||||
'title' => (string) $project->title(),
|
||||
'uri' => (string) $project->uri(),
|
||||
],
|
||||
'file' => $file ? [
|
||||
'uuid' => (string) $file->uuid(),
|
||||
'url' => (string) $file->uuid()
|
||||
] : false,
|
||||
];
|
||||
|
||||
$this->replies = $replies ?? [];
|
||||
$this->text = $text;
|
||||
$this->author = [
|
||||
'name' => (string) $author->name(),
|
||||
'email' => (string) $author->email(),
|
||||
'uuid' => (string) $author->uuid(),
|
||||
'role' => (string) $author->role(),
|
||||
];
|
||||
$this->date = $date;
|
||||
$this->id = $id;
|
||||
$this->type = $type;
|
||||
$this->isRead = false;
|
||||
$this->position = $position;
|
||||
}
|
||||
|
||||
public function location() {
|
||||
return $this->location;
|
||||
}
|
||||
|
||||
public function file() {
|
||||
return $this->location['file'];
|
||||
}
|
||||
|
||||
public function replies() {
|
||||
return $this->replies;
|
||||
}
|
||||
|
||||
public function text() {
|
||||
return $this->text;
|
||||
}
|
||||
|
||||
public function author() {
|
||||
return $this->author;
|
||||
}
|
||||
|
||||
public function date() {
|
||||
return $this->date;
|
||||
}
|
||||
|
||||
public function id() {
|
||||
return $this->id;
|
||||
}
|
||||
|
||||
public function type() {
|
||||
return $this->type;
|
||||
}
|
||||
|
||||
public function isRead() {
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function read() {
|
||||
$this->isRead = true;
|
||||
return $this->isRead;
|
||||
$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 unread() {
|
||||
$this->isRead = false;
|
||||
return $this->isRead;
|
||||
}
|
||||
|
||||
public function pageIndex() {
|
||||
$this->position['pageIndex'];
|
||||
}
|
||||
|
||||
public function toArray() {
|
||||
return [
|
||||
'location' => $this->location,
|
||||
|
|
|
|||
|
|
@ -6,12 +6,12 @@ load([
|
|||
|
||||
F::loadClasses([
|
||||
'adrienpayet\\notifications\\Notification' => __DIR__ . '/src/Notification.php',
|
||||
'adrienpayet\\notifications\\location\\Location' => __DIR__ . '/src/location/Location.php',
|
||||
'adrienpayet\\notifications\\location\\PageDetails' => __DIR__ . '/src/location/PageDetails.php',
|
||||
'adrienpayet\\notifications\\location\\ProjectDetails' => __DIR__ . '/src/location/ProjectDetails.php',
|
||||
'adrienpayet\\notifications\\location\\FileDetails' => __DIR__ . '/src/location/FileDetails.php',
|
||||
'adrienpayet\\notifications\\Position' => __DIR__ . '/src/Position.php',
|
||||
'adrienpayet\\Author' => __DIR__ . '/../classes/Author.php'
|
||||
'adrienpayet\\D2P\\data\\Position' => __DIR__ . '/../classes/Position.php',
|
||||
'adrienpayet\\D2P\data\Author' => __DIR__ . '/../classes/Author.php',
|
||||
'adrienpayet\\D2P\\data\\location\\Location' => __DIR__ . '/../classes/location/Location.php',
|
||||
'adrienpayet\\D2P\\data\\location\\PageDetails' => __DIR__ . '/../classes/location/PageDetails.php',
|
||||
'adrienpayet\\D2P\\data\\location\\ProjectDetails' => __DIR__ . '/../classes/location/ProjectDetails.php',
|
||||
'adrienpayet\\D2P\\data\\location\\FileDetails' => __DIR__ . '/../classes/location/FileDetails.php',
|
||||
]);
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
<?php
|
||||
|
||||
namespace adrienpayet\notifications;
|
||||
use adrienpayet\notifications\location\Location;
|
||||
use adrienpayet\Author;
|
||||
use adrienpayet\D2P\data\location\Location;
|
||||
use adrienpayet\D2P\data\Author;
|
||||
|
||||
class Notification
|
||||
{
|
||||
|
|
@ -23,7 +23,7 @@ class Notification
|
|||
$this->author = new Author($data["author"]);
|
||||
$this->date = $data["date"];
|
||||
$this->id = $data["id"];
|
||||
$this->isRead = $data["isRead"];
|
||||
$this->isRead = "false";
|
||||
|
||||
if ($data["type"] === "comment") {
|
||||
$this->position = new Position($data["position"]);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue