abstract class vB_Notification_Content extends vB_Notification

Traits

Constants

RECIPIENT_KEY_PREFIX

GUESTS_CAN_SEND

GROUP_CHILDREN

TYPENAME

REGEX_ALLOWED_TYPENAME

DELIM

FCM_SUPPORTED

Properties

protected $notificationData from vB_Notification
protected $recipients from vB_Notification
static protected $triggers from vB_Notification
static protected $updateEvents
static $recipientsInfoCache from vB_Notification
protected array $validSourceContentTypes Content types that will be allowed to send notifications. from vB_Notification
protected array $validSourceChannelTypes Channel types that will be allowed to send notifications. from vB_Notification

Methods

__sleep()

No description

__wakeup()

No description

__construct($trigger = '', $notificationData = array(), $recipients = array())

No description

static String|NULL
getHashedLookupid(String $lookupid)

Returns the md5() of the $lookupid or NULL if $lookupid is empty.

Array[String]
getNotificationData()

Returns the notification data.

Int[]
getRecipients()

Returns the array of recipients to receive this notification

Array[int]
getCachedRecipientData()

Returns the memory cached array of recipients' information like email, languageid etc.

cancelNotification()

No description

static 
validateUpdateEvent($event)

No description

static 
handleUpdateEvents(String $event, Array $eventData)

Handle update/dismiss events. The required data in $eventData depends on the particular event.

String
overwriteRule()

If there is an existing notification for a recipient (judged by comparing the lookupid), this function guides whether the new notification should overwrite the old one. Coder may want to consider checking for $this->notificationData['trigger'] for a more complex handling for different triggers.

Int[Int]
validateProvidedRecipients(Int[] $recipients)

Ensures that the recipients list is unique. Subclasses may perform additional validation and unset certain recipients as necessary.

validateAndCleanNotificationData($notificationData)

Validates the notification data, checks the context to see if we should send this notification type, and throws exceptions if we should not or cannot send this notification type. If all is okay, it may set additional notification data specific to this notification type.

validateSourceContentType(int $nodecontenttypeid)

Checks the source node content type and throws an exception if it is not allowed to send a notification.

validateSourceChannelType(string $nodechanneltype)

Checks the source channel type and throws an exception if it is not allowed to send a notification.

setRecipients(Int[] $recipients = array())

Set the recipients array. Goes through the provided list of userids, removes the sender, any recipients that are ignoring the sender, & any duplicates before setting the remaining list to the $this->recipients instance variable.

filterRecipients()

Child may override this to set specific rules on how to filter out recipients (e.g. view permissions, friend status, etc).

Int[]
addAdditionalRecipients()

Only subclasses know which users it should automatically add to the recipients list.

checkIfSenderCanSend($sender)

No description

Bool
checkExtraPermissionsForSender($sender)

Check any additional permissions that are specific to the notification type.

removeOptOuts()

Remove any recipient in $this->recipients who is ignoring the sender.

Bool
typeEnabledForUser(Array $user)

Returns False if user opted out of this notification type.

static 
getTriggers()

No description

static 
getUpdateEvents()

No description

removeIgnoringRecipients()

Remove any recipient in $this->recipients who is ignoring the sender.

static String|NULL
fetchLookupid(Array $notificationData, Bool $skipValidation = false)

Fetch the lookupid based on the defineUnique() function & the class's "address".

static String[String]
defineUnique($notificationData, $skipValidation)

This function defines what makes 2 notifications of this TYPE sent to, or belonging to a single recipient distinct or duplicates.

static 
clearMemory()

No description

static Array
fetchPhraseArray(Array $notificationData)

Returns the phrase data used by privatemessage_notificationdetail template to render the individual notification.

static String
generateNotificationQueueKey(Array $notificationData)

This function allows "collisions" to occur to limit or allow multiple notifications to a recipient.

static 
getFCMExtraData($data, $languageids)

No description

static String|Bool
renderEmailPhrases(Array $data)

Returns the rendered phrase used in notification emails for this type.

Details

in vB_Trait_NoSerialize at line 15
__sleep()

