Development Guide
System Notifications
This documentation is only relevant for ILIAS 4.4.x and above. This is a work in progress.
The guideline for this can be found at Feature Wiki: System Notification Guideline
ilMailNotification vs. ilSystemNotification
All notifications have to be sent (internally) through ilMailNotification
, which provides a technical abstraction and low-level code to handle context-specific settings, e.g. personal workspace permission handling.ilSystemNotification
handles the content structure and should be used whenever possible - the notification will be sent using ilMailNotification
. If the guideline rules it supports are too strict for your case you can use ilMailNotification
directly (e.g. addBody()
), this might be the case for dynamic content as ilSystemNotification
only supports lang-ids and has no concept of placeholders.
Basic Usage
The guideline proposes a general structure for system notifications. This structure is supported by ilSystemNotification
which should be used for any notification issued automatically (via cron or triggered by an event, e.g. object change notifications).
The basic blocks of the structure are:
- Subject
- Introduction
- Object-Information
- Additional Information
- Changed by
- Goto Link
- Task
- Reason
Example 1 (Repository, Module "Exercise")
1 | include_once "./Services/Notification/classes/class.ilSystemNotification.php"; |
Example 1 Annotations
- -
- -
- The object id to add object title to details and a goto link. It is optional - when missing all object-relevant information is removed from the notification.
- All relevant language modules are given.
- Keep in mind to set language ids not parsed strings as they are depending on the recipient language!
- For custom text blocks you can use
setIntroductionDirect()
which will be added to the mail without any parsing but you should use this only as a last resort. - Additional information is presented either as single line "[caption]: [value]" or multi-line (3rd Parameter)
- If no specific caption for the goto link is given, the fallback "URL" is used
- -
- -
- -
sendMail()
has 3 Parameters:
- user_ids
- additional goto suffix, e.g. for sub-"objects" as pages or blog postings
- the permission to check for the goto link (default: "read"), if the check fails the recipient will not get the notification! You can set the permission to
null
if necessary, e.g. when sending to external email addresses (which should work).
sendMail()
will return the user ids which have received the notification.If no specific ref_id was set via
setRefId()
the system will try to find a ref_id by object id. It will select the first accessible for the recipient.Example 2 (Personal Workspace, "Blog")
1 | include_once "./Services/Notification/classes/class.ilSystemNotification.php"; |
Example 2 Annotations
- -
- Parameter: Personal Workspace mode aka "Where did my ref_id go?"
- -
- If you have a specific ref_id in your context it should be set (instead of
setObjId()
). - If the notification was triggered by an event you can add the "responsible" user (as opposed to cron-jobs)
- -
$a_action
: different events lead to different messages.- -
- -
- -
- 3rd Parameter: multi-line
- -
- -
- -
- -
- 2nd Parameter: goto suffix
- 3rd Paramter: goto permission
Additional notes
ilSystemNotification
does not have a threshold for repeating messages, see ilNotification
for that. Attachments and HTML are not supported (yet?). Depending on the user settings the messages will be sent internally or as email.
If there is the need to handle the mail transport separately use composeAndGetMessage()
.
See ilCourseMembershipMailNotification
for an example how to use ilMailNotification
directly.