Open Monograph Press  3.3.0
OAIDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.oai.PKPOAIDAO');
18 
19 class OAIDAO extends PKPOAIDAO {
20 
23 
26 
28  var $_pressDao;
29 
32 
34  var $_seriesCache;
35 
39  function __construct() {
40  parent::__construct();
41 
42  $this->_publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
43  $this->_seriesDao = DAORegistry::getDAO('SeriesDAO');
44  $this->_pressDao = DAORegistry::getDAO('PressDAO');
45  }
46 
52  function getPress($pressId) {
53  if (!isset($this->_pressCache[$pressId])) {
54  $this->_pressCache[$pressId] = $this->_pressDao->getById($pressId);
55  }
56  return $this->_pressCache[$pressId];
57  }
58 
64  function getSeries($seriesId) {
65  if (!isset($this->_seriesCache[$seriesId])) {
66  $this->_seriesCache[$seriesId] = $this->_seriesDao->getById($seriesId);
67  }
68  return $this->_seriesCache[$seriesId];
69  }
70 
71  //
72  // Sets
73  //
74 
82  function getSets($pressId = null, $offset, $limit, &$total) {
83  if (isset($pressId)) {
84  $presses = array($this->getPress($pressId));
85  } else {
86  $pressFactory = $this->_pressDao->getAll();
87  $presses = $pressFactory->toArray();
88  }
89 
90  // FIXME Set descriptions
91  $sets = array();
92  foreach ($presses as $press) {
93  $title = $press->getLocalizedName();
94  $abbrev = $press->getPath();
95 
96  $dataObjectTombstoneDao = DAORegistry::getDAO('DataObjectTombstoneDAO'); /* @var $dataObjectTombstoneDao DataObjectTombstoneDAO */
97  $publicationFormatSets = $dataObjectTombstoneDao->getSets(ASSOC_TYPE_PRESS, $press->getId());
98 
99  if (!array_key_exists(urlencode($abbrev), $publicationFormatSets)) array_push($sets, new OAISet(urlencode($abbrev), $title, ''));
100 
101  $seriesFactory = $this->_seriesDao->getByPressId($press->getId());
102  foreach ($seriesFactory->toArray() as $series) {
103  if (array_key_exists(urlencode($abbrev) . ':' . urlencode($series->getPath()), $publicationFormatSets)) {
104  unset($publicationFormatSets[urlencode($abbrev) . ':' . urlencode($series->getPath())]);
105  }
106  array_push($sets, new OAISet(urlencode($abbrev) . ':' . urlencode($series->getPath()), $series->getLocalizedTitle(), ''));
107  }
108  foreach ($publicationFormatSets as $publicationFormatSetSpec => $publicationFormatSetName) {
109  array_push($sets, new OAISet($publicationFormatSetSpec, $publicationFormatSetName, ''));
110  }
111  }
112 
113  HookRegistry::call('OAIDAO::getSets', array(&$this, $pressId, $offset, $limit, $total, &$sets));
114 
115  $total = count($sets);
116  $sets = array_slice($sets, $offset, $limit);
117 
118  return $sets;
119  }
120 
128  function getSetPressSeriesId($pressSpec, $seriesSpec, $restrictPressId = null) {
129  $press = $this->_pressDao->getByPath($pressSpec);
130  if (!isset($press) || (isset($restrictPressId) && $press->getId() != $restrictPressId)) {
131  return array(0, 0);
132  }
133 
134  $pressId = $press->getId();
135  $seriesId = null;
136 
137  if (isset($seriesSpec)) {
138  $series = $this->_seriesDao->getByPath($seriesSpec, $press->getId());
139  if ($series && is_a($series, 'Series')) {
140  $seriesId = $series->getId();
141  } else {
142  $seriesId = 0;
143  }
144  }
145 
146  return array($pressId, $seriesId);
147  }
148 
149 
150  //
151  // Protected methods.
152  //
156  function setOAIData($record, $row, $isRecord = true) {
157  $press = $this->getPress($row['press_id']);
158  $series = $this->getSeries($row['series_id']);
159  $publicationFormatId = $row['data_object_id'];
160 
161  $record->identifier = $this->oai->publicationFormatIdToIdentifier($publicationFormatId);
162  $record->sets = array(urlencode($press->getPath()) . ($series?':' . urlencode($series->getPath()):''));
163 
164  if ($isRecord) {
165  $publicationFormat = $this->_publicationFormatDao->getById($publicationFormatId);
166  $publication = Services::get('publication')->get($publicationFormat->getData('publicationId'));
167  $submission = Services::get('submission')->get($publication->getData('submissionId'));
168  $record->setData('publicationFormat', $publicationFormat);
169  $record->setData('monograph', $submission);
170  $record->setData('press', $press);
171  $record->setData('series', $series);
172  }
173 
174  return $record;
175  }
176 
188  function _getRecordsRecordSet($setIds, $from, $until, $set, $submissionId = null, $orderBy = 'press_id, data_object_id') {
189  $pressId = array_shift($setIds);
190  $seriesId = array_shift($setIds);
191 
192  $params = array();
193  if ($pressId) $params[] = (int) $pressId;
194  if ($seriesId) $params[] = (int) $seriesId;
195  if ($submissionId) $params[] = (int) $submissionId;
196  if ($pressId) $params[] = (int) $pressId;
197  if ($seriesId) $params[] = (int) $seriesId;
198  if (isset($set)) $params[] = $set;
199  if ($submissionId) $params[] = (int) $submissionId;
200 
201  import('lib.pkp.classes.submission.PKPSubmission'); // STATUS_DECLINED
202  $result = $this->retrieve(
203  'SELECT ms.last_modified AS last_modified,
204  pf.publication_format_id AS data_object_id,
205  p.press_id AS press_id,
206  pub.series_id AS series_id,
207  NULL AS tombstone_id,
208  NULL AS set_spec,
209  NULL AS oai_identifier
210  FROM publication_formats pf
211  JOIN publications pub ON (pub.publication_id = pf.publication_id)
212  JOIN submissions ms ON (ms.current_publication_id = pub.publication_id)
213  LEFT JOIN series s ON (s.series_id = pub.series_id)
214  JOIN presses p ON (p.press_id = ms.context_id)
215  WHERE p.enabled = 1
216  ' . ($pressId?' AND p.press_id = ?':'') . '
217  ' . ($seriesId?' AND pub.series_id = ?':'') . '
218  AND ms.status <> ' . STATUS_DECLINED . '
219  AND pf.is_available = 1
220  AND pub.date_published IS NOT NULL
221  ' . ($from?' AND ms.last_modified >= ' . $this->datetimeToDB($from):'') . '
222  ' . ($until?' AND ms.last_modified <= ' . $this->datetimeToDB($until):'') . '
223  ' . ($submissionId?' AND pf.publication_format_id=?':'') . '
224  UNION
225  SELECT dot.date_deleted AS last_modified,
226  dot.data_object_id AS data_object_id,
227  tsop.assoc_id AS press_id,
228  tsos.assoc_id AS series_id,
229  dot.tombstone_id,
230  dot.set_spec,
231  dot.oai_identifier
232  FROM
233  data_object_tombstones dot
234  LEFT JOIN data_object_tombstone_oai_set_objects tsop ON ' . (isset($pressId) ? '(tsop.tombstone_id = dot.tombstone_id AND tsop.assoc_type = ' . ASSOC_TYPE_PRESS . ' AND tsop.assoc_id = ?)' : 'tsop.assoc_id = null') . '
235  LEFT JOIN data_object_tombstone_oai_set_objects tsos ON ' . (isset($seriesId) ? '(tsos.tombstone_id = dot.tombstone_id AND tsos.assoc_type = ' . ASSOC_TYPE_SERIES . ' AND tsos.assoc_id = ?)' : 'tsos.assoc_id = null') . '
236  WHERE 1=1
237  ' . ($from?' AND dot.date_deleted >= ' . $this->datetimeToDB($from):'') . '
238  ' . ($until?' AND dot.date_deleted <= ' . $this->datetimeToDB($until):'') . '
239  ' . (isset($set)?' AND dot.set_spec = ?':'') . '
240  ' . ($submissionId?' AND dot.data_object_id = ?':'') . '
241  ORDER BY ' . $orderBy,
242  $params
243  );
244 
245  return $result;
246  }
247 }
248 
249 
OAIDAO\setOAIData
setOAIData($record, $row, $isRecord=true)
Definition: OAIDAO.inc.php:171
PKPOAIDAO
Base class for DAO operations for the OAI interface.
Definition: PKPOAIDAO.inc.php:19
OAIDAO\$_publicationFormatDao
$_publicationFormatDao
Definition: OAIDAO.inc.php:25
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
OAIDAO
DAO operations for the OMP OAI interface.
Definition: OAIDAO.inc.php:19
OAIDAO\__construct
__construct()
Definition: OAIDAO.inc.php:54
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
OAIDAO\$_pressCache
$_pressCache
Definition: OAIDAO.inc.php:43
OAISet
Definition: OAIStruct.inc.php:235
OAIDAO\_getRecordsRecordSet
_getRecordsRecordSet($setIds, $from, $until, $set, $submissionId=null, $orderBy='press_id, data_object_id')
Definition: OAIDAO.inc.php:203
OAIDAO\getSetPressSeriesId
getSetPressSeriesId($pressSpec, $seriesSpec, $restrictPressId=null)
Definition: OAIDAO.inc.php:143
OAIDAO\getSets
getSets($pressId=null, $offset, $limit, &$total)
Definition: OAIDAO.inc.php:97
DAO\datetimeToDB
datetimeToDB($dt)
Definition: DAO.inc.php:299
OAIDAO\getSeries
getSeries($seriesId)
Definition: OAIDAO.inc.php:79
OAIDAO\$_seriesCache
$_seriesCache
Definition: OAIDAO.inc.php:49
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
OAIDAO\$_pressDao
$_pressDao
Definition: OAIDAO.inc.php:37
OAIDAO\getPress
getPress($pressId)
Definition: OAIDAO.inc.php:67
OAIDAO\$_seriesDao
$_seriesDao
Definition: OAIDAO.inc.php:31
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49