Elgg  Version master
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
Elgg\Notifications\NotificationsService Class Reference

Notifications service. More...

Public Member Functions

 __construct (protected Queue $queue, protected \ElggSession $session, protected EventsService $elgg_events)
 Constructor. More...
 
 registerEvent (string $type, string $subtype, string $action='create', string $handler=NotificationEventHandler::class)
 Register a notification event. More...
 
 unregisterEvent (string $type, string $subtype, string $action='create', string $handler=NotificationEventHandler::class)
 Unregister a notification event. More...
 
 getEvents ()
 Return the notification events. More...
 
 registerMethod (string $name)
 Register a delivery method for notifications. More...
 
 unregisterMethod (string $name)
 Unregister a delivery method for notifications. More...
 
 getMethods ()
 Returns registered delivery methods for notifications. More...
 
 isRegisteredMethod (string $method)
 Check if a notification method is registed. More...
 
 enqueueEvent (string $action, \ElggData $object, ?\ElggEntity $actor=null)
 Add a notification event to the queue. More...
 
 processQueue (int $stopTime)
 Pull notification events from queue until stop time is reached. More...
 
 sendInstantNotifications (\ElggEntity $sender, array $recipients=[], array $params=[])
 Notify a user via their preferences. More...
 
 sendInstantNotification (\ElggUser $recipient, string $action, \ElggData $subject, array $params=[], ?\ElggEntity $from=null)
 Send an instant notification to a user. More...
 

Protected Member Functions

 getSubscriptionHandlers (string $type, string $subtype, string $action)
 Get the subscription notification handlers. More...
 
 getInstantHandlers (string $type, string $subtype, string $action)
 Get the instant notification handlers. More...
 

Protected Attributes

array $events = []
 
array $methods = []
 

Detailed Description

Notifications service.

Definition at line 16 of file NotificationsService.php.

Constructor & Destructor Documentation

◆ __construct()

Elgg\Notifications\NotificationsService::__construct ( protected Queue  $queue,
protected \ElggSession  $session,
protected EventsService  $elgg_events 
)

Constructor.

Parameters
Queue$queueQueue
\ElggSession$sessionSession service
EventsService$elgg_eventsEvents service

Definition at line 33 of file NotificationsService.php.

Member Function Documentation

◆ enqueueEvent()

Elgg\Notifications\NotificationsService::enqueueEvent ( string  $action,
\ElggData  $object,
?\ElggEntity  $actor = null 
)

Add a notification event to the queue.

Parameters
string$actionAction name
\ElggData$objectThe object of the action
null | \ElggEntity$actor(optional) The actor of the notification (default: logged-in user or owner of $object)
Returns
void

Definition at line 178 of file NotificationsService.php.

◆ getEvents()

Elgg\Notifications\NotificationsService::getEvents ( )

Return the notification events.

Returns
array

Definition at line 116 of file NotificationsService.php.

◆ getInstantHandlers()

Elgg\Notifications\NotificationsService::getInstantHandlers ( string  $type,
string  $subtype,
string  $action 
)
protected

Get the instant notification handlers.

Parameters
string$type'object', 'user', 'group', 'site'
string$subtypeThe subtype of the entity
string$actionThe notification action
Returns
array

Definition at line 241 of file NotificationsService.php.

◆ getMethods()

Elgg\Notifications\NotificationsService::getMethods ( )

Returns registered delivery methods for notifications.

Returns
string[]
See also
elgg_get_notification_methods()

Definition at line 154 of file NotificationsService.php.

◆ getSubscriptionHandlers()

Elgg\Notifications\NotificationsService::getSubscriptionHandlers ( string  $type,
string  $subtype,
string  $action 
)
protected

Get the subscription notification handlers.

Parameters
string$type'object', 'user', 'group', 'site'
string$subtypeThe subtype of the entity
string$actionThe notification action
Returns
array

Definition at line 215 of file NotificationsService.php.

◆ isRegisteredMethod()

Elgg\Notifications\NotificationsService::isRegisteredMethod ( string  $method)

Check if a notification method is registed.

Parameters
string$methodthe notification method
Returns
bool

