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)  

AccessKeyDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 // $Id$
17 
18 
19 import('security.AccessKey');
20 
21 class AccessKeyDAO extends DAO {
27  function &getAccessKey($accessKeyId) {
28  $result =& $this->retrieve(
29  sprintf(
30  'SELECT * FROM access_keys WHERE access_key_id = ? AND expiry_date > %s',
32  ),
33  array((int) $accessKeyId)
34  );
35 
36  $accessKey = null;
37  if ($result->RecordCount() != 0) {
38  $accessKey =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
39  }
40  $result->Close();
41  unset($result);
42  return $accessKey;
43  }
44 
51  function &getAccessKeyByUserId($context, $userId) {
52  $result =& $this->retrieve(
53  sprintf(
54  'SELECT * FROM access_keys WHERE context = ? AND user_id = ? AND expiry_date > %s',
56  ),
57  array($context, $userId)
58  );
59 
60  $returner = null;
61  if ($result->RecordCount() != 0) {
62  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
63  }
64  $result->Close();
65  unset($result);
66  return $returner;
67  }
68 
77  function &getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId = null) {
78  $paramArray = array($context, $keyHash, (int) $userId);
79  if (isset($assocId)) $paramArray[] = (int) $assocId;
80  $result =& $this->retrieve(
81  sprintf(
82  'SELECT * FROM access_keys WHERE context = ? AND key_hash = ? AND user_id = ? AND expiry_date > %s' . (isset($assocId)?' AND assoc_id = ?':''),
84  ),
85  $paramArray
86  );
87 
88  $returner = null;
89  if ($result->RecordCount() != 0) {
90  $returner =& $this->_returnAccessKeyFromRow($result->GetRowAssoc(false));
91  }
92  $result->Close();
93  unset($result);
94  return $returner;
95  }
96 
102  function &_returnAccessKeyFromRow(&$row) {
103  $accessKey = new AccessKey();
104  $accessKey->setId($row['access_key_id']);
105  $accessKey->setKeyHash($row['key_hash']);
106  $accessKey->setExpiryDate($this->datetimeFromDB($row['expiry_date']));
107  $accessKey->setContext($row['context']);
108  $accessKey->setAssocId($row['assoc_id']);
109  $accessKey->setUserId($row['user_id']);
110 
111  HookRegistry::call('AccessKeyDAO::_returnAccessKeyFromRow', array(&$accessKey, &$row));
112 
113  return $accessKey;
114  }
115 
120  function insertAccessKey(&$accessKey) {
121  $this->update(
122  sprintf('INSERT INTO access_keys
123  (key_hash, expiry_date, context, assoc_id, user_id)
124  VALUES
125  (?, %s, ?, ?, ?)',
126  $this->datetimeToDB($accessKey->getExpiryDate())),
127  array(
128  $accessKey->getKeyHash(),
129  $accessKey->getContext(),
130  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
131  (int) $accessKey->getUserId()
132  )
133  );
134 
135  $accessKey->setId($this->getInsertAccessKeyId());
136  return $accessKey->getId();
137  }
138 
143  function updateObject(&$accessKey) {
144  return $this->update(
145  sprintf('UPDATE access_keys
146  SET
147  key_hash = ?,
148  expiry_date = %s,
149  context = ?,
150  assoc_id = ?,
151  user_id = ?
152  WHERE access_key_id = ?',
153  $this->datetimeToDB($accessKey->getExpiryDate())),
154  array(
155  $accessKey->getKeyHash(),
156  $accessKey->getContext(),
157  $accessKey->getAssocId()==''?null:(int) $accessKey->getAssocId(),
158  (int) $accessKey->getUserId(),
159  (int) $accessKey->getId()
160  )
161  );
162  }
163 
164  function updateAccessKey(&$accessKey) {
165  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
166  return $this->updateObject($accessKey);
167  }
168 
173  function deleteObject(&$accessKey) {
174  return $this->deleteAccessKeyById($accessKey->getId());
175  }
176 
177  function deleteAccessKey(&$accessKey) {
178  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
179  return $this->deleteObject($accessKey);
180  }
181 
186  function deleteAccessKeyById($accessKeyId) {
187  return $this->update(
188  'DELETE FROM access_keys WHERE access_key_id = ?',
189  array((int) $accessKeyId)
190  );
191  }
192 
198  function transferAccessKeys($oldUserId, $newUserId) {
199  return $this->update(
200  'UPDATE access_keys SET user_id = ? WHERE user_id = ?',
201  array((int) $newUserId, (int) $oldUserId)
202  );
203  }
204 
208  function deleteExpiredKeys() {
209  return $this->update(
210  sprintf(
211  'DELETE FROM access_keys WHERE expiry_date <= %s',
213  )
214  );
215  }
216 
221  function getInsertAccessKeyId() {
222  return $this->getInsertId('access_keys', 'access_key_id');
223  }
224 }
225 
226 ?>
transferAccessKeys($oldUserId, $newUserId)
config TEMPLATE inc php
Definition: config.inc.php:4
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:62
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
updateAccessKey(&$accessKey)
& getAccessKeyByKeyHash($context, $userId, $keyHash, $assocId=null)
getCurrentDate($ts=null)
Definition: Core.inc.php:90
datetimeFromDB($dt)
Definition: DAO.inc.php:276
deleteObject(&$accessKey)
insertAccessKey(&$accessKey)
& getAccessKey($accessKeyId)
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
deleteAccessKey(&$accessKey)
& getAccessKeyByUserId($context, $userId)
deleteAccessKeyById($accessKeyId)
call($hookName, $args=null)
& _returnAccessKeyFromRow(&$row)
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
AccessKey class.