ILIAS  release_5-0 Revision 5.0.0-1144-gc4397b1f870
ilNotificationDatabaseHandler Class Reference
+ Collaboration diagram for ilNotificationDatabaseHandler:

Static Public Member Functions

static setUserConfig ($userid, array $configArray)
 Sets the configuration for all given configurations. More...
 
static loadUserConfig ($userid)
 
static enqueueByUsers (ilNotificationConfig $notification, array $userids)
 
static enqueueByListener (ilNotificationConfig $notification, $ref_id)
 
static storeNotification (ilNotificationConfig $notification)
 
static removeNotification ($id)
 
static getUsersByListener ($module, $sender_id)
 
static disableListeners ($module, $sender_id)
 
static enableListeners ($module, $sender_id, array $users=array())
 
static registerChannel ($name, $title, $description, $class, $classfile, $config_type)
 Registers a new notification channel for distributing notifications. More...
 
static registerType ($name, $title, $description, $notification_group, $config_type)
 Registers a new notification type. More...
 
static getAvailableChannels ($config_types=array(), $includeDisabled=false)
 
static getAvailableTypes ($config_types=array())
 
static setConfigTypeForType ($type_name, $config_name)
 
static setConfigTypeForChannel ($channel_name, $config_name)
 
static getUsersWithCustomConfig (array $userid)
 

Static Protected Member Functions

static fillPlaceholders ($results, $vars, $langVarToTypeDict)
 
static findPlaceholders ($pattern, $translation)
 

Static Private Member Functions

static replaceFields ($string, $foundPlaceholders, $params, $startTag, $endTage)
 

Detailed Description

Definition at line 5 of file class.ilNotificationDatabaseHelper.php.

Member Function Documentation

◆ disableListeners()

static ilNotificationDatabaseHandler::disableListeners (   $module,
  $sender_id 
)
static

Definition at line 315 of file class.ilNotificationDatabaseHelper.php.

315 {
316 global $ilDB;
317
318 $query = 'UPDATE '. ilNotificationSetupHelper::$tbl_userlistener .' SET disabled = 1 WHERE module = %s AND sender_id = %s';
319 $types = array('text', 'integer');
320 $values = array($module, $sender_id);
321
322 $ilDB->manipulateF($query, $types, $values);
323 }
global $ilDB

References $ilDB, $query, and ilNotificationSetupHelper\$tbl_userlistener.

Referenced by ilNotificationSystem\toListeners().

+ Here is the caller graph for this function:

◆ enableListeners()

static ilNotificationDatabaseHandler::enableListeners (   $module,
  $sender_id,
array  $users = array() 
)
static

Definition at line 325 of file class.ilNotificationDatabaseHelper.php.

325 {
326 global $ilDB;
327
328 $query = 'UPDATE '. ilNotificationSetupHelper::$tbl_userlistener .' SET disabled = 0 WHERE module = %s AND sender_id = %s';
329
330 if ($users) {
331 $query .= ' ' . $ilDB->in('usr_id', $users);
332 }
333
334 $types = array('text', 'integer');
335 $values = array($module, $sender_id);
336
337 $ilDB->manipulateF($query, $types, $values);
338 }

References $ilDB, $query, and ilNotificationSetupHelper\$tbl_userlistener.

Referenced by ilNotificationSystem\enableListeners(), and ilNotificationSystem\enableUserListeners().

+ Here is the caller graph for this function:

◆ enqueueByListener()

static ilNotificationDatabaseHandler::enqueueByListener ( ilNotificationConfig  $notification,
  $ref_id 
)
static

Definition at line 235 of file class.ilNotificationDatabaseHelper.php.

235 {
236 global $ilDB;
237
238 $notification_id = ilNotificationDatabaseHandler::storeNotification($notification);
239 $valid_until = $notification->getValidForSeconds() ? (time() + $notification->getValidForSeconds()) : 0;
240
241 $query = 'INSERT INTO ' . ilNotificationSetupHelper::$tbl_notification_queue . ' (notification_id, usr_id, valid_until) '
242 .' (SELECT %s, usr_id, %s FROM '. ilNotificationSetupHelper::$tbl_userlistener .' WHERE disabled = 0 AND module = %s AND sender_id = %s)';
243
244 $types = array('integer', 'integer', 'text', 'integer');
245
246 $values = array($notification_id, $valid_until, $notification->getType(), $ref_id);
247
248 $ilDB->manipulateF($query, $types, $values);
249 }
static storeNotification(ilNotificationConfig $notification)
$ref_id
Definition: sahs_server.php:39

