Open Journal Systems  3.0.0
 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  return $settings;
67  }
68 
76  function updateNotificationSubscriptionSettings($settingName, $settings, $userId, $contextId) {
77  // Delete old settings first, then insert new settings
78  $this->update('DELETE FROM notification_subscription_settings WHERE user_id = ? AND setting_name = ? AND context = ?',
79  array((int) $userId, $settingName, (int) $contextId));
80 
81  foreach ($settings as $setting) {
82  $this->update(
83  'INSERT INTO notification_subscription_settings
84  (setting_name, setting_value, user_id, context, setting_type)
85  VALUES
86  (?, ?, ?, ?, ?)',
87  array(
88  $settingName,
89  (int) $setting,
90  (int) $userId,
91  (int) $contextId,
92  'int'
93  )
94  );
95  }
96  }
97 
104  function getUserIdByRSSToken($token, $contextId) {
105  $result = $this->retrieve(
106  'SELECT user_id FROM notification_subscription_settings WHERE setting_value = ? AND setting_name = ? AND context = ?',
107  array($token, 'token', (int) $contextId)
108  );
109 
110  $row = $result->GetRowAssoc(false);
111  $userId = $row['user_id'];
112 
113  $result->Close();
114  return $userId;
115  }
116 
123  function getRSSTokenByUserId($userId, $contextId) {
124  $result = $this->retrieve(
125  'SELECT setting_value FROM notification_subscription_settings WHERE user_id = ? AND setting_name = ? AND context = ?',
126  array((int) $userId, 'token', (int) $contextId)
127  );
128 
129  $row = $result->GetRowAssoc(false);
130  $tokenId = $row['setting_value'];
131 
132  $result->Close();
133  return $tokenId;
134  }
135 
142  function insertNewRSSToken($userId, $contextId) {
143  $token = uniqid(rand());
144 
145  // Recurse if this token already exists
146  if($this->getUserIdByRSSToken($token, $contextId)) return $this->insertNewRSSToken($userId, $contextId);
147 
148  $this->update(
149  'INSERT INTO notification_subscription_settings
150  (setting_name, setting_value, user_id, context, setting_type)
151  VALUES
152  (?, ?, ?, ?, ?)',
153  array(
154  'token',
155  $token,
156  (int) $userId,
157  (int) $contextId,
158  'string'
159  )
160  );
161 
162  return $token;
163  }
164 
165 }
166 
167 ?>
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
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:208
deleteNotificationSubscriptionSettings($notificationId, $userId, $settingName=null)