00001 <?php
00002
00016 import('lib.pkp.classes.oai.PKPOAIDAO');
00017
00018 class OAIDAO extends PKPOAIDAO {
00019
00021 var $_publicationFormatDao;
00022
00024 var $_publishedMonographDao;
00025
00027 var $_seriesDao;
00028
00030 var $_pressDao;
00031
00033 var $_pressCache;
00034
00036 var $_seriesCache;
00037
00041 function OAIDAO() {
00042 parent::PKPOAIDAO();
00043
00044 $this->_publicationFormatDao = DAORegistry::getDAO('PublicationFormatDAO');
00045 $this->_publishedMonographDao = DAORegistry::getDAO('PublishedMonographDAO');
00046 $this->_seriesDao = DAORegistry::getDAO('SeriesDAO');
00047 $this->_pressDao = DAORegistry::getDAO('PressDAO');
00048 }
00049
00053 function getEarliestDatestamp($setIds) {
00054 return parent::getEarliestDatestamp('SELECT MIN(COALESCE(dot.date_deleted, ms.last_modified))', $setIds);
00055 }
00056
00062 function &getPress($pressId) {
00063 if (!isset($this->_pressCache[$pressId])) {
00064 $this->_pressCache[$pressId] =& $this->_pressDao->getById($pressId);
00065 }
00066 return $this->_pressCache[$pressId];
00067 }
00068
00074 function &getSeries($seriesId) {
00075 if (!isset($this->_seriesCache[$seriesId])) {
00076 $this->_seriesCache[$seriesId] =& $this->_seriesDao->getById($seriesId);
00077 }
00078 return $this->_seriesCache[$seriesId];
00079 }
00080
00081
00082
00083
00084
00092 function &getSets($pressId = null, $offset, $limit, &$total) {
00093 if (isset($pressId)) {
00094 $presses = array($this->getPress($pressId));
00095 } else {
00096 $pressFactory =& $this->_pressDao->getPresses();
00097 $presses =& $pressFactory->toArray();
00098 }
00099
00100
00101 $sets = array();
00102 foreach ($presses as $press) {
00103 $title = $press->getLocalizedName();
00104 $abbrev = $press->getPath();
00105 array_push($sets, new OAISet(urlencode($abbrev), $title, ''));
00106
00107 $dataObjectTombstoneDao =& DAORegistry::getDAO('DataObjectTombstoneDAO');
00108 $publicationFormatSets = $dataObjectTombstoneDao->getSets(ASSOC_TYPE_PRESS, $press->getId());
00109
00110 $seriesFactory =& $this->_seriesDao->getByPressId($press->getId());
00111 foreach ($seriesFactory->toArray() as $series) {
00112 if (array_key_exists(urlencode($abbrev) . ':' . urlencode($series->getPath()), $publicationFormatSets)) {
00113 unset($publicationFormatSets[urlencode($abbrev) . ':' . urlencode($series->getPath())]);
00114 }
00115 array_push($sets, new OAISet(urlencode($abbrev) . ':' . urlencode($series->getPath()), $series->getLocalizedTitle(), ''));
00116 }
00117 foreach ($publicationFormatSets as $publicationFormatSetSpec => $publicationFormatSetName) {
00118 array_push($sets, new OAISet($publicationFormatSetSpec, $publicationFormatSetName, ''));
00119 }
00120 }
00121
00122 HookRegistry::call('OAIDAO::getSets', array(&$this, $pressId, $offset, $limit, $total, &$sets));
00123
00124 $total = count($sets);
00125 $sets = array_slice($sets, $offset, $limit);
00126
00127 return $sets;
00128 }
00129
00137 function getSetPressSeriesId($pressSpec, $seriesSpec, $restrictPressId = null) {
00138 $pressId = null;
00139
00140 $press =& $this->_pressDao->getPressByPath($pressSpec);
00141 if (!isset($press) || (isset($restrictPressId) && $press->getId() != $restrictPressId)) {
00142 return array(0, 0);
00143 }
00144
00145 $pressId = $press->getId();
00146 $seriesId = null;
00147
00148 if (isset($seriesSpec)) {
00149 $series =& $this->_seriesDao->getByPath($seriesSpec, $press->getId());
00150 if (is_a($series, 'Series')) {
00151 $seriesId = $series->getId();
00152 } else {
00153 $seriesId = 0;
00154 }
00155 }
00156
00157 return array($pressId, $seriesId);
00158 }
00159
00160
00161
00162
00163
00167 function getRecordSelectStatement() {
00168 return 'SELECT COALESCE(dot.date_deleted, ms.last_modified) AS last_modified,
00169 COALESCE(pf.publication_format_id, dot.data_object_id) AS data_object_id,
00170 COALESCE(p.press_id, tsop.assoc_id) AS press_id,
00171 COALESCE(tsos.assoc_id, s.series_id) AS series_id,
00172 dot.tombstone_id,
00173 dot.set_spec,
00174 dot.oai_identifier';
00175 }
00176
00180 function getRecordJoinClause($publicationFormatId = null, $setIds = array(), $set = null) {
00181 assert(is_array($setIds));
00182 list($pressId, $seriesId) = $setIds;
00183 return 'LEFT JOIN publication_formats pf ON (m.i=0' . (isset($publicationFormatId) ? ' AND pf.publication_format_id = ?' : '') . ')
00184 LEFT JOIN published_monographs pm ON (pm.monograph_id = pf.monograph_id)
00185 LEFT JOIN monographs ms ON (ms.monograph_id = pm.monograph_id' . (isset($pressId) ? ' AND ms.press_id = ?' : '') . (isset($seriesId) && $seriesId != 0 ? ' AND ms.series_id = ?' : '') .')
00186 LEFT JOIN series s ON (s.series_id = ms.series_id)
00187 LEFT JOIN presses p ON (p.press_id = ms.press_id)
00188 LEFT JOIN data_object_tombstones dot ON (m.i = 1' . (isset($publicationFormatId) ? ' AND dot.data_object_id = ?' : '') . (isset($set) ? ' AND dot.set_spec = ?' : '') . ')
00189 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') .
00190 ' 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');
00191 }
00192
00196 function getAccessibleRecordWhereClause() {
00197 return 'WHERE ((p.enabled = 1 AND ms.status <> ' . STATUS_ARCHIVED . ' AND pf.is_available = 1) OR dot.data_object_id IS NOT NULL)';
00198 }
00199
00203 function getDateRangeWhereClause($from, $until) {
00204 return (isset($from) ? ' AND ((dot.date_deleted IS NOT NULL AND dot.date_deleted >= '. $this->datetimeToDB($from) .') OR (dot.date_deleted IS NULL AND ms.last_modified >= ' . $this->datetimeToDB($from) .'))' : '')
00205 . (isset($until) ? ' AND ((dot.date_deleted IS NOT NULL AND dot.date_deleted <= ' .$this->datetimeToDB($until) .') OR (dot.date_deleted IS NULL AND ms.last_modified <= ' . $this->datetimeToDB($until) .'))' : '')
00206 . ' ORDER BY press_id';
00207 }
00208
00212 function &setOAIData(&$record, &$row, $isRecord = true) {
00213 $press =& $this->getPress($row['press_id']);
00214 $series =& $this->getSeries($row['series_id']);
00215 $publicationFormatId = $row['data_object_id'];
00216
00217 $record->identifier = $this->oai->publicationFormatIdToIdentifier($publicationFormatId);
00218 $record->sets = array(urlencode($press->getPath()) . ($series?':' . urlencode($series->getPath()):''));
00219
00220 if ($isRecord) {
00221 $publicationFormat =& $this->_publicationFormatDao->getById($publicationFormatId);
00222 $monograph =& $this->_publishedMonographDao->getById($publicationFormat->getMonographId());
00223 $record->setData('publicationFormat', $publicationFormat);
00224 $record->setData('monograph', $monograph);
00225 $record->setData('press', $press);
00226 $record->setData('series', $series);
00227 }
00228
00229 return $record;
00230 }
00231 }
00232
00233 ?>