Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
OAIDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.oai.PKPOAIDAO');
18 import('classes.issue.Issue');
19 
20 class OAIDAO extends PKPOAIDAO {
21 
24  var $sectionDao;
25  var $publishedArticleDao;
26  var $articleGalleyDao;
27  var $issueDao;
28  var $authorDao;
29  var $journalSettingsDao;
30 
31  var $journalCache;
32  var $sectionCache;
33  var $issueCache;
34 
38  function OAIDAO() {
39  parent::PKPOAIDAO();
40  $this->journalDao = DAORegistry::getDAO('JournalDAO');
41  $this->sectionDao = DAORegistry::getDAO('SectionDAO');
42  $this->publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
43  $this->articleGalleyDao = DAORegistry::getDAO('ArticleGalleyDAO');
44  $this->issueDao = DAORegistry::getDAO('IssueDAO');
45  $this->authorDao = DAORegistry::getDAO('AuthorDAO');
46  $this->journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
47 
48  $this->journalCache = array();
49  $this->sectionCache = array();
50  }
51 
55  function getEarliestDatestamp($setIds = array()) {
56  return parent::getEarliestDatestamp('SELECT CASE WHEN COALESCE(dot.date_deleted, a.last_modified) > i.last_modified THEN i.last_modified ELSE COALESCE(dot.date_deleted, a.last_modified) END', $setIds);
57  }
58 
64  function &getJournal($journalId) {
65  if (!isset($this->journalCache[$journalId])) {
66  $this->journalCache[$journalId] =& $this->journalDao->getById($journalId);
67  }
68  return $this->journalCache[$journalId];
69  }
70 
76  function &getIssue($issueId) {
77  if (!isset($this->issueCache[$issueId])) {
78  $this->issueCache[$issueId] = $this->issueDao->getById($issueId);
79  }
80  return $this->issueCache[$issueId];
81  }
82 
88  function &getSection($sectionId) {
89  if (!isset($this->sectionCache[$sectionId])) {
90  $this->sectionCache[$sectionId] = $this->sectionDao->getById($sectionId);
91  }
92  return $this->sectionCache[$sectionId];
93  }
94 
95 
96  //
97  // Sets
98  //
106  function &getJournalSets($journalId, $offset, $limit, &$total) {
107  if (isset($journalId)) {
108  $journals = array($this->journalDao->getById($journalId));
109  } else {
110  $journals = $this->journalDao->getAll();
111  $journals = $journals->toArray();
112  }
113 
114  // FIXME Set descriptions
115  $sets = array();
116  foreach ($journals as $journal) {
117  $title = $journal->getLocalizedName();
118  $abbrev = $journal->getPath();
119  array_push($sets, new OAISet(urlencode($abbrev), $title, ''));
120 
121  $tombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO');
122  $articleTombstoneSets = $tombstoneDao->getSets(ASSOC_TYPE_JOURNAL, $journal->getId());
123 
124  $sections = $this->sectionDao->getByJournalId($journal->getId());
125  foreach ($sections->toArray() as $section) {
126  if (array_key_exists(urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev()), $articleTombstoneSets)) {
127  unset($articleTombstoneSets[urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev())]);
128  }
129  array_push($sets, new OAISet(urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev()), $section->getLocalizedTitle(), ''));
130  }
131  foreach ($articleTombstoneSets as $articleTombstoneSetSpec => $articleTombstoneSetName) {
132  array_push($sets, new OAISet($articleTombstoneSetSpec, $articleTombstoneSetName, ''));
133  }
134  }
135 
136  HookRegistry::call('OAIDAO::getJournalSets', array($this, $journalId, $offset, $limit, $total, &$sets));
137 
138  $total = count($sets);
139  $sets = array_slice($sets, $offset, $limit);
140 
141  return $sets;
142  }
143 
151  function getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId = null) {
152  $journal =& $this->journalDao->getByPath($journalSpec);
153  if (!isset($journal) || (isset($restrictJournalId) && $journal->getId() != $restrictJournalId)) {
154  return array(0, 0);
155  }
156 
157  $journalId = $journal->getId();
158  $sectionId = null;
159 
160  if (isset($sectionSpec)) {
161  $section = $this->sectionDao->getByAbbrev($sectionSpec, $journal->getId());
162  if (isset($section)) {
163  $sectionId = $section->getId();
164  } else {
165  $sectionId = 0;
166  }
167  }
168 
169  return array($journalId, $sectionId);
170  }
171 
172  //
173  // Protected methods.
174  //
179  return 'SELECT CASE WHEN COALESCE(dot.date_deleted, a.last_modified) < i.last_modified THEN i.last_modified ELSE COALESCE(dot.date_deleted, a.last_modified) END AS last_modified,
180  COALESCE(a.submission_id, dot.data_object_id) AS submission_id,
181  COALESCE(j.journal_id, tsoj.assoc_id) AS journal_id,
182  COALESCE(tsos.assoc_id, s.section_id) AS section_id,
183  i.issue_id,
184  dot.tombstone_id,
185  dot.set_spec,
186  dot.oai_identifier';
187  }
188 
192  function getRecordJoinClause($articleId = null, $setIds = array(), $set = null) {
193  if (isset($setIds[1])) {
194  list($journalId, $sectionId) = $setIds;
195  } else {
196  list($journalId) = $setIds;
197  }
198  return 'LEFT JOIN published_submissions pa ON (m.i=0' . (isset($articleId) ? ' AND pa.submission_id = ?' : '') . ')
199  LEFT JOIN submissions a ON (a.submission_id = pa.submission_id' . (isset($journalId) ? ' AND a.context_id = ?' : '') . (isset($sectionId) ? ' AND a.section_id = ?' : '') .')
200  LEFT JOIN issues i ON (i.issue_id = pa.issue_id)
201  LEFT JOIN sections s ON (s.section_id = a.section_id)
202  LEFT JOIN journals j ON (j.journal_id = a.context_id)
203  LEFT JOIN data_object_tombstones dot ON (m.i = 1' . (isset($articleId) ? ' AND dot.data_object_id = ?' : '') . (isset($set) ? ' AND dot.set_spec = ?' : '') .')
204  LEFT JOIN data_object_tombstone_oai_set_objects tsoj ON ' . (isset($journalId) ? '(tsoj.tombstone_id = dot.tombstone_id AND tsoj.assoc_type = ' . ASSOC_TYPE_JOURNAL . ' AND tsoj.assoc_id = ?)' : 'tsoj.assoc_id = null') .
205  ' LEFT JOIN data_object_tombstone_oai_set_objects tsos ON ' . (isset($sectionId) ? '(tsos.tombstone_id = dot.tombstone_id AND tsos.assoc_type = ' . ASSOC_TYPE_SECTION . ' AND tsos.assoc_id = ?)' : 'tsos.assoc_id = null');
206  }
207 
212  return 'WHERE ((s.section_id IS NOT NULL AND i.published = 1 AND j.enabled = 1 AND a.status <> ' . STATUS_ARCHIVED . ') OR dot.data_object_id IS NOT NULL)';
213  }
214 
218  function getDateRangeWhereClause($from, $until) {
219  return (isset($from) ? ' AND CASE WHEN COALESCE(dot.date_deleted, a.last_modified) < i.last_modified THEN (i.last_modified >= ' . $this->datetimeToDB($from) . ') ELSE ((dot.date_deleted IS NOT NULL AND dot.date_deleted >= ' . $this->datetimeToDB($from) . ') OR (dot.date_deleted IS NULL AND a.last_modified >= ' . $this->datetimeToDB($from) . ')) END' : '')
220  . (isset($until) ? ' AND CASE WHEN COALESCE(dot.date_deleted, a.last_modified) < i.last_modified THEN (i.last_modified <= ' . $this->datetimeToDB($until) . ') ELSE ((dot.date_deleted IS NOT NULL AND dot.date_deleted <= ' . $this->datetimeToDB($until) . ') OR (dot.date_deleted IS NULL AND a.last_modified <= ' . $this->datetimeToDB($until) . ')) END' : '')
221  . ' ORDER BY journal_id';
222  }
223 
227  function &setOAIData(&$record, $row, $isRecord = true) {
228  $journal = $this->getJournal($row['journal_id']);
229  $section = $this->getSection($row['section_id']);
230  $articleId = $row['submission_id'];
231 
232  $record->identifier = $this->oai->articleIdToIdentifier($articleId);
233  $record->sets = array(urlencode($journal->getPath()) . ':' . urlencode($section->getLocalizedAbbrev()));
234 
235  if ($isRecord) {
236  $publishedArticle = $this->publishedArticleDao->getPublishedArticleByArticleId($articleId);
237  $issue = $this->getIssue($row['issue_id']);
238  $galleys = $this->articleGalleyDao->getBySubmissionId($articleId)->toArray();
239 
240  $record->setData('article', $publishedArticle);
241  $record->setData('journal', $journal);
242  $record->setData('section', $section);
243  $record->setData('issue', $issue);
244  $record->setData('galleys', $galleys);
245  }
246 
247  return $record;
248  }
249 }
250 
251 ?>
static & getDAO($name, $dbconn=null)
& setOAIData(&$record, $row, $isRecord=true)
Definition: OAIDAO.inc.php:227
Base class for DAO operations for the OAI interface.
getEarliestDatestamp($setIds=array())
Definition: OAIDAO.inc.php:55
getAccessibleRecordWhereClause()
Definition: OAIDAO.inc.php:211
& getJournal($journalId)
Definition: OAIDAO.inc.php:64
DAO operations for the OJS OAI interface.
Definition: OAIDAO.inc.php:20
getDateRangeWhereClause($from, $until)
Definition: OAIDAO.inc.php:218
getRecordJoinClause($articleId=null, $setIds=array(), $set=null)
Definition: OAIDAO.inc.php:192
static call($hookName, $args=null)
& getIssue($issueId)
Definition: OAIDAO.inc.php:76
getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId=null)
Definition: OAIDAO.inc.php:151
OAIDAO()
Definition: OAIDAO.inc.php:38
& getSection($sectionId)
Definition: OAIDAO.inc.php:88
datetimeToDB($dt)
Definition: DAO.inc.php:293
getRecordSelectStatement()
Definition: OAIDAO.inc.php:178
& getJournalSets($journalId, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:106