References $ilDB, $query, $ref_id, ilNotificationSetupHelper\$tbl_notification_queue, ilNotificationSetupHelper\$tbl_userlistener, ilNotificationConfig\getType(), ilNotificationConfig\getValidForSeconds(), and storeNotification().

Referenced by ilNotificationSystem\toListeners().

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

◆ enqueueByUsers()

static ilNotificationDatabaseHandler::enqueueByUsers ( ilNotificationConfig  $notification,
array  $userids 
)
static

Definition at line 213 of file class.ilNotificationDatabaseHelper.php.

213 {
214 if (!$userids)
215 return;
216
217 global $ilDB;
218
219 $notification_id = ilNotificationDatabaseHandler::storeNotification($notification);
220 $valid_until = $notification->getValidForSeconds() ? (time() + $notification->getValidForSeconds()) : 0;
221
222 foreach($userids as $userid) {
223 $ilDB->insert(
225 array(
226 'notification_id' => array('integer', $notification_id),
227 'usr_id' => array('integer', $userid),
228 'valid_until' => array('integer', $valid_until),
229 )
230 );
231 }
232
233 }

References $ilDB, ilNotificationSetupHelper\$tbl_notification_queue, ilNotificationConfig\getValidForSeconds(), and storeNotification().

Referenced by ilNotificationSystem\toUsers().

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

◆ fillPlaceholders()

static ilNotificationDatabaseHandler::fillPlaceholders (   $results,
  $vars,
  $langVarToTypeDict 
)
staticprotected
Parameters
array$results
array$vars
array$langVarToTypeDict
Returns
array mixed

Definition at line 66 of file class.ilNotificationDatabaseHelper.php.

67 {
68 $pattern_old = '/##(.+?)##/im';
69 $pattern = '/\[(.+?)\]/im';
70
71 foreach($results as $langVar => $res)
72 {
73 $placeholdersStack = array();
74 $res->lang = array();
75
76 foreach($res->lang_untouched as $iso2shorthandle => $translation)
77 {
78 $translation = str_replace("\\n", "\n", $translation);
79 $placeholdersStack[] = self::findPlaceholders($pattern, $translation);
80 $translation = self::replaceFields($translation, $placeholdersStack[count($placeholdersStack) - 1], $vars[$langVarToTypeDict[$langVar]]->getParameters(), '[', ']');
81 $placeholdersStack[] = self::findPlaceholders($pattern_old, $translation);
82 $res->lang[$iso2shorthandle] = self::replaceFields($translation, $placeholdersStack[count($placeholdersStack) - 1], $vars[$langVarToTypeDict[$langVar]]->getParameters(), '##', '##');
83 }
84
85 $res->params = array_diff(
86 array_unique(
87 call_user_func_array('array_merge', $placeholdersStack)
88 ),
89 array_keys($vars[$langVarToTypeDict[$langVar]]->getParameters())
90 );
91 }
92
93 return $results;
94 }
static replaceFields($string, $foundPlaceholders, $params, $startTag, $endTage)
static findPlaceholders($pattern, $translation)
$results

References $res, $results, findPlaceholders(), and replaceFields().

+ Here is the call graph for this function:

◆ findPlaceholders()

static ilNotificationDatabaseHandler::findPlaceholders (   $pattern,
  $translation 
)
staticprotected
Parameters
string$pattern
string$translation
Returns
array

Definition at line 102 of file class.ilNotificationDatabaseHelper.php.

103 {
104 $foundPlaceholders = array();
105 preg_match_all($pattern, $translation, $foundPlaceholders);
106 return (array)$foundPlaceholders[1];
107 }

Referenced by fillPlaceholders().

+ Here is the caller graph for this function:

◆ getAvailableChannels()

static ilNotificationDatabaseHandler::getAvailableChannels (   $config_types = array(),
  $includeDisabled = false 
)
static

Definition at line 394 of file class.ilNotificationDatabaseHelper.php.

