00001 <?php
00002
00016 import('classes.monograph.PublishedMonograph');
00017 import('classes.monograph.MonographDAO');
00018
00019 class PublishedMonographDAO extends MonographDAO {
00023 function PublishedMonographDAO() {
00024 parent::MonographDAO();
00025 }
00026
00033 function &getByPressId($pressId, $searchText = null, $rangeInfo = null) {
00034 $primaryLocale = AppLocale::getPrimaryLocale();
00035 $locale = AppLocale::getLocale();
00036
00037 $params = array(
00038 REALLY_BIG_NUMBER,
00039 'title', $primaryLocale,
00040 'title', $locale,
00041 'abbrev', $primaryLocale,
00042 'abbrev', $locale,
00043 ASSOC_TYPE_PRESS,
00044 (int) $pressId
00045 );
00046
00047 if ($searchText !== null) {
00048 $params[] = $params[] = $params[] = "%$searchText%";
00049 }
00050
00051 $result =& $this->retrieveRange(
00052 'SELECT ' . ($searchText !== null?'DISTINCT ':'') . '
00053 pm.*,
00054 m.*,
00055 COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
00056 COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev,
00057 COALESCE(f.seq, ?) AS order_by
00058 FROM published_monographs pm
00059 JOIN monographs m ON pm.monograph_id = m.monograph_id
00060 LEFT JOIN series s ON s.series_id = m.series_id
00061 LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
00062 LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
00063 LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
00064 LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
00065 ' . ($searchText !== null?'
00066 LEFT JOIN authors a ON m.monograph_id = a.submission_id
00067 LEFT JOIN monograph_settings mt ON (mt.monograph_id = m.monograph_id AND mt.setting_name = \'title\')
00068 ':'') . '
00069 LEFT JOIN features f ON (f.monograph_id = m.monograph_id AND f.assoc_type = ? AND f.assoc_id = m.press_id)
00070 WHERE pm.date_published IS NOT NULL AND m.press_id = ?
00071 ' . ($searchText !== null?' AND (mt.setting_value LIKE ? OR a.first_name LIKE ? OR a.last_name LIKE ?)':'') . '
00072 ORDER BY order_by, pm.date_published',
00073 $params,
00074 $rangeInfo
00075 );
00076
00077 $returner = new DAOResultFactory($result, $this, '_fromRow');
00078 return $returner;
00079 }
00080
00087 function &getPressFeatures($pressId, $rangeInfo = null) {
00088 $primaryLocale = AppLocale::getPrimaryLocale();
00089 $locale = AppLocale::getLocale();
00090
00091 $result =& $this->retrieveRange(
00092 'SELECT pm.*,
00093 m.*,
00094 COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
00095 COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev
00096 FROM published_monographs pm
00097 JOIN monographs m ON pm.monograph_id = m.monograph_id
00098 LEFT JOIN series s ON s.series_id = m.series_id
00099 LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
00100 LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
00101 LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
00102 LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
00103 JOIN features f ON (f.monograph_id = m.monograph_id AND f.assoc_type = ? AND f.assoc_id = m.press_id)
00104 WHERE pm.date_published IS NOT NULL AND m.press_id = ?
00105 ORDER BY f.seq, pm.date_published',
00106 array(
00107 'title', $primaryLocale,
00108 'title', $locale,
00109 'abbrev', $primaryLocale,
00110 'abbrev', $locale,
00111 ASSOC_TYPE_PRESS,
00112 (int) $pressId
00113 ),
00114 $rangeInfo
00115 );
00116
00117 $returner = new DAOResultFactory($result, $this, '_fromRow');
00118 return $returner;
00119 }
00120
00128 function &getBySeriesId($seriesId, $pressId = null, $rangeInfo = null) {
00129 $primaryLocale = AppLocale::getPrimaryLocale();
00130 $locale = AppLocale::getLocale();
00131
00132 $params = array(
00133 'title', $primaryLocale,
00134 'title', $locale,
00135 'abbrev', $primaryLocale,
00136 'abbrev', $locale,
00137 ASSOC_TYPE_SERIES,
00138 (int) $seriesId
00139 );
00140
00141 if ($pressId) $params[] = (int) $pressId;
00142
00143 $params[] = REALLY_BIG_NUMBER;
00144
00145 $result =& $this->retrieveRange(
00146 'SELECT pm.*,
00147 m.*,
00148 COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
00149 COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev
00150 FROM published_monographs pm
00151 JOIN monographs m ON pm.monograph_id = m.monograph_id
00152 JOIN series s ON s.series_id = m.series_id
00153 LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
00154 LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
00155 LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
00156 LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
00157 LEFT JOIN features f ON (f.monograph_id = m.monograph_id AND f.assoc_type = ? AND f.assoc_id = s.series_id)
00158 WHERE pm.date_published IS NOT NULL AND s.series_id = ?
00159 ' . ($pressId?' AND m.press_id = ?':'' ) . '
00160 ORDER BY COALESCE(f.seq, ?) ASC, pm.date_published',
00161 $params,
00162 $rangeInfo
00163 );
00164
00165 $returner = new DAOResultFactory($result, $this, '_fromRow');
00166 return $returner;
00167 }
00168
00176 function &getByCategoryId($categoryId, $pressId = null, $rangeInfo = null) {
00177 $primaryLocale = AppLocale::getPrimaryLocale();
00178 $locale = AppLocale::getLocale();
00179
00180 $params = array(
00181 REALLY_BIG_NUMBER,
00182 'title', $primaryLocale,
00183 'title', $locale,
00184 'abbrev', $primaryLocale,
00185 'abbrev', $locale,
00186 (int) $categoryId, (int) $categoryId, (int) $categoryId,
00187 ASSOC_TYPE_SERIES
00188 );
00189
00190 if ($pressId) $params[] = (int) $pressId;
00191
00192 $result =& $this->retrieveRange(
00193 'SELECT DISTINCT pm.*,
00194 m.*,
00195 COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
00196 COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev,
00197 COALESCE(f.seq, ?) AS order_by
00198 FROM published_monographs pm
00199 JOIN monographs m ON pm.monograph_id = m.monograph_id
00200 LEFT JOIN series s ON s.series_id = m.series_id
00201 LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
00202 LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
00203 LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
00204 LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
00205 LEFT JOIN monograph_categories mc ON (mc.monograph_id = m.monograph_id AND mc.category_id = ?)
00206 LEFT JOIN series_categories sca ON (sca.series_id = s.series_id)
00207 LEFT JOIN categories sc ON (sc.category_id = sca.category_id AND sc.category_id = ?)
00208 LEFT JOIN features f ON (f.monograph_id = m.monograph_id AND f.assoc_type = ? AND f.assoc_id = ?)
00209 WHERE pm.date_published IS NOT NULL AND (sc.category_id IS NOT NULL OR mc.category_id IS NOT NULL)
00210 ' . ($pressId?' AND m.press_id = ?':'' ) . '
00211 ORDER BY order_by, pm.date_published',
00212 $params,
00213 $rangeInfo
00214 );
00215
00216 $returner = new DAOResultFactory($result, $this, '_fromRow');
00217 return $returner;
00218 }
00219
00226 function &getById($monographId, $pressId = null, $metadataApprovedOnly = true) {
00227 $primaryLocale = AppLocale::getPrimaryLocale();
00228 $locale = AppLocale::getLocale();
00229 $params = array(
00230 'title', $primaryLocale,
00231 'title', $locale,
00232 'abbrev', $primaryLocale,
00233 'abbrev', $locale,
00234 (int) $monographId
00235 );
00236 if ($pressId) $params[] = (int) $pressId;
00237
00238 $result =& $this->retrieve(
00239 'SELECT m.*,
00240 pm.*,
00241 COALESCE(stl.setting_value, stpl.setting_value) AS series_title,
00242 COALESCE(sal.setting_value, sapl.setting_value) AS series_abbrev
00243 FROM monographs m
00244 JOIN published_monographs pm ON (pm.monograph_id = m.monograph_id)
00245 LEFT JOIN series s ON s.series_id = m.series_id
00246 LEFT JOIN series_settings stpl ON (s.series_id = stpl.series_id AND stpl.setting_name = ? AND stpl.locale = ?)
00247 LEFT JOIN series_settings stl ON (s.series_id = stl.series_id AND stl.setting_name = ? AND stl.locale = ?)
00248 LEFT JOIN series_settings sapl ON (s.series_id = sapl.series_id AND sapl.setting_name = ? AND sapl.locale = ?)
00249 LEFT JOIN series_settings sal ON (s.series_id = sal.series_id AND sal.setting_name = ? AND sal.locale = ?)
00250 WHERE m.monograph_id = ?
00251 ' . ($pressId?' AND m.press_id = ?':'')
00252 . ($metadataApprovedOnly?' AND pm.date_published IS NOT NULL':''),
00253 $params
00254 );
00255
00256 $returner = null;
00257 if ($result->RecordCount() != 0) {
00258 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00259 }
00260
00261 $result->Close();
00262 unset($result);
00263
00264 return $returner;
00265 }
00266
00271 function newDataObject() {
00272 return new PublishedMonograph();
00273 }
00274
00281 function &_fromRow($row, $callHooks = true) {
00282
00283 $publishedMonograph =& parent::_fromRow($row, $callHooks);
00284
00285
00286 $publishedMonograph->setDatePublished($this->datetimeFromDB($row['date_published']));
00287 $publishedMonograph->setAudience($row['audience']);
00288 $publishedMonograph->setAudienceRangeQualifier($row['audience_range_qualifier']);
00289 $publishedMonograph->setAudienceRangeFrom($row['audience_range_from']);
00290 $publishedMonograph->setAudienceRangeTo($row['audience_range_to']);
00291 $publishedMonograph->setAudienceRangeExact($row['audience_range_exact']);
00292 $publishedMonograph->setCoverImage(unserialize($row['cover_image']));
00293
00294 if ($callHooks) HookRegistry::call('PublishedMonographDAO::_fromRow', array(&$publishedMonograph, &$row));
00295 return $publishedMonograph;
00296 }
00297
00298
00303 function insertObject(&$publishedMonograph) {
00304
00305 $this->update(
00306 sprintf('INSERT INTO published_monographs
00307 (monograph_id, date_published, audience, audience_range_qualifier, audience_range_from, audience_range_to, audience_range_exact, cover_image)
00308 VALUES
00309 (?, %s, ?, ?, ?, ?, ?, ?)',
00310 $this->datetimeToDB($publishedMonograph->getDatePublished())),
00311 array(
00312 (int) $publishedMonograph->getId(),
00313 $publishedMonograph->getAudience(),
00314 $publishedMonograph->getAudienceRangeQualifier(),
00315 $publishedMonograph->getAudienceRangeFrom(),
00316 $publishedMonograph->getAudienceRangeTo(),
00317 $publishedMonograph->getAudienceRangeExact(),
00318 serialize($publishedMonograph->getCoverImage() ? $publishedMonograph->getCoverImage() : array()),
00319 )
00320 );
00321 }
00322
00327 function deleteById($monographId) {
00328 $this->update(
00329 'DELETE FROM published_monographs WHERE monograph_id = ?',
00330 (int) $monographId
00331 );
00332 }
00333
00338 function updateObject($publishedMonograph) {
00339 $this->update(
00340 sprintf('UPDATE published_monographs
00341 SET date_published = %s,
00342 audience = ?,
00343 audience_range_qualifier = ?,
00344 audience_range_from = ?,
00345 audience_range_to = ?,
00346 audience_range_exact = ?,
00347 cover_image = ?
00348 WHERE monograph_id = ?',
00349 $this->datetimeToDB($publishedMonograph->getDatePublished())),
00350 array(
00351 $publishedMonograph->getAudience(),
00352 $publishedMonograph->getAudienceRangeQualifier(),
00353 $publishedMonograph->getAudienceRangeFrom(),
00354 $publishedMonograph->getAudienceRangeTo(),
00355 $publishedMonograph->getAudienceRangeExact(),
00356 serialize($publishedMonograph->getCoverImage() ? $publishedMonograph->getCoverImage() : array()),
00357 (int) $publishedMonograph->getId()
00358 )
00359 );
00360 }
00361 }
00362
00363 ?>