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

Subscription service. More...

Public Member Functions

 __construct (protected Database $db, protected RelationshipsTable $relationshipsTable, protected EventsService $events)
 Constructor. More...
 
 getNotificationEventSubscriptions (NotificationEvent $event, array $methods, array $exclude_guids_for_records=[])
 Get the subscriptions for this notification event. More...
 
 getSubscriptionsForContainer (int $container_guid, array $methods, string $type=null, string $subtype=null, string $action=null, int $actor_guid=0)
 Get the subscriptions for the content created inside this container. More...
 
 addSubscription (int $user_guid, string $method, int $target_guid, string $type=null, string $subtype=null, string $action=null)
 Subscribe a user to notifications about a target entity. More...
 
 hasSubscription (int $user_guid, string $method, int $target_guid, string $type=null, string $subtype=null, string $action=null)
 Check if a subscription exists. More...
 
 hasSubscriptions (int $user_guid, int $target_guid, array $methods=[])
 Check if any subscription exists. More...
 
 removeSubscription (int $user_guid, string $method, int $target_guid, string $type=null, string $subtype=null, string $action=null)
 Unsubscribe a user to notifications about a target entity. More...
 
 removeSubscriptions (int $user_guid, int $target_guid, array $methods=[])
 Unsubscribe a user from all notifications about the target entity. More...
 
 getSubscribers (int $target_guid, array $methods=[])
 Get all subscribers of the target guid. More...
 
 getEntitySubscriptions (int $target_guid=0, int $user_guid=0, array $methods=[], string $type=null, string $subtype=null, string $action=null)
 Get the current subscriptions for the given entity. More...
 
 muteNotifications (int $user_guid, int $target_guid)
 Mute notifications about events affecting the target. More...
 
 unmuteNotifications (int $user_guid, int $target_guid)
 No longer nute notifications about events affecting the target. More...
 
 hasMutedNotifications (int $user_guid, int $target_guid)
 Check if the user has notifications muted about events affecting the target. More...
 
 filterSubscriptions (array $subscriptions, NotificationEvent $event, bool $filter_muted=true)
 Apply filtering to subscriptions, like muted notifications etc. More...
 

Public Attributes

const RELATIONSHIP_PREFIX = 'notify'
 
const MUTE_NOTIFICATIONS_RELATIONSHIP = 'mute_notifications'
 

Protected Member Functions

 filterMutedNotifications (array $subscriptions, NotificationEvent $event)
 Filter subscriptions based on muted notification settings related to the notification event. More...
 
 filterDelayedEmailSubscribers (array $subscriptions)
 When a user has both 'email' and 'delayed_email' subscription remove the delayed email as it would be a duplicate. More...
 
 filterTimedMutedSubscribers (array $subscriptions)
 Filter users who have set a period in which not to receive notifications. More...
 
 getSubscriptionRecords (array $container_guid, array $methods, string $type=null, string $subtype=null, string $action=null, int $actor_guid=0)
 Get subscription records from the database. More...
 
 getMethodRelationships (array $methods, string $type=null, string $subtype=null, string $action=null)
 Get the relationship names for notifications. More...
 
 assertValidTypeSubtypeActionForSubscription ($type, $subtype, $action)
 Validate subscription input for type, subtype and action. More...
 

Detailed Description

Subscription service.

Definition at line 20 of file SubscriptionsService.php.

Constructor & Destructor Documentation

Elgg\Notifications\SubscriptionsService::__construct ( protected Database  $db,
protected RelationshipsTable  $relationshipsTable,
protected EventsService  $events 
)

Constructor.

Parameters
Database$dbDatabase service
RelationshipsTable$relationshipsTableRelationship database table
EventsService$eventsEvents service

Definition at line 39 of file SubscriptionsService.php.

Member Function Documentation

Elgg\Notifications\SubscriptionsService::addSubscription ( int  $user_guid,
string  $method,
int  $target_guid,
string  $type = null,
string  $subtype = null,
string  $action = null 
)

Subscribe a user to notifications about a target entity.

This method will return false if the subscription already exists.

Parameters
int$user_guidThe GUID of the user to subscribe to notifications
string$methodThe delivery method of the notifications
int$target_guidThe entity to receive notifications about
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
Returns
bool
Exceptions
InvalidArgumentException

Definition at line 176 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::assertValidTypeSubtypeActionForSubscription (   $type,
  $subtype,
  $action 
)
protected

Validate subscription input for type, subtype and action.

Parameters
string$typeentity type
string$subtypeentity subtype
string$actionnotification action (eg. 'create')
Returns
void
Exceptions
InvalidArgumentException

Definition at line 691 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::filterDelayedEmailSubscribers ( array  $subscriptions)
protected

When a user has both 'email' and 'delayed_email' subscription remove the delayed email as it would be a duplicate.

Parameters
array$subscriptionsList of subscribers to filter
Returns
array

Definition at line 570 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::filterMutedNotifications ( array  $subscriptions,
NotificationEvent  $event 
)
protected

Filter subscriptions based on muted notification settings related to the notification event.

This filters out muted notifications based on:

Parameters
array$subscriptionsList of subscribers to filter
NotificationEvent$eventNotification event from which to get information
Returns
array

Definition at line 522 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::filterSubscriptions ( array  $subscriptions,
NotificationEvent  $event,
bool  $filter_muted = true 
)

Apply filtering to subscriptions, like muted notifications etc.

Parameters
array$subscriptionsList of subscribers to filter
NotificationEvent$eventNotification event from which to get information
bool$filter_mutedShould the muting rules be applied to the subscriptions (default: true)
Returns
array

Definition at line 491 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::filterTimedMutedSubscribers ( array  $subscriptions)
protected

Filter users who have set a period in which not to receive notifications.