394 {
395 global $ilDB;
396
397 $query = 'SELECT channel_name, title, description, class, include, config_type FROM ' . ilNotificationSetupHelper::$tbl_notification_channels;
398 if ($config_types)
399 $query .= ' WHERE ' . $ilDB->in('config_type', $config_types, false, 'text');
400
401 $rset = $ilDB->query($query);
402
403 $result = array();
404
405 $settings = new ilSetting('notifications');
406
407 while ($row = $ilDB->fetchAssoc($rset)) {
408 if (!$includeDisabled && !$settings->get('enable_' . $row['channel_name']))
409 continue;
410
411 $result[$row['channel_name']] = array (
412 'name' => $row['channel_name'],
413 'title' => $row['title'],
414 'description' => $row['description'],
415 'handler' => $row['class'],
416 'include' => $row['include'],
417 'config_type' => $row['config_type'],
418 );
419 }
420
421 return $result;
422 }
$result
ILIAS Setting Class.

References $ilDB, $query, $result, $row, and ilNotificationSetupHelper\$tbl_notification_channels.

Referenced by ilNotificationGUI\getAvailableChannels(), ilNotificationAdminSettingsForm\getGeneralSettingsForm(), setUserConfig(), ilObjNotificationAdminGUI\showChannelsObject(), ilObjNotificationAdminGUI\showConfigMatrixObject(), and ilNotificationSystem\toUsers().

+ Here is the caller graph for this function:

◆ getAvailableTypes()

static ilNotificationDatabaseHandler::getAvailableTypes (   $config_types = array())
static

Definition at line 424 of file class.ilNotificationDatabaseHelper.php.

424 {
425 global $ilDB;
426
427 $query = 'SELECT type_name, title, description, notification_group, config_type FROM ' . ilNotificationSetupHelper::$tbl_notification_types;
428 if ($config_types)
429 $query .= ' WHERE ' . $ilDB->in('config_type', $config_types, false, 'text');
430
431
432 $rset = $ilDB->query($query);
433
434 $result = array();
435
436 while ($row = $ilDB->fetchAssoc($rset)) {
437 $result[$row['type_name']] = array (
438 'name' => $row['type_name'],
439 'title' => $row['title'],
440 'description' => $row['description'],
441 'group' => $row['notification_group'],
442 'config_type' => $row['config_type'],
443 );
444 }
445
446 return $result;
447 }

References $ilDB, $query, $result, $row, and ilNotificationSetupHelper\$tbl_notification_types.

Referenced by ilNotificationGUI\getAvailableTypes(), setUserConfig(), ilObjNotificationAdminGUI\showConfigMatrixObject(), ilObjNotificationAdminGUI\showTypesObject(), and ilNotificationSystem\toUsers().

+ Here is the caller graph for this function:

◆ getUsersByListener()

static ilNotificationDatabaseHandler::getUsersByListener (   $module,
  $sender_id 
)
static

Definition at line 299 of file class.ilNotificationDatabaseHelper.php.

299 {
300 global $ilDB;
301
302 $query = 'SELECT usr_id FROM '. ilNotificationSetupHelper::$tbl_userlistener .' WHERE disabled = 0 AND module = %s AND sender_id = %s';
303 $types = array('text', 'integer');
304 $values = array($module, $sender_id);
305
306 $users = array();
307
308 $rset = $ilDB->queryF($query, $types, $values);
309 while($row = $ilDB->fetchAssoc($rset)) {
310 $users[] = $row['usr_id'];
311 }
312 return $users;
313 }

References $ilDB, $query, $row, and ilNotificationSetupHelper\$tbl_userlistener.

Referenced by ilNotificationSystem\toListeners().

+ Here is the caller graph for this function:

◆ getUsersWithCustomConfig()

static ilNotificationDatabaseHandler::getUsersWithCustomConfig ( array  $userid)
static

Definition at line 466 of file class.ilNotificationDatabaseHelper.php.

466 {
467 global $ilDB;
468 $query = 'SELECT usr_id, value FROM usr_pref WHERE ' . $ilDB->in('usr_id', $userid, false, 'integer') . ' AND keyword="use_custom_notification_setting" AND value="1"';
469 $rset = $ilDB->query($query);
470 $result = array();
471 while($row = $ilDB->fetchAssoc($rset)) {
472 $result[$row['usr_id']] = (bool)$row['value'];
473 }
474 return $result;
475 }

References $ilDB, $query, $result, and $row.

Referenced by ilNotificationSystem\toUsers().

