• Main Page
  • Modules
  • Classes
  • Files
  • File List

classes/press/PressDAO.inc.php

00001 <?php
00015 import('classes.press.Press');
00016 
00017 class PressDAO extends DAO {
00021    function PressDAO() {
00022       parent::DAO();
00023    }
00024 
00030    function getById($pressId) {
00031       $result =& $this->retrieve('SELECT * FROM presses WHERE press_id = ?', (int) $pressId);
00032 
00033       $returner = null;
00034       if ($result->RecordCount() != 0) {
00035          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00036       }
00037       $result->Close();
00038       return $returner;
00039    }
00040 
00045    function getNames() {
00046       $presses = array();
00047 
00048       $pressIterator =& $this->getPresses();
00049       while ($press =& $pressIterator->next()) {
00050          $presses[$press->getId()] = $press->getLocalizedName();
00051          unset($press);
00052       }
00053       unset($pressIterator);
00054 
00055       return $presses;
00056    }
00057 
00062    function newDataObject() {
00063       return new Press();
00064    }
00065 
00071    function &_fromRow(&$row) {
00072       $press = $this->newDataObject();
00073       $press->setId($row['press_id']);
00074       $press->setPath($row['path']);
00075       $press->setSequence($row['seq']);
00076       $press->setEnabled($row['enabled']);
00077       $press->setPrimaryLocale($row['primary_locale']);
00078 
00079       HookRegistry::call('PressDAO::_fromRow', array(&$press, &$row));
00080 
00081       return $press;
00082    }
00083 
00089    function pressExistsByPath($path) {
00090       $result =& $this->retrieve(
00091          'SELECT COUNT(*) FROM presses WHERE path = ?', $path
00092       );
00093       $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00094 
00095       $result->Close();
00096       unset($result);
00097 
00098       return $returner;
00099    }
00100 
00107    function &getPressByPath($path) {
00108       $returner =& $this->getByPath($path);
00109       return $returner;
00110    }
00111 
00117    function &getByPath($path) {
00118       $returner = null;
00119       $result =& $this->retrieve(
00120          'SELECT * FROM presses WHERE path = ?', (string) $path
00121       );
00122 
00123       if ($result->RecordCount() != 0) {
00124          $returner =& $this->_fromRow($result->GetRowAssoc(false));
00125       }
00126       $result->Close();
00127       unset($result);
00128       return $returner;
00129    }
00130 
00135    function &getPresses($rangeInfo = null) {
00136       $result =& $this->retrieveRange(
00137          'SELECT * FROM presses ORDER BY seq',
00138          false, $rangeInfo
00139       );
00140 
00141       $returner = new DAOResultFactory($result, $this, '_fromRow');
00142       return $returner;
00143    }
00144 
00149    function insertObject(&$press) {
00150       $this->update(
00151          'INSERT INTO presses
00152             (path, seq, enabled, primary_locale)
00153             VALUES
00154             (?, ?, ?, ?)',
00155          array(
00156             $press->getPath(),
00157             (int) $press->getSequence() == null ? 0 : $press->getSequence(),
00158             $press->getEnabled() ? 1 : 0,
00159             $press->getPrimaryLocale()
00160          )
00161       );
00162 
00163       $press->setId($this->getInsertPressId());
00164       return $press->getId();
00165    }
00166 
00171    function updateObject(&$press) {
00172       return $this->update(
00173          'UPDATE presses
00174             SET
00175                path = ?,
00176                seq = ?,
00177                enabled = ?,
00178                primary_locale = ?
00179             WHERE press_id = ?',
00180          array(
00181             $press->getPath(),
00182             (int) $press->getSequence(),
00183             $press->getEnabled() ? 1 : 0,
00184             $press->getPrimaryLocale(),
00185             (int) $press->getId()
00186          )
00187       );
00188    }
00189 
00194    function &getEnabledPresses() {
00195       $result =& $this->retrieve(
00196          'SELECT * FROM presses WHERE enabled=1 ORDER BY seq'
00197       );
00198 
00199       $resultFactory = new DAOResultFactory($result, $this, '_fromRow');
00200       return $resultFactory;
00201    }
00202 
00207    function getInsertPressId() {
00208       return $this->getInsertId('presses', 'press_id');
00209    }
00210 
00215    function deleteById($pressId) {
00216       $pressSettingsDao =& DAORegistry::getDAO('PressSettingsDAO');
00217       $pressSettingsDao->deleteSettingsByPress($pressId);
00218 
00219       $seriesDao =& DAORegistry::getDAO('SeriesDAO');
00220       $seriesDao->deleteByPressId($pressId);
00221 
00222       $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
00223       $emailTemplateDao->deleteEmailTemplatesByPress($pressId);
00224 
00225       $monographDao =& DAORegistry::getDAO('MonographDAO');
00226       $monographDao->deleteByPressId($pressId);
00227 
00228       $userGroupDao =& DAORegistry::getDAO('UserGroupDAO');
00229       $userGroupDao->deleteAssignmentsByContextId($pressId);
00230       $userGroupDao->deleteByContextId($pressId);
00231 
00232       $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
00233       $pluginSettingsDao->deleteSettingsByPressId($pressId);
00234 
00235       $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00236       $reviewFormDao->deleteByAssocId(ASSOC_TYPE_PRESS, $pressId);
00237 
00238       $genreDao =& DAORegistry::getDAO('GenreDAO');
00239       $genreDao->deleteByPressId($pressId);
00240 
00241       $featureDao =& DAORegistry::getDAO('FeatureDAO');
00242       $featureDao->deleteByAssoc(ASSOC_TYPE_PRESS, $pressId);
00243 
00244       $newReleaseDao =& DAORegistry::getDAO('NewReleaseDAO');
00245       $newReleaseDao->deleteByAssoc(ASSOC_TYPE_PRESS, $pressId);
00246 
00247       $this->update('DELETE FROM press_defaults WHERE press_id = ?', (int) $pressId);
00248 
00249       return $this->update(
00250          'DELETE FROM presses WHERE press_id = ?', (int) $pressId
00251       );
00252    }
00253 
00257    function resequencePresses() {
00258       $result =& $this->retrieve(
00259          'SELECT press_id FROM presses ORDER BY seq'
00260       );
00261 
00262       for ($i=1; !$result->EOF; $i++) {
00263          list($pressId) = $result->fields;
00264          $this->update(
00265             'UPDATE presses SET seq = ? WHERE press_id = ?',
00266             array(
00267                $i,
00268                $pressId
00269             )
00270          );
00271 
00272          $result->MoveNext();
00273       }
00274 
00275       $result->Close();
00276       unset($result);
00277    }
00278 }
00279 
00280 ?>

Generated on Mon Sep 17 2012 13:58:55 for Open Monograph Press by  doxygen 1.7.1