Open Preprint Systems  3.3.0
OAIDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.oai.PKPOAIDAO');
18 
19 class OAIDAO extends PKPOAIDAO {
20 
26 
29 
33  function __construct() {
34  parent::__construct();
35  $this->journalDao = DAORegistry::getDAO('JournalDAO');
36  $this->sectionDao = DAORegistry::getDAO('SectionDAO');
37  $this->articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
38  $this->authorDao = DAORegistry::getDAO('AuthorDAO');
39 
40  $this->journalCache = array();
41  $this->sectionCache = array();
42  }
43 
48  }
49 
55  function &getJournal($journalId) {
56  if (!isset($this->journalCache[$journalId])) {
57  $this->journalCache[$journalId] = $this->journalDao->getById($journalId);
58  }
59  return $this->journalCache[$journalId];
60  }
61 
67  function &getSection($sectionId) {
68  if (!isset($this->sectionCache[$sectionId])) {
69  $this->sectionCache[$sectionId] = $this->sectionDao->getById($sectionId);
70  }
71  return $this->sectionCache[$sectionId];
72  }
73 
74 
75  //
76  // Sets
77  //
85  function &getJournalSets($journalId, $offset, $limit, &$total) {
86  if (isset($journalId)) {
87  $journals = array($this->journalDao->getById($journalId));
88  } else {
89  $journals = $this->journalDao->getAll(true);
90  $journals = $journals->toArray();
91  }
92 
93  // FIXME Set descriptions
94  $sets = array();
95  foreach ($journals as $journal) {
96  $title = $journal->getLocalizedName();
97  $abbrev = $journal->getPath();
98  array_push($sets, new OAISet(urlencode($abbrev), $title, ''));
99 
100  $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
101  $articleTombstoneSets = $tombstoneDao->getSets(ASSOC_TYPE_JOURNAL, $journal->getId());
102 
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())]);
107  }
108  array_push($sets, new OAISet(urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev()), $section->getLocalizedTitle(), ''));
109  }
110  foreach ($articleTombstoneSets as $articleTombstoneSetSpec => $articleTombstoneSetName) {
111  array_push($sets, new OAISet($articleTombstoneSetSpec, $articleTombstoneSetName, ''));
112  }
113  }
114 
115  HookRegistry::call('OAIDAO::getJournalSets', array($this, $journalId, $offset, $limit, $total, &$sets));
116 
117  $total = count($sets);
118  $sets = array_slice($sets, $offset, $limit);
119 
120  return $sets;
121  }
122 
130  function getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId = null) {
131  $journal =& $this->journalDao->getByPath($journalSpec);
132  if (!isset($journal) || (isset($restrictJournalId) && $journal->getId() != $restrictJournalId)) {
133  return array(0, 0);
134  }
135 
136  $journalId = $journal->getId();
137  $sectionId = null;
138 
139  if (isset($sectionSpec)) {
140  $section = $this->sectionDao->getByAbbrev($sectionSpec, $journal->getId());
141  if (isset($section)) {
142  $sectionId = $section->getId();
143  } else {
144  $sectionId = 0;
145  }
146  }
147 
148  return array($journalId, $sectionId);
149  }
150 
151  //
152  // Protected methods.
153  //
157  function setOAIData($record, $row, $isRecord = true) {
158  $journal = $this->getJournal($row['journal_id']);
159  $section = $this->getSection($row['section_id']);
160  $articleId = $row['submission_id'];
161 
162  $record->identifier = $this->oai->articleIdToIdentifier($articleId);
163  $record->sets = array(urlencode($journal->getPath()) . ':' . urlencode($section->getLocalizedAbbrev()));
164 
165  if ($isRecord) {
166  $submission = Services::get('submission')->get($articleId);
167  $galleys = $this->articleGalleyDao->getByPublicationId($submission->getCurrentPublication()->getId())->toArray();
168 
169  $record->setData('article', $submission);
170  $record->setData('journal', $journal);
171  $record->setData('section', $section);
172  $record->setData('galleys', $galleys);
173  }
174 
175  return $record;
176  }
177 
189  function _getRecordsRecordSet($setIds, $from, $until, $set, $submissionId = null, $orderBy = 'journal_id, submission_id') {
190  $journalId = array_shift($setIds);
191  $sectionId = array_shift($setIds);
192 
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;
199  if (isset($set)) {
200  $params[] = $set;
201  $params[] = $set . ':%';
202  }
203  if ($submissionId) $params[] = (int) $submissionId;
204  $result = $this->retrieve(
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,
210  NULL AS set_spec,
211  NULL AS oai_identifier
212  FROM
213  submissions a
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 = ?':'') . '
224  UNION
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,
229  dot.tombstone_id,
230  dot.set_spec,
231  dot.oai_identifier
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 = ?)' : '') . '
235  WHERE 1=1
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,
241  $params
242  );
243  return $result;
244  }
245 }
246 
247 
OAIDAO\setOAIData
setOAIData($record, $row, $isRecord=true)
Definition: OAIDAO.inc.php:157
OAIDAO\$sectionCache
$sectionCache
Definition: OAIDAO.inc.php:28
OAIDAO\getSetJournalSectionId
getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId=null)
Definition: OAIDAO.inc.php:130
OAIDAO\$journalDao
$journalDao
Definition: OAIDAO.inc.php:22
PKPOAIDAO
Base class for DAO operations for the OAI interface.
Definition: PKPOAIDAO.inc.php:19
OAIDAO\getEarliestDatestampQuery
getEarliestDatestampQuery()
Definition: OAIDAO.inc.php:47
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
OAIDAO
DAO operations for the OJS OAI interface.
Definition: OAIDAO.inc.php:19
OAIDAO\__construct
__construct()
Definition: OAIDAO.inc.php:33
OAIDAO\$authorDao
$authorDao
Definition: OAIDAO.inc.php:25
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
OAIDAO\$journalCache
$journalCache
Definition: OAIDAO.inc.php:27
OAIDAO\getJournalSets
& getJournalSets($journalId, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:85
OAISet
Definition: OAIStruct.inc.php:235
OAIDAO\_getRecordsRecordSet
_getRecordsRecordSet($setIds, $from, $until, $set, $submissionId=null, $orderBy='journal_id, submission_id')
Definition: OAIDAO.inc.php:189
DAO\datetimeToDB
datetimeToDB($dt)
Definition: DAO.inc.php:299
OAIDAO\$sectionDao
$sectionDao
Definition: OAIDAO.inc.php:23
OAIDAO\getSection
& getSection($sectionId)
Definition: OAIDAO.inc.php:67
OAIDAO\$articleGalleyDao
$articleGalleyDao
Definition: OAIDAO.inc.php:24
OAI\sets
sets($offset, $limit, &$total)
Definition: OAI.inc.php:172
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
OAIDAO\getJournal
& getJournal($journalId)
Definition: OAIDAO.inc.php:55
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49