ocs  2.3.6
About: OCS (Open Conference System) is a Web publishing tool that will create a complete Web presence for your scholarly conference.
  Fossies Dox: ocs-2.3.6.tar.gz  ("inofficial" and yet experimental doxygen-generated source code documentation)  

NotificationSettingsDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 // $Id$
17 
23  parent::DAO();
24  }
25 
33  function &getNotificationSettings($userId) {
35  $productName = $application->getName();
36  $context =& Request::getContext();
37  $contextId = $context->getId();
38 
39  $notificationSettings = array();
40 
41  $result =& $this->retrieve(
42  'SELECT setting_value FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
43  array((int) $userId, $productName, 'notify', (int) $contextId)
44  );
45 
46  while (!$result->EOF) {
47  $row = $result->GetRowAssoc(false);
48  $notificationSettings[] = (int) $row['setting_value'];
49  $result->moveNext();
50  }
51 
52  $result->Close();
53  unset($result);
54 
55  return $notificationSettings;
56  }
57 
65  function &getNotificationEmailSettings($userId) {
67  $productName = $application->getName();
68  $context =& Request::getContext();
69  $contextId = $context->getId();
70 
71  $emailSettings = array();
72 
73  $result =& $this->retrieve(
74  'SELECT setting_value FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
75  array((int) $userId, $productName, 'email', (int) $contextId)
76  );
77 
78  while (!$result->EOF) {
79  $row = $result->GetRowAssoc(false);
80  $emailSettings[] = (int) $row['setting_value'];
81  $result->moveNext();
82  }
83 
84  $result->Close();
85  unset($result);
86 
87  return $emailSettings;
88  }
89 
95  function updateNotificationSettings($notificationSettings, $userId) {
97  $productName = $application->getName();
98  $context =& Request::getContext();
99  $contextId = $context->getId();
100 
101  // Delete old settings first, then insert new settings
102  $this->update('DELETE FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
103  array((int) $userId, $productName, 'notify', (int) $contextId));
104 
105  for ($i=0; $i<count($notificationSettings); $i++) {
106  $this->update(
107  'INSERT INTO notification_settings
108  (setting_name, setting_value, user_id, product, context)
109  VALUES
110  (?, ?, ?, ?, ?)',
111  array(
112  "notify",
113  $notificationSettings[$i],
114  (int) $userId,
115  $productName,
116  (int) $contextId
117  )
118  );
119  }
120  }
121 
127  function updateNotificationEmailSettings($emailSettings, $userId) {
129  $productName = $application->getName();
130  $context =& Request::getContext();
131  $contextId = $context->getId();
132 
133  // Delete old settings first, then insert new settings
134  $this->update('DELETE FROM notification_settings WHERE user_id = ? AND product = ? AND setting_name = ? AND context = ?',
135  array($userId, $productName, 'email', $contextId));
136 
137  for ($i=0; $i<count($emailSettings); $i++) {
138  $this->update(
139  'INSERT INTO notification_settings
140  (setting_name, setting_value, user_id, product, context)
141  VALUES
142  (?, ?, ?, ?, ?)',
143  array(
144  "email",
145  $emailSettings[$i],
146  (int) $userId,
147  $productName,
148  (int) $contextId
149  )
150  );
151  }
152  }
153 
159  function getUserIdByRSSToken($token) {
161  $productName = $application->getName();
162  $context =& Request::getContext();
163  $contextId = $context->getId();
164 
165  $result =& $this->retrieve(
166  'SELECT user_id FROM notification_settings WHERE setting_value = ? AND setting_name = ? AND product = ? AND context = ?',
167  array($token, 'token', $productName, (int) $contextId)
168  );
169 
170  $row = $result->GetRowAssoc(false);
171  $userId = $row['user_id'];
172 
173  $result->Close();
174  unset($result);
175 
176  return $userId;
177  }
178 
184  function getRSSTokenByUserId($userId) {
186  $productName = $application->getName();
187  $context =& Request::getContext();
188  $contextId = $context->getId();
189 
190  $result =& $this->retrieve(
191  'SELECT setting_value FROM notification_settings WHERE user_id = ? AND setting_name = ? AND product = ? AND context = ?',
192  array((int) $userId, 'token', $productName, (int) $contextId)
193  );
194 
195  $row = $result->GetRowAssoc(false);
196  $userId = $row['setting_value'];
197 
198  $result->Close();
199  unset($result);
200 
201  return $userId;
202  }
203 
209  function insertNewRSSToken($userId) {
211  $productName = $application->getName();
212  $context =& Request::getContext();
213  $contextId = $context->getId();
214 
215  $token = uniqid(rand());
216 
217  $this->update(
218  'INSERT INTO notification_settings
219  (setting_name, setting_value, user_id, product, context)
220  VALUES
221  (?, ?, ?, ?, ?)',
222  array(
223  'token',
224  $token,
225  (int) $userId,
226  $productName,
227  (int) $contextId
228  )
229  );
230 
231  return $token;
232  }
233 
239  function subscribeGuest($email) {
241  $productName = $application->getName();
242  $context =& Request::getContext();
243  $contextId = $context->getId();
244 
245  // Check that the email doesn't already exist
246  $result =& $this->retrieve(
247  'SELECT * FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
248  array(
249  'mailList',
250  $email,
251  $productName,
252  (int) $contextId
253  )
254  );
255 
256  if ($result->RecordCount() != 0) {
257  return false;
258  } else {
259  $this->update(
260  'DELETE FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND user_id = ? AND product = ? AND context = ?',
261  array(
262  'mailListUnconfirmed',
263  $email,
264  0,
265  $productName,
266  (int) $contextId
267  )
268  );
269  $this->update(
270  'INSERT INTO notification_settings
271  (setting_name, setting_value, user_id, product, context)
272  VALUES
273  (?, ?, ?, ?, ?)',
274  array(
275  'mailListUnconfirmed',
276  $email,
277  0,
278  $productName,
279  (int) $contextId
280  )
281  );
282  }
283 
284  // Get assoc_id into notification_settings table, also used as user_id for access key
285  $assocId = $this->getInsertNotificationSettingId();
286 
287  import('security.AccessKeyManager');
288  $accessKeyManager = new AccessKeyManager();
289 
290  $password = $accessKeyManager->createKey('MailListContext', $assocId, $assocId, 60); // 60 days
291  return $password;
292  }
293 
300  function unsubscribeGuest($email, $password) {
302  $productName = $application->getName();
303  $context =& Request::getContext();
304  $contextId = $context->getId();
305 
306  $result =& $this->retrieve(
307  'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND product = ? AND context = ?',
308  array(
309  'mailList',
310  $productName,
311  (int) $contextId
312  )
313  );
314 
315  $row = $result->GetRowAssoc(false);
316  $userId = (int) $row['setting_id'];
317 
318  $result->Close();
319  unset($result);
320 
321  import('security.AccessKeyManager');
322  $accessKeyManager = new AccessKeyManager();
323  $accessKeyHash = AccessKeyManager::generateKeyHash($password);
324  $accessKey = $accessKeyManager->validateKey('MailListContext', $userId, $accessKeyHash);
325 
326  if ($accessKey) {
327  $this->update(
328  'DELETE FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
329  array(
330  'mailList',
331  $email,
332  $productName,
333  (int) $contextId
334  )
335  );
336  $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
337  $accessKeyDao->deleteObject($accessKey);
338  return true;
339  } else return false;
340  }
341 
346  function getMailListSettingId($email, $settingName = 'mailListUnconfirmed') {
348  $productName = $application->getName();
349  $context =& Request::getContext();
350  $contextId = $context->getId();
351 
352  $result =& $this->retrieve(
353  'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
354  array(
355  $settingName,
356  $email,
357  $productName,
358  (int) $contextId
359  )
360  );
361 
362  $row = $result->GetRowAssoc(false);
363  $settingId = (int) $row['setting_id'];
364 
365  return $settingId;
366  }
367 
372  function confirmMailListSubscription($settingId) {
373  return $this->update(
374  'UPDATE notification_settings SET setting_name = ? WHERE setting_id = ?',
375  array('mailList', (int) $settingId)
376  );
377  }
378 
383  function getMailList() {
385  $productName = $application->getName();
386  $context =& Request::getContext();
387  $contextId = $context->getId();
388  $mailList = array();
389 
390  $result =& $this->retrieve(
391  'SELECT setting_value FROM notification_settings WHERE setting_name = ? AND product = ? AND context = ?',
392  array(
393  'mailList',
394  $productName,
395  (int) $contextId
396  )
397  );
398 
399  while (!$result->EOF) {
400  $row = $result->GetRowAssoc(false);
401  $mailList[] = $row['setting_value'];
402  $result->moveNext();
403  }
404 
405  $result->Close();
406  unset($result);
407 
408  return $mailList;
409  }
410 
416  function resetPassword($email) {
418  $productName = $application->getName();
419  $context =& Request::getContext();
420  $contextId = $context->getId();
421 
422  $result =& $this->retrieve(
423  'SELECT setting_id FROM notification_settings WHERE setting_name = ? AND setting_value = ? AND product = ? AND context = ?',
424  array(
425  'mailList',
426  $email,
427  $productName,
428  (int) $contextId
429  )
430  );
431 
432  $row = $result->GetRowAssoc(false);
433  $settingId = $row['setting_id'];
434 
435  $result->Close();
436  unset($result);
437 
438  $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
439  $accessKey = $accessKeyDao->getAccessKeyByUserId('MailListContext', $settingId);
440 
441  if ($accessKey) {
443  $accessKey->setKeyHash(md5($key));
444 
445  $accessKeyDao =& DAORegistry::getDAO('AccessKeyDAO');
446  $accessKeyDao->updateObject($accessKey);
447  return $key;
448  } else return false;
449  }
450 
456  return $this->getInsertId('notification_settings', 'setting_id');
457  }
458 
459 }
460 
461 ?>
config TEMPLATE inc php
Definition: config.inc.php:4
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getMailListSettingId($email, $settingName='mailListUnconfirmed')
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
generatePassword($length=8)
$application
Definition: index.php:64
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
updateNotificationEmailSettings($emailSettings, $userId)
Class defining operations for AccessKey management.
Operations for retrieving and modifying user's notification settings.
& getDAO($name, $dbconn=null)
updateNotificationSettings($notificationSettings, $userId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186