Notify
in package
Uses
BackwardCompatibility
This abstract class contains the main functionality to toggle email notification preferences for topics, boards and announcements.
It is extended by concrete classes that deal with each of those.
Mods can add support for more notification types by extending this class.
Table of Contents
Constants
- MODE_ALERT = 2
- MODE_BOTH = 3
- MODE_IGNORE = 0
- MODE_NO_ALERT = -1
- MODE_NO_EMAIL = -2
- MODE_NONE = 1
- PREF_ALERT = 1
- PREF_BOTH = 3
- PREF_EMAIL = 2
- PREF_NONE = 0
Properties
- $type : string
- $alert_pref : int
- $id : int
- $member_info : array<string|int, mixed>
- $mode : int
- $token : string
- $backcompat : array<string|int, mixed>
Methods
- createUnsubscribeToken() : string
- Builds an unsubscribe token.
- deleteNotifyPrefs() : mixed
- Deletes notification preference.
- execute() : void
- Dispatcher to whichever sub-action method is necessary.
- exportStatic() : void
- Provides a way to export a class's public static properties and methods to global namespace.
- getMemberWithToken() : array<string|int, mixed>
- Verifies a member's unsubscribe token, then returns some member info.
- getNotifyPrefs() : array<string|int, mixed>
- Fetches the list of preferences (or a single/subset of preferences) for notifications for one or more users.
- setNotifyPrefs() : mixed
- Sets the list of preferences for a single user.
- ask() : mixed
- askTemplateData() : mixed
- Sets any additional data needed for the ask template.
- changeBoardTopicPref() : mixed
- Updates notification preferences for the board or topic.
- changePref() : mixed
- Updates the notification preference in the database.
- getSuccessMsg() : mixed
- Gets the success message to display.
- prepareAjaxResponse() : mixed
- Adds some stuff to Utils::$context for AJAX output.
- saToMode() : mixed
- Converts $_GET['sa'] to $_GET['mode'].
- setAlertPref() : mixed
- Sets $this->alert_pref.
- setId() : mixed
- For board and topic, make sure we have the necessary ID.
- setMemberInfo() : mixed
- Sets $this->member_info with info about the member in question.
- setMode() : mixed
- Sets $this->mode.
- showConfirmation() : mixed
- Shows a confirmation message.
Constants
MODE_ALERT
public
mixed
MODE_ALERT
= 2
MODE_BOTH
public
mixed
MODE_BOTH
= 3
MODE_IGNORE
public
mixed
MODE_IGNORE
= 0
MODE_NO_ALERT
public
mixed
MODE_NO_ALERT
= -1
MODE_NO_EMAIL
public
mixed
MODE_NO_EMAIL
= -2
MODE_NONE
public
mixed
MODE_NONE
= 1
PREF_ALERT
public
mixed
PREF_ALERT
= 1
PREF_BOTH
public
mixed
PREF_BOTH
= 3
PREF_EMAIL
public
mixed
PREF_EMAIL
= 2
PREF_NONE
public
mixed
PREF_NONE
= 0
Properties
$type
public
string
$type
The notification type that this action handles.
$alert_pref
protected
int
$alert_pref
Preference value to save to the table.
$id
protected
int
$id
ID of the topic or board.
$member_info
protected
array<string|int, mixed>
$member_info
Information about the user whose notifications preferences are changing. Will include ID number and email address.
$mode
protected
int
$mode
Requested notification mode.
$token
protected
string
$token
The unsubscribe token that the user supplied, if any.
$backcompat
private
static array<string|int, mixed>
$backcompat
= ['func_names' => ['getNotifyPrefs' => 'getNotifyPrefs', 'setNotifyPrefs' => 'setNotifyPrefs', 'deleteNotifyPrefs' => 'deleteNotifyPrefs', 'getMemberWithToken' => 'getMemberWithToken', 'createUnsubscribeToken' => 'createUnsubscribeToken']]
BackwardCompatibility settings for this class.
Methods
createUnsubscribeToken()
Builds an unsubscribe token.
public
static createUnsubscribeToken(int $memID, string $email[, string $type = '' ][, int $itemID = 0 ]) : string
Parameters
- $memID : int
-
The id of the member that this token is for
- $email : string
-
The member's email address
- $type : string = ''
-
The type of notification the token is for (e.g. 'board', 'topic', etc.)
- $itemID : int = 0
-
The id of the notification item, if applicable.
Return values
string —The unsubscribe token
deleteNotifyPrefs()
Deletes notification preference.
public
static deleteNotifyPrefs(int $memID, array<string|int, mixed> $prefs) : mixed
Parameters
- $memID : int
-
The user whose preference you're setting
- $prefs : array<string|int, mixed>
-
The preferences to delete
execute()
Dispatcher to whichever sub-action method is necessary.
public
execute() : void
exportStatic()
Provides a way to export a class's public static properties and methods to global namespace.
public
static exportStatic() : void
To do so:
- Use this trait in the class.
- At the END of the class's file, call its exportStatic() method.
Although it might not seem that way at first glance, this approach conforms to section 2.3 of PSR 1, since executing this method is simply a dynamic means of declaring functions when the file is included; it has no other side effects.
Regarding the $backcompat items:
A class's static properties are not exported to global variables unless explicitly included in $backcompat['prop_names']. Likewise, a class's static methods are not exported as global functions unless explicitly included in $backcompat['func_names'].
$backcompat['prop_names'] is a simple array where the keys are the names of one or more of a class's static properties, and the values are the names of global variables. In each case, the global variable will be set to a reference to the static property. Static properties that are not named in this array will not be exported.
$backcompat['func_names'] is a simple array where the keys are the names of one or more of a class's static methods, and the values are the names that should be used for global functions that will encapsulate those methods. Methods that are not named in this array will not be exported.
Adding non-static properties or methods to the $backcompat arrays will produce runtime errors. It is the responsibility of the developer to make sure not to do this.
getMemberWithToken()
Verifies a member's unsubscribe token, then returns some member info.
public
static getMemberWithToken(string $type) : array<string|int, mixed>
Parameters
- $type : string
-
The type of notification the token is for (e.g. 'board', 'topic', etc.)
Return values
array<string|int, mixed> —The id and email address of the specified member
getNotifyPrefs()
Fetches the list of preferences (or a single/subset of preferences) for notifications for one or more users.
public
static getNotifyPrefs(int|array<string|int, mixed> $members[, string|array<string|int, mixed> $prefs = '' ][, bool $process_default = false ]) : array<string|int, mixed>
Parameters
- $members : int|array<string|int, mixed>
-
A user id or an array of (integer) user ids to load preferences for
- $prefs : string|array<string|int, mixed> = ''
-
An empty string to load all preferences, or a string (or array) of preference name(s) to load
- $process_default : bool = false
-
Whether to apply the default values to the members' values or not.
Return values
array<string|int, mixed> —An array of user ids => array (pref name -> value), with user id 0 representing the defaults
setNotifyPrefs()
Sets the list of preferences for a single user.
public
static setNotifyPrefs(int $memID[, array<string|int, mixed> $prefs = [] ]) : mixed
Parameters
- $memID : int
-
The user whose preferences you are setting
- $prefs : array<string|int, mixed> = []
-
An array key of pref -> value
ask()
protected
ask() : mixed
askTemplateData()
Sets any additional data needed for the ask template.
protected
abstract askTemplateData() : mixed
changeBoardTopicPref()
Updates notification preferences for the board or topic.
protected
changeBoardTopicPref() : mixed
changePref()
Updates the notification preference in the database.
protected
abstract changePref() : mixed
getSuccessMsg()
Gets the success message to display.
protected
abstract getSuccessMsg() : mixed
prepareAjaxResponse()
Adds some stuff to Utils::$context for AJAX output.
protected
prepareAjaxResponse() : mixed
saToMode()
Converts $_GET['sa'] to $_GET['mode'].
protected
abstract saToMode() : mixed
sa=on/off is used for email subscribe/unsubscribe links.
setAlertPref()
Sets $this->alert_pref.
protected
setAlertPref() : mixed
setId()
For board and topic, make sure we have the necessary ID.
protected
abstract setId() : mixed
setMemberInfo()
Sets $this->member_info with info about the member in question.
protected
setMemberInfo() : mixed
setMode()
Sets $this->mode.
protected
setMode() : mixed
showConfirmation()
Shows a confirmation message.
protected
showConfirmation() : mixed