Open Journal Systems  2.4.4
 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  unset($result);
48  return $accessKey;
49  }
50 
57  function &getAccessKeyByUserId($context, $userId) {
58  $result =& $this->retrieve(
59  sprintf(
60  'SELECT * FROM access_keys WHERE context = ? AND user_id = ? AND expiry_date > %s',
62  ),
63  array($context, $userId)
64  );
65 
66  $returner = null;
67  if ($result->RecordCount() != 0) {
68  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
69  }
70  $result->Close();
71  unset($result);
72  return $returner;
73  }
74 
83  function &getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId = null) {
84  $paramArray = array($context, $keyHash, (int) $userId);
85  if (isset($assocId)) $paramArray[] = (int) $assocId;
86  $result =& $this->retrieve(
87  sprintf(
88  'SELECT * FROM access_keys WHERE context = ? AND key_hash = ? AND user_id = ? AND expiry_date > %s' . (isset($assocId)?' AND assoc_id = ?':''),
90  ),
91  $paramArray
92  );
93 
94  $returner = null;
95  if ($result->RecordCount() != 0) {
96  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
97  }
98  $result->Close();
99  unset($result);
100  return $returner;
101  }
102 
107  function newDataObject() {
108  return new AccessKey();
109  }
110 
116  function &_returnAccessKeyFromRow(&$row) {
117  $accessKey = $this->newDataObject();
118  $accessKey->setId($row['access_key_id']);
119  $accessKey->setKeyHash($row['key_hash']);
120  $accessKey->setExpiryDate($this->datetimeFromDB($row['expiry_date']));
121  $accessKey->setContext($row['context']);
122  $accessKey->setAssocId($row['assoc_id']);
123  $accessKey->setUserId($row['user_id']);
124 
125  HookRegistry::call('AccessKeyDAO::_returnAccessKeyFromRow', array(&$accessKey, &$row));
126 
127  return $accessKey;
128  }
129 
134  function insertAccessKey(&$accessKey) {
135  $this->update(
136  sprintf('INSERT INTO access_keys
137  (key_hash, expiry_date, context, assoc_id, user_id)
138  VALUES
139  (?, %s, ?, ?, ?)',
140  $this->datetimeToDB($accessKey->getExpiryDate())),
141  array(
142  $accessKey->getKeyHash(),
143  $accessKey->getContext(),
144  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
145  (int) $accessKey->getUserId()
146  )
147  );
148 
149  $accessKey->setId($this->getInsertAccessKeyId());
150  return $accessKey->getId();
151  }
152 
157  function updateObject(&$accessKey) {
158  return $this->update(
159  sprintf('UPDATE access_keys
160  SET
161  key_hash = ?,
162  expiry_date = %s,
163  context = ?,
164  assoc_id = ?,
165  user_id = ?
166  WHERE access_key_id = ?',
167  $this->datetimeToDB($accessKey->getExpiryDate())),
168  array(
169  $accessKey->getKeyHash(),
170  $accessKey->getContext(),
171  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
172  (int) $accessKey->getUserId(),
173  (int) $accessKey->getId()
174  )
175  );
176  }
177 
178  function updateAccessKey(&$accessKey) {
179  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
180  return $this->updateObject($accessKey);
181  }
182 
187  function deleteObject(&$accessKey) {
188  return $this->deleteAccessKeyById($accessKey->getId());
189  }
190 
191  function deleteAccessKey(&$accessKey) {
192  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
193  return $this->deleteObject($accessKey);
194  }
195 
200  function deleteAccessKeyById($accessKeyId) {
201  return $this->update(
202  'DELETE FROM access_keys WHERE access_key_id = ?',
203  array((int) $accessKeyId)
204  );
205  }
206 
212  function transferAccessKeys($oldUserId, $newUserId) {
213  return $this->update(
214  'UPDATE access_keys SET user_id = ? WHERE user_id = ?',
215  array((int) $newUserId, (int) $oldUserId)
216  );
217  }
218 
222  function deleteExpiredKeys() {
223  return $this->update(
224  sprintf(
225  'DELETE FROM access_keys WHERE expiry_date <= %s',
227  )
228  );
229  }
230 
235  function getInsertAccessKeyId() {
236  return $this->getInsertId('access_keys', 'access_key_id');
237  }
238 }
239 
240 ?>
transferAccessKeys($oldUserId, $newUserId)
updateObject(&$accessKey)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
Operations for retrieving and modifying AccessKey objects.
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
& getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId=null)
getCurrentDate($ts=null)
Definition: Core.inc.php:94
datetimeFromDB($dt)
Definition: DAO.inc.php:316
deleteObject(&$accessKey)
insertAccessKey(&$accessKey)
& getAccessKey($accessKeyId)
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getAccessKeyByUserId($context, $userId)
deleteAccessKeyById($accessKeyId)
call($hookName, $args=null)
& _returnAccessKeyFromRow(&$row)
datetimeToDB($dt)
Definition: DAO.inc.php:296
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
AccessKey class.