+ Here is the caller graph for this function:

◆ loadUserConfig()

static ilNotificationDatabaseHandler::loadUserConfig (   $userid)
static

Definition at line 192 of file class.ilNotificationDatabaseHelper.php.

192 {
193 global $ilDB;
194
195 $query = 'SELECT module, channel FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id = %s';
196 $types = array('integer');
197 $values = array($userid);
198
199 $res = $ilDB->queryF($query, $types, $values);
200
201 $result = array();
202
203 while ($row = $ilDB->fetchAssoc($res)) {
204 if (!$result[$row['module']])
205 $result[$row['module']] = array();
206
207 $result[$row['module']][] = $row['channel'];
208 }
209
210 return $result;
211 }

References $ilDB, $query, $res, $result, $row, and ilNotificationSetupHelper\$tbl_userconfig.

Referenced by ilObjNotificationAdminGUI\showConfigMatrixObject(), ilNotificationGUI\showSettingsObject(), and ilNotificationSystem\toUsers().

+ Here is the caller graph for this function:

◆ registerChannel()

static ilNotificationDatabaseHandler::registerChannel (   $name,
  $title,
  $description,
  $class,
  $classfile,
  $config_type 
)
static

Registers a new notification channel for distributing notifications.

@global ilDB $ilDB

Parameters
type$nametechnical name of the type
type$titlehuman readable title for configuration guis
type$descriptionnot yet used human readable description
type$classclass name of the handler class
type$classfileclass file location of the handler class
type$config_type'set_by_user' or 'set_by_admin'; restricts if users can override the configuartion for this channel

Definition at line 352 of file class.ilNotificationDatabaseHelper.php.

352 {
353 global $ilDB;
354
355 $ilDB->insert(
357 array(
358 'channel_name' => array('text', $name),
359 'title' => array('text', $title),
360 'description' => array('text', $description),
361 'class' => array('text', $class),
362 'include' => array('text', $classfile),
363 'config_type' => array('text', $config_type),
364 )
365 );
366 }

References $ilDB, and ilNotificationSetupHelper\$tbl_notification_channels.

Referenced by ilNotificationSetupHelper\registerChannel().

+ Here is the caller graph for this function:

◆ registerType()

static ilNotificationDatabaseHandler::registerType (   $name,
  $title,
  $description,
  $notification_group,
  $config_type 
)
static

Registers a new notification type.

@global ilDB $ilDB

Parameters
string$nametechnical name of the type
string$titlehuman readable title for configuration guis
string$descriptionnot yet used human readable description
string$notification_groupnot yet used group
string$config_type'set_by_user' or 'set_by_admin'; restricts if users can override the configuartion for this type

Definition at line 379 of file class.ilNotificationDatabaseHelper.php.

379 {
380 global $ilDB;
381
382 $ilDB->insert(
384 array(
385 'type_name' => array('text', $name),
386 'title' => array('text', $title),
387 'description' => array('text', $description),
388 'notification_group' => array('text', $notification_group),
389 'config_type' => array('text', $config_type),
390 )
391 );
392 }

References $ilDB, and ilNotificationSetupHelper\$tbl_notification_types.

Referenced by ilNotificationSetupHelper\registerType().

+ Here is the caller graph for this function:

◆ removeNotification()

static ilNotificationDatabaseHandler::removeNotification (   $id)
static

Definition at line 289 of file class.ilNotificationDatabaseHelper.php.

289 {
290 global $ilDB;
291
292 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_data . ' WHERE notification_id = ?';
293 $types = array('integer');
294 $values = array($id);
295
296 $ilDB->manipulateF($query, $types, $values);
297 }

References $ilDB, $query, and ilNotificationSetupHelper\$tbl_notification_data.

◆ replaceFields()

static ilNotificationDatabaseHandler::replaceFields (   $string,
  $foundPlaceholders,
  $params,
  $startTag,
  $endTage 
)
staticprivate
Parameters
string$string
array$foundPlaceholders
array$params
string$startTag
string$endTag
Returns
string

Definition at line 118 of file class.ilNotificationDatabaseHelper.php.

119 {
120 foreach($foundPlaceholders as $placeholder)
121 {
122 if(array_key_exists(strtoupper($placeholder), $params))
123 {
124 $string = str_ireplace($startTag . $placeholder . $endTage, $params[strtoupper($placeholder)], $string);
125 }
126 if(array_key_exists(strtolower($placeholder), $params))
127 {
128 $string = str_ireplace($startTag . $placeholder . $endTage, $params[strtolower($placeholder)], $string);
129 }
130 }
131 return $string;
132 }

