ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
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 314 of file class.ilNotificationDatabaseHelper.php.

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

Referenced by ilNotificationSystem\toListeners().

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  }
if($modEnd===false) $module
Definition: module.php:59
$query
Create styles array
The data for the language used.
global $ilDB
+ 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.

References $ilDB, $module, $query, ilNotificationSetupHelper\$tbl_userlistener, $users, and array.

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

326  {
327  global $ilDB;
328 
329  $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_userlistener . ' SET disabled = 0 WHERE module = %s AND sender_id = %s';
330 
331  if ($users) {
332  $query .= ' ' . $ilDB->in('usr_id', $users);
333  }
334 
335  $types = array('text', 'integer');
336  $values = array($module, $sender_id);
337 
338  $ilDB->manipulateF($query, $types, $values);
339  }
if($modEnd===false) $module
Definition: module.php:59
$query
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
global $ilDB
+ Here is the caller graph for this function:

◆ enqueueByListener()

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

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

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

Referenced by ilNotificationSystem\toListeners().

231  {
232  global $ilDB;
233 
234  $notification_id = ilNotificationDatabaseHandler::storeNotification($notification);
235  $valid_until = $notification->getValidForSeconds() ? (time() + $notification->getValidForSeconds()) : 0;
236 
237  $query = 'INSERT INTO ' . ilNotificationSetupHelper::$tbl_notification_queue . ' (notification_id, usr_id, valid_until, visible_for) '
238  . ' (SELECT %s, usr_id, %s, %s FROM ' . ilNotificationSetupHelper::$tbl_userlistener . ' WHERE disabled = 0 AND module = %s AND sender_id = %s)';
239 
240  $types = array('integer', 'integer', 'integer', 'text', 'integer');
241 
242  $values = array($notification_id, $valid_until, $notification->getVisibleForSeconds(), $notification->getType(), $ref_id);
243 
244  $ilDB->manipulateF($query, $types, $values);
245  }
static storeNotification(ilNotificationConfig $notification)
$query
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 206 of file class.ilNotificationDatabaseHelper.php.

References $ilDB, ilNotificationSetupHelper\$tbl_notification_queue, $userid, array, ilNotificationConfig\getValidForSeconds(), ilNotificationConfig\getVisibleForSeconds(), storeNotification(), and time.

Referenced by ilNotificationSystem\toUsers().

207  {
208  if (!$userids) {
209  return;
210  }
211 
212  global $ilDB;
213 
214  $notification_id = ilNotificationDatabaseHandler::storeNotification($notification);
215  $valid_until = $notification->getValidForSeconds() ? (time() + $notification->getValidForSeconds()) : 0;
216 
217  foreach ($userids as $userid) {
218  $ilDB->insert(
220  array(
221  'notification_id' => array('integer', $notification_id),
222  'usr_id' => array('integer', $userid),
223  'valid_until' => array('integer', $valid_until),
224  'visible_for' => array('integer', $notification->getVisibleForSeconds())
225  )
226  );
227  }
228  }
if(empty($userids)) $userid
$userids
static storeNotification(ilNotificationConfig $notification)
Create styles array
The data for the language used.
global $ilDB
Add data(end) time
Method that wraps PHPs time in order to allow simulations with the workflow.
+ 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 61 of file class.ilNotificationDatabaseHelper.php.

References $res, $results, and array.

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

◆ findPlaceholders()

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

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

References array.

96  {
97  $foundPlaceholders = array();
98  preg_match_all($pattern, $translation, $foundPlaceholders);
99  return (array) $foundPlaceholders[1];
100  }
Create styles array
The data for the language used.

◆ getAvailableChannels()

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

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

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

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

