ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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.

22 {
23 require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
24 require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
25 require_once 'Services/Notifications/classes/class.ilNotificationMailHandler.php';
26
27 // add default handlers
28 $this->addHandler('echo', new ilNotificationEchoHandler());
29 $this->addHandler('osd', new ilNotificationOSDHandler());
30 $this->addHandler('mail', new ilNotificationMailHandler());
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 47 of file class.ilNotificationSystem.php.

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

References $handler.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ enableListeners()

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

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

251 {
252 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
254 }
static enableListeners($module, $sender_id, array $users=array())
if($modEnd===false) $module
Definition: module.php:59

References $module, and ilNotificationDatabaseHandler\enableListeners().

+ Here is the call graph for this function:

◆ enableUserListeners()

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

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

257 {
258 if (!$users) {
259 return;
260 }
261 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
263 }
$users
Definition: authpage.php:44

References $module, $users, 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.

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

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 233 of file class.ilNotificationSystem.php.

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

References 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 245 of file class.ilNotificationSystem.php.

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

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 221 of file class.ilNotificationSystem.php.

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

References $users, and 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 172 of file class.ilNotificationSystem.php.

173 {
174 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
175 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
176
177 if ($processAsync == false) {
179 self::toUsers($notification, $users, false);
180 if ($notification->hasDisableAfterDeliverySet()) {
182 }
183 } else {
185 }
186 }
static enqueueByListener(ilNotificationConfig $notification, $ref_id)
toUsers(ilNotificationConfig $notification, $users, $processAsync=false)
Creates the user notifications and send them.

References $users, 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 197 of file class.ilNotificationSystem.php.

198 {
199 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
200 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
201
202 global $rbacreview;
203
204 $users = array();
205 foreach ($roles as $role) {
206 $users[] = $rbacreview->assignedUsers($role);
207 }
208 // make sure to handle every user only once
209 $users = array_unique(call_user_func_array('array_merge', $users));
210
211 self::toUsers($notification, $users, $processAsync);
212 }

References $users, and 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 64 of file class.ilNotificationSystem.php.

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

References $data, $h, $handler, $instance, $lang, $users, ilNotificationDatabaseHandler\enqueueByUsers(), ilNotificationDatabaseHandler\getAvailableChannels(), ilNotificationDatabaseHandler\getAvailableTypes(), ilObjectFactory\getInstanceByObjId(), 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: