00001 <?php
00002
00022
00023
00024
00025 import('oai.OAI');
00026 import('oai.ojs.OAIDAO');
00027
00028 class JournalOAI extends OAI {
00030 var $site;
00031
00033 var $journal;
00034
00036 var $journalId;
00037
00039 var $dao;
00040
00041
00045 function JournalOAI($config) {
00046 parent::OAI($config);
00047
00048 $this->site = &Request::getSite();
00049 $this->journal = &Request::getJournal();
00050 $this->journalId = isset($this->journal) ? $this->journal->getJournalId() : null;
00051 $this->dao = &DAORegistry::getDAO('OAIDAO');
00052 $this->dao->setOAI($this);
00053 }
00054
00060 function articleIdToIdentifier($articleId) {
00061 return 'oai:' . $this->config->repositoryId . ':' . 'article/' . $articleId;
00062 }
00063
00069 function identifierToArticleId($identifier) {
00070 $prefix = 'oai:' . $this->config->repositoryId . ':' . 'article/';
00071 if (strstr($identifier, $prefix)) {
00072 return (int) str_replace($prefix, '', $identifier);
00073 } else {
00074 return false;
00075 }
00076 }
00077
00082 function setSpecToSectionId($setSpec, $journalId = null) {
00083 $tmpArray = split(':', $setSpec);
00084 if (count($tmpArray) == 1) {
00085 list($journalSpec) = $tmpArray;
00086 $sectionSpec = null;
00087 } else if (count($tmpArray) == 2) {
00088 list($journalSpec, $sectionSpec) = $tmpArray;
00089 } else {
00090 return array(0, 0);
00091 }
00092 return $this->dao->getSetJournalSectionId($journalSpec, $sectionSpec, $this->journalId);
00093 }
00094
00095
00096
00097
00098
00099
00103 function &repositoryInfo() {
00104 $info = &new OAIRepository();
00105
00106 if (isset($this->journal)) {
00107 $info->repositoryName = $this->journal->getJournalTitle();
00108 $info->adminEmail = $this->journal->getSetting('contactEmail');
00109
00110 } else {
00111 $info->repositoryName = $this->site->getSiteTitle();
00112 $info->adminEmail = $this->site->getSiteContactEmail();
00113 }
00114
00115 $info->sampleIdentifier = $this->articleIdToIdentifier(1);
00116 $info->earliestDatestamp = $this->dao->getEarliestDatestamp($this->journalId);
00117
00118 return $info;
00119 }
00120
00124 function validIdentifier($identifier) {
00125 return $this->identifierToArticleId($identifier) !== false;
00126 }
00127
00131 function identifierExists($identifier) {
00132 $recordExists = false;
00133 $articleId = $this->identifierToArticleId($identifier);
00134 if ($articleId) {
00135 $recordExists = $this->dao->recordExists($articleId, $this->journalId);
00136 }
00137 return $recordExists;
00138 }
00139
00143 function &record($identifier) {
00144 $articleId = $this->identifierToArticleId($identifier);
00145 if ($articleId) {
00146 $record = &$this->dao->getRecord($articleId, $this->journalId);
00147 }
00148 if (!isset($record)) {
00149 $record = false;
00150 }
00151 return $record;
00152 }
00153
00157 function &records($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
00158 $sectionId = null;
00159 if (isset($set)) {
00160 list($journalId, $sectionId) = $this->setSpecToSectionId($set);
00161 } else {
00162 $journalId = $this->journalId;
00163 }
00164 $records = &$this->dao->getRecords($journalId, $sectionId, $from, $until, $offset, $limit, $total);
00165 return $records;
00166 }
00167
00171 function &identifiers($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
00172 $sectionId = null;
00173 if (isset($set)) {
00174 list($journalId, $sectionId) = $this->setSpecToSectionId($set);
00175 } else {
00176 $journalId = $this->journalId;
00177 }
00178 $records = &$this->dao->getIdentifiers($journalId, $sectionId, $from, $until, $offset, $limit, $total);
00179 return $records;
00180 }
00181
00185 function &sets($offset, &$total) {
00186 $sets = &$this->dao->getJournalSets($this->journalId, $offset, $total);
00187 return $sets;
00188 }
00189
00193 function &resumptionToken($tokenId) {
00194 $this->dao->clearTokens();
00195 $token = $this->dao->getToken($tokenId);
00196 if (!isset($token)) {
00197 $token = false;
00198 }
00199 return $token;
00200 }
00201
00205 function &saveResumptionToken($offset, $params) {
00206 $token = &new OAIResumptionToken(null, $offset, $params, time() + $this->config->tokenLifetime);
00207 $this->dao->insertToken($token);
00208 return $token;
00209 }
00210 }
00211
00212 ?>