Piwik\

Notification

Describes a UI notification.

UI notifications are messages displayed to the user near the top of the screen. Notifications consist of a message, a context (the message type), a priority and a display type.

The context affects the way the message looks, but not how it is displayed.

The display type determines how the message is displayed.

The priority determines where it is shown in the list of all displayed notifications.

Examples

Display an error message

$notification = new Notification('My Error Message');
$notification->context = Notification::CONTEXT_ERROR;
Notification\Manager::notify('myUniqueNotificationId', $notification);

Display a temporary success message

$notification = new Notification('Success');
$notification->context = Notification::CONTEXT_SUCCESS;
$notification->type = Notification::TYPE_TOAST;
Notification\Manager::notify('myUniqueNotificationId', $notification);

Display a message near the top of the screen

$notification = new Notification('Urgent: Your password has expired!');
$notification->context = Notification::CONTEXT_INFO;
$notification->type = Notification::TYPE_PERSISTENT;
$notification->priority = Notification::PRIORITY_MAX;

Constants

This class defines the following constants:

  • FLAG_NO_CLEAR — If this flag is applied, no close icon will be displayed. Note: persistent notifications always have a close icon. Inherited from Notification- FLAG_CLEAR — If this flag is applied, a close icon will be displayed. Inherited from Notification- TYPE_PERSISTENT — Notifications of this type will be displayed until the new user explicitly closes the notification. Inherited from Notification

FLAG_NO_CLEAR

See $flags.

FLAG_CLEAR

See $flags.

TYPE_PERSISTENT

The notifications will display even if the user reloads the page.

Properties

This class defines the following properties:

  • $title — The notification title.
  • $message — The notification message.
  • $flags — Contains extra display options.
  • $type — The notification's display type.
  • $context — The notification's context (message type).
  • $priority — The notification's priority.
  • $raw — If true, the message will not be escaped before being outputted as HTML.

$title

The notification title. The title is optional and is displayed directly before the message content.

Signature

  • It is a string value.

$message

The notification message. Must be set.

Signature

  • It is a string value.

$flags

Contains extra display options.

Usage: $notification->flags = Notification::FLAG_BAR | Notification::FLAG_FOO.

Signature

  • It is a int value.

$type

The notification's display type. See TYPE_* constants in Notification.

Signature

  • It is a string value.

$context

The notification's context (message type). See CONTEXT_* constants in Notification.

A notification's context determines how it will be styled.

Signature

  • It is a string value.

$priority

The notification's priority. The higher the priority, the higher the order. See PRIORITY_* constants in Notification to see possible priority values.

Signature

  • It is a int value.

$raw

If true, the message will not be escaped before being outputted as HTML. If you set this to true, make sure you escape text yourself in order to avoid XSS vulnerabilities.

Signature

  • It is a bool value.

Methods

The class defines the following methods:

  • __construct() — Constructor.
  • hasNoClear() — Returns 1 if the notification will be displayed without a close button, 0 if otherwise.
  • getPriority() — Returns the notification's priority.

__construct()

Constructor.

Signature

  • It accepts the following parameter(s):
    • $message (string) — The notification message.
  • It throws one of the following exceptions:

hasNoClear()

Returns 1 if the notification will be displayed without a close button, 0 if otherwise.

Signature

  • Returns: int1 or 0.

getPriority()

Returns the notification's priority. If no priority has been set, a priority will be set based on the notification's context.

Signature

  • It returns a int value.