Alert
in package
An abstract class that defines Admin Alerts for CMSMS.
Admin alerts have a name, priority, title, message, a timestamp and can optionally refer to a module. Methods are used to test if a module is for a specific user, and to format the message.
Alerts are stored as preferences in the database. If the name is the name of the class or something else that is not data or time dependant the only one instance of that alert can be stored in the database. This class usses the ArrayAccess interface to behave like a PHP array.
Tags
Table of Contents
Constants
- PRIORITY_HIGH = '_high'
- High priority
- PRIORITY_LOW = '_low'
- Low/Simple priority
- PRIORITY_NORMAL = '_normal'
- Normal priority
Methods
- __construct() : mixed
- Constructor.
- __get() : mixed
- PHP's magic __get method.
- __set() : mixed
- PHP's magic __set method.
- delete() : mixed
- Delete this alert from the database.
- get_icon() : string
- Return the URL for an iconf or this alert.
- get_message() : string
- Return the message for this alert.
- get_prefname() : string
- Get the name of the preference that this alert will be stored as.
- get_title() : mixed
- Return the title for this alert
- load_all() : mixed
- Load all known alerts from the database.
- load_by_name() : Alert
- Given an alert preference name, load it from the database.
- load_my_alerts() : array<string|int, Alert>
- Load all alerts that are suitable for the specified user id.
- save() : mixed
- Save an alert object to the database.
- decode_object() : Alert
- Decode a serialized object read from the database.
- encode_object() : string
- Encode an alert into a format suitable for storing
- get_fixed_prefname() : mixed
- is_for() : bool
- Test if this alert is suitable for a specified admin uid
Constants
PRIORITY_HIGH
High priority
public
mixed
PRIORITY_HIGH
= '_high'
PRIORITY_LOW
Low/Simple priority
public
mixed
PRIORITY_LOW
= '_low'
PRIORITY_NORMAL
Normal priority
public
mixed
PRIORITY_NORMAL
= '_normal'
Methods
__construct()
Constructor.
public
__construct() : mixed
Initialize the name to a unique name, the priority to normal, and the creaed time.
__get()
PHP's magic __get method.
public
__get(string $key) : mixed
Programmers can get the name, module, priority and title. If an unknown key is provided an exception thrown.
Parameters
- $key : string
Tags
__set()
PHP's magic __set method.
public
__set(string $key, string $val) : mixed
Progrramers can modify the name, module, priority, and title of the alert. Alerts can only be modified before the object is stored in the database. Not afterwards. If an unknown key, or invalid priority is provided then an exception is thrown.
Parameters
- $key : string
- $val : string
Tags
delete()
Delete this alert from the database.
public
delete() : mixed
get_icon()
Return the URL for an iconf or this alert.
public
abstract get_icon() : string
Tags
Return values
stringget_message()
Return the message for this alert.
public
abstract get_message() : string
Tags
Return values
stringget_prefname()
Get the name of the preference that this alert will be stored as.
public
get_prefname([string $name = null ]) : string
Parameters
- $name : string = null
-
optionaly provide a name for the alert. If not specified the current alert name will be used.
Return values
stringget_title()
Return the title for this alert
public
abstract get_title() : mixed
Tags
load_all()
Load all known alerts from the database.
public
static load_all() : mixed
return Alert[]
load_by_name()
Given an alert preference name, load it from the database.
public
static load_by_name(string $name[, mixed $throw = true ]) : Alert
Parameters
- $name : string
-
The preference name
- $throw : mixed = true
Tags
Return values
Alertload_my_alerts()
Load all alerts that are suitable for the specified user id.
public
static load_my_alerts([int|null $uid = null ]) : array<string|int, Alert>
Parameters
- $uid : int|null = null
-
The admin userid to test for. If no uid is specified, the currently logged in admin user id is used.
Return values
array<string|int, Alert>save()
Save an alert object to the database.
public
save() : mixed
Tags
decode_object()
Decode a serialized object read from the database.
protected
static decode_object(string $serialized) : Alert
Parameters
- $serialized : string
-
A serialized array, containing an optional module name that must be loaded and the serialized alert object.
Return values
Alertencode_object()
Encode an alert into a format suitable for storing
protected
static encode_object(Alert $obj) : string
Parameters
- $obj : Alert
-
The object to be ecoded.
Return values
string —A serialized array, containing an optional module name that must be loaded, and the serrialized alert object.
get_fixed_prefname()
protected
static get_fixed_prefname(mixed $name) : mixed
Parameters
- $name : mixed
is_for()
Test if this alert is suitable for a specified admin uid
protected
abstract is_for(int $admin_uid) : bool
Parameters
- $admin_uid : int