17 import(
'lib.pkp.classes.oai.PKPOAIDAO');
34 parent::__construct();
40 $this->journalCache = array();
41 $this->sectionCache = array();
56 if (!isset($this->journalCache[$journalId])) {
57 $this->journalCache[$journalId] = $this->journalDao->getById($journalId);
59 return $this->journalCache[$journalId];
68 if (!isset($this->sectionCache[$sectionId])) {
69 $this->sectionCache[$sectionId] = $this->sectionDao->getById($sectionId);
71 return $this->sectionCache[$sectionId];
86 if (isset($journalId)) {
87 $journals = array($this->journalDao->getById($journalId));
89 $journals = $this->journalDao->getAll(
true);
90 $journals = $journals->toArray();
95 foreach ($journals as $journal) {
96 $title = $journal->getLocalizedName();
97 $abbrev = $journal->getPath();
98 array_push($sets,
new OAISet(urlencode($abbrev), $title,
''));
101 $articleTombstoneSets = $tombstoneDao->getSets(ASSOC_TYPE_JOURNAL, $journal->getId());
103 $sections = $this->sectionDao->getByJournalId($journal->getId());
104 foreach ($sections->toArray() as $section) {
105 if (array_key_exists(urlencode($abbrev) .
':' . urlencode($section->getLocalizedAbbrev()), $articleTombstoneSets)) {
106 unset($articleTombstoneSets[urlencode($abbrev) .
':' . urlencode($section->getLocalizedAbbrev())]);
108 array_push($sets,
new OAISet(urlencode($abbrev) .
':' . urlencode($section->getLocalizedAbbrev()), $section->getLocalizedTitle(),
''));
110 foreach ($articleTombstoneSets as $articleTombstoneSetSpec => $articleTombstoneSetName) {
111 array_push($sets,
new OAISet($articleTombstoneSetSpec, $articleTombstoneSetName,
''));
115 HookRegistry::call(
'OAIDAO::getJournalSets', array($this, $journalId, $offset, $limit, $total, &$sets));
117 $total = count($sets);
118 $sets = array_slice($sets, $offset, $limit);
131 $journal =& $this->journalDao->getByPath($journalSpec);
132 if (!isset($journal) || (isset($restrictJournalId) && $journal->getId() != $restrictJournalId)) {
136 $journalId = $journal->getId();
139 if (isset($sectionSpec)) {
140 $section = $this->sectionDao->getByAbbrev($sectionSpec, $journal->getId());
141 if (isset($section)) {
142 $sectionId = $section->getId();
148 return array($journalId, $sectionId);
158 $journal = $this->
getJournal($row[
'journal_id']);
159 $section = $this->
getSection($row[
'section_id']);
160 $articleId = $row[
'submission_id'];
162 $record->identifier = $this->oai->articleIdToIdentifier($articleId);
163 $record->
sets = array(urlencode($journal->getPath()) .
':' . urlencode($section->getLocalizedAbbrev()));
167 $galleys = $this->articleGalleyDao->getByPublicationId($submission->getCurrentPublication()->getId())->toArray();
169 $record->setData(
'article', $submission);
170 $record->setData(
'journal', $journal);
171 $record->setData(
'section', $section);
172 $record->setData(
'galleys', $galleys);
189 function _getRecordsRecordSet($setIds, $from, $until, $set, $submissionId =
null, $orderBy =
'journal_id, submission_id') {
190 $journalId = array_shift($setIds);
191 $sectionId = array_shift($setIds);
193 $params = array(
'enableOai', (
int) STATUS_PUBLISHED);
194 if (isset($journalId)) $params[] = (int) $journalId;
195 if (isset($sectionId)) $params[] = (
int) $sectionId;
196 if ($submissionId) $params[] = (int) $submissionId;
197 if (isset($journalId)) $params[] = (
int) $journalId;
198 if (isset($sectionId)) $params[] = (
int) $sectionId;
201 $params[] = $set .
':%';
203 if ($submissionId) $params[] = (int) $submissionId;
205 'SELECT a.last_modified AS last_modified,
206 a.submission_id AS submission_id,
207 j.journal_id AS journal_id,
208 s.section_id AS section_id,
209 NULL AS tombstone_id,
211 NULL AS oai_identifier
214 JOIN publications p ON (a.current_publication_id = p.publication_id)
215 JOIN sections s ON (s.section_id = p.section_id)
216 JOIN journals j ON (j.journal_id = a.context_id)
217 JOIN journal_settings jsoai ON (jsoai.journal_id = j.journal_id AND jsoai.setting_name=? AND jsoai.setting_value=\'1\')
218 WHERE p.date_published IS NOT NULL AND j.enabled = 1 AND a.status = ?
219 ' . (isset($journalId) ?
' AND j.journal_id = ?':
'') .
'
220 ' . (isset($sectionId) ?
' AND p.section_id = ?':
'') .
'
221 ' . ($from?
' AND a.last_modified >= ' . $this->
datetimeToDB($from):
'') .
'
222 ' . ($until?
' AND a.last_modified <= ' . $this->
datetimeToDB($until):
'') .
'
223 ' . ($submissionId?
' AND a.submission_id = ?':
'') .
'
225 SELECT dot.date_deleted AS last_modified,
226 dot.data_object_id AS submission_id,
227 ' . (isset($journalId) ?
'tsoj.assoc_id' :
'NULL') .
' AS assoc_id,' .
'
228 ' . (isset($sectionId)?
'tsos.assoc_id' :
'NULL') .
' AS section_id,
232 FROM data_object_tombstones dot' .
'
233 ' . (isset($journalId) ?
'JOIN data_object_tombstone_oai_set_objects tsoj ON (tsoj.tombstone_id = dot.tombstone_id AND tsoj.assoc_type = ' . ASSOC_TYPE_JOURNAL .
' AND tsoj.assoc_id = ?)' :
'') .
'
234 ' . (isset($sectionId)?
'JOIN data_object_tombstone_oai_set_objects tsos ON (tsos.tombstone_id = dot.tombstone_id AND tsos.assoc_type = ' . ASSOC_TYPE_SECTION .
' AND tsos.assoc_id = ?)' :
'') .
'
236 ' . (isset($set)?
' AND (dot.set_spec = ? OR dot.set_spec LIKE ?)':
'') .
'
237 ' . ($from?
' AND dot.date_deleted >= ' . $this->
datetimeToDB($from):
'') .
'
238 ' . ($until?
' AND dot.date_deleted <= ' . $this->
datetimeToDB($until):
'') .
'
239 ' . ($submissionId?
' AND dot.data_object_id = ?':
'') .
'
240 ORDER BY ' . $orderBy,