Open Journal Systems  2.4.3
 All Classes Namespaces Functions Variables Groups Pages
NotificationMailListDAO.inc.php
1 <?php
2 
22  parent::DAO();
23  }
24 
31  function subscribeGuest($email, $contextId) {
32  $token = uniqid(rand());
33 
34  // Recurse if this token already exists
35  if($this->getMailListIdByToken($token, $contextId)) return $this->subscribeGuest($email, $contextId);
36 
37  // Check that the email doesn't already exist
38  $result =& $this->retrieve(
39  'SELECT * FROM notification_mail_list WHERE email = ? AND context = ?',
40  array(
41  $email,
42  (int) $contextId
43  )
44  );
45  if ($result->RecordCount() != 0) return false;
46 
47  $this->update(
48  'INSERT INTO notification_mail_list
49  (email, context, token)
50  VALUES
51  (?, ?, ?)',
52  array(
53  $email,
54  (int) $contextId,
55  $token
56  )
57  );
58 
59  return $token;
60  }
61 
68  function getMailListIdByToken($token, $contextId) {
69  $result =& $this->retrieve(
70  'SELECT notification_mail_list_id FROM notification_mail_list WHERE token = ? AND context = ?',
71  array($token, (int) $contextId)
72  );
73 
74  $row = $result->GetRowAssoc(false);
75  $notificationMailListId = $row['notification_mail_list_id'];
76 
77  $result->Close();
78  unset($result);
79 
80  return $notificationMailListId;
81  }
82 
90  function unsubscribeGuest($token, $contextId) {
91  $notificationMailListId = $this->getMailListIdByToken($token, $contextId);
92 
93  if($notificationMailListId) {
94  return $this->update(
95  'DELETE FROM notification_mail_list WHERE notification_mail_list_id = ?',
96  array((int) $notificationMailListId)
97  );
98  } else return false;
99  }
100 
106  function confirmMailListSubscription($notificationMailListId) {
107  return $this->update(
108  'UPDATE notification_mail_list SET confirmed = 1 WHERE notification_mail_list_id = ?',
109  array((int) $notificationMailListId)
110  );
111  }
112 
118  function getMailList($contextId) {
119  $result =& $this->retrieve(
120  'SELECT email, token FROM notification_mail_list WHERE context = ?',
121  (int) $contextId
122  );
123 
124  $mailList = array();
125  while (!$result->EOF) {
126  $row = $result->GetRowAssoc(false);
127  $mailList[] = $row;
128  $result->MoveNext();
129  }
130 
131  $result->Close();
132  unset($result);
133 
134  return $mailList;
135  }
136 
142  return $this->getInsertId('notification_mail_list', 'notification_mail_list_id');
143  }
144 
145 }
146 
147 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
getMailListIdByToken($token, $contextId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
confirmMailListSubscription($notificationMailListId)
Operations for getting and setting subscriptions to the non-user notification mailing list...
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211