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)  

CaptchaDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 // $Id$
17 
18 
19 import('captcha.Captcha');
20 
21 class CaptchaDAO extends DAO {
27  function &getCaptchasBySessionId($sessionId) {
28  $captchas = array();
29 
30  $result =& $this->retrieve(
31  'SELECT * FROM captchas WHERE session_id = ?',
32  array((int) $sessionId)
33  );
34 
35  while (!$result->EOF) {
36  $captchas[] =& $this->_returnCaptchaFromRow($result->GetRowAssoc(false));
37  $result->moveNext();
38  }
39 
40  $result->Close();
41  unset($result);
42 
43  return $captchas;
44  }
45 
51  function &getExpiredCaptchas($lifespan = 86400) {
52  $captchas = array();
53  $threshold = time() - $lifespan;
54 
55  $result =& $this->retrieve(
56  'SELECT c.*
57  FROM captchas c
58  LEFT JOIN sessions s ON (s.session_id = c.session_id)
59  WHERE s.session_id IS NULL OR
60  c.date_created <= ' . $this->datetimeToDB($threshold)
61  );
62 
63  while (!$result->EOF) {
64  $captchas[] =& $this->_returnCaptchaFromRow($result->GetRowAssoc(false));
65  $result->moveNext();
66  }
67 
68  $result->Close();
69  unset($result);
70 
71  return $captchas;
72  }
73 
79  function &getCaptcha($captchaId) {
80  $result =& $this->retrieve(
81  'SELECT * FROM captchas WHERE captcha_id = ?',
82  array((int) $captchaId)
83  );
84 
85  $captcha = null;
86  if ($result->RecordCount() != 0) {
87  $captcha =& $this->_returnCaptchaFromRow($result->GetRowAssoc(false));
88  }
89 
90  $result->Close();
91  unset($result);
92 
93  return $captcha;
94  }
95 
101  function &_returnCaptchaFromRow($row) {
102  $captcha = new Captcha();
103  $captcha->setId($row['captcha_id']);
104  $captcha->setSessionId($row['session_id']);
105  $captcha->setValue($row['value']);
106  $captcha->setDateCreated($this->datetimeFromDB($row['date_created']));
107 
108  HookRegistry::call('CaptchaDAO::_returnCaptchaFromRow', array(&$captcha, &$row));
109 
110  return $captcha;
111  }
112 
118  function insertCaptcha(&$captcha) {
119  $captcha->setDateCreated(Core::getCurrentDate());
120  $this->update(
121  sprintf('INSERT INTO captchas
122  (session_id, value, date_created)
123  VALUES
124  (?, ?, %s)',
125  $this->datetimeToDB($captcha->getDateCreated())),
126  array(
127  (int) $captcha->getSessionId(),
128  $captcha->getValue()
129  )
130  );
131 
132  $captcha->setId($this->getInsertCaptchaId());
133  return $captcha->getId();
134  }
135 
140  function getInsertCaptchaId() {
141  return $this->getInsertId('captchas', 'captcha_id');
142  }
143 
148  function deleteObject(&$captcha) {
149  $result = $this->update(
150  'DELETE FROM captchas WHERE captcha_id = ?',
151  array((int) $captcha->getId())
152  );
153  }
154 
155  function deleteCaptcha(&$captcha) {
156  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
157  return $this->deleteObject($captcha);
158  }
159 
164  function updateObject(&$captcha) {
165  $this->update(
166  sprintf('UPDATE captchas
167  SET
168  session_id = ?,
169  value = ?,
170  date_created = %s
171  WHERE captcha_id = ?',
172  $this->datetimeToDB($captcha->getDateCreated())),
173  array(
174  (int) $captcha->getSessionId(),
175  $captcha->getValue(),
176  (int) $captcha->getId()
177  )
178  );
179  }
180 
181  function updateCaptcha(&$captcha) {
182  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
183  return $this->updateObject($captcha);
184  }
185 }
186 
187 ?>
& getExpiredCaptchas($lifespan=86400)
config TEMPLATE inc php
Definition: config.inc.php:4
updateObject(&$captcha)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
deleteObject(&$captcha)
getInsertId($table='', $id='', $callHooks=true)
Definition: DAO.inc.php:225
& _returnCaptchaFromRow($row)
getCurrentDate($ts=null)
Definition: Core.inc.php:90
updateCaptcha(&$captcha)
datetimeFromDB($dt)
Definition: DAO.inc.php:276
getVar($section, $key, $default=null)
Definition: Config.inc.php:35
insertCaptcha(&$captcha)
call($hookName, $args=null)
deleteCaptcha(&$captcha)
Operations for retrieving and modifying Captcha keys.
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
& getCaptchasBySessionId($sessionId)
Class for Captcha verifiers.
Definition: Captcha.inc.php:24
& getCaptcha($captchaId)