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)  

OAIDAO.inc.php
Go to the documentation of this file.
1 <?php
2 
16 //$Id$
17 
18 import('oai.OAI');
19 
20 class OAIDAO extends DAO {
21 
23  var $oai;
24 
27  var $trackDao;
33 
37 
41  function OAIDAO() {
42  parent::DAO();
43  $this->conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
44  $this->schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
45  $this->trackDao =& DAORegistry::getDAO('TrackDAO');
46  $this->publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
47  $this->paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
48  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
49  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
50  $this->conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
51 
52  $this->conferenceCache = array();
53  $this->schedConfCache = array();
54  $this->trackCache = array();
55  }
56 
61  function setOAI(&$oai) {
62  $this->oai = $oai;
63  }
64 
65  //
66  // Records
67  //
68 
74  function getEarliestDatestamp($conferenceId = null) {
75  $result =& $this->retrieve(
76  'SELECT MIN(p.last_modified)
77  FROM papers p,
78  published_papers pp,
79  sched_confs sc,
80  conferences c
81  WHERE p.paper_id = pp.paper_id AND
82  p.sched_conf_id = sc.sched_conf_id AND
83  sc.conference_id = c.conference_id AND
84  c.enabled = 1'
85  . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
86 
87  isset($conferenceId) ? array((int) $conferenceId) : false
88  );
89 
90  if (isset($result->fields[0])) {
91  $timestamp = strtotime($this->datetimeFromDB($result->fields[0]));
92  }
93  if (!isset($timestamp) || $timestamp == -1) {
94  $timestamp = 0;
95  }
96 
97  $result->Close();
98  unset($result);
99 
100  return $timestamp;
101  }
102 
109  function recordExists($paperId, $conferenceId = null) {
110  $params = array((int) $paperId);
111  if (isset($conferenceId)) $params[] = (int) $conferenceId;
112  $result =& $this->retrieve(
113  'SELECT COUNT(*)
114  FROM published_papers pp,
115  papers p,
116  sched_confs sc,
117  conferences c
118  WHERE pp.paper_id = ? AND
119  pp.paper_id = p.paper_id AND
120  sc.sched_conf_id = p.sched_conf_id AND
121  c.conference_id = sc.conference_id'
122  . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
123  $params
124  );
125 
126  $returner = $result->fields[0] == 1;
127 
128  $result->Close();
129  unset($result);
130 
131  return $returner;
132  }
133 
140  function &getRecord($paperId, $conferenceId = null) {
141  $result =& $this->retrieve(
142  'SELECT pp.*, p.*,
143  c.path AS conference_path,
144  c.conference_id AS conference_id,
145  s.path AS sched_conf_path
146  FROM published_papers pp, conferences c, sched_confs s, papers p
147  LEFT JOIN tracks t ON t.track_id = p.track_id
148  WHERE pp.paper_id = p.paper_id AND
149  c.conference_id = s.conference_id AND
150  s.sched_conf_id = p.sched_conf_id AND
151  c.enabled = 1 AND
152  pp.paper_id = ?'
153  . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
154  isset($conferenceId) ? array((int) $paperId, (int) $conferenceId) : array((int) $paperId)
155  );
156 
157  $returner = null;
158  if ($result->RecordCount() != 0) {
159  $row =& $result->GetRowAssoc(false);
160  $returner =& $this->_returnRecordFromRow($row);
161  }
162 
163  $result->Close();
164  unset($result);
165 
166  return $returner;
167  }
168 
181  function &getRecords($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total) {
182  $records = array();
183 
184  $params = array();
185  if (isset($conferenceId)) {
186  array_push($params, (int) $conferenceId);
187  }
188  if (isset($schedConfId)) {
189  array_push($params, (int) $schedConfId);
190  }
191  if (isset($trackId)) {
192  array_push($params, (int) $trackId);
193  }
194  $result =& $this->retrieve(
195  'SELECT pp.*, p.*,
196  c.path AS conference_path,
197  c.conference_id AS conference_id,
198  s.path AS sched_conf_path
199  FROM published_papers pp,
200  conferences c,
201  sched_confs s,
202  papers p
203  LEFT JOIN tracks t ON t.track_id = p.track_id
204  WHERE pp.paper_id = p.paper_id AND
205  p.sched_conf_id = s.sched_conf_id AND
206  c.enabled = 1 AND
207  s.conference_id = c.conference_id'
208  . (isset($conferenceId) ? ' AND c.conference_id = ?' : '')
209  . (isset($schedConfId) ? ' AND s.sched_conf_id = ?' : '')
210  . (isset($trackId) ? ' AND p.track_id = ?' : '')
211  . (isset($from) ? ' AND p.last_modified >= ' . $this->datetimeToDB($from) : '')
212  . (isset($until) ? ' AND p.last_modified <= ' . $this->datetimeToDB($until) : ''),
213  $params
214  );
215 
216  $total = $result->RecordCount();
217 
218  $result->Move($offset);
219  for ($count = 0; $count < $limit && !$result->EOF; $count++) {
220  $row =& $result->GetRowAssoc(false);
221  $records[] =& $this->_returnRecordFromRow($row);
222  $result->moveNext();
223  }
224 
225  $result->Close();
226  unset($result);
227 
228  return $records;
229  }
230 
243  function &getIdentifiers($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total) {
244  $records = array();
245 
246  $params = array();
247  if (isset($conferenceId)) {
248  array_push($params, (int) $conferenceId);
249  }
250  if (isset($schedConfId)) {
251  array_push($params, (int) $schedConfId);
252  }
253  if (isset($trackId)) {
254  array_push($params, (int) $trackId);
255  }
256  $result =& $this->retrieve(
257  'SELECT pp.paper_id,
258  p.last_modified,
259  c.path AS conference_path,
260  c.conference_id,
261  s.path AS sched_conf_path,
262  s.sched_conf_id,
263  p.track_id
264  FROM published_papers pp,
265  conferences c,
266  sched_confs s,
267  papers p
268  LEFT JOIN tracks t ON t.track_id = p.track_id
269  WHERE pp.paper_id = p.paper_id AND
270  p.sched_conf_id = s.sched_conf_id AND
271  c.enabled = 1 AND
272  s.conference_id = c.conference_id'
273  . (isset($conferenceId) ? ' AND c.conference_id = ?' : '')
274  . (isset($schedConfId) ? ' AND s.sched_conf_id = ?' : '')
275  . (isset($trackId) ? ' AND p.track_id = ?' : '')
276  . (isset($from) ? ' AND p.last_modified >= ' . $this->datetimeToDB($from) : '')
277  . (isset($until) ? ' AND p.last_modified <= ' . $this->datetimeToDB($until) : ''),
278  $params
279  );
280 
281  $total = $result->RecordCount();
282 
283  $result->Move($offset);
284  for ($count = 0; $count < $limit && !$result->EOF; $count++) {
285  $row =& $result->GetRowAssoc(false);
286  $records[] =& $this->_returnIdentifierFromRow($row);
287  $result->moveNext();
288  }
289 
290  $result->Close();
291  unset($result);
292 
293  return $records;
294  }
295 
296  function stripAssocArray($values) {
297  foreach (array_keys($values) as $key) {
298  $values[$key] = strip_tags($values[$key]);
299  }
300  return $values;
301  }
302 
308  function &getConference($conferenceId) {
309  if (!isset($this->conferenceCache[$conferenceId])) {
310  $this->conferenceCache[$conferenceId] =& $this->conferenceDao->getConference($conferenceId);
311  }
312  return $this->conferenceCache[$conferenceId];
313  }
314 
320  function &getSchedConf($schedConfId) {
321  if (!isset($this->schedConfCache[$schedConfId])) {
322  $this->schedConfCache[$schedConfId] =& $this->schedConfDao->getSchedConf($schedConfId);
323  }
324  return $this->schedConfCache[$schedConfId];
325  }
326 
332  function &getTrack($trackId) {
333  if (!isset($this->trackCache[$trackId])) {
334  $this->trackCache[$trackId] =& $this->trackDao->getTrack($trackId);
335  }
336  return $this->trackCache[$trackId];
337  }
338 
344  function &_returnRecordFromRow(&$row) {
345  $record = new OAIRecord();
346 
347  $paperId = $row['paper_id'];
348 /* if ($this->conferenceSettingsDao->getSetting($row['conference_id'], 'enablePublicPaperId')) {
349  if (!empty($row['public_paper_id'])) {
350  $paperId = $row['public_paper_id'];
351  }
352  } */
353 
354  $paper =& $this->publishedPaperDao->getPublishedPaperByPaperId($paperId);
355  $conference =& $this->getConference($row['conference_id']);
356  $schedConf =& $this->getSchedConf($row['sched_conf_id']);
357  $track =& $this->getTrack($row['track_id']);
358  $galleys =& $this->paperGalleyDao->getGalleysByPaper($paperId);
359 
360  $record->setData('paper', $paper);
361  $record->setData('conference', $conference);
362  $record->setData('schedConf', $schedConf);
363  $record->setData('track', $track);
364  $record->setData('galleys', $galleys);
365 
366  // FIXME Use public ID in OAI identifier?
367  $record->identifier = $this->oai->paperIdToIdentifier($row['paper_id']);
368  $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified'])));
369  $record->sets = array($conference->getPath() . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev());
370 
371  return $record;
372  }
373 
379  function &_returnIdentifierFromRow(&$row) {
380  $record = new OAIRecord();
381  $conference =& $this->getConference($row['conference_id']);
382  $schedConf =& $this->getSchedConf($row['sched_conf_id']);
383  $track =& $this->getTrack($row['track_id']);
384 
385  $record->identifier = $this->oai->paperIdToIdentifier($row['paper_id']);
386  $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified'])));
387  $record->sets = array($conference->getPath() . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev());
388 
389  return $record;
390  }
391 
392  //
393  // Resumption tokens
394  //
395 
399  function clearTokens() {
400  $this->update(
401  'DELETE FROM oai_resumption_tokens WHERE expire < ?', time()
402  );
403  }
404 
409  function &getToken($tokenId) {
410  $result =& $this->retrieve(
411  'SELECT * FROM oai_resumption_tokens WHERE token = ?',
412  array($tokenId)
413  );
414 
415  if ($result->RecordCount() == 0) {
416  $token = null;
417 
418  } else {
419  $row =& $result->getRowAssoc(false);
420  $token = new OAIResumptionToken($row['token'], $row['record_offset'], unserialize($row['params']), $row['expire']);
421  }
422 
423  $result->Close();
424  unset($result);
425 
426  return $token;
427  }
428 
434  function &insertToken(&$token) {
435  do {
436  // Generate unique token ID
437  $token->id = md5(uniqid(mt_rand(), true));
438  $result =& $this->retrieve(
439  'SELECT COUNT(*) FROM oai_resumption_tokens WHERE token = ?',
440  array($token->id)
441  );
442  $val = $result->fields[0];
443 
444  $result->Close();
445  unset($result);
446  } while($val != 0);
447 
448  $this->update(
449  'INSERT INTO oai_resumption_tokens (token, record_offset, params, expire)
450  VALUES
451  (?, ?, ?, ?)',
452  array($token->id, $token->offset, serialize($token->params), $token->expire)
453  );
454 
455  return $token;
456  }
457 
458  //
459  // Sets
460  //
461 
469  function &getConferenceSets($conferenceId, $offset, &$total) {
470  if (isset($conferenceId)) {
471  $conferences = array($this->conferenceDao->getConference($conferenceId));
472  } else {
473  $conferences =& $this->conferenceDao->getConferences();
474  $conferences =& $conferences->toArray();
475  }
476 
477  // FIXME Set descriptions
478  $sets = array();
479  foreach ($conferences as $conference) {
480  $title = $conference->getConferenceTitle();
481  $abbrev = $conference->getPath();
482  array_push($sets, new OAISet($abbrev, $title, ''));
483 
484  $tracks =& $this->trackDao->getConferenceTracks($conference->getId());
485  foreach ($tracks->toArray() as $track) {
486  $schedConf =& $this->getSchedConf($track->getSchedConfId());
487  array_push($sets, new OAISet($abbrev . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev(), $track->getTrackTitle(), ''));
488  unset($schedConf);
489  }
490  }
491 
492  if ($offset != 0) {
493  $sets = array_slice($sets, $offset);
494  }
495 
496  return $sets;
497  }
498 
507  function getSetConferenceTrackId($conferenceSpec, $schedConfSpec, $trackSpec, $restrictConferenceId = null) {
508  $conferenceId = null;
509  $schedConfId = null;
510 
511  $conference =& $this->conferenceDao->getConferenceByPath($conferenceSpec);
512  if (!isset($conference) || (isset($restrictConferenceId) && $conference->getId() != $restrictConferenceId)) {
513  return array(0, 0, 0);
514  }
515 
516  $conferenceId = $conference->getId();
517  $trackId = null;
518 
519  if (isset($schedConfSpec)) {
520  $schedConf =& $this->schedConfDao->getSchedConfByPath($schedConfSpec, $conferenceId);
521  if (!$schedConf) return array(0, 0, 0);
522  }
523 
524  if (isset($trackSpec)) {
525  if (!$schedConf) return array(0, 0, 0);
526  $track =& $this->trackDao->getTrackByAbbrev($trackSpec, $schedConf->getId());
527  if (isset($track)) {
528  $trackId = $track->getId();
529  } else {
530  $trackId = 0;
531  }
532  }
533 
534  return array($conferenceId, $schedConfId, $trackId);
535  }
536 }
537 
538 ?>
getSetConferenceTrackId($conferenceSpec, $schedConfSpec, $trackSpec, $restrictConferenceId=null)
Definition: OAIDAO.inc.php:507
config TEMPLATE inc php
Definition: config.inc.php:4
& getConference($conferenceId)
Definition: OAIDAO.inc.php:308
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:30
$conferenceCache
Definition: OAIDAO.inc.php:34
stripAssocArray($values)
Definition: OAIDAO.inc.php:296
$suppFileDao
Definition: OAIDAO.inc.php:31
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:62
clearTokens()
Definition: OAIDAO.inc.php:399
& getToken($tokenId)
Definition: OAIDAO.inc.php:409
setOAI(&$oai)
Definition: OAIDAO.inc.php:61
& _returnIdentifierFromRow(&$row)
Definition: OAIDAO.inc.php:379
$paperGalleyDao
Definition: OAIDAO.inc.php:29
$publishedPaperDao
Definition: OAIDAO.inc.php:28
& insertToken(&$token)
Definition: OAIDAO.inc.php:434
$conferenceDao
Definition: OAIDAO.inc.php:26
& getRecords($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:181
DAO operations for the OCS OAI interface.
Definition: OAIDAO.inc.php:20
& getTrack($trackId)
Definition: OAIDAO.inc.php:332
datetimeFromDB($dt)
Definition: DAO.inc.php:276
$conferenceSettingsDao
Definition: OAIDAO.inc.php:32
recordExists($paperId, $conferenceId=null)
Definition: OAIDAO.inc.php:109
UTCDate($timestamp=0, $includeTime=true)
& getSchedConf($schedConfId)
Definition: OAIDAO.inc.php:320
& getDAO($name, $dbconn=null)
OAIDAO()
Definition: OAIDAO.inc.php:41
& getRecord($paperId, $conferenceId=null)
Definition: OAIDAO.inc.php:140
& getConferenceSets($conferenceId, $offset, &$total)
Definition: OAIDAO.inc.php:469
datetimeToDB($dt)
Definition: DAO.inc.php:258
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:186
& getIdentifiers($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:243
& _returnRecordFromRow(&$row)
Definition: OAIDAO.inc.php:344
getEarliestDatestamp($conferenceId=null)
Definition: OAIDAO.inc.php:74
$schedConfCache
Definition: OAIDAO.inc.php:35