Open Journal Systems  3.0.0
 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  return $notificationMailListId;
79  }
80 
87  function unsubscribeGuest($token, $contextId) {
88  $notificationMailListId = $this->getMailListIdByToken($token, $contextId);
89 
90  if($notificationMailListId) {
91  return $this->update(
92  'DELETE FROM notification_mail_list WHERE notification_mail_list_id = ?',
93  array((int) $notificationMailListId)
94  );
95  } else return false;
96  }
97 
103  function confirmMailListSubscription($notificationMailListId) {
104  return $this->update(
105  'UPDATE notification_mail_list SET confirmed = 1 WHERE notification_mail_list_id = ?',
106  array((int) $notificationMailListId)
107  );
108  }
109 
115  function getMailList($contextId) {
116  $result = $this->retrieve(
117  'SELECT email FROM notification_mail_list WHERE context = ?',
118  (int) $contextId
119  );
120 
121  $mailList = array();
122  while (!$result->EOF) {
123  $row = $result->GetRowAssoc(false);
124  $mailList[] = $row['email'];
125  $result->MoveNext();
126  }
127 
128  $result->Close();
129  return $mailList;
130  }
131 
136  function getInsertId() {
137  return $this->_getInsertId('notification_mail_list', 'notification_mail_list_id');
138  }
139 
140 }
141 
142 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
getMailListIdByToken($token, $contextId)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
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:208