398  {
399  global $ilDB;
400 
401  $query = 'SELECT channel_name, title, description, class, include, config_type FROM ' . ilNotificationSetupHelper::$tbl_notification_channels;
402  if ($config_types) {
403  $query .= ' WHERE ' . $ilDB->in('config_type', $config_types, false, 'text');
404  }
405 
406  $rset = $ilDB->query($query);
407 
408  $result = array();
409 
410  $settings = new ilSetting('notifications');
411 
412  while ($row = $ilDB->fetchAssoc($rset)) {
413  if (!$includeDisabled && !$settings->get('enable_' . $row['channel_name'])) {
414  continue;
415  }
416 
417  $result[$row['channel_name']] = array(
418  'name' => $row['channel_name'],
419  'title' => $row['title'],
420  'description' => $row['description'],
421  'handler' => $row['class'],
422  'include' => $row['include'],
423  'config_type' => $row['config_type'],
424  );
425  }
426 
427  return $result;
428  }
$result
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getAvailableTypes()

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

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

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

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

431  {
432  global $ilDB;
433 
434  $query = 'SELECT type_name, title, description, notification_group, config_type FROM ' . ilNotificationSetupHelper::$tbl_notification_types;
435  if ($config_types) {
436  $query .= ' WHERE ' . $ilDB->in('config_type', $config_types, false, 'text');
437  }
438 
439 
440  $rset = $ilDB->query($query);
441 
442  $result = array();
443 
444  while ($row = $ilDB->fetchAssoc($rset)) {
445  $result[$row['type_name']] = array(
446  'name' => $row['type_name'],
447  'title' => $row['title'],
448  'description' => $row['description'],
449  'group' => $row['notification_group'],
450  'config_type' => $row['config_type'],
451  );
452  }
453 
454  return $result;
455  }
$result
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ getUsersByListener()

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

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

References $ilDB, $module, $query, $row, ilNotificationSetupHelper\$tbl_userlistener, $users, and array.

Referenced by ilNotificationSystem\toListeners().

298  {
299  global $ilDB;
300 
301  $query = 'SELECT usr_id FROM ' . ilNotificationSetupHelper::$tbl_userlistener . ' WHERE disabled = 0 AND module = %s AND sender_id = %s';
302  $types = array('text', 'integer');
303  $values = array($module, $sender_id);
304 
305  $users = array();
306 
307  $rset = $ilDB->queryF($query, $types, $values);
308  while ($row = $ilDB->fetchAssoc($rset)) {
309  $users[] = $row['usr_id'];
310  }
311  return $users;
312  }
if($modEnd===false) $module
Definition: module.php:59
$query
Create styles array
The data for the language used.
$users
Definition: authpage.php:44
global $ilDB
+ Here is the caller graph for this function:

◆ getUsersWithCustomConfig()

static ilNotificationDatabaseHandler::getUsersWithCustomConfig ( array  $userid)
static

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

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

Referenced by ilNotificationSystem\toUsers().

477  {
478  global $ilDB;
479  $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"';
480  $rset = $ilDB->query($query);
481  $result = array();
482  while ($row = $ilDB->fetchAssoc($rset)) {
483  $result[$row['usr_id']] = (bool) $row['value'];
484  }
485  return $result;
486  }
$result
if(empty($userids)) $userid
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ loadUserConfig()

static ilNotificationDatabaseHandler::loadUserConfig (   $userid)
static

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

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

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

184  {
185  global $ilDB;
186 
187  $query = 'SELECT module, channel FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id = %s';
188  $types = array('integer');
189  $values = array($userid);
190 
191  $res = $ilDB->queryF($query, $types, $values);
192 
193  $result = array();
194 
195  while ($row = $ilDB->fetchAssoc($res)) {
196  if (!$result[$row['module']]) {
197  $result[$row['module']] = array();
198  }
199 
200  $result[$row['module']][] = $row['channel'];
201  }
202 
203  return $result;
204  }
$result
if(empty($userids)) $userid
foreach($_POST as $key=> $value) $res
$query
Create styles array
The data for the language used.
global $ilDB
+ 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.

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

References $description, $ilDB, $name, ilNotificationSetupHelper\$tbl_notification_channels, $title, and array.

Referenced by ilNotificationSetupHelper\registerChannel().