Referenced by fillPlaceholders().

+ Here is the caller graph for this function:

◆ setConfigTypeForChannel()

static ilNotificationDatabaseHandler::setConfigTypeForChannel (   $channel_name,
  $config_name 
)
static

Definition at line 457 of file class.ilNotificationDatabaseHelper.php.

457 {
458 global $ilDB;
459 $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_channels . ' SET config_type = %s WHERE channel_name = %s';
460 $types = array('text', 'text');
461 $values = array($config_name, $channel_name);
462 $ilDB->manipulateF($query, $types, $values);
463 }

References $ilDB, $query, and ilNotificationSetupHelper\$tbl_notification_channels.

Referenced by ilObjNotificationAdminGUI\saveChannelsObject(), and ilObjNotificationAdminGUI\saveGeneralSettingsObject().

+ Here is the caller graph for this function:

◆ setConfigTypeForType()

static ilNotificationDatabaseHandler::setConfigTypeForType (   $type_name,
  $config_name 
)
static

Definition at line 449 of file class.ilNotificationDatabaseHelper.php.

449 {
450 global $ilDB;
451 $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_types . ' SET config_type = %s WHERE type_name = %s';
452 $types = array('text', 'text');
453 $values = array($config_name, $type_name);
454 $ilDB->manipulateF($query, $types, $values);
455 }

References $ilDB, $query, and ilNotificationSetupHelper\$tbl_notification_types.

Referenced by ilObjNotificationAdminGUI\saveTypesObject().

+ Here is the caller graph for this function:

◆ setUserConfig()

static ilNotificationDatabaseHandler::setUserConfig (   $userid,
array  $configArray 
)
static

Sets the configuration for all given configurations.

Old configurations are completly removed before the new are inserted.

structure of $configArray

array( 'chat_invitation' => array( 'mail' => true, 'osd' => false ), 'adobeconnect_invitation' => array( 'mail' => true, 'osd' => true ), );

If the userid is -1, the settings are stored as general settings (default values or used if configuration type is set_by_admin).

@global ilDB $ilDB

Parameters
int$userid
array$configArray

Definition at line 158 of file class.ilNotificationDatabaseHelper.php.

158 {
159 global $ilDB;
160
161 if ($userid != -1) {
162 $channels = self::getAvailableChannels(array('set_by_user'));
163 $types = self::getAvailableTypes(array('set_by_user'));
164 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id=%s AND ' . $ilDB->in('module', array_keys($types), false, 'text') . ' AND ' . $ilDB->in('channel', array_keys($channels), false, 'text');
165 }
166 else {
167 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id=%s';
168 }
169
170 $types = array('integer');
171 $values = array($userid);
172
173 // delete old settings
174 $ilDB->manipulateF($query, $types, $values);
175
176 foreach ($configArray as $type => $channels) {
177 foreach ($channels as $channel => $value) {
178 if (!$value)
179 continue;
180 $ilDB->insert(
182 array(
183 'usr_id' => array('integer', $userid),
184 'module' => array('text', $type),
185 'channel' => array('text', $channel),
186 )
187 );
188 }
189 }
190 }
static getAvailableChannels($config_types=array(), $includeDisabled=false)

References $ilDB, $query, ilNotificationSetupHelper\$tbl_userconfig, getAvailableChannels(), and getAvailableTypes().

Referenced by ilObjNotificationAdminGUI\saveConfigMatrixObject(), and ilNotificationGUI\saveSettingsObject().

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

◆ storeNotification()

static ilNotificationDatabaseHandler::storeNotification ( ilNotificationConfig  $notification)
static

Definition at line 273 of file class.ilNotificationDatabaseHelper.php.

273 {
274 global $ilDB;
275
277
278 $ilDB->insert(
280 array(
281 'notification_id' => array('integer', $id),
282 'serialized' => array('text', serialize($notification)),
283 )
284 );
285
286 return $id;
287 }

References $ilDB, and ilNotificationSetupHelper\$tbl_notification_data.

Referenced by enqueueByListener(), and enqueueByUsers().

+ Here is the caller graph for this function:

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