in vB_Trait_NoSerialize at line 20
__wakeup()

in vB_Notification at line 126
final __construct($trigger = '', $notificationData = array(), $recipients = array())

Parameters

$trigger
$notificationData
$recipients

in vB_Notification at line 228
final static String|NULL getHashedLookupid(String $lookupid)

Returns the md5() of the $lookupid or NULL if $lookupid is empty.

Parameters

String $lookupid

Return Value

String|NULL 32 character string or NULL.

in vB_Notification at line 250
final Array[String] getNotificationData()

Returns the notification data.

Return Value

Array[String] Notification data including - int|NULL sender - string|NULL lookupid - int|NULL sentbynodeid - string typename - int lastsenttime - string trigger - int priority

in vB_Notification at line 260
final Int[] getRecipients()

Returns the array of recipients to receive this notification

Return Value

Int[] Recipients.

in vB_Notification at line 276
final Array[int] getCachedRecipientData()

Returns the memory cached array of recipients' information like email, languageid etc.

Return Value

Array[int] Nested array of user data keyed by userid. Each subarray holds an individual recipient's data including: - string 'email' - string 'username' - int 'languageid' - int 'emailnotification'

in vB_Notification at line 281
final protected checkExistingNotifications()

in vB_Notification at line 325
final protected cancelNotification()

in vB_Notification at line 331
final static protected validateUpdateEvent($event)

Parameters

$event

in vB_Notification at line 359
static handleUpdateEvents(String $event, Array $eventData)

Handle update/dismiss events. The required data in $eventData depends on the particular event.

Children may also handle their specific events.

Parameters

String $event One of the event strings in static::$updateEvents
Array $eventData When $event is 'read_topic'|'read_channel', expects: int 'nodeid' int 'userid' (Optional)

at line 107
protected String overwriteRule()

If there is an existing notification for a recipient (judged by comparing the lookupid), this function guides whether the new notification should overwrite the old one. Coder may want to consider checking for $this->notificationData['trigger'] for a more complex handling for different triggers.

Return Value

String Must be 'always'|'if_read'|'never'. These values indicate, respectively, that the new notification should always overwrite, only overwrite if the old one is read, or never overwrite while the old one exists.

in vB_Notification at line 487
protected Int[Int] validateProvidedRecipients(Int[] $recipients)

Ensures that the recipients list is unique. Subclasses may perform additional validation and unset certain recipients as necessary.

Parameters

Int[] $recipients List of recipients provided to constructor.

Return Value

Int[Int] Userids keyed by userids

Exceptions

Exception() If for some reason this notification cannot be constructed given the context data in $notificationData. Constructor will catch the exception and cancel this notification.

at line 56
protected validateAndCleanNotificationData($notificationData)

Validates the notification data, checks the context to see if we should send this notification type, and throws exceptions if we should not or cannot send this notification type. If all is okay, it may set additional notification data specific to this notification type.

Parameters

$notificationData

Exceptions

Exception() If for some reason this notification type cannot be sent given the context data in $notificationData

in vB_Notification at line 568
protected validateSourceContentType(int $nodecontenttypeid)

Checks the source node content type and throws an exception if it is not allowed to send a notification.

Parameters

int $nodecontenttypeid Content type id for the source node

in vB_Notification at line 584
protected validateSourceChannelType(string $nodechanneltype)

Checks the source channel type and throws an exception if it is not allowed to send a notification.

Parameters

string $nodechanneltype Channel type for the source node

in vB_Notification at line 602
final protected setRecipients(Int[] $recipients = array())

Set the recipients array. Goes through the provided list of userids, removes the sender, any recipients that are ignoring the sender, & any duplicates before setting the remaining list to the $this->recipients instance variable.

Parameters

Int[] $recipients

in vB_Notification at line 663
protected filterRecipients()

Child may override this to set specific rules on how to filter out recipients (e.g. view permissions, friend status, etc).

This is in the base class because most notifications are related to a node and should check view perms on the node. Remove any recipients who cannot view the triggering node to prevent leaking data via notification emails or firebase cloud messages.

