Open Monograph Press  3.3.0
PressOAI.inc.php
1 <?php
2 
23 import('lib.pkp.classes.oai.OAI');
24 import('classes.oai.omp.OAIDAO');
25 
26 class PressOAI extends OAI {
28  var $site;
29 
31  var $press;
32 
34  var $pressId;
35 
37  var $dao;
38 
39 
43  function __construct($config) {
44  parent::__construct($config);
45 
46  $request = Application::get()->getRequest();
47 
48  $this->site = $request->getSite();
49  $this->press = $request->getPress();
50  $this->pressId = isset($this->press) ? $this->press->getId() : null;
51  $this->dao = DAORegistry::getDAO('OAIDAO');
52  $this->dao->setOAI($this);
53  }
54 
59  function getNonPathInfoParams() {
60  return array('press', 'page');
61  }
62 
68  function publicationFormatIdToIdentifier($publicationFormatId) {
69  return $this->_getIdentifierPrefix() . $publicationFormatId;
70  }
71 
77  function identifierToPublicationFormatId($identifier) {
78  $prefix = $this->_getIdentifierPrefix();
79  if (strstr($identifier, $prefix)) {
80  return (int) str_replace($prefix, '', $identifier);
81  } else {
82  return false;
83  }
84  }
85 
92  function setSpecToSeriesId($setSpec, $pressId = null) {
93  $tmpArray = preg_split('/:/', $setSpec);
94  if (count($tmpArray) == 1) {
95  list($pressSpec) = $tmpArray;
96  $pressSpec = urldecode($pressSpec);
97  $seriesSpec = null;
98  } else if (count($tmpArray) == 2) {
99  list($pressSpec, $seriesSpec) = $tmpArray;
100  $pressSpec = urldecode($pressSpec);
101  $seriesSpec = urldecode($seriesSpec);
102  } else {
103  return array(0, 0);
104  }
105  return $this->dao->getSetPressSeriesId($pressSpec, $seriesSpec, $this->pressId);
106  }
107 
108 
109  //
110  // OAI interface functions
111  //
112 
116  function repositoryInfo() {
117  $info = new OAIRepository();
118 
119  if (isset($this->press)) {
120  $info->repositoryName = $this->press->getLocalizedName();
121  $info->adminEmail = $this->press->getSetting('contactEmail');
122 
123  } else {
124  $info->repositoryName = $this->site->getLocalizedTitle();
125  $info->adminEmail = $this->site->getLocalizedContactEmail();
126  }
127 
128  $info->sampleIdentifier = $this->publicationFormatIdToIdentifier(1);
129  $info->earliestDatestamp = $this->dao->getEarliestDatestamp(array($this->pressId));
130 
131  $info->toolkitTitle = 'Open Monograph Press';
132  $versionDao = DAORegistry::getDAO('VersionDAO'); /* @var $versionDao VersionDAO */
133  $currentVersion = $versionDao->getCurrentVersion();
134  $info->toolkitVersion = $currentVersion->getVersionString(false);
135  $info->toolkitURL = 'http://pkp.sfu.ca/omp/';
136 
137  return $info;
138  }
139 
143  function validIdentifier($identifier) {
144  return $this->identifierToPublicationFormatId($identifier) !== false;
145  }
146 
150  function identifierExists($identifier) {
151  $recordExists = false;
152  $publicationFormatId = $this->identifierToPublicationFormatId($identifier);
153  if ($publicationFormatId) {
154  $recordExists = $this->dao->recordExists($publicationFormatId, array($this->pressId));
155  }
156  return $recordExists;
157  }
158 
162  function record($identifier) {
163  $publicationFormatId = $this->identifierToPublicationFormatId($identifier);
164  if ($publicationFormatId) {
165  $record = $this->dao->getRecord($publicationFormatId, array($this->pressId));
166  }
167  if (!isset($record)) {
168  $record = false;
169  }
170  return $record;
171  }
172 
176  function records($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
177  $records = null;
178  if (!HookRegistry::call('PressOAI::records', array(&$this, $from, $until, $set, $offset, $limit, $total, &$records))) {
179  $seriesId = null;
180  if (isset($set)) {
181  list($pressId, $seriesId) = $this->setSpecToSeriesId($set);
182  } else {
184  }
185  $records = $this->dao->getRecords(array($pressId, $seriesId), $from, $until, $set, $offset, $limit, $total);
186  }
187  return $records;
188  }
189 
193  function identifiers($metadataPrefix, $from, $until, $set, $offset, $limit, &$total) {
194  $records = null;
195  if (!HookRegistry::call('PressOAI::identifiers', array(&$this, $from, $until, $set, $offset, $limit, $total, &$records))) {
196  $seriesId = null;
197  if (isset($set)) {
198  list($pressId, $seriesId) = $this->setSpecToSeriesId($set);
199  } else {
201  }
202  $records = $this->dao->getIdentifiers(array($pressId, $seriesId), $from, $until, $set, $offset, $limit, $total);
203  }
204  return $records;
205  }
206 
210  function sets($offset, $limit, &$total) {
211  $sets = null;
212  if (!HookRegistry::call('PressOAI::sets', array(&$this, $offset, $limit, $total, &$sets))) {
213  $sets = $this->dao->getSets($this->pressId, $offset, $limit, $total);
214  }
215  return $sets;
216  }
217 
221  function resumptionToken($tokenId) {
222  $this->dao->clearTokens();
223  $token = $this->dao->getToken($tokenId);
224  if (!isset($token)) {
225  $token = false;
226  }
227  return $token;
228  }
229 
233  function saveResumptionToken($offset, $params) {
234  $token = new OAIResumptionToken(null, $offset, $params, time() + $this->config->tokenLifetime);
235  $this->dao->insertToken($token);
236  return $token;
237  }
238 
239 
240  //
241  // Private helper methods
242  //
247  function _getIdentifierPrefix() {
248  return 'oai:' . $this->config->repositoryId . ':' . 'publicationFormat/';
249  }
250 }
251 
252 
PressOAI\$dao
$dao
Definition: PressOAI.inc.php:49
OAIRepository
Definition: OAIStruct.inc.php:84
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PressOAI\sets
sets($offset, $limit, &$total)
Definition: PressOAI.inc.php:222
PressOAI\resumptionToken
resumptionToken($tokenId)
Definition: PressOAI.inc.php:233
OAI\$params
$params
Definition: OAI.inc.php:38
PressOAI\repositoryInfo
repositoryInfo()
Definition: PressOAI.inc.php:128
PressOAI\$press
$press
Definition: PressOAI.inc.php:37
PressOAI\__construct
__construct($config)
Definition: PressOAI.inc.php:55
PressOAI\_getIdentifierPrefix
_getIdentifierPrefix()
Definition: PressOAI.inc.php:259
PressOAI\getNonPathInfoParams
getNonPathInfoParams()
Definition: PressOAI.inc.php:71
PressOAI
OMP-specific OAI interface. Designed to support both a site-wide and press-specific OAI interface (ba...
Definition: PressOAI.inc.php:26
PressOAI\setSpecToSeriesId
setSpecToSeriesId($setSpec, $pressId=null)
Definition: PressOAI.inc.php:104
PressOAI\publicationFormatIdToIdentifier
publicationFormatIdToIdentifier($publicationFormatId)
Definition: PressOAI.inc.php:80
PressOAI\$site
$site
Definition: PressOAI.inc.php:31
PressOAI\record
record($identifier)
Definition: PressOAI.inc.php:174
PressOAI\records
records($metadataPrefix, $from, $until, $set, $offset, $limit, &$total)
Definition: PressOAI.inc.php:188
OAIResumptionToken
Definition: OAIStruct.inc.php:140
OAI\$config
$config
Definition: OAI.inc.php:32
PressOAI\identifierExists
identifierExists($identifier)
Definition: PressOAI.inc.php:162
PressOAI\saveResumptionToken
saveResumptionToken($offset, $params)
Definition: PressOAI.inc.php:245
PressOAI\identifiers
identifiers($metadataPrefix, $from, $until, $set, $offset, $limit, &$total)
Definition: PressOAI.inc.php:205
OAI
Class to process and respond to OAI requests.
Definition: OAI.inc.php:27
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PressOAI\validIdentifier
validIdentifier($identifier)
Definition: PressOAI.inc.php:155
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
PressOAI\$pressId
$pressId
Definition: PressOAI.inc.php:43
PressOAI\identifierToPublicationFormatId
identifierToPublicationFormatId($identifier)
Definition: PressOAI.inc.php:89