Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
AccessKeyDAO.inc.php
1 <?php
2 
18 import('lib.pkp.classes.security.AccessKey');
19 
20 class AccessKeyDAO extends DAO {
24  function AccessKeyDAO() {
25  parent::DAO();
26  }
27 
33  function &getAccessKey($accessKeyId) {
34  $result = $this->retrieve(
35  sprintf(
36  'SELECT * FROM access_keys WHERE access_key_id = ? AND expiry_date > %s',
38  ),
39  array((int) $accessKeyId)
40  );
41 
42  $accessKey = null;
43  if ($result->RecordCount() != 0) {
44  $accessKey =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
45  }
46  $result->Close();
47  return $accessKey;
48  }
49 
56  function &getAccessKeyByUserId($context, $userId) {
57  $result = $this->retrieve(
58  sprintf(
59  'SELECT * FROM access_keys WHERE context = ? AND user_id = ? AND expiry_date > %s',
61  ),
62  array($context, $userId)
63  );
64 
65  $returner = null;
66  if ($result->RecordCount() != 0) {
67  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
68  }
69  $result->Close();
70  return $returner;
71  }
72 
81  function &getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId = null) {
82  $paramArray = array($context, $keyHash, (int) $userId);
83  if (isset($assocId)) $paramArray[] = (int) $assocId;
84  $result = $this->retrieve(
85  sprintf(
86  'SELECT * FROM access_keys WHERE context = ? AND key_hash = ? AND user_id = ? AND expiry_date > %s' . (isset($assocId)?' AND assoc_id = ?':''),
88  ),
89  $paramArray
90  );
91 
92  $returner = null;
93  if ($result->RecordCount() != 0) {
94  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
95  }
96  $result->Close();
97  return $returner;
98  }
99 
104  function newDataObject() {
105  return new AccessKey();
106  }
107 
113  function &_returnAccessKeyFromRow($row) {
114  $accessKey = $this->newDataObject();
115  $accessKey->setId($row['access_key_id']);
116  $accessKey->setKeyHash($row['key_hash']);
117  $accessKey->setExpiryDate($this->datetimeFromDB($row['expiry_date']));
118  $accessKey->setContext($row['context']);
119  $accessKey->setAssocId($row['assoc_id']);
120  $accessKey->setUserId($row['user_id']);
121 
122  HookRegistry::call('AccessKeyDAO::_returnAccessKeyFromRow', array(&$accessKey, &$row));
123 
124  return $accessKey;
125  }
126 
131  function insertObject($accessKey) {
132  $this->update(
133  sprintf('INSERT INTO access_keys
134  (key_hash, expiry_date, context, assoc_id, user_id)
135  VALUES
136  (?, %s, ?, ?, ?)',
137  $this->datetimeToDB($accessKey->getExpiryDate())),
138  array(
139  $accessKey->getKeyHash(),
140  $accessKey->getContext(),
141  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
142  (int) $accessKey->getUserId()
143  )
144  );
145 
146  $accessKey->setId($this->getInsertId());
147  return $accessKey->getId();
148  }
149 
154  function updateObject(&$accessKey) {
155  return $this->update(
156  sprintf('UPDATE access_keys
157  SET
158  key_hash = ?,
159  expiry_date = %s,
160  context = ?,
161  assoc_id = ?,
162  user_id = ?
163  WHERE access_key_id = ?',
164  $this->datetimeToDB($accessKey->getExpiryDate())),
165  array(
166  $accessKey->getKeyHash(),
167  $accessKey->getContext(),
168  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
169  (int) $accessKey->getUserId(),
170  (int) $accessKey->getId()
171  )
172  );
173  }
174 
179  function deleteObject(&$accessKey) {
180  return $this->deleteAccessKeyById($accessKey->getId());
181  }
182 
187  function deleteAccessKeyById($accessKeyId) {
188  return $this->update(
189  'DELETE FROM access_keys WHERE access_key_id = ?',
190  array((int) $accessKeyId)
191  );
192  }
193 
199  function transferAccessKeys($oldUserId, $newUserId) {
200  return $this->update(
201  'UPDATE access_keys SET user_id = ? WHERE user_id = ?',
202  array((int) $newUserId, (int) $oldUserId)
203  );
204  }
205 
209  function deleteExpiredKeys() {
210  return $this->update(
211  sprintf(
212  'DELETE FROM access_keys WHERE expiry_date <= %s',
214  )
215  );
216  }
217 
222  function getInsertId() {
223  return $this->_getInsertId('access_keys', 'access_key_id');
224  }
225 }
226 
227 ?>
transferAccessKeys($oldUserId, $newUserId)
updateObject(&$accessKey)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
Operations for retrieving and modifying AccessKey objects.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
& _returnAccessKeyFromRow($row)
& getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId=null)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
datetimeFromDB($dt)
Definition: DAO.inc.php:313
static call($hookName, $args=null)
deleteObject(&$accessKey)
& getAccessKey($accessKeyId)
& getAccessKeyByUserId($context, $userId)
deleteAccessKeyById($accessKeyId)
datetimeToDB($dt)
Definition: DAO.inc.php:293
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
insertObject($accessKey)
AccessKey class.
static getCurrentDate($ts=null)
Definition: Core.inc.php:95