SimpleAlert View code

Extends \CMSMS\AdminAlerts\Alert

The SimpleAlert class is a type of alert that allows the developer to create alerts with pre-defined titles, messages, icons, and permissions.

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.

since 2.2
package

CMS

license

GPL

author

Robert Campbell (calguy1000@cmsmadesimple.org)

prop

string[] $perms An array of permission names. The logged in user must have at least one of these permissions to see the alert.

prop

string $icon The complete URL to an icon to associate with this alert

prop

string $msg The message to display. Note: Since alerts are stored in the database, and can be created asynchronously you cannot rely on language strings for the message or title when using this class.

Methods

__construct() 

Constructor.

inherited

Initialize the name to a unique name, the priority to normal, and the creaed time.

__get(string $key) : \CMSMS\AdminAlerts\string;

PHP's magic __get method.

inherited

Programmers can get the name, module, priority and title. If an unknown key is provided an exception thrown.

Arguments

string $key

Response

\CMSMS\AdminAlerts\string;

__set(string $key, string $val) 

PHP's magic __set method.

inherited

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.

Arguments

string $key

string $val

is_for(integer $admin_uid) : boolean

Test if this alert is suitable for a specified admin uid

inherited abstract

Arguments

integer $admin_uid

Response

boolean

get_title() 

Return the title for this alert

inherited abstract
get_message() : string

Return the message for this alert.

inherited abstract

Response

string

get_icon() : string

Return the URL for an iconf or this alert.

inherited abstract

Response

string

get_prefname(string $name = null) : string

Get the name of the preference that this alert will be stored as.

inherited

Arguments

string $name

optionaly provide a name for the alert. If not specified the current alert name will be used.

Response

string

decode_object(string $serialized) : \CMSMS\AdminAlerts\Alert

Decode a serialized object read from the database.

inherited static

Arguments

string $serialized

A serialized array, containing an optional module name that must be loaded and the serialized alert object.

Response

\CMSMS\AdminAlerts\Alert

encode_object(\CMSMS\AdminAlerts\Alert $obj) : string

Encode an alert into a format suitable for storing

inherited static

Arguments

\CMSMS\AdminAlerts\Alert $obj

The object to be ecoded.

Response

string

A serialized array, containing an optional module name that must be loaded, and the serrialized alert object.

load_by_name(string $name) : \CMSMS\AdminAlerts\Alert

Given an alert preference name, load it from the database.

inherited static

Arguments

string $name

The preference name

Response

\CMSMS\AdminAlerts\Alert

load_all() 

Load all known alerts from the database.

inherited static

return Alert[]

load_my_alerts(integer|null $uid = null) : array<mixed,\CMSMS\AdminAlerts\Alert>

Load all alerts that are suitable for the specified user id.

inherited static

Arguments

integer|null $uid

The admin userid to test for. If no uid is specified, the currently logged in admin user id is used.

Response

array<mixed,\CMSMS\AdminAlerts\Alert>

save() 

Save an alert object to the database.

inherited
delete() 

Delete this alert from the database.

inherited

Constants

High priority

PRIORITY_HIGH
inherited

Normal priority

PRIORITY_NORMAL
inherited

Low/Simple priority

PRIORITY_LOW
inherited