in vB_Notification at line 708
protected Int[] addAdditionalRecipients()

Only subclasses know which users it should automatically add to the recipients list.

Recipients generated by this function WILL NOT allow duplicate recipients.

Return Value

Int[] Integer list of recipients.

in vB_Notification at line 713
final protected checkIfSenderCanSend($sender)

Parameters

$sender

in vB_Notification at line 740
protected Bool checkExtraPermissionsForSender($sender)

Check any additional permissions that are specific to the notification type.

Only subclasses know what global settings or usergroup permissions it needs to check.

Parameters

$sender

Return Value

Bool Return false to abort sending this notification

in vB_Notification at line 750
final protected removeOptOuts()

Remove any recipient in $this->recipients who is ignoring the sender.

in vB_Notification at line 815
protected Bool typeEnabledForUser(Array $user)

Returns False if user opted out of this notification type.

Parameters

Array $user Expecting user table data including: - int 'userid' - int 'notification_options'

Return Value

Bool

in vB_Notification at line 820
static getTriggers()

in vB_Notification at line 825
static getUpdateEvents()

in vB_Notification at line 835
final protected removeIgnoringRecipients()

Remove any recipient in $this->recipients who is ignoring the sender.

in vB_Notification at line 883
final static String|NULL fetchLookupid(Array $notificationData, Bool $skipValidation = false)

Fetch the lookupid based on the defineUnique() function & the class's "address".

Parameters

Array $notificationData Data required by this class's defineUnique() function to generate a lookupid. Usually includes: - INT|NULL sender, - INT|NULL sentbynodeid, - String|NULL customdata
Bool $skipValidation Optional, default false. If true, defineUnique will skip any validation and assume that $notificationData is correct and that $notificationData contains all data required to create the unique key.

Return Value

String|NULL NULL only if defineUnique() returns empty string/array, indicating that this type should NEVER be grouped.

Exceptions

Exception() If fetching lookupid fails ... ... because fetching the unique prefix fails due to missing data ... TODO: finish DOCBLOCK

at line 112
static protected String[String] defineUnique($notificationData, $skipValidation)

This function defines what makes 2 notifications of this TYPE sent to, or belonging to a single recipient distinct or duplicates.

For example, you may group a notification type by the sentbynodeid and sender. In that case, you should return the following: return array( "sentbynodeid" => $notificationData['sentbynodeid'], "sender" => $notificationData['sender'], ); If every single notification of this type should be unique, just return an empty array: return array(); else if every single notification of this type should be grouped together per recipient, just return an array of constant(s): return array( "group" => "all", ); Note that if any of the specified values in the return array is EMPTY, the notification generation code will throw an exception.

Parameters

$notificationData
$skipValidation

Return Value

String[String]

in vB_Notification at line 984
final static clearMemory()

in vB_Notification at line 1005
static Array fetchPhraseArray(Array $notificationData)

Returns the phrase data used by privatemessage_notificationdetail template to render the individual notification.

Parameters

Array $notificationData Notification data required for this notification type, including - int sender - ...

Return Value

Array First element is the string phrase title, second element is an array of replacement data used by the phrase.

at line 131
static String generateNotificationQueueKey(Array $notificationData)

This function allows "collisions" to occur to limit or allow multiple notifications to a recipient.

Collisions are handled by the library based on the priority of the collided notification currently in the queue.

Parameters

Array $notificationData Notification data required for this notification type, including - int recipient - string lookupid - int priority - ...

Return Value

String Note that empty string will be considered as an "always unique" request, meaning it will allow multiple notifications to a single recipient!

in vB_Notification at line 1040
static getFCMExtraData($data, $languageids)

Parameters

$data
$languageids

in vB_Notification at line 1057
static String|Bool renderEmailPhrases(Array $data)

Returns the rendered phrase used in notification emails for this type.

Parameters

Array $data Notification data required for this notification type, including - int recipient - int languageid - string recipient_username - ... other data from getNotificationData()

Return Value

String|Bool Rendered email phrase or False if it doesn't have an email or its email goes through the legacy email function.