Definition at line 165 of file NotificationsService.php.

◆ processQueue()

Elgg\Notifications\NotificationsService::processQueue ( int  $stopTime)

Pull notification events from queue until stop time is reached.

Parameters
int$stopTimeThe Unix time to stop sending notifications
Returns
int The number of notification events handled

Definition at line 273 of file NotificationsService.php.

◆ registerEvent()

Elgg\Notifications\NotificationsService::registerEvent ( string  $type,
string  $subtype,
string  $action = 'create',
string  $handler = NotificationEventHandler::class 
)

Register a notification event.

Parameters
string$type'object', 'user', 'group', 'site'
string$subtypeThe subtype or name of the entity
string$actionAn event is usually described by the first string passed to elgg_trigger_event(). Examples include 'create', 'update', and 'publish' (default: 'create').
string$handlerNotificationEventHandler classname
Returns
void
Exceptions
InvalidArgumentException
See also
elgg_register_notification_event()

Definition at line 53 of file NotificationsService.php.

◆ registerMethod()

Elgg\Notifications\NotificationsService::registerMethod ( string  $name)

Register a delivery method for notifications.

Parameters
string$nameThe notification method name
Returns
void
See also
elgg_register_notification_method()

Definition at line 128 of file NotificationsService.php.

◆ sendInstantNotification()

Elgg\Notifications\NotificationsService::sendInstantNotification ( \ElggUser  $recipient,
string  $action,
\ElggData  $subject,
array  $params = [],
?\ElggEntity  $from = null 
)

Send an instant notification to a user.

Parameters
\ElggUser$recipientThe recipient user
string$actionThe action on $subject
\ElggData$subjectThe notification subject
array$paramsAdditional params use $params['methods_override'] to override the recipient notification methods (eg 'email' or 'site')
null | \ElggEntity$fromSender of the message
Returns
array
Since
6.3

Definition at line 383 of file NotificationsService.php.

◆ sendInstantNotifications()

Elgg\Notifications\NotificationsService::sendInstantNotifications ( \ElggEntity  $sender,
array  $recipients = [],
array  $params = [] 
)

Notify a user via their preferences.

Returns an array in the form: [ 25 => [ 'email' => true, 'sms' => false, ], 55 => [], ]

Parameters
\ElggEntity$senderSender of the notification
\ElggUser[]$recipientsAn array of entities to notify
array$paramsNotification parameters

@uses $params['subject'] string Default message subject @uses $params['body'] string Default message body @uses $params['object'] null|\ElggEntity|\ElggAnnotation The object that is triggering the notification. @uses $params['action'] null|string Word that describes the action that is triggering the notification (e.g. "create" or "update"). Defaults to "notify_user" @uses $params['summary'] null|string Summary that notification plugins can use alongside the notification title and body. @uses $params['methods_override'] string|array A string, or an array of strings specifying the delivery methods to use - or leave blank for delivery using the user's chosen delivery methods.

Returns
array

Definition at line 354 of file NotificationsService.php.

◆ unregisterEvent()

Elgg\Notifications\NotificationsService::unregisterEvent ( string  $type,
string  $subtype,
string  $action = 'create',
string  $handler = NotificationEventHandler::class 
)

Unregister a notification event.

Parameters
string$type'object', 'user', 'group', 'site'
string$subtypeThe subtype of the entity
string$actionThe notification action to unregister (default: 'create')
string$handlerNotificationEventHandler class to unregister
Returns
void
See also
elgg_unregister_notification_event()

Definition at line 88 of file NotificationsService.php.

◆ unregisterMethod()

Elgg\Notifications\NotificationsService::unregisterMethod ( string  $name)

Unregister a delivery method for notifications.

Parameters
string$nameThe notification method name
Returns
void
See also
elgg_unregister_notification_method()

Definition at line 140 of file NotificationsService.php.

Member Data Documentation

◆ $events

array Elgg\Notifications\NotificationsService::$events = []
protected

Definition at line 21 of file NotificationsService.php.

◆ $methods

array Elgg\Notifications\NotificationsService::$methods = []
protected

Definition at line 24 of file NotificationsService.php.


The documentation for this class was generated from the following file: