Open Journal Systems  3.0.0
 All Data Structures Namespaces Functions Variables Groups Pages
JournalDAO.inc.php
1 <?php
2 
17 import('lib.pkp.classes.context.ContextDAO');
18 import('classes.journal.Journal');
19 import('lib.pkp.classes.metadata.MetadataTypeDescription');
20 
21 define('JOURNAL_FIELD_TITLE', 1);
22 define('JOURNAL_FIELD_SEQUENCE', 2);
23 
24 class JournalDAO extends ContextDAO {
28  function JournalDAO() {
29  parent::ContextDAO();
30  }
31 
36  function newDataObject() {
37  return new Journal();
38  }
39 
45  function _fromRow($row) {
46  $journal = parent::_fromRow($row);
47  $journal->setPrimaryLocale($row['primary_locale']);
48  $journal->setEnabled($row['enabled']);
49  HookRegistry::call('JournalDAO::_returnJournalFromRow', array(&$journal, &$row));
50  return $journal;
51  }
52 
57  function updateObject($journal) {
58  return $this->update(
59  'UPDATE journals
60  SET path = ?,
61  seq = ?,
62  enabled = ?,
63  primary_locale = ?
64  WHERE journal_id = ?',
65  array(
66  $journal->getPath(),
67  (float) $journal->getSequence(),
68  $journal->getEnabled() ? 1 : 0,
69  $journal->getPrimaryLocale(),
70  (int) $journal->getId()
71  )
72  );
73  }
74 
79  function deleteById($journalId) {
80  $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
81  $journalSettingsDao->deleteById($journalId);
82 
83  $sectionDao = DAORegistry::getDAO('SectionDAO');
84  $sectionDao->deleteByJournalId($journalId);
85 
86  $issueDao = DAORegistry::getDAO('IssueDAO');
87  $issueDao->deleteByJournalId($journalId);
88 
89  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
90  $emailTemplateDao->deleteEmailTemplatesByContext($journalId);
91 
92  $subscriptionDao = DAORegistry::getDAO('IndividualSubscriptionDAO');
93  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
94  $subscriptionDao = DAORegistry::getDAO('InstitutionalSubscriptionDAO');
95  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
96 
97  $subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');
98  $subscriptionTypeDao->deleteSubscriptionTypesByJournal($journalId);
99 
100  $giftDao = DAORegistry::getDAO('GiftDAO');
101  $giftDao->deleteGiftsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
102 
103  $announcementDao = DAORegistry::getDAO('AnnouncementDAO');
104  $announcementDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
105 
106  $announcementTypeDao = DAORegistry::getDAO('AnnouncementTypeDAO');
107  $announcementTypeDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
108 
109  $articleDao = DAORegistry::getDAO('ArticleDAO');
110  $articleDao->deleteByContextId($journalId);
111 
112  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO');
113  $pluginSettingsDao->deleteByContextId($journalId);
114 
115  $reviewFormDao = DAORegistry::getDAO('ReviewFormDAO');
116  $reviewFormDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
117 
118  parent::deleteById($journalId);
119  }
120 
125  function getTitles($enabledOnly = false) {
126  $journals = array();
127  $journalIterator = $this->getAll($enabledOnly);
128  while ($journal = $journalIterator->next()) {
129  $journals[$journal->getId()] = $journal->getLocalizedName();
130  }
131  return $journals;
132  }
133 
141  function deleteAllPubIds($journalId, $pubIdType) {
142  $pubObjectDaos = array('IssueDAO', 'ArticleDAO', 'ArticleGalleyDAO');
143  foreach($pubObjectDaos as $daoName) {
144  $dao = DAORegistry::getDAO($daoName);
145  $dao->deleteAllPubIds($journalId, $pubIdType);
146  }
147  }
148 
162  function anyPubIdExists($journalId, $pubIdType, $pubId,
163  $assocType = ASSOC_TYPE_ANY, $assocId = 0) {
164  $pubObjectDaos = array(
165  ASSOC_TYPE_ISSUE => 'IssueDAO',
166  ASSOC_TYPE_ARTICLE => 'ArticleDAO',
167  ASSOC_TYPE_GALLEY => 'ArticleGalleyDAO',
168  ASSOC_TYPE_ISSUE_GALLEY => 'IssueGalleyDAO',
169  );
170  foreach($pubObjectDaos as $daoAssocType => $daoName) {
171  $dao = DAORegistry::getDAO($daoName);
172  if ($assocType == $daoAssocType) {
173  $excludedId = $assocId;
174  } else {
175  $excludedId = 0;
176  }
177  if ($dao->pubIdExists($pubIdType, $pubId, $excludedId, $journalId)) return true;
178  }
179  return false;
180  }
181 
182  //
183  // Protected methods
184  //
189  protected function _getTableName() {
190  return 'journals';
191  }
192 
197  protected function _getSettingsTableName() {
198  return 'journal_settings';
199  }
200 
205  protected function _getPrimaryKeyColumn() {
206  return 'journal_id';
207  }
208 }
209 
210 ?>
static & getDAO($name, $dbconn=null)
deleteById($journalId)
deleteAllPubIds($journalId, $pubIdType)
Describes basic journal properties.
Definition: Journal.inc.php:30
Operations for retrieving and modifying context objects.
getTitles($enabledOnly=false)
anyPubIdExists($journalId, $pubIdType, $pubId, $assocType=ASSOC_TYPE_ANY, $assocId=0)
Operations for retrieving and modifying Journal objects.
updateObject($journal)
static call($hookName, $args=null)
getAll($enabledOnly=false, $rangeInfo=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208