00001 <?php
00002
00022 import('lib.pkp.classes.oai.OAI');
00023 import('classes.oai.omp.OAIDAO');
00024
00025 class PressOAI extends OAI {
00027 var $site;
00028
00030 var $press;
00031
00033 var $pressId;
00034
00036 var $dao;
00037
00038
00042 function PressOAI($config) {
00043 parent::OAI($config);
00044
00045 $this->site =& Request::getSite();
00046 $this->press =& Request::getPress();
00047 $this->pressId = isset($this->press) ? $this->press->getId() : null;
00048 $this->dao =& DAORegistry::getDAO('OAIDAO');
00049 $this->dao->setOAI($this);
00050 }
00051
00056 function getNonPathInfoParams() {
00057 return array('press', 'page');
00058 }
00059
00065 function publicationFormatIdToIdentifier($publicationFormatId) {
00066 $prefix = $this->_getIdentifierPrefix();
00067 return $prefix . $publicationFormatId;
00068 }
00069
00075 function identifierToPublicationFormatId($identifier) {
00076 $prefix = $this->_getIdentifierPrefix();
00077 if (strstr($identifier, $prefix)) {
00078 return (int) str_replace($prefix, '', $identifier);
00079 } else {
00080 return false;
00081 }
00082 }
00083
00090 function setSpecToSeriesId($setSpec, $pressId = null) {
00091 $tmpArray = split(':', $setSpec);
00092 if (count($tmpArray) == 1) {
00093 list($pressSpec) = $tmpArray;
00094 $pressSpec = urldecode($pressSpec);
00095 $seriesSpec = null;
00096 } else if (count($tmpArray) == 2) {
00097 list($pressSpec, $seriesSpec) = $tmpArray;
00098 $pressSpec = urldecode($pressSpec);
00099 $seriesSpec = urldecode($seriesSpec);
00100 } else {
00101 return array(0, 0);
00102 }
00103 return $this->dao->getSetPressSeriesId($pressSpec, $seriesSpec, $this->pressId);
00104 }
00105
00106
00107
00108
00109
00110
00114 function &repositoryInfo() {
00115 $info = new OAIRepository();
00116
00117 if (isset($this->press)) {
00118 $info->repositoryName = $this->press->getLocalizedName();
00119 $info->adminEmail = $this->press->getSetting('contactEmail');
00120
00121 } else {
00122 $info->repositoryName = $this->site->getLocalizedTitle();
00123 $info->adminEmail = $this->site->getLocalizedContactEmail();
00124 }
00125
00126 $info->sampleIdentifier = $this->publicationFormatIdToIdentifier(1);
00127 $info->earliestDatestamp = $this->dao->getEarliestDatestamp(array($this->pressId));
00128
00129 $info->toolkitTitle = 'Open Monograph Press';
00130 $versionDao =& DAORegistry::getDAO('VersionDAO');
00131 $currentVersion =& $versionDao->getCurrentVersion();
00132 $info->toolkitVersion = $currentVersion->getVersionString(false);
00133 $info->toolkitURL = 'http://pkp.sfu.ca/omp/';
00134
00135 return $info;
00136 }
00137
00141 function validIdentifier($identifier) {
00142 return $this->identifierToPublicationFormatId($identifier) !== false;
00143 }
00144
00148 function identifierExists($identifier) {
00149 $recordExists = false;
00150 $publicationFormatId = $this->identifierToPublicationFormatId($identifier);
00151 if ($publicationFormatId) {
00152 $recordExists = $this->dao->recordExists($publicationFormatId, array($this->pressId));
00153 }
00154 return $recordExists;
00155 }
00156
00160 function &record($identifier) {
00161 $publicationFormatId = $this->identifierToPublicationFormatId($identifier);
00162 if ($publicationFormatId) {
00163 $record =& $this->dao->getRecord($publicationFormatId, array($this->pressId));
00164 }
00165 if (!isset($record)) {
00166 $record = false;
00167 }
00168 return $record;
00169 }
00170
00174 function &records($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
00175 $records = null;
00176 if (!HookRegistry::call('PressOAI::records', array(&$this, $from, $until, $set, $offset, $limit, $total, &$records))) {
00177 $seriesId = null;
00178 if (isset($set)) {
00179 list($pressId, $seriesId) = $this->setSpecToSeriesId($set);
00180 } else {
00181 $pressId = $this->pressId;
00182 }
00183 $records =& $this->dao->getRecords(array($pressId, $seriesId), $from, $until, $set, $offset, $limit, $total);
00184 }
00185 return $records;
00186 }
00187
00191 function &identifiers($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
00192 $records = null;
00193 if (!HookRegistry::call('PressOAI::identifiers', array(&$this, $from, $until, $set, $offset, $limit, $total, &$records))) {
00194 $seriesId = null;
00195 if (isset($set)) {
00196 list($pressId, $seriesId) = $this->setSpecToSeriesId($set);
00197 } else {
00198 $pressId = $this->pressId;
00199 }
00200 $records =& $this->dao->getIdentifiers(array($pressId, $sectionId), $from, $until, $set, $offset, $limit, $total);
00201 }
00202 return $records;
00203 }
00204
00208 function &sets($offset, $limit, &$total) {
00209 $sets = null;
00210 if (!HookRegistry::call('PressOAI::sets', array(&$this, $offset, $limit, $total, &$sets))) {
00211 $sets =& $this->dao->getSets($this->pressId, $offset, $limit, $total);
00212 }
00213 return $sets;
00214 }
00215
00219 function &resumptionToken($tokenId) {
00220 $this->dao->clearTokens();
00221 $token = $this->dao->getToken($tokenId);
00222 if (!isset($token)) {
00223 $token = false;
00224 }
00225 return $token;
00226 }
00227
00231 function &saveResumptionToken($offset, $params) {
00232 $token = new OAIResumptionToken(null, $offset, $params, time() + $this->config->tokenLifetime);
00233 $this->dao->insertToken($token);
00234 return $token;
00235 }
00236
00237
00238
00239
00240
00245 function _getIdentifierPrefix() {
00246 return 'oai:' . $this->config->repositoryId . ':' . 'publicationFormat/';
00247 }
00248 }
00249
00250 ?>