ILIAS  Release_4_4_x_branch Revision 61816
 All Data Structures Namespaces Files Functions Variables Groups Pages
ilNotificationSystem Class Reference

Main notification handling routines for sending notifications to recipients. More...

+ Collaboration diagram for ilNotificationSystem:

Static Public Member Functions

static sendNotificationToUsers (ilNotificationConfig $notification, $users, $processAsync=false)
static sendNotificationToListeners (ilNotificationConfig $notification, $ref_id, $processAsync=false)
static sendNotificationToRoles (ilNotificationConfig $notification, array $roles, $processAsync=false)
static enableListeners ($module, $ref_id)
static enableUserListeners ($module, $ref_id, array $users)

Private Member Functions

 __construct ()
 addHandler ($channel, ilNotificationHandler $handler)
 Registers a new handler for the given channel name.
 toUsers (ilNotificationConfig $notification, $users, $processAsync=false)
 Creates the user notifications and send them.
 toListeners (ilNotificationConfig $notification, $ref_id, $processAsync=false)
 Sends the notification to all listener which are subscribed to the given ref_id.
 toRoles (ilNotificationConfig $notification, array $roles, $processAsync=false)
 Send a notification to a list of roles.

Static Private Member Functions

static getInstance ()

Private Attributes

 $handler = array()
 $defaultLanguage = 'en'

Static Private Attributes

static $instance

Detailed Description

Main notification handling routines for sending notifications to recipients.

Recipients may be

  • a list of user ids
  • roles
  • users which registered a listener to an ref_id

Definition at line 13 of file class.ilNotificationSystem.php.

Constructor & Destructor Documentation

ilNotificationSystem::__construct ( )
private

Definition at line 21 of file class.ilNotificationSystem.php.

References addHandler().

{
require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
require_once 'Services/Notifications/classes/class.ilNotificationMailHandler.php';
// add default handlers
$this->addHandler('echo', new ilNotificationEchoHandler());
$this->addHandler('osd', new ilNotificationOSDHandler());
$this->addHandler('mail', new ilNotificationMailHandler());
}

+ Here is the call graph for this function:

Member Function Documentation

ilNotificationSystem::addHandler (   $channel,
ilNotificationHandler  $handler 
)
private

Registers a new handler for the given channel name.

Parameters
string$channel
ilNotificationHandler$handler

Definition at line 46 of file class.ilNotificationSystem.php.

References $handler.

Referenced by __construct().

{
if (!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel]))
$this->handler[$channel] = array();
$this->handler[$channel][] = $handler;
}

+ Here is the caller graph for this function:

static ilNotificationSystem::enableListeners (   $module,
  $ref_id 
)
static

Definition at line 238 of file class.ilNotificationSystem.php.

References $ref_id.

Referenced by enableUserListeners().

{
require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
}

+ Here is the caller graph for this function:

static ilNotificationSystem::enableUserListeners (   $module,
  $ref_id,
array  $users 
)
static

Definition at line 243 of file class.ilNotificationSystem.php.

References $ref_id, and enableListeners().

{
if (!$users)
return;
require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
}

+ Here is the call graph for this function:

static ilNotificationSystem::getInstance ( )
staticprivate

Definition at line 33 of file class.ilNotificationSystem.php.

References $instance.

Referenced by sendNotificationToListeners(), sendNotificationToRoles(), and sendNotificationToUsers().

{
if (!self::$instance) {
self::$instance = new self();
}
}

+ Here is the caller graph for this function:

static ilNotificationSystem::sendNotificationToListeners ( ilNotificationConfig  $notification,
  $ref_id,
  $processAsync = false 
)
static
See Also
ilNotificationSystem::toListeners()
Parameters
ilNotificationConfig$notification
int$ref_id
boolean$processAsync

Definition at line 223 of file class.ilNotificationSystem.php.

References $ref_id, and getInstance().

Referenced by ilNotificationConfig\notifyByListeners().

{
self::getInstance()->toListeners($notification, $ref_id, $processAsync);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilNotificationSystem::sendNotificationToRoles ( ilNotificationConfig  $notification,
array  $roles,
  $processAsync = false 
)
static
See Also
ilNotificationSystem::toRoles()
Parameters
ilNotificationConfig$notification
string[]$users
boolean$processAsync

Definition at line 234 of file class.ilNotificationSystem.php.

References getInstance().

Referenced by ilNotificationConfig\notifyByRoles().

{
self::getInstance()->toRoles($notification, $roles, $processAsync);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

static ilNotificationSystem::sendNotificationToUsers ( ilNotificationConfig  $notification,
  $users,
  $processAsync = false 
)
static
See Also
ilNotificationSystem::toUsers()
Parameters
ilNotificationConfig$notification
int[]$users
boolean$processAsync

Definition at line 212 of file class.ilNotificationSystem.php.

References getInstance().

Referenced by ilNotificationConfig\notifyByUsers(), and ilNotificationOSDHandler\removeNotification().

{
self::getInstance()->toUsers($notification, $users, $processAsync);
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

ilNotificationSystem::toListeners ( ilNotificationConfig  $notification,
  $ref_id,
  $processAsync = false 
)
private

Sends the notification to all listener which are subscribed to the given ref_id.

Parameters
ilNotificationConfig$notification
type$ref_id
type$processAsync

Definition at line 164 of file class.ilNotificationSystem.php.

References $ref_id, ilNotificationDatabaseHandler\disableListeners(), ilNotificationDatabaseHandler\enqueueByListener(), ilNotificationConfig\getType(), ilNotificationDatabaseHandler\getUsersByListener(), ilNotificationConfig\hasDisableAfterDeliverySet(), and toUsers().

{
require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
if ($processAsync == false) {
self::toUsers($notification, $users, false);
if ($notification->hasDisableAfterDeliverySet()) {
}
}
else {
}
}

+ Here is the call graph for this function:

ilNotificationSystem::toRoles ( ilNotificationConfig  $notification,
array  $roles,
  $processAsync = false 
)
private

Send a notification to a list of roles.

The recipients are fetched by calling $rbacreview->assignedUsers($roles[$i]).

ilRbacReview $rbacreview

Parameters
ilNotificationConfig$notification
array$roles
boolean$processAsync

Definition at line 189 of file class.ilNotificationSystem.php.

References toUsers().

{
require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
global $rbacreview;
$users = array();
foreach($roles as $role) {
$users[] = $rbacreview->assignedUsers($role);
}
// make sure to handle every user only once
$users = array_unique(call_user_func_array('array_merge', $users));
self::toUsers($notification, $users, $processAsync);
}

+ Here is the call graph for this function:

ilNotificationSystem::toUsers ( ilNotificationConfig  $notification,
  $users,
  $processAsync = false 
)
private

Creates the user notifications and send them.

If processAsync is true the notifications will be serialized and persisted to the database

Parameters
ilNotificationConfig$notification
type$users
type$processAsync
Todo:
was ist hier?

Definition at line 61 of file class.ilNotificationSystem.php.

References $handler, $instance, $lang, $usr_id, ilNotificationDatabaseHandler\enqueueByUsers(), ilNotificationDatabaseHandler\getAvailableChannels(), ilNotificationDatabaseHandler\getAvailableTypes(), ilNotificationConfig\getLanguageParameters(), ilNotificationConfig\getType(), ilNotificationConfig\getUserInstance(), ilNotificationDatabaseHandler\getUsersWithCustomConfig(), and ilNotificationDatabaseHandler\loadUserConfig().

Referenced by toListeners(), and toRoles().

{
require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
// if async processing is disabled send them immediately
if ($processAsync == false) {
// loading the default configuration
// @todo this loop might be obsolet :)
foreach($users as $user_id) {
if ($usersWithCustomConfig[$user_id]) {
}
}
// load all available channels
// load all available types
// preload translation vars
$lang = ilNotificationDatabaseHandler::getTranslatedLanguageVariablesOfNotificationParameters($notification->getLanguageParameters());
$user_by_handler = array();
// check if the type allows custom user configurations for determining
// the output channel (e.g. send chat notifications only via osd)
if ($types[$notification->getType()]['config_type'] == 'set_by_user') {
$it = new ilNotificationUserIterator($notification->getType(), $users);
$channelsByAdmin = false;
// add the user to each channel he configured in his own configuration
foreach($it as $usr_id => $data) {
// the configured user channel is (currently) not known
if (!$channels[$data['channel']])
continue;
if (!$user_by_handler[$data['channel']])
$user_by_handler[$data['channel']] = array();
$user_by_handler[$data['channel']][] = $usr_id;
}
}
// if type is configured to allow settings only applied by admin
else if ($types[$notification->getType()]['config_type'] != 'disabled') {
$channelsByAdmin = true;
//$user_by_handler = array();
if (isset($adminConfig[$notification->getType()])) {
foreach($adminConfig[$notification->getType()] as $channel) {
if (!$channels[$channel])
continue;
$user_by_handler[$channel] = $users;
}
}
}
$userCache = array();
// process the notifications for each output channel
foreach($user_by_handler as $handler => $users) {
$handler = $this->handler[$handler];
// and process each user for the current output channel
foreach($users as $userId) {
if (!$userCache[$userId]) {
$userCache[$userId] = new ilObjUser($userId);
}
$user = $userCache[$userId];
// optain the message instance for the user
// @todo this step could be cached on a per user basis
// as it is independed from the output handler
$instance = $notification->getUserInstance($user, $lang, $this->defaultLanguage);
foreach($handler as $h) {
// fire the notification
$h->notify($instance);
}
}
}
}
// use async processing
else {
// just enque the current configuration
}
}

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

Field Documentation

ilNotificationSystem::$defaultLanguage = 'en'
private

Definition at line 19 of file class.ilNotificationSystem.php.

ilNotificationSystem::$handler = array()
private

Definition at line 17 of file class.ilNotificationSystem.php.

Referenced by addHandler(), and toUsers().

ilNotificationSystem::$instance
staticprivate

Definition at line 15 of file class.ilNotificationSystem.php.

Referenced by getInstance(), and toUsers().


The documentation for this class was generated from the following file: