Development Guide

Notifications Service

Notification Content

A notification consist of ...

  • type (e.g. chat_invitation)
  • title (an ILIAS language variable with placeholders or a plain text, if the language variable could not be resolved)
  • short description (an ILIAS language variable with placeholders or a plain text, if the language variable could not be resolved)
  • long description (an ILIAS language variable with placeholders or a plain text, if the language variable could not be resolved)
  • icon (optional)
  • link (optional)
The delivery channel has to decide whether it uses the short description, the long description, or both of them.

Language Variables for Descriptions

Below you can see how you can use placeholders in your language variables.

  • chatroom#:#chat_invitation#:#Invitation from [INVITER_NAME] to Chatroom [ROOM_NAME]
  • chatroom#:#chat_invitation_long#:#[SALUTATION]\n\nYou have been invited to a chatroom:\nChatroom Title: [ROOM_NAME]\nInvited by: [INVITER_NAME]\nURL: [LINK]\n\nIf you want to join the chatroom please follow the given URL.
  • chatroom#:#chat_invitation_short#:#Please click the title link to enter the chatroom.

Code Examples

Example with Language Variables/Placeholders

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$recipient_id = 6;
$sender_id = 6;
 
$placeholders = array(
'link' => 'http://my.invitation.link',
'inviter_name' => 'Michael Jansen',
'room_name' => 'My Private Chatroom',
'salutation' => 'Mr. Max Mustermann'
);
 
require_once 'Services/Notifications/classes/class.ilNotificationConfig.php';
$notification = new ilNotificationConfig('chat_invitation');
$notification->setTitleVar('chat_invitation', $placeholders, 'chatroom');
$notification->setShortDescriptionVar('chat_invitation_short', $placeholders, 'chatroom');
$notification->setLongDescriptionVar('chat_invitation_long', $placeholders, 'chatroom');
$notification->setAutoDisable(false);
$notification->setLink('http://my.invitation.link');
$notification->setIconPath('templates/default/images/icon_chtr_s.png');
$notification->setValidForSeconds(0);
$notification->setHandlerParam('mail.sender', $sender_id);
$notification->notifyByUsers(array($recipient_id));

Custom Example

1
2
3
4
5
6
7
8
9
10
11
12
$recipient_id = 6;
$sender_id = 6;

require_once 'Services/Notifications/classes/class.ilNotificationConfig.php';
$notification = new ilNotificationConfig('chat_invitation');
$notification->setTitleVar('Example title (no language variable)');
$notification->setShortDescriptionVar('Example (short) description (no language variable)');
$notification->setLongDescriptionVar('Example (long) description (no language variable)');
$notification->setAutoDisable(false);
$notification->setValidForSeconds(0);
$notification->setHandlerParam('mail.sender', $sender_id);
$notification->notifyByUsers(array($recipient_id));

General

Delivery Methods:

  • notifyByUsers
  • notifyByListeners (The subscription process is no implemented, yet. The INSERT INTO listener_table .... is missing.)
  • notifyByRoles
 
The notification system is able to deliver the configured notification directly.
Furthermore you can send them asynchronously (recommended if a notification should be delivered to many recipients). In this case, we have to implement a new cron job task for the ILIAS core (also available in a certain Subversion branch).

Delivered Notifications

Mail System (internal message, external email, or both - depending on the recipients' settings)