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.

References addHandler().

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  }
addHandler($channel, ilNotificationHandler $handler)
Registers a new handler for the given channel name.
Notification handler for sending notifications the to recipients email address.
Basic notification handler that dumps basic notification information to stdout.
+ 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.

References $handler, and array.

Referenced by __construct().

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  }
Create styles array
The data for the language used.
+ 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.

References $module, and ilNotificationDatabaseHandler\enableListeners().

251  {
252  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
254  }
if($modEnd===false) $module
Definition: module.php:59
static enableListeners($module, $sender_id, array $users=array())
+ 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.

References $module, and ilNotificationDatabaseHandler\enableListeners().

257  {
258  if (!$users) {
259  return;
260  }
261  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
263  }
if($modEnd===false) $module
Definition: module.php:59
$users
Definition: authpage.php:44
static enableListeners($module, $sender_id, array $users=array())
+ 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  }

◆ 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.

Referenced by ilNotificationConfig\notifyByListeners().

234  {
235  self::getInstance()->toListeners($notification, $ref_id, $processAsync);
236  }
+ 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.

Referenced by ilNotificationConfig\notifyByRoles().

246  {
247  self::getInstance()->toRoles($notification, $roles, $processAsync);
248  }
+ 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.

References $users.

Referenced by ilNotificationConfig\notifyByUsers().

222  {
223  self::getInstance()->toUsers($notification, $users, $processAsync);
224  }
$users
Definition: authpage.php:44
+ 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.

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

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()) {
181  ilNotificationDatabaseHandler::disableListeners($notification->getType(), $ref_id);
182  }
183  } else {
184  ilNotificationDatabaseHandler::enqueueByListener($notification, $ref_id);
185  }
186  }
static enqueueByListener(ilNotificationConfig $notification, $ref_id)
$users
Definition: authpage.php:44
+ 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]).

ilRbacReview $rbacreview

Parameters
ilNotificationConfig$notification
array$roles
boolean$processAsync

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

References $users, and array.

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  }
Create styles array
The data for the language used.
$users
Definition: authpage.php:44

◆ 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.

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

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  }
static enqueueByUsers(ilNotificationConfig $notification, array $userids)
$h
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
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
static getAvailableChannels($config_types=array(), $includeDisabled=false)
getUserInstance(ilObjUser $user, $languageVars, $defaultLanguage)
+ Here is the call 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 toUsers().


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