ILIAS  release_5-1 Revision 5.0.0-5477-g43f3e3fab5f
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. More...
 
 toUsers (ilNotificationConfig $notification, $users, $processAsync=false)
 Creates the user notifications and send them. More...
 
 toListeners (ilNotificationConfig $notification, $ref_id, $processAsync=false)
 Sends the notification to all listener which are subscribed to the given ref_id. More...
 
 toRoles (ilNotificationConfig $notification, array $roles, $processAsync=false)
 Send a notification to a list of roles. More...
 

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

◆ __construct()

ilNotificationSystem::__construct ( )
private

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

21 {
22 require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
23 require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
24 require_once 'Services/Notifications/classes/class.ilNotificationMailHandler.php';
25
26 // add default handlers
27 $this->addHandler('echo', new ilNotificationEchoHandler());
28 $this->addHandler('osd', new ilNotificationOSDHandler());
29 $this->addHandler('mail', new ilNotificationMailHandler());
30
31 }
Basic notification handler that dumps basic notification information to stdout.
Notification handler for sending notifications the to recipients email address.
Notification handler for senden a notification popup to the recipients browser.
addHandler($channel, ilNotificationHandler $handler)
Registers a new handler for the given channel name.

References addHandler().

+ Here is the call graph for this function:

Member Function Documentation

◆ addHandler()

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.

46 {
47 if (!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel]))
48 $this->handler[$channel] = array();
49
50 $this->handler[$channel][] = $handler;
51 }

References $handler.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ enableListeners()

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

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

238 {
239 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
241 }
static enableListeners($module, $sender_id, array $users=array())
$ref_id
Definition: sahs_server.php:39

References $ref_id, and ilNotificationDatabaseHandler\enableListeners().

+ Here is the call graph for this function:

◆ enableUserListeners()

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

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

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

References $ref_id, and ilNotificationDatabaseHandler\enableListeners().

+ Here is the call graph for this function:

◆ getInstance()

static ilNotificationSystem::getInstance ( )
staticprivate

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

33 {
34 if (!self::$instance) {
35 self::$instance = new self();
36 }
37 return self::$instance;
38 }

References $instance.

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

+ Here is the caller graph for this function:

◆ sendNotificationToListeners()

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.

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

References $ref_id, and getInstance().

Referenced by ilNotificationConfig\notifyByListeners().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotificationToRoles()

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.

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

References getInstance().

Referenced by ilNotificationConfig\notifyByRoles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ sendNotificationToUsers()

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.

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

References getInstance().

Referenced by ilNotificationConfig\notifyByUsers().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ toListeners()

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.

164 {
165 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
166 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
167
168 if ($processAsync == false) {
170 self::toUsers($notification, $users, false);
171 if ($notification->hasDisableAfterDeliverySet()) {
173 }
174 }
175 else {
177 }
178 }
static enqueueByListener(ilNotificationConfig $notification, $ref_id)
toUsers(ilNotificationConfig $notification, $users, $processAsync=false)
Creates the user notifications and send them.

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

+ Here is the call graph for this function:

◆ toRoles()

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]).

@global ilRbacReview $rbacreview

Parameters
ilNotificationConfig$notification
array$roles
boolean$processAsync

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

189 {
190 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
191 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
192
193 global $rbacreview;
194
195 $users = array();
196 foreach($roles as $role) {
197 $users[] = $rbacreview->assignedUsers($role);
198 }
199 // make sure to handle every user only once
200 $users = array_unique(call_user_func_array('array_merge', $users));
201
202 self::toUsers($notification, $users, $processAsync);
203 }

References toUsers().

+ Here is the call graph for this function:

◆ toUsers()

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.

61 {
62
63 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
64 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
65
66
67 // if async processing is disabled send them immediately
68 if ($processAsync == false) {
69
70 // loading the default configuration
72 $usersWithCustomConfig = ilNotificationDatabaseHandler::getUsersWithCustomConfig($users);
73
74 // @todo this loop might be obsolet :)
75 foreach($users as $user_id) {
76 if ($usersWithCustomConfig[$user_id]) {
78 }
79 }
80
81 // load all available channels
83 // load all available types
85 // preload translation vars
86 $lang = ilNotificationDatabaseHandler::getTranslatedLanguageVariablesOfNotificationParameters($notification->getLanguageParameters());
87
88 $user_by_handler = array();
89
90 // check if the type allows custom user configurations for determining
91 // the output channel (e.g. send chat notifications only via osd)
92 if ($types[$notification->getType()]['config_type'] == 'set_by_user') {
93 $it = new ilNotificationUserIterator($notification->getType(), $users);
94
95 $channelsByAdmin = false;
96
97 // add the user to each channel he configured in his own configuration
98 foreach($it as $usr_id => $data) {
99 // the configured user channel is (currently) not known
100 if (!$channels[$data['channel']])
101 continue;
102
103 if (!$user_by_handler[$data['channel']])
104 $user_by_handler[$data['channel']] = array();
105
106 $user_by_handler[$data['channel']][] = $usr_id;
107 }
108 }
109 // if type is configured to allow settings only applied by admin
110 else if ($types[$notification->getType()]['config_type'] != 'disabled') {
111 $channelsByAdmin = true;
112 //$user_by_handler = array();
113
114 if (isset($adminConfig[$notification->getType()])) {
115
116 foreach($adminConfig[$notification->getType()] as $channel) {
117 if (!$channels[$channel])
118 continue;
119 $user_by_handler[$channel] = $users;
120
121 }
122 }
123 }
124
125
126 $userCache = array();
127
128 // process the notifications for each output channel
129 foreach($user_by_handler as $handler => $users) {
130 $handler = $this->handler[$handler];
131 // and process each user for the current output channel
132 foreach($users as $userId) {
133 if (!$userCache[$userId]) {
134 $userCache[$userId] = new ilObjUser($userId);
135 }
136 $user = $userCache[$userId];
137
138 // optain the message instance for the user
139 // @todo this step could be cached on a per user basis
140 // as it is independed from the output handler
141 $instance = $notification->getUserInstance($user, $lang, $this->defaultLanguage);
142 foreach($handler as $h) {
143 // fire the notification
144 $h->notify($instance);
145 }
146 }
147 }
148 }
149 // use async processing
150 else {
151 // just enque the current configuration
153 }
154 }
getUserInstance(ilObjUser $user, $languageVars, $defaultLanguage)
static getAvailableChannels($config_types=array(), $includeDisabled=false)
static enqueueByUsers(ilNotificationConfig $notification, array $userids)
wrapper for iterating a list of user settings by providing the user ids
$h
$data

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

Referenced by toListeners(), and toRoles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Field Documentation

◆ $defaultLanguage

ilNotificationSystem::$defaultLanguage = 'en'
private

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

◆ $handler

ilNotificationSystem::$handler = array()
private

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

Referenced by addHandler(), and toUsers().

◆ $instance

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: