Notification
in package
Notification class to handle sending notifications to a user or users Notifications can be alerts or emails
Tags
Table of Contents
Properties
- $_alertUrl : string|null
- $_authorId : int
- $_recipients : array<string|int, mixed>
- $_skipPurify : bool
- $_type : string
- $_types : array<string|int, mixed>
Methods
- __construct() : mixed
- Instantiate a new notification
- addType() : void
- Register a custom notification type
- getTypes() : array<string|int, mixed>
- Returns all registered notification types
- send() : void
- sendAlert() : void
- sendEmail() : void
Properties
$_alertUrl
private
string|null
$_alertUrl
= \null
$_authorId
private
int
$_authorId
$_recipients
private
array<string|int, mixed>
$_recipients
= []
$_skipPurify
private
bool
$_skipPurify
$_type
private
string
$_type
$_types
private
static array<string|int, mixed>
$_types
= []
Methods
__construct()
Instantiate a new notification
public
__construct(string $type, string|LanguageKey $title, string|LanguageKey $content, int|array<string|int, int> $recipients, int $authorId[, callable|null $contentCallback = null ][, bool $skipPurify = false ][, string|null $alertUrl = null ]) : mixed
Parameters
- $type : string
-
Type of notification
- $title : string|LanguageKey
-
Title of notification
- $content : string|LanguageKey
-
Notification content. For alerts, if $alertUrl is set, this will ignored. If $alertUrl is not set, this will be the content of the alert. This will always be the content of the email.
- $recipients : int|array<string|int, int>
-
Notification recipient or recipients - array of user IDs
- $authorId : int
-
User ID that sent the notification
- $contentCallback : callable|null = null
-
Optional callback to perform for each recipient's content
- $skipPurify : bool = false
-
Whether to skip content purifying, default false
- $alertUrl : string|null = null
-
Optional URL to link to when clicking the alert
Tags
addType()
Register a custom notification type
public
static addType(string $type, string $value[, array<string|int, mixed> $defaultPreferences = [] ]) : void
Parameters
- $type : string
- $value : string
-
Human-readable
- $defaultPreferences : array<string|int, mixed> = []
-
Set of default preferences in form preferenceKey => true/false
getTypes()
Returns all registered notification types
public
static getTypes() : array<string|int, mixed>
Return values
array<string|int, mixed>send()
public
send() : void
sendAlert()
private
sendAlert(int $userId, string $title, string $content) : void
Parameters
- $userId : int
- $title : string
- $content : string
sendEmail()
private
sendEmail(int $userId, string $title, string $content) : void
Parameters
- $userId : int
- $title : string
- $content : string