00001 <?php
00002
00016 import ('classes.press.Series');
00017
00018 class SeriesDAO extends DAO {
00022 function SeriesDAO() {
00023 parent::DAO();
00024 }
00025
00032 function &getById($seriesId, $pressId = null) {
00033 $params = array((int) $seriesId);
00034 if ($pressId) $params[] = (int) $pressId;
00035
00036 $result =& $this->retrieve(
00037 'SELECT *
00038 FROM series
00039 WHERE series_id = ?
00040 ' . ($pressId?' AND press_id = ?':''),
00041 $params
00042 );
00043
00044 $returner = null;
00045 if ($result->RecordCount() != 0) {
00046 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00047 }
00048
00049 $result->Close();
00050 unset($result);
00051
00052 return $returner;
00053 }
00054
00061 function &getByPath($path, $pressId) {
00062 $returner = null;
00063 $result =& $this->retrieve(
00064 'SELECT * FROM series WHERE path = ? AND press_id = ?',
00065 array((string) $path, (int) $pressId)
00066 );
00067
00068 if ($result->RecordCount() != 0) {
00069 $returner =& $this->_fromRow($result->GetRowAssoc(false));
00070 }
00071
00072 $result->Close();
00073 unset($result);
00074
00075 return $returner;
00076 }
00077
00082 function newDataObject() {
00083 return new Series();
00084 }
00085
00091 function _fromRow(&$row) {
00092 $series = $this->newDataObject();
00093
00094 $series->setId($row['series_id']);
00095 $series->setPressId($row['press_id']);
00096 $series->setFeatured($row['featured']);
00097 $series->setPath($row['path']);
00098 $series->setImage(unserialize($row['image']));
00099
00100 $this->getDataObjectSettings('series_settings', 'series_id', $row['series_id'], $series);
00101
00102 HookRegistry::call('SeriesDAO::_fromRow', array(&$series, &$row));
00103
00104 return $series;
00105 }
00106
00111 function getLocaleFieldNames() {
00112 return array('title', 'description', 'prefix', 'subtitle');
00113 }
00114
00119 function updateLocaleFields(&$series) {
00120 $this->updateDataObjectSettings(
00121 'series_settings',
00122 $series,
00123 array('series_id' => (int) $series->getId())
00124 );
00125 }
00126
00131 function insertObject(&$series) {
00132 $this->update(
00133 'INSERT INTO series
00134 (press_id, featured, path, image)
00135 VALUES
00136 (?, ?, ?, ?)',
00137 array(
00138 (int) $series->getPressId(),
00139 (int) $series->getFeatured(),
00140 (string) $series->getPath(),
00141 serialize($series->getImage() ? $series->getImage() : array()),
00142 )
00143 );
00144
00145 $series->setId($this->getInsertSeriesId());
00146 $this->updateLocaleFields($series);
00147 return $series->getId();
00148 }
00149
00154 function updateObject($series) {
00155 $returner = $this->update(
00156 'UPDATE series
00157 SET press_id = ?,
00158 featured = ?,
00159 path = ?,
00160 image = ?
00161 WHERE series_id = ?',
00162 array(
00163 (int) $series->getPressId(),
00164 (int) $series->getFeatured(),
00165 (string) $series->getPath(),
00166 serialize($series->getImage() ? $series->getImage() : array()),
00167 (int) $series->getId(),
00168 )
00169 );
00170 $this->updateLocaleFields($series);
00171 return $returner;
00172 }
00173
00178 function deleteObject(&$series) {
00179 return $this->deleteById($series->getId(), $series->getPressId());
00180 }
00181
00187 function deleteById($seriesId, $pressId = null) {
00188
00189 if (!$this->seriesExists($seriesId, $pressId)) return false;
00190
00191 $seriesEditorsDao =& DAORegistry::getDAO('SeriesEditorsDAO');
00192 $seriesEditorsDao->deleteEditorsBySeriesId($seriesId, $pressId);
00193
00194
00195 $monographDao =& DAORegistry::getDAO('MonographDAO');
00196 $monographDao->removeMonographsFromSeries($seriesId);
00197
00198
00199 $this->update('DELETE FROM series WHERE series_id = ?', (int) $seriesId);
00200 $this->update('DELETE FROM series_settings WHERE series_id = ?', (int) $seriesId);
00201 }
00202
00209 function deleteByPressId($pressId) {
00210 $series =& $this->getByPressId($pressId);
00211 while (($series =& $series->next())) {
00212 $this->deleteObject($series);
00213 unset($series);
00214 }
00215 }
00216
00222 function &getEditorSeries($pressId) {
00223 $result =& $this->retrieve(
00224 'SELECT a.*,
00225 ae.user_id AS editor_id
00226 FROM series_editors ae,
00227 series a
00228 WHERE ae.series_id = a.series_id AND
00229 a.press_id = ae.press_id AND
00230 a.press_id = ?',
00231 (int) $pressId
00232 );
00233
00234 $returner = array();
00235 while (!$result->EOF) {
00236 $row = $result->GetRowAssoc(false);
00237 $series =& $this->_fromRow($row);
00238 if (!isset($returner[$row['editor_id']])) {
00239 $returner[$row['editor_id']] = array($series);
00240 } else {
00241 $returner[$row['editor_id']][] = $series;
00242 }
00243 $result->MoveNext();
00244 unset($series);
00245 }
00246
00247 $result->Close();
00248 unset($result);
00249
00250 return $returner;
00251 }
00252
00257 function &getByPressId($pressId, $rangeInfo = null) {
00258 $result =& $this->retrieveRange(
00259 'SELECT * FROM series WHERE press_id = ?',
00260 (int) $pressId,
00261 $rangeInfo
00262 );
00263
00264 $returner = new DAOResultFactory($result, $this, '_fromRow');
00265 return $returner;
00266 }
00267
00272 function &getTitlesByPressId($pressId, $submittableOnly = false) {
00273 $seriesTitles = array();
00274
00275 $seriesIterator =& $this->getByPressId($pressId, null);
00276 while (($series =& $seriesIterator->next())) {
00277 if ($submittableOnly) {
00278 if (!$series->getEditorRestricted()) {
00279 $seriesTitles[$series->getId()] = join(' ', array($series->getLocalizedPrefix(), $series->getLocalizedTitle()));
00280 }
00281 } else {
00282 $seriesTitles[$series->getId()] = join(' ', array($series->getLocalizedPrefix(), $series->getLocalizedTitle()));
00283 }
00284 unset($series);
00285 }
00286
00287 return $seriesTitles;
00288 }
00289
00296 function seriesExists($seriesId, $pressId) {
00297 $result =& $this->retrieve(
00298 'SELECT COUNT(*) FROM series WHERE series_id = ? AND press_id = ?',
00299 array((int) $seriesId, (int) $pressId)
00300 );
00301 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00302
00303 $result->Close();
00304 unset($result);
00305
00306 return $returner;
00307 }
00308
00313 function getInsertSeriesId() {
00314 return $this->getInsertId('series', 'series_id');
00315 }
00316
00322 function addCategory($seriesId, $categoryId) {
00323 $this->update(
00324 'INSERT INTO series_categories
00325 (series_id, category_id)
00326 VALUES
00327 (?, ?)',
00328 array(
00329 (int) $seriesId,
00330 (int) $categoryId
00331 )
00332 );
00333 }
00334
00340 function removeCategory($seriesId, $categoryId) {
00341 $this->update(
00342 'DELETE FROM series_categories WHERE series_id = ? AND category_id = ?',
00343 array(
00344 (int) $seriesId,
00345 (int) $categoryId
00346 )
00347 );
00348 }
00349
00355 function getCategories($seriesId, $pressId = null) {
00356 $params = array((int) $seriesId);
00357 if ($pressId) $params[] = (int) $pressId;
00358
00359 $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00360 $result =& $this->retrieve(
00361 'SELECT c.*
00362 FROM categories c,
00363 series_categories sc,
00364 series s
00365 WHERE c.category_id = sc.category_id AND
00366 s.series_id = ? AND
00367 ' . ($pressId?' c.press_id = s.press_id AND s.press_id = ? AND':'') . '
00368 s.series_id = sc.series_id',
00369 $params
00370 );
00371
00372
00373 $returner = new DAOResultFactory($result, $categoryDao, '_fromRow');
00374 return $returner;
00375 }
00376
00382 function getUnassignedCategories($seriesId, $pressId = null) {
00383 $params = array((int) $seriesId);
00384 if ($pressId) $params[] = (int) $pressId;
00385
00386 $categoryDao =& DAORegistry::getDAO('CategoryDAO');
00387 $result =& $this->retrieve(
00388 'SELECT c.*
00389 FROM series s
00390 JOIN categories c ON (c.press_id = s.press_id)
00391 LEFT JOIN series_categories sc ON (s.series_id = sc.series_id AND sc.category_id = c.category_id)
00392 WHERE s.series_id = ? AND
00393 ' . ($pressId?' s.press_id = ? AND':'') . '
00394 sc.series_id IS NULL',
00395 $params
00396 );
00397
00398
00399 $returner = new DAOResultFactory($result, $categoryDao, '_fromRow');
00400 return $returner;
00401 }
00402
00409 function categoryAssociationExists($seriesId, $categoryId) {
00410 $result =& $this->retrieve(
00411 'SELECT COUNT(*) FROM series_categories WHERE series_id = ? AND category_id = ?',
00412 array((int) $seriesId, (int) $categoryId)
00413 );
00414 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00415
00416 $result->Close();
00417 unset($result);
00418
00419 return $returner;
00420 }
00421 }
00422
00423 ?>