Open Journal Systems  2.4.4
 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  unset($result);
53  return $params;
54  }
55 
61  function updateNotificationSetting($notificationId, $name, $value, $isLocalized = false, $type = null) {
62  $keyFields = array('setting_name', 'locale', 'notification_id');
63  if (!$isLocalized) {
64  $value = $this->convertToDB($value, $type);
65  $this->replace('notification_settings',
66  array(
67  'notification_id' => (int) $notificationId,
68  'setting_name' => $name,
69  'setting_value' => $value,
70  'setting_type' => $type,
71  'locale' => ''
72  ),
73  $keyFields
74  );
75  } else {
76  if (is_array($value)) foreach ($value as $locale => $localeValue) {
77  $this->update('DELETE FROM notification_settings WHERE notification_id = ? AND setting_name = ? AND locale = ?', array($notificationId, $name, $locale));
78  if (empty($localeValue)) continue;
79  $type = null;
80  $this->update('INSERT INTO notification_settings
81  (notification_id, setting_name, setting_value, setting_type, locale)
82  VALUES (?, ?, ?, ?, ?)',
83  array(
84  $notificationId, $name, $this->convertToDB($localeValue, $type), $type, $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 
101 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
convertFromDB($value, $type)
Definition: DAO.inc.php:338
Operations for retrieving and modifying Notification metadata.
convertToDB($value, &$type)
Definition: DAO.inc.php:394
replace($table, $arrFields, $keyCols)
Definition: DAO.inc.php:240
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
updateNotificationSetting($notificationId, $name, $value, $isLocalized=false, $type=null)
deleteSettingsByNotificationId($notificationId)