Parameters
array$subscriptionsList of subscribers to filter
Returns
array

Definition at line 590 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getEntitySubscriptions ( int  $target_guid = 0,
int  $user_guid = 0,
array  $methods = [],
string  $type = null,
string  $subtype = null,
string  $action = null 
)

Get the current subscriptions for the given entity.

Parameters
int$target_guidThe GUID of the entity to get subscriptions for
int$user_guidThe GUID of the user to check subscriptions for
string$methodsThe delivery method of the notifications
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
Returns
[]
Exceptions
InvalidArgumentException

Definition at line 387 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getMethodRelationships ( array  $methods,
string  $type = null,
string  $subtype = null,
string  $action = null 
)
protected

Get the relationship names for notifications.

Parameters
array$methodsNotification methods
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
Returns
array

Definition at line 666 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getNotificationEventSubscriptions ( NotificationEvent  $event,
array  $methods,
array  $exclude_guids_for_records = [] 
)

Get the subscriptions for this notification event.

The return array is of the form:

array( <user guid>=""> => array('email', 'sms', 'ajax'), );

Parameters
NotificationEvent$eventNotification event
array$methodsNotification methods
array$exclude_guids_for_recordsGUIDs to exclude from fetching subscription records
Returns
array

Definition at line 61 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getSubscribers ( int  $target_guid,
array  $methods = [] 
)

Get all subscribers of the target guid.

Parameters
int$target_guidthe entity of the subscriptions
array$methods(optional) The delivery method of the notifications
Returns
[]

Definition at line 346 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getSubscriptionRecords ( array  $container_guid,
array  $methods,
string  $type = null,
string  $subtype = null,
string  $action = null,
int  $actor_guid = 0 
)
protected

Get subscription records from the database.

Records are an object with two vars: guid and methods with the latter being a comma-separated list of subscription relationship names.

Parameters
int[]$container_guid The GUID of the subscription target
array$methodsNotification methods
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
int$actor_guid(optional) Notification event actor to exclude from the database subscriptions
Returns
array

Definition at line 630 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::getSubscriptionsForContainer ( int  $container_guid,
array  $methods,
string  $type = null,
string  $subtype = null,
string  $action = null,
int  $actor_guid = 0 
)

Get the subscriptions for the content created inside this container.

The return array is of the form:

array( <user guid>=""> => array('email', 'sms', 'ajax'), );

Parameters
int$container_guidGUID of the entity acting as a container
array$methodsNotification methods
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
int$actor_guid(optional) Notification event actor to exclude from the database subscriptions
Returns
array User GUIDs (keys) and their subscription types (values).

Definition at line 131 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::hasMutedNotifications ( int  $user_guid,
int  $target_guid 
)

Check if the user has notifications muted about events affecting the target.

Parameters
int$user_guidThe GUID of the user to check muted notifcations for
int$target_guidThe GUID of the entity to for which to check muted notifications
Returns
bool

Definition at line 478 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::hasSubscription ( int  $user_guid,
string  $method,
int  $target_guid,
string  $type = null,
string  $subtype = null,
string  $action = null 
)

Check if a subscription exists.

Parameters
int$user_guidThe GUID of the user to check subscriptions for
string$methodThe delivery method of the notifications
int$target_guidThe entity to receive notifications about
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
Returns
bool
Exceptions
InvalidArgumentException
Since
4.0

Definition at line 215 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::hasSubscriptions ( int  $user_guid,
int  $target_guid,
array  $methods = [] 
)

Check if any subscription exists.

Parameters
int$user_guidThe GUID of the user to check subscriptions for
int$target_guidThe entity to receive notifications about
array$methodsThe delivery method of the notifications
Returns
bool
Since
4.0

Definition at line 243 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::muteNotifications ( int  $user_guid,
int  $target_guid 
)

Mute notifications about events affecting the target.

Parameters
int$user_guidThe GUID of the user to mute notifcations for
int$target_guidThe GUID of the entity to for which to mute notifications
Returns
bool

Definition at line 451 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::removeSubscription ( int  $user_guid,
string  $method,
int  $target_guid,
string  $type = null,
string  $subtype = null,
string  $action = null 
)

Unsubscribe a user to notifications about a target entity.

Parameters
int$user_guidThe GUID of the user to unsubscribe to notifications
string$methodThe delivery method of the notifications to stop
int$target_guidThe entity to stop receiving notifications about
string$type(optional) entity type
string$subtype(optional) entity subtype
string$action(optional) notification action (eg. 'create')
Returns
bool
Exceptions
InvalidArgumentException

Definition at line 285 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::removeSubscriptions ( int  $user_guid,
int  $target_guid,
array  $methods = [] 
)

Unsubscribe a user from all notifications about the target entity.

Parameters
int$user_guidThe GUID of the user to unsubscribe to notifications
int$target_guidThe entity to stop receiving notifications about
array$methods(optional) The delivery method of the notifications to stop
Returns
bool
Since
4.0

Definition at line 318 of file SubscriptionsService.php.

Elgg\Notifications\SubscriptionsService::unmuteNotifications ( int  $user_guid,
int  $target_guid 
)

No longer nute notifications about events affecting the target.

Parameters
int$user_guidThe GUID of the user to unmute notifcations for
int$target_guidThe GUID of the entity to for which to unmute notifications
Returns
bool

Definition at line 466 of file SubscriptionsService.php.

Member Data Documentation

const Elgg\Notifications\SubscriptionsService::MUTE_NOTIFICATIONS_RELATIONSHIP = 'mute_notifications'

Definition at line 30 of file SubscriptionsService.php.

const Elgg\Notifications\SubscriptionsService::RELATIONSHIP_PREFIX = 'notify'

Definition at line 25 of file SubscriptionsService.php.


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