ILIAS  release_5-2 Revision v5.2.25-18-g3f80b828510
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().

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  }
addHandler($channel, ilNotificationHandler $handler)
Registers a new handler for the given channel name.
Notification handler for sending notifications the to recipients email address.
Notification handler for senden a notification popup to the recipients browser.
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 46 of file class.ilNotificationSystem.php.

References $handler, and array.

Referenced by __construct().

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

References $ref_id, and ilNotificationDatabaseHandler\enableListeners().

242  {
243  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
245  }
$ref_id
Definition: sahs_server.php:39
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 247 of file class.ilNotificationSystem.php.

References $ref_id, and ilNotificationDatabaseHandler\enableListeners().

247  {
248  if (!$users)
249  return;
250  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
252  }
$ref_id
Definition: sahs_server.php:39
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.

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

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

References $ref_id.

Referenced by ilNotificationConfig\notifyByListeners().

227  {
228  self::getInstance()->toListeners($notification, $ref_id, $processAsync);
229  }
$ref_id
Definition: sahs_server.php:39
+ 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 238 of file class.ilNotificationSystem.php.

Referenced by ilNotificationConfig\notifyByRoles().

238  {
239  self::getInstance()->toRoles($notification, $roles, $processAsync);
240  }
+ 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 216 of file class.ilNotificationSystem.php.

Referenced by ilNotificationConfig\notifyByUsers().

216  {
217  self::getInstance()->toUsers($notification, $users, $processAsync);
218  }
+ 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 168 of file class.ilNotificationSystem.php.

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

168  {
169  require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
170  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
171 
172  if ($processAsync == false) {
174  self::toUsers($notification, $users, false);
175  if ($notification->hasDisableAfterDeliverySet()) {
177  }
178  }
179  else {
181  }
182  }
static enqueueByListener(ilNotificationConfig $notification, $ref_id)
$ref_id
Definition: sahs_server.php:39
+ 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 193 of file class.ilNotificationSystem.php.

References array.

193  {
194  require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
195  require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
196 
197  global $rbacreview;
198 
199  $users = array();
200  foreach($roles as $role) {
201  $users[] = $rbacreview->assignedUsers($role);
202  }
203  // make sure to handle every user only once
204  $users = array_unique(call_user_func_array('array_merge', $users));
205 
206  self::toUsers($notification, $users, $processAsync);
207  }
Create styles array
The data for the language used.

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

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

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  $user = ilObjectFactory::getInstanceByObjId($userId, false);
135  if (!$user || !($user instanceof \ilObjUser)) {
136  continue;
137  }
138  $userCache[$userId] = $user;
139  }
140  $user = $userCache[$userId];
141 
142  // optain the message instance for the user
143  // @todo this step could be cached on a per user basis
144  // as it is independed from the output handler
145  $instance = $notification->getUserInstance($user, $lang, $this->defaultLanguage);
146  foreach ($handler as $h) {
147  // fire the notification
148  $h->notify($instance);
149  }
150  }
151  }
152  }
153  // use async processing
154  else {
155  // just enque the current configuration
156  ilNotificationDatabaseHandler::enqueueByUsers($notification, $users);
157  }
158  }
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.
for($i=1; $i<=count($kw_cases_sel); $i+=1) $lang
Definition: langwiz.php:349
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: