create and delete notification for a project working
This commit is contained in:
parent
8c6e21c707
commit
9222069ef5
9 changed files with 105 additions and 52 deletions
37
public/site/plugins/notifications/src/NotificationsPage.php
Normal file
37
public/site/plugins/notifications/src/NotificationsPage.php
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
<?php
|
||||
namespace adrienpayet\notifications;
|
||||
use Kirby\Cms\Page;
|
||||
use Kirby\Data\Yaml;
|
||||
use adrienpayet\notifications\Notification;
|
||||
|
||||
class NotificationsPage extends Page {
|
||||
public function createNotification($notificationData) {
|
||||
$newNotification = new Notification($notificationData);
|
||||
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
$notifications[] = $newNotification->toArray();
|
||||
|
||||
$this->update([
|
||||
'notifications' => $notifications
|
||||
]);
|
||||
}
|
||||
|
||||
public function deleteNotification($notificationId) {
|
||||
$notifications = $this->notifications()->isNotEmpty()
|
||||
? Yaml::decode($this->notifications()->value())
|
||||
: [];
|
||||
|
||||
foreach ($notifications as $key => $notification) {
|
||||
if ($notification['id'] === $notificationId) {
|
||||
unset($notifications[$key]);
|
||||
}
|
||||
}
|
||||
|
||||
$this->update([
|
||||
'notifications' => Yaml::encode(array_values($notifications))
|
||||
]);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue