Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
NotificationSubscriptionSettingsDAO.inc.php
1 <?php
2 
25  parent::DAO();
26  }
27 
34  function deleteNotificationSubscriptionSettings($notificationId, $userId, $settingName = null) {
35  $params = array((int) $notificationId, (int) $userId);
36  if ($settingName) $params[] = $settingName;
37 
38  return $this->update(
39  'DELETE FROM notification_subscription_settings
40  WHERE notification_id= ? AND user_id = ?' . isset($settingName) ? ' AND setting_name = ?' : '',
41  $params
42  );
43  }
44 
52  function &getNotificationSubscriptionSettings($settingName, $userId, $contextId) {
53  $result =& $this->retrieve(
54  'SELECT setting_value FROM notification_subscription_settings WHERE user_id = ? AND setting_name = ? AND context = ?',
55  array((int) $userId, $settingName, (int) $contextId)
56  );
57 
58  $settings = array();
59  while (!$result->EOF) {
60  $row = $result->GetRowAssoc(false);
61  $settings[] = (int) $row['setting_value'];
62  $result->MoveNext();
63  }
64 
65  $result->Close();
66  unset($result);
67 
68  return $settings;
69  }
70 
78  function updateNotificationSubscriptionSettings($settingName, $settings, $userId, $contextId) {
79  // Delete old settings first, then insert new settings
80  $this->update('DELETE FROM notification_subscription_settings WHERE user_id = ? AND setting_name = ? AND context = ?',
81  array((int) $userId, $settingName, (int) $contextId));
82 
83  foreach ($settings as $setting) {
84  $this->update(
85  'INSERT INTO notification_subscription_settings
86  (setting_name, setting_value, user_id, context, setting_type)
87  VALUES
88  (?, ?, ?, ?, ?)',
89  array(
90  $settingName,
91  (int) $setting,
92  (int) $userId,
93  (int) $contextId,
94  'int'
95  )
96  );
97  }
98  }
99 
106  function getUserIdByRSSToken($token, $contextId) {
107  $result =& $this->retrieve(
108  'SELECT user_id FROM notification_subscription_settings WHERE setting_value = ? AND setting_name = ? AND context = ?',
109  array($token, 'token', (int) $contextId)
110  );
111 
112  $row = $result->GetRowAssoc(false);
113  $userId = $row['user_id'];
114 
115  $result->Close();
116  unset($result);
117 
118  return $userId;
119  }
120 
127  function getRSSTokenByUserId($userId, $contextId) {
128  $result =& $this->retrieve(
129  'SELECT setting_value FROM notification_subscription_settings WHERE user_id = ? AND setting_name = ? AND context = ?',
130  array((int) $userId, 'token', (int) $contextId)
131  );
132 
133  $row = $result->GetRowAssoc(false);
134  $tokenId = $row['setting_value'];
135 
136  $result->Close();
137  unset($result);
138 
139  return $tokenId;
140  }
141 
148  function insertNewRSSToken($userId, $contextId) {
149  $token = uniqid(rand());
150 
151  // Recurse if this token already exists
152  if($this->getUserIdByRSSToken($token, $contextId)) return $this->insertNewRSSToken($userId, $contextId);
153 
154  $this->update(
155  'INSERT INTO notification_subscription_settings
156  (setting_name, setting_value, user_id, context, setting_type)
157  VALUES
158  (?, ?, ?, ?, ?)',
159  array(
160  'token',
161  $token,
162  (int) $userId,
163  (int) $contextId,
164  'string'
165  )
166  );
167 
168  return $token;
169  }
170 
171 }
172 
173 ?>
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
updateNotificationSubscriptionSettings($settingName, $settings, $userId, $contextId)
Operations for retrieving and modifying user&#39;s notification settings. This class stores user settings...
& getNotificationSubscriptionSettings($settingName, $userId, $contextId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteNotificationSubscriptionSettings($notificationId, $userId, $settingName=null)