Open Monograph Press  3.3.0
NotificationSettingsDAO.inc.php
1 <?php
2 
18 import('classes.notification.Notification');
19 
21 
27  function getNotificationSettings($notificationId) {
28  $result = $this->retrieve(
29  'SELECT * FROM notification_settings WHERE notification_id = ?',
30  (int) $notificationId
31  );
32 
33  $params = array();
34  while (!$result->EOF) {
35  $row = $result->GetRowAssoc(false);
36  $name = $row['setting_name'];
37  $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
38  $locale = $row['locale'];
39 
40  if ($locale == '') $params[$name] = $value;
41  else $params[$name][$locale] = $value;
42  $result->MoveNext();
43  }
44 
45  $result->Close();
46  return $params;
47  }
48 
58  function updateNotificationSetting($notificationId, $name, $value, $isLocalized = false, $type = null) {
59  $keyFields = array('setting_name', 'locale', 'notification_id');
60  if (!$isLocalized) {
61  $value = $this->convertToDB($value, $type);
62  $this->replace('notification_settings',
63  array(
64  'notification_id' => (int) $notificationId,
65  'setting_name' => $name,
66  'setting_value' => $value,
67  'setting_type' => $type,
68  'locale' => ''
69  ),
70  $keyFields
71  );
72  } else {
73  if (is_array($value)) foreach ($value as $locale => $localeValue) {
74  $this->update('DELETE FROM notification_settings WHERE notification_id = ? AND setting_name = ? AND locale = ?', array($notificationId, $name, $locale));
75  if (empty($localeValue)) continue;
76  $type = null;
77  $this->update('INSERT INTO notification_settings
78  (notification_id, setting_name, setting_value, setting_type, locale)
79  VALUES (?, ?, ?, ?, ?)',
80  array(
81  (int) $notificationId,
82  $name, $this->convertToDB($localeValue, $type),
83  $type,
84  $locale
85  )
86  );
87  }
88  }
89  }
90 
95  function deleteSettingsByNotificationId($notificationId) {
96  return $this->update('DELETE FROM notification_settings WHERE notification_id = ?', (int) $notificationId);
97  }
98 }
99 
100 
NotificationSettingsDAO\updateNotificationSetting
updateNotificationSetting($notificationId, $name, $value, $isLocalized=false, $type=null)
Definition: NotificationSettingsDAO.inc.php:58
NotificationSettingsDAO\deleteSettingsByNotificationId
deleteSettingsByNotificationId($notificationId)
Definition: NotificationSettingsDAO.inc.php:95
DAO\convertToDB
convertToDB($value, &$type)
Definition: DAO.inc.php:401
NotificationSettingsDAO\getNotificationSettings
getNotificationSettings($notificationId)
Definition: NotificationSettingsDAO.inc.php:27
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
DAO\convertFromDB
convertFromDB($value, $type)
Definition: DAO.inc.php:341
NotificationSettingsDAO
Operations for retrieving and modifying Notification metadata.
Definition: NotificationSettingsDAO.inc.php:20
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
DAO\replace
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:243
DAO
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:31