Source of file NotifyService.php
Size: 2,481 Bytes - Last Modified: 2021-12-23T10:25:43+00:00
/var/www/docs.ssmods.com/process/src/src/Service/NotifyService.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 | <?php namespace Symbiote\Notifications\Service; use SilverStripe\Security\Member; use Symbiote\Notifications\Model\InternalNotification; class NotifyService { public function webEnabledMethods() { return array( 'list' => 'GET', 'read' => 'POST', 'see' => 'POST' ); } /** * List all the notifications a user has, on a particular item, * and/or of a particular type * * @return DataList|null */ public function list() { $member = Member::currentUser(); if (!$member) { return false; } return $member->getNotifications(); } /** * Mark a Notification as read, accepts a notification ID and returns a * boolean for success or failure. * * @param string|int $ID The ID of an InternalNotification for the current * logged in Member * @return boolean true when marked read otherwise false */ public function read($ID) { $member = Member::currentUser(); if (!$member) { return false; } if ($ID) { $notification = InternalNotification::get() ->filter([ 'ID' => $ID, 'ToID' => $member->ID, 'IsRead' => false ])->first(); if ($notification) { $notification->IsRead = true; $notification->write(); return true; } } return false; } /** * Mark a Notification as seen, accepts a notification ID and returns a * boolean for success or failure. * * @param string|int $ID The ID of an InternalNotification for the current * logged in Member * @return boolean true when marked seen otherwise false */ public function see($ID) { $member = Member::currentUser(); if (!$member) { return false; } if ($ID) { $notification = InternalNotification::get() ->filter([ 'ID' => $ID, 'ToID' => $member->ID ])->first(); if ($notification) { if (!$notification->IsSeen) { $notification->IsSeen = true; $notification->write(); } return true; } } return false; } } |