ILIAS  release_7 Revision v7.30-3-g800a261c036
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 (\ilRbacReview $rbacReview=null)
 
 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'
 
 $rbacReview
 

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 ( \ilRbacReview  $rbacReview = null)
private

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

24 {
25 require_once 'Services/Notifications/classes/class.ilNotificationEchoHandler.php';
26 require_once 'Services/Notifications/classes/class.ilNotificationOSDHandler.php';
27 require_once 'Services/Notifications/classes/class.ilNotificationMailHandler.php';
28
29 // add default handlers
30 $this->addHandler('echo', new ilNotificationEchoHandler());
31 $this->addHandler('osd', new ilNotificationOSDHandler());
32 $this->addHandler('mail', new ilNotificationMailHandler());
33
34 if ($rbacReview === null) {
35 global $DIC;
36 $rbacReview = $DIC->rbac()->review();
37 }
38 $this->rbacReview = $rbacReview;
39 }
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.
global $DIC
Definition: goto.php:24

References $DIC, $rbacReview, and 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 55 of file class.ilNotificationSystem.php.

56 {
57 if (!array_key_exists($channel, $this->handler) || !is_array($this->handler[$channel])) {
58 $this->handler[$channel] = array();
59 }
60
61 $this->handler[$channel][] = $handler;
62 }

References $handler.

Referenced by __construct().

+ Here is the caller graph for this function:

◆ enableListeners()

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

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

256 {
257 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
259 }
static enableListeners($module, $sender_id, array $users=array())

References ilNotificationDatabaseHandler\enableListeners().

+ Here is the call graph for this function:

◆ enableUserListeners()

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

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

262 {
263 if (!$users) {
264 return;
265 }
266 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
267 ilNotificationDatabaseHandler::enableListeners($module, $ref_id, $users);
268 }

References ilNotificationDatabaseHandler\enableListeners().

+ Here is the call graph for this function:

◆ getInstance()

static ilNotificationSystem::getInstance ( )
staticprivate

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

42 {
43 if (!self::$instance) {
44 self::$instance = new self();
45 }
46 return self::$instance;
47 }

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

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

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

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

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

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

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

181 {
182 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
183 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
184
185 if ($processAsync == false) {
186 $users = ilNotificationDatabaseHandler::getUsersByListener($notification->getType(), $ref_id);
187 self::toUsers($notification, $users, false);
188 if ($notification->hasDisableAfterDeliverySet()) {
190 }
191 } else {
193 }
194 }
static enqueueByListener(ilNotificationConfig $notification, $ref_id)
toUsers(ilNotificationConfig $notification, $users, $processAsync=false)
Creates the user notifications and send them.

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

Parameters
ilNotificationConfig$notification
array$roles
boolean$processAsync

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

205 {
206 require_once 'Services/Notifications/classes/class.ilNotificationUserIterator.php';
207 require_once 'Services/Notifications/classes/class.ilNotificationDatabaseHelper.php';
208
209 $users = array();
210 foreach ($roles as $role) {
211 $users[] = $this->rbacReview->assignedUsers($role);
212 }
213 // make sure to handle every user only once
214 $users = array_unique(call_user_func_array('array_merge', $users));
215
216 self::toUsers($notification, $users, $processAsync);
217 }

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

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

References $data, $handler, $instance, $lang, 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().

◆ $rbacReview

ilNotificationSystem::$rbacReview
private

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

Referenced by __construct().


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