354  {
355  global $ilDB;
356 
357  $ilDB->insert(
359  array(
360  'channel_name' => array('text', $name),
361  'title' => array('text', $title),
362  'description' => array('text', $description),
363  'class' => array('text', $class),
364  'include' => array('text', $classfile),
365  'config_type' => array('text', $config_type),
366  )
367  );
368  }
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
global $ilDB
+ 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.

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

References $description, $ilDB, $name, ilNotificationSetupHelper\$tbl_notification_types, $title, and array.

Referenced by ilNotificationSetupHelper\registerType().

382  {
383  global $ilDB;
384 
385  $ilDB->insert(
387  array(
388  'type_name' => array('text', $name),
389  'title' => array('text', $title),
390  'description' => array('text', $description),
391  'notification_group' => array('text', $notification_group),
392  'config_type' => array('text', $config_type),
393  )
394  );
395  }
if($format !==null) $name
Definition: metadata.php:146
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ removeNotification()

static ilNotificationDatabaseHandler::removeNotification (   $id)
static

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

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

287  {
288  global $ilDB;
289 
290  $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_notification_data . ' WHERE notification_id = ?';
291  $types = array('integer');
292  $values = array($id);
293 
294  $ilDB->manipulateF($query, $types, $values);
295  }
if(!array_key_exists('StateId', $_REQUEST)) $id
$query
Create styles array
The data for the language used.
global $ilDB

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

References $params.

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

◆ setConfigTypeForChannel()

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

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

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

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

467  {
468  global $ilDB;
469  $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_channels . ' SET config_type = %s WHERE channel_name = %s';
470  $types = array('text', 'text');
471  $values = array($config_name, $channel_name);
472  $ilDB->manipulateF($query, $types, $values);
473  }
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ setConfigTypeForType()

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

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

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

Referenced by ilObjNotificationAdminGUI\saveTypesObject().

458  {
459  global $ilDB;
460  $query = 'UPDATE ' . ilNotificationSetupHelper::$tbl_notification_types . ' SET config_type = %s WHERE type_name = %s';
461  $types = array('text', 'text');
462  $values = array($config_name, $type_name);
463  $ilDB->manipulateF($query, $types, $values);
464  }
$query
Create styles array
The data for the language used.
global $ilDB
+ 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).

ilDB $ilDB

Parameters
int$userid
array$configArray

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

References $ilDB, $query, ilNotificationSetupHelper\$tbl_userconfig, $type, $userid, and array.

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

149  {
150  global $ilDB;
151 
152  if ($userid != -1) {
153  $channels = self::getAvailableChannels(array('set_by_user'));
154  $types = self::getAvailableTypes(array('set_by_user'));
155  $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');
156  } else {
157  $query = 'DELETE FROM ' . ilNotificationSetupHelper::$tbl_userconfig . ' WHERE usr_id=%s';
158  }
159 
160  $types = array('integer');
161  $values = array($userid);
162 
163  // delete old settings
164  $ilDB->manipulateF($query, $types, $values);
165 
166  foreach ($configArray as $type => $channels) {
167  foreach ($channels as $channel => $value) {
168  if (!$value) {
169  continue;
170  }
171  $ilDB->insert(
173  array(
174  'usr_id' => array('integer', $userid),
175  'module' => array('text', $type),
176  'channel' => array('text', $channel),
177  )
178  );
179  }
180  }
181  }
$type
if(empty($userids)) $userid
$query
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

◆ storeNotification()

static ilNotificationDatabaseHandler::storeNotification ( ilNotificationConfig  $notification)
static

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

References $id, $ilDB, ilNotificationSetupHelper\$tbl_notification_data, and array.

Referenced by enqueueByListener(), and enqueueByUsers().

270  {
271  global $ilDB;
272 
274 
275  $ilDB->insert(
277  array(
278  'notification_id' => array('integer', $id),
279  'serialized' => array('text', serialize($notification)),
280  )
281  );
282 
283  return $id;
284  }
if(!array_key_exists('StateId', $_REQUEST)) $id
Create styles array
The data for the language used.
global $ilDB
+ Here is the caller graph for this function:

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