classes/oai/ocs/OAIDAO.inc.php

Go to the documentation of this file.
00001 <?php
00002 
00016 //$Id$
00017 
00018 import('oai.OAI');
00019 
00020 class OAIDAO extends DAO {
00021 
00023    var $oai;
00024 
00026    var $conferenceDao;
00027    var $trackDao;
00028    var $publishedPaperDao;
00029    var $paperGalleyDao;
00030    var $authorDao;
00031    var $suppFileDao;
00032    var $conferenceSettingsDao;
00033 
00034    var $conferenceCache;
00035    var $schedConfCache;
00036    var $trackCache;
00037 
00041    function OAIDAO() {
00042       parent::DAO();
00043       $this->conferenceDao =& DAORegistry::getDAO('ConferenceDAO');
00044       $this->schedConfDao =& DAORegistry::getDAO('SchedConfDAO');
00045       $this->trackDao =& DAORegistry::getDAO('TrackDAO');
00046       $this->publishedPaperDao =& DAORegistry::getDAO('PublishedPaperDAO');
00047       $this->paperGalleyDao =& DAORegistry::getDAO('PaperGalleyDAO');
00048       $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
00049       $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
00050       $this->conferenceSettingsDao =& DAORegistry::getDAO('ConferenceSettingsDAO');
00051 
00052       $this->conferenceCache = array();
00053       $this->schedConfCache = array();
00054       $this->trackCache = array();
00055    }
00056 
00061    function setOAI(&$oai) {
00062       $this->oai = $oai;
00063    }
00064 
00065    //
00066    // Records
00067    //
00068 
00074    function getEarliestDatestamp($conferenceId = null) {
00075       $result =& $this->retrieve(
00076          'SELECT  MIN(p.last_modified)
00077          FROM  papers p,
00078             published_papers pp,
00079             sched_confs sc,
00080             conferences c
00081          WHERE p.paper_id = pp.paper_id AND
00082             p.sched_conf_id = sc.sched_conf_id AND
00083             sc.conference_id = c.conference_id AND
00084             c.enabled = 1'
00085          . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
00086 
00087          isset($conferenceId) ? array((int) $conferenceId) : false
00088       );
00089 
00090       if (isset($result->fields[0])) {
00091          $timestamp = strtotime($this->datetimeFromDB($result->fields[0]));
00092       }
00093       if (!isset($timestamp) || $timestamp == -1) {
00094          $timestamp = 0;
00095       }
00096 
00097       $result->Close();
00098       unset($result);
00099 
00100       return $timestamp;
00101    }
00102 
00109    function recordExists($paperId, $conferenceId = null) {
00110       $params = array((int) $paperId);
00111       if (isset($conferenceId)) $params[] = (int) $conferenceId;
00112       $result =& $this->retrieve(
00113          'SELECT COUNT(*)
00114          FROM  published_papers pp,
00115             papers p,
00116             sched_confs sc,
00117             conferences c
00118          WHERE pp.paper_id = ? AND
00119             pp.paper_id = p.paper_id AND
00120             sc.sched_conf_id = p.sched_conf_id AND
00121             c.conference_id = sc.conference_id'
00122          . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
00123          $params
00124       );
00125 
00126       $returner = $result->fields[0] == 1;
00127 
00128       $result->Close();
00129       unset($result);
00130 
00131       return $returner;
00132    }
00133 
00140    function &getRecord($paperId, $conferenceId = null) {
00141       $result =& $this->retrieve(
00142          'SELECT  pp.*, p.*,
00143             c.path AS conference_path,
00144             c.conference_id AS conference_id,
00145             s.path AS sched_conf_path
00146          FROM  published_papers pp, conferences c, sched_confs s, papers p
00147             LEFT JOIN tracks t ON t.track_id = p.track_id
00148          WHERE pp.paper_id = p.paper_id AND
00149             c.conference_id = s.conference_id AND
00150             s.sched_conf_id = p.sched_conf_id AND
00151             c.enabled = 1 AND
00152             pp.paper_id = ?'
00153          . (isset($conferenceId) ? ' AND c.conference_id = ?' : ''),
00154          isset($conferenceId) ? array((int) $paperId, (int) $conferenceId) : array((int) $paperId)
00155       );
00156 
00157       $returner = null;
00158       if ($result->RecordCount() != 0) {
00159          $row =& $result->GetRowAssoc(false);
00160          $returner =& $this->_returnRecordFromRow($row);
00161       }
00162 
00163       $result->Close();
00164       unset($result);
00165 
00166       return $returner;
00167    }
00168 
00181    function &getRecords($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total) {
00182       $records = array();
00183 
00184       $params = array();
00185       if (isset($conferenceId)) {
00186          array_push($params, (int) $conferenceId);
00187       }
00188       if (isset($schedConfId)) {
00189          array_push($params, (int) $schedConfId);
00190       }
00191       if (isset($trackId)) {
00192          array_push($params, (int) $trackId);
00193       }
00194       $result =& $this->retrieve(
00195          'SELECT  pp.*, p.*,
00196             c.path AS conference_path,
00197             c.conference_id AS conference_id,
00198             s.path AS sched_conf_path
00199          FROM  published_papers pp,
00200             conferences c,
00201             sched_confs s,
00202             papers p
00203             LEFT JOIN tracks t ON t.track_id = p.track_id
00204          WHERE pp.paper_id = p.paper_id AND
00205             p.sched_conf_id = s.sched_conf_id AND
00206             c.enabled = 1 AND
00207             s.conference_id = c.conference_id'
00208          . (isset($conferenceId) ? ' AND c.conference_id = ?' : '')
00209          . (isset($schedConfId) ? ' AND s.sched_conf_id = ?' : '')
00210          . (isset($trackId) ? ' AND p.track_id = ?' : '')
00211          . (isset($from) ? ' AND p.last_modified >= ' . $this->datetimeToDB($from) : '')
00212          . (isset($until) ? ' AND p.last_modified <= ' . $this->datetimeToDB($until) : ''),
00213          $params
00214       );
00215 
00216       $total = $result->RecordCount();
00217 
00218       $result->Move($offset);
00219       for ($count = 0; $count < $limit && !$result->EOF; $count++) {
00220          $row =& $result->GetRowAssoc(false);
00221          $records[] =& $this->_returnRecordFromRow($row);
00222          $result->moveNext();
00223       }
00224 
00225       $result->Close();
00226       unset($result);
00227 
00228       return $records;
00229    }
00230 
00243    function &getIdentifiers($conferenceId, $schedConfId, $trackId, $from, $until, $offset, $limit, &$total) {
00244       $records = array();
00245 
00246       $params = array();
00247       if (isset($conferenceId)) {
00248          array_push($params, (int) $conferenceId);
00249       }
00250       if (isset($schedConfId)) {
00251          array_push($params, (int) $schedConfId);
00252       }
00253       if (isset($trackId)) {
00254          array_push($params, (int) $trackId);
00255       }
00256       $result =& $this->retrieve(
00257          'SELECT  pp.paper_id,
00258             p.last_modified,
00259             c.path AS conference_path,
00260             c.conference_id,
00261             s.path AS sched_conf_path,
00262             s.sched_conf_id,
00263             p.track_id
00264          FROM  published_papers pp,
00265             conferences c,
00266             sched_confs s,
00267             papers p
00268             LEFT JOIN tracks t ON t.track_id = p.track_id
00269          WHERE pp.paper_id = p.paper_id AND
00270             p.sched_conf_id = s.sched_conf_id AND
00271             c.enabled = 1 AND
00272             s.conference_id = c.conference_id'
00273          . (isset($conferenceId) ? ' AND c.conference_id = ?' : '')
00274          . (isset($schedConfId) ? ' AND s.sched_conf_id = ?' : '')
00275          . (isset($trackId) ? ' AND p.track_id = ?' : '')
00276          . (isset($from) ? ' AND p.last_modified >= ' . $this->datetimeToDB($from) : '')
00277          . (isset($until) ? ' AND p.last_modified <= ' . $this->datetimeToDB($until) : ''),
00278          $params
00279       );
00280 
00281       $total = $result->RecordCount();
00282 
00283       $result->Move($offset);
00284       for ($count = 0; $count < $limit && !$result->EOF; $count++) {
00285          $row =& $result->GetRowAssoc(false);
00286          $records[] =& $this->_returnIdentifierFromRow($row);
00287          $result->moveNext();
00288       }
00289 
00290       $result->Close();
00291       unset($result);
00292 
00293       return $records;
00294    }
00295 
00296    function stripAssocArray($values) {
00297       foreach (array_keys($values) as $key) {
00298          $values[$key] = strip_tags($values[$key]);
00299       }
00300       return $values;
00301    }
00302  
00308    function &getConference($conferenceId) {
00309       if (!isset($this->conferenceCache[$conferenceId])) {
00310          $this->conferenceCache[$conferenceId] =& $this->conferenceDao->getConference($conferenceId);
00311       }
00312       return $this->conferenceCache[$conferenceId];
00313    }
00314 
00320    function &getSchedConf($schedConfId) {
00321       if (!isset($this->schedConfCache[$schedConfId])) {
00322          $this->schedConfCache[$schedConfId] =& $this->schedConfDao->getSchedConf($schedConfId);
00323       }
00324       return $this->schedConfCache[$schedConfId];
00325    }
00326 
00332    function &getTrack($trackId) {
00333       if (!isset($this->trackCache[$trackId])) {
00334          $this->trackCache[$trackId] =& $this->trackDao->getTrack($trackId);
00335       }
00336       return $this->trackCache[$trackId];
00337    }
00338 
00344    function &_returnRecordFromRow(&$row) {
00345       $record = new OAIRecord();
00346 
00347       $paperId = $row['paper_id'];
00348 /*    if ($this->conferenceSettingsDao->getSetting($row['conference_id'], 'enablePublicPaperId')) {
00349          if (!empty($row['public_paper_id'])) {
00350             $paperId = $row['public_paper_id'];
00351          }
00352       } */
00353 
00354       $paper =& $this->publishedPaperDao->getPublishedPaperByPaperId($paperId);
00355       $conference =& $this->getConference($row['conference_id']);
00356       $schedConf =& $this->getSchedConf($row['sched_conf_id']);
00357       $track =& $this->getTrack($row['track_id']);
00358       $galleys =& $this->paperGalleyDao->getGalleysByPaper($paperId);
00359 
00360       $record->setData('paper', $paper);
00361       $record->setData('conference', $conference);
00362       $record->setData('schedConf', $schedConf);
00363       $record->setData('track', $track);
00364       $record->setData('galleys', $galleys);
00365       
00366       // FIXME Use public ID in OAI identifier?
00367       $record->identifier = $this->oai->paperIdToIdentifier($row['paper_id']);
00368       $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified'])));
00369       $record->sets = array($conference->getPath() . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev());
00370 
00371       return $record;
00372    }
00373 
00379    function &_returnIdentifierFromRow(&$row) {
00380       $record = new OAIRecord();
00381       $conference =& $this->getConference($row['conference_id']);
00382       $schedConf =& $this->getSchedConf($row['sched_conf_id']);
00383       $track =& $this->getTrack($row['track_id']);
00384 
00385       $record->identifier = $this->oai->paperIdToIdentifier($row['paper_id']);
00386       $record->datestamp = OAIUtils::UTCDate(strtotime($this->datetimeFromDB($row['last_modified'])));
00387       $record->sets = array($conference->getPath() . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev());
00388 
00389       return $record;
00390    }
00391 
00392    //
00393    // Resumption tokens
00394    //
00395 
00399    function clearTokens() {
00400       $this->update(
00401          'DELETE FROM oai_resumption_tokens WHERE expire < ?', time()
00402       );
00403    }
00404 
00409    function &getToken($tokenId) {
00410       $result =& $this->retrieve(
00411          'SELECT * FROM oai_resumption_tokens WHERE token = ?',
00412          array($tokenId)
00413       );
00414 
00415       if ($result->RecordCount() == 0) {
00416          $token = null;
00417 
00418       } else {
00419          $row =& $result->getRowAssoc(false);
00420          $token = new OAIResumptionToken($row['token'], $row['record_offset'], unserialize($row['params']), $row['expire']);
00421       }
00422 
00423       $result->Close();
00424       unset($result);
00425 
00426       return $token;
00427    }
00428 
00434    function &insertToken(&$token) {
00435       do {
00436          // Generate unique token ID
00437          $token->id = md5(uniqid(mt_rand(), true));
00438          $result =& $this->retrieve(
00439             'SELECT COUNT(*) FROM oai_resumption_tokens WHERE token = ?',
00440             array($token->id)
00441          );
00442          $val = $result->fields[0];
00443 
00444          $result->Close();
00445          unset($result);
00446       } while($val != 0);
00447 
00448       $this->update(
00449          'INSERT INTO oai_resumption_tokens (token, record_offset, params, expire)
00450          VALUES
00451          (?, ?, ?, ?)',
00452          array($token->id, $token->offset, serialize($token->params), $token->expire)
00453       );
00454 
00455       return $token;
00456    }
00457 
00458    //
00459    // Sets
00460    //
00461 
00469    function &getConferenceSets($conferenceId, $offset, &$total) {
00470       if (isset($conferenceId)) {
00471          $conferences = array($this->conferenceDao->getConference($conferenceId));
00472       } else {
00473          $conferences =& $this->conferenceDao->getConferences();
00474          $conferences =& $conferences->toArray();
00475       }
00476 
00477       // FIXME Set descriptions
00478       $sets = array();
00479       foreach ($conferences as $conference) {
00480          $title = $conference->getConferenceTitle();
00481          $abbrev = $conference->getPath();
00482          array_push($sets, new OAISet($abbrev, $title, ''));
00483 
00484          $tracks =& $this->trackDao->getConferenceTracks($conference->getId());
00485          foreach ($tracks->toArray() as $track) {
00486             $schedConf =& $this->getSchedConf($track->getSchedConfId());
00487             array_push($sets, new OAISet($abbrev . ':' . $schedConf->getPath() . ':' . $track->getLocalizedAbbrev(), $track->getTrackTitle(), ''));
00488             unset($schedConf);
00489          }
00490       }
00491 
00492       if ($offset != 0) {
00493          $sets = array_slice($sets, $offset);
00494       }
00495 
00496       return $sets;
00497    }
00498 
00507    function getSetConferenceTrackId($conferenceSpec, $schedConfSpec, $trackSpec, $restrictConferenceId = null) {
00508       $conferenceId = null;
00509       $schedConfId = null;
00510 
00511       $conference =& $this->conferenceDao->getConferenceByPath($conferenceSpec);
00512       if (!isset($conference) || (isset($restrictConferenceId) && $conference->getId() != $restrictConferenceId)) {
00513          return array(0, 0, 0);
00514       }
00515 
00516       $conferenceId = $conference->getId();
00517       $trackId = null;
00518 
00519       if (isset($schedConfSpec)) {
00520          $schedConf =& $this->schedConfDao->getSchedConfByPath($schedConfSpec, $conferenceId);
00521          if (!$schedConf) return array(0, 0, 0);
00522       }
00523 
00524       if (isset($trackSpec)) {
00525          if (!$schedConf) return array(0, 0, 0);
00526          $track =& $this->trackDao->getTrackByAbbrev($trackSpec, $schedConf->getId());
00527          if (isset($track)) {
00528             $trackId = $track->getId();
00529          } else {
00530             $trackId = 0;
00531          }
00532       }
00533 
00534       return array($conferenceId, $schedConfId, $trackId);
00535    }
00536 }
00537 
00538 ?>

Generated on 25 Jul 2013 for Open Conference Systems by  doxygen 1.4.7