Open Journal Systems  2.4.4
 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 $suppFileDao;
30  var $journalSettingsDao;
31 
32  var $journalCache;
33  var $sectionCache;
34  var $issueCache;
35 
39  function OAIDAO() {
40  parent::PKPOAIDAO();
41  $this->journalDao =& DAORegistry::getDAO('JournalDAO');
42  $this->sectionDao =& DAORegistry::getDAO('SectionDAO');
43  $this->publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
44  $this->articleGalleyDao =& DAORegistry::getDAO('ArticleGalleyDAO');
45  $this->issueDao =& DAORegistry::getDAO('IssueDAO');
46  $this->authorDao =& DAORegistry::getDAO('AuthorDAO');
47  $this->suppFileDao =& DAORegistry::getDAO('SuppFileDAO');
48  $this->journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
49 
50  $this->journalCache = array();
51  $this->sectionCache = array();
52  }
53 
57  function getEarliestDatestamp($setIds = array()) {
58  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);
59  }
60 
66  function &getJournal($journalId) {
67  if (!isset($this->journalCache[$journalId])) {
68  $this->journalCache[$journalId] =& $this->journalDao->getById($journalId);
69  }
70  return $this->journalCache[$journalId];
71  }
72 
78  function &getIssue($issueId) {
79  if (!isset($this->issueCache[$issueId])) {
80  $this->issueCache[$issueId] =& $this->issueDao->getIssueById($issueId);
81  }
82  return $this->issueCache[$issueId];
83  }
84 
90  function &getSection($sectionId) {
91  if (!isset($this->sectionCache[$sectionId])) {
92  $this->sectionCache[$sectionId] =& $this->sectionDao->getSection($sectionId);
93  }
94  return $this->sectionCache[$sectionId];
95  }
96 
97 
98  //
99  // Sets
100  //
108  function &getJournalSets($journalId, $offset, $limit, &$total) {
109  if (isset($journalId)) {
110  $journals = array($this->journalDao->getById($journalId));
111  } else {
112  $journals =& $this->journalDao->getJournals();
113  $journals =& $journals->toArray();
114  }
115 
116  // FIXME Set descriptions
117  $sets = array();
118  foreach ($journals as $journal) {
119  $title = $journal->getLocalizedTitle();
120  $abbrev = $journal->getPath();
121  array_push($sets, new OAISet(urlencode($abbrev), $title, ''));
122 
123  $tombstoneDao =& DAORegistry::getDAO('DataObjectTombstoneDAO');
124  $articleTombstoneSets = $tombstoneDao->getSets(ASSOC_TYPE_JOURNAL, $journal->getId());
125 
126  $sections =& $this->sectionDao->getJournalSections($journal->getId());
127  foreach ($sections->toArray() as $section) {
128  if (array_key_exists(urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev()), $articleTombstoneSets)) {
129  unset($articleTombstoneSets[urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev())]);
130  }
131  array_push($sets, new OAISet(urlencode($abbrev) . ':' . urlencode($section->getLocalizedAbbrev()), $section->getLocalizedTitle(), ''));
132  }
133  foreach ($articleTombstoneSets as $articleTombstoneSetSpec => $articleTombstoneSetName) {
134  array_push($sets, new OAISet($articleTombstoneSetSpec, $articleTombstoneSetName, ''));
135  }
136  }
137 
138  HookRegistry::call('OAIDAO::getJournalSets', array(&$this, $journalId, $offset, $limit, $total, &$sets));
139 
140  $total = count($sets);
141  $sets = array_slice($sets, $offset, $limit);
142 
143  return $sets;
144  }
145 
153  function getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId = null) {
154  $journalId = null;
155 
156  $journal =& $this->journalDao->getJournalByPath($journalSpec);
157  if (!isset($journal) || (isset($restrictJournalId) && $journal->getId() != $restrictJournalId)) {
158  return array(0, 0);
159  }
160 
161  $journalId = $journal->getId();
162  $sectionId = null;
163 
164  if (isset($sectionSpec)) {
165  $section =& $this->sectionDao->getSectionByAbbrev($sectionSpec, $journal->getId());
166  if (isset($section)) {
167  $sectionId = $section->getId();
168  } else {
169  $sectionId = 0;
170  }
171  }
172 
173  return array($journalId, $sectionId);
174  }
175 
176  //
177  // Protected methods.
178  //
183  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,
184  COALESCE(a.article_id, dot.data_object_id) AS article_id,
185  COALESCE(j.journal_id, tsoj.assoc_id) AS journal_id,
186  COALESCE(tsos.assoc_id, s.section_id) AS section_id,
187  i.issue_id,
188  dot.tombstone_id,
189  dot.set_spec,
190  dot.oai_identifier';
191  }
192 
196  function getRecordJoinClause($articleId = null, $setIds = array(), $set = null) {
197  if (isset($setIds[1])) {
198  list($journalId, $sectionId) = $setIds;
199  } else {
200  list($journalId) = $setIds;
201  }
202  return 'LEFT JOIN published_articles pa ON (m.i=0' . (isset($articleId) ? ' AND pa.article_id = ?' : '') . ')
203  LEFT JOIN articles a ON (a.article_id = pa.article_id' . (isset($journalId) ? ' AND a.journal_id = ?' : '') . (isset($sectionId) ? ' AND a.section_id = ?' : '') .')
204  LEFT JOIN issues i ON (i.issue_id = pa.issue_id)
205  LEFT JOIN sections s ON (s.section_id = a.section_id)
206  LEFT JOIN journals j ON (j.journal_id = a.journal_id)
207  LEFT JOIN data_object_tombstones dot ON (m.i = 1' . (isset($articleId) ? ' AND dot.data_object_id = ?' : '') . (isset($set) ? ' AND dot.set_spec = ?' : '') .')
208  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') .
209  ' 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');
210  }
211 
216  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)';
217  }
218 
222  function getDateRangeWhereClause($from, $until) {
223  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' : '')
224  . (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' : '')
225  . ' ORDER BY journal_id';
226  }
227 
231  function &setOAIData(&$record, &$row, $isRecord = true) {
232  $journal =& $this->getJournal($row['journal_id']);
233  $section =& $this->getSection($row['section_id']);
234  $articleId = $row['article_id'];
235 
236  $record->identifier = $this->oai->articleIdToIdentifier($articleId);
237  $record->sets = array(urlencode($journal->getPath()) . ':' . urlencode($section->getLocalizedAbbrev()));
238 
239  if ($isRecord) {
240  $publishedArticle =& $this->publishedArticleDao->getPublishedArticleByArticleId($articleId);
241  $issue =& $this->getIssue($row['issue_id']);
242  $galleys =& $this->articleGalleyDao->getGalleysByArticle($articleId);
243 
244  $record->setData('article', $publishedArticle);
245  $record->setData('journal', $journal);
246  $record->setData('section', $section);
247  $record->setData('issue', $issue);
248  $record->setData('galleys', $galleys);
249  }
250 
251  return $record;
252  }
253 }
254 
255 ?>
& sets($offset, &$total)
Definition: OAI.inc.php:168
Base class for DAO operations for the OAI interface.
getEarliestDatestamp($setIds=array())
Definition: OAIDAO.inc.php:57
getAccessibleRecordWhereClause()
Definition: OAIDAO.inc.php:215
& getJournal($journalId)
Definition: OAIDAO.inc.php:66
DAO operations for the OJS OAI interface.
Definition: OAIDAO.inc.php:20
getDateRangeWhereClause($from, $until)
Definition: OAIDAO.inc.php:222
getRecordJoinClause($articleId=null, $setIds=array(), $set=null)
Definition: OAIDAO.inc.php:196
& getIssue($issueId)
Definition: OAIDAO.inc.php:78
getSetJournalSectionId($journalSpec, $sectionSpec, $restrictJournalId=null)
Definition: OAIDAO.inc.php:153
& getDAO($name, $dbconn=null)
OAIDAO()
Definition: OAIDAO.inc.php:39
call($hookName, $args=null)
& getSection($sectionId)
Definition: OAIDAO.inc.php:90
datetimeToDB($dt)
Definition: DAO.inc.php:296
& setOAIData(&$record, &$row, $isRecord=true)
Definition: OAIDAO.inc.php:231
getRecordSelectStatement()
Definition: OAIDAO.inc.php:182
& getJournalSets($journalId, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:108