Notifications
in component
Notifications for administrators: the bell in the admin header (Ka Extensions adds it to the header of OpenCart 3). A module adds a notification with a code and removes it when it is not actual anymore; an administrator closes it with the cross, that deletes it.
The bell shows the notifications of the logged in administrator and the notifications for all administrators (user_id = 0). It is shown only to administrators with access to the Extensions > Ka Extensions page. The text is a ready string in the admin language made by the module, it is escaped on output (no HTML, no links).
The methods work in the admin area and in the catalog. In the catalog (and without a logged in administrator) add() stores a notification for all administrators.
Example:
use \extension\ka_extensions\Notifications;
// for all administrators, until somebody closes it or for one day
Notifications::addForAll('mymodule_daily_limit', 'My Module: the daily limit is reached.', 86400);
if (Notifications::get('mymodule_daily_limit') !== null) {
// shown now
}
Notifications::remove('mymodule_daily_limit');
The notifications are stored in the table ka_notification (created on the Ka Extensions page or on the first write).
Table of Contents
Constants
- TABLE = 'ka_notification'
Methods
- add() : mixed
- Adds a notification for the logged in administrator, it is updated when the administrator
has a notification with this code. Without a logged in administrator (e.g. in the catalog)
the notification is for all administrators, as addForAll() does. - addForAll() : mixed
- Adds a notification for all administrators (user_id = 0) or updates it. There is one
notification for everybody: when one administrator closes it, it is deleted for all. - get() : mixed
- Returns the text of the notification with this code: the one of the logged in administrator
first, then the one for all administrators. Null when there is none or it has expired. - remove() : mixed
- Removes the notification with this code of the logged in administrator and the one for all
administrators.
Constants
TABLE
public
mixed
TABLE
= 'ka_notification'
Methods
add()
Adds a notification for the logged in administrator, it is updated when the administrator has a notification with this code. Without a logged in administrator (e.g. in the catalog) the notification is for all administrators, as addForAll() does.
public
static add(mixed $code, mixed $text[, mixed $ttl = 0 ]) : mixed
$ttl - lifetime in seconds, 0 = until an administrator closes it.
Parameters
- $code : mixed
- $text : mixed
- $ttl : mixed = 0
addForAll()
Adds a notification for all administrators (user_id = 0) or updates it. There is one notification for everybody: when one administrator closes it, it is deleted for all.
public
static addForAll(mixed $code, mixed $text[, mixed $ttl = 0 ]) : mixed
$ttl - lifetime in seconds, 0 = until an administrator closes it.
Parameters
- $code : mixed
- $text : mixed
- $ttl : mixed = 0
get()
Returns the text of the notification with this code: the one of the logged in administrator first, then the one for all administrators. Null when there is none or it has expired.
public
static get(mixed $code) : mixed
Parameters
- $code : mixed
remove()
Removes the notification with this code of the logged in administrator and the one for all administrators.
public
static remove(mixed $code) : mixed
Parameters
- $code : mixed