ILIAS  release_7 Revision v7.30-3-g800a261c036
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 305 of file class.ilNotificationDatabaseHelper.php.

306 {
307 global $DIC;
308
309 $ilDB = $DIC->database();
310
311 $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_userlistener . ' SET disabled = 1 WHERE module = %s AND sender_id = %s';
312 $types = array('text', 'integer');
313 $values = array($module, $sender_id);
314
315 $ilDB->manipulateF($query, $types, $values);
316 }
global $DIC
Definition: goto.php:24
$query
global $ilDB

References $DIC, $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 318 of file class.ilNotificationDatabaseHelper.php.

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

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

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

References $DIC, $ilDB, $query, ilNotificationSetupHelper\$tbl_notification_queue, ilNotificationSetupHelper\$tbl_userlistener, ilNotificationConfig\getType(), ilNotificationConfig\getValidForSeconds(), ilNotificationConfig\getVisibleForSeconds(), 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 209 of file class.ilNotificationDatabaseHelper.php.

210 {
211 if (!$userids) {
212 return;
213 }
214
215 global $DIC;
216
217 $ilDB = $DIC->database();
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 'visible_for' => array('integer', $notification->getVisibleForSeconds())
230 )
231 );
232 }
233 }

References $DIC, $ilDB, ilNotificationSetupHelper\$tbl_notification_queue, ilNotificationConfig\getValidForSeconds(), ilNotificationConfig\getVisibleForSeconds(), 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 60 of file class.ilNotificationDatabaseHelper.php.

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

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 94 of file class.ilNotificationDatabaseHelper.php.

95 {
96 $foundPlaceholders = array();
97 preg_match_all($pattern, $translation, $foundPlaceholders);
98 return (array) $foundPlaceholders[1];
99 }

Referenced by fillPlaceholders().

+ Here is the caller graph for this function:

◆ getAvailableChannels()

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

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

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

References $DIC, $ilDB, $query, $result, 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 431 of file class.ilNotificationDatabaseHelper.php.

432 {
433 global $DIC;
434
435 $ilDB = $DIC->database();
436
437 $query = 'SELECT type_name, title, description, notification_group, config_type FROM ' . ilNotificationSetupHelper::$tbl_notification_types;
438 if ($config_types) {
439 $query .= ' WHERE ' . $ilDB->in('config_type', $config_types, false, 'text');
440 }
441
442
443 $rset = $ilDB->query($query);
444
445 $result = array();
446
447 while ($row = $ilDB->fetchAssoc($rset)) {
448 $result[$row['type_name']] = array(
449 'name' => $row['type_name'],
450 'title' => $row['title'],
451 'description' => $row['description'],
452 'group' => $row['notification_group'],
453 'config_type' => $row['config_type'],
454 );
455 }
456
457 return $result;
458 }

References $DIC, $ilDB, $query, $result, 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 286 of file class.ilNotificationDatabaseHelper.php.

287 {
288 global $DIC;
289
290 $ilDB = $DIC->database();
291
292 $query = 'SELECT usr_id FROM ' . ilNotificationSetupHelper::$tbl_userlistener . ' WHERE disabled = 0 AND module = %s AND sender_id = %s';
293 $types = array('text', 'integer');
294 $values = array($module, $sender_id);
295
296 $users = array();
297
298 $rset = $ilDB->queryF($query, $types, $values);
299 while ($row = $ilDB->fetchAssoc($rset)) {
300 $users[] = $row['usr_id'];
301 }
302 return $users;
303 }

References $DIC, $ilDB, $query, 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 485 of file class.ilNotificationDatabaseHelper.php.

486 {
487 global $DIC;
488
489 $ilDB = $DIC->database();
490
491 $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"';
492 $rset = $ilDB->query($query);
493 $result = array();
494 while ($row = $ilDB->fetchAssoc($rset)) {
495 $result[$row['usr_id']] = (bool) $row['value'];
496 }
497 return $result;
498 }

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

Referenced by ilNotificationSystem\toUsers().

+ Here is the caller graph for this function:

◆ loadUserConfig()

static ilNotificationDatabaseHandler::loadUserConfig (   $userid)
static

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

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

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

Referenced by ilObjContactAdministrationGUI\saveConfigurationForm(), ilObjNotificationAdminGUI\showConfigMatrixObject(), ilObjContactAdministrationGUI\showConfigurationForm(), 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 348 of file class.ilNotificationDatabaseHelper.php.

349 {
350 global $DIC;
351
352 $ilDB = $DIC->database();
353
354 $ilDB->insert(
356 array(
357 'channel_name' => array('text', $name),
358 'title' => array('text', $title),
359 'description' => array('text', $description),
360 'class' => array('text', $class),
361 'include' => array('text', $classfile),
362 'config_type' => array('text', $config_type),
363 )
364 );
365 }
if($format !==null) $name
Definition: metadata.php:230

References $DIC, $ilDB, $name, 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 378 of file class.ilNotificationDatabaseHelper.php.

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

References $DIC, $ilDB, $name, 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 273 of file class.ilNotificationDatabaseHelper.php.

274 {
275 global $DIC;
276
277 $ilDB = $DIC->database();
278
279 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_data . ' WHERE notification_id = ?';
280 $types = array('integer');
281 $values = array($id);
282
283 $ilDB->manipulateF($query, $types, $values);
284 }

References $DIC, $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 110 of file class.ilNotificationDatabaseHelper.php.

111 {
112 foreach ($foundPlaceholders as $placeholder) {
113 if (array_key_exists(strtoupper($placeholder), $params)) {
114 $string = str_ireplace($startTag . $placeholder . $endTage, $params[strtoupper($placeholder)], $string);
115 }
116 if (array_key_exists(strtolower($placeholder), $params)) {
117 $string = str_ireplace($startTag . $placeholder . $endTage, $params[strtolower($placeholder)], $string);
118 }
119 }
120 return $string;
121 }

Referenced by fillPlaceholders().

+ Here is the caller graph for this function:

◆ setConfigTypeForChannel()

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

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

473 {
474 global $DIC;
475
476 $ilDB = $DIC->database();
477
478 $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_channels . ' SET config_type = %s WHERE channel_name = %s';
479 $types = array('text', 'text');
480 $values = array($config_name, $channel_name);
481 $ilDB->manipulateF($query, $types, $values);
482 }

References $DIC, $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 460 of file class.ilNotificationDatabaseHelper.php.

461 {
462 global $DIC;
463
464 $ilDB = $DIC->database();
465
466 $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_types . ' SET config_type = %s WHERE type_name = %s';
467 $types = array('text', 'text');
468 $values = array($config_name, $type_name);
469 $ilDB->manipulateF($query, $types, $values);
470 }

References $DIC, $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 147 of file class.ilNotificationDatabaseHelper.php.

148 {
149 global $DIC;
150
151 $ilDB = $DIC->database();
152
153 if ($userid != -1) {
154 $channels = self::getAvailableChannels(array('set_by_user'));
155 $types = self::getAvailableTypes(array('set_by_user'));
156 $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');
157 } else {
158 $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id=%s';
159 }
160
161 $types = array('integer');
162 $values = array($userid);
163
164 // delete old settings
165 $ilDB->manipulateF($query, $types, $values);
166
167 foreach ($configArray as $type => $channels) {
168 foreach ($channels as $channel => $value) {
169 if (!$value) {
170 continue;
171 }
172 $ilDB->insert(
174 array(
175 'usr_id' => array('integer', $userid),
176 'module' => array('text', $type),
177 'channel' => array('text', $channel),
178 )
179 );
180 }
181 }
182 }
static getAvailableChannels($config_types=array(), $includeDisabled=false)
$type

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

Referenced by ilObjNotificationAdminGUI\saveConfigMatrixObject(), ilObjContactAdministrationGUI\saveConfigurationForm(), 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 254 of file class.ilNotificationDatabaseHelper.php.

255 {
256 global $DIC;
257
258 $ilDB = $DIC->database();
259
261
262 $ilDB->insert(
264 array(
265 'notification_id' => array('integer', $id),
266 'serialized' => array('text', serialize($notification)),
267 )
268 );
269
270 return $id;
271 }

References $DIC, $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: