Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
NotificationSettingsDAO.inc.php
1 <?php
2 
18 import('classes.notification.Notification');
19 
25  parent::DAO();
26  }
27 
33  function getNotificationSettings($notificationId) {
34  $result = $this->retrieve(
35  'SELECT * FROM notification_settings WHERE notification_id = ?',
36  (int) $notificationId
37  );
38 
39  $params = array();
40  while (!$result->EOF) {
41  $row = $result->GetRowAssoc(false);
42  $name = $row['setting_name'];
43  $value = $this->convertFromDB($row['setting_value'], $row['setting_type']);
44  $locale = $row['locale'];
45 
46  if ($locale == '') $params[$name] = $value;
47  else $params[$name][$locale] = $value;
48  $result->MoveNext();
49  }
50 
51  $result->Close();
52  return $params;
53  }
54 
64  function updateNotificationSetting($notificationId, $name, $value, $isLocalized = false, $type = null) {
65  $keyFields = array('setting_name', 'locale', 'notification_id');
66  if (!$isLocalized) {
67  $value = $this->convertToDB($value, $type);
68  $this->replace('notification_settings',
69  array(
70  'notification_id' => (int) $notificationId,
71  'setting_name' => $name,
72  'setting_value' => $value,
73  'setting_type' => $type,
74  'locale' => ''
75  ),
76  $keyFields
77  );
78  } else {
79  if (is_array($value)) foreach ($value as $locale => $localeValue) {
80  $this->update('DELETE FROM notification_settings WHERE notification_id = ? AND setting_name = ? AND locale = ?', array($notificationId, $name, $locale));
81  if (empty($localeValue)) continue;
82  $type = null;
83  $this->update('INSERT INTO notification_settings
84  (notification_id, setting_name, setting_value, setting_type, locale)
85  VALUES (?, ?, ?, ?, ?)',
86  array(
87  (int) $notificationId,
88  $name, $this->convertToDB($localeValue, $type),
89  $type,
90  $locale
91  )
92  );
93  }
94  }
95  }
96 
101  function deleteSettingsByNotificationId($notificationId) {
102  return $this->update('DELETE FROM notification_settings WHERE notification_id = ?', (int) $notificationId);
103  }
104 }
105 
106 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
convertFromDB($value, $type)
Definition: DAO.inc.php:335
Operations for retrieving and modifying Notification metadata.
convertToDB($value, &$type)
Definition: DAO.inc.php:391
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:237
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
updateNotificationSetting($notificationId, $name, $value, $isLocalized=false, $type=null)