Open Journal Systems  3.0.0
 All Classes 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 insertObject(&$journal) {
58  $this->update(
59  'INSERT INTO journals
60  (path, seq, enabled, primary_locale)
61  VALUES
62  (?, ?, ?, ?)',
63  array(
64  $journal->getPath(),
65  $journal->getSequence() == null ? 0 : $journal->getSequence(),
66  $journal->getEnabled() ? 1 : 0,
67  $journal->getPrimaryLocale()
68  )
69  );
70 
71  $journal->setId($this->getInsertId());
72  return $journal->getId();
73  }
74 
79  function updateObject(&$journal) {
80  return $this->update(
81  'UPDATE journals
82  SET
83  path = ?,
84  seq = ?,
85  enabled = ?,
86  primary_locale = ?
87  WHERE journal_id = ?',
88  array(
89  $journal->getPath(),
90  $journal->getSequence(),
91  $journal->getEnabled() ? 1 : 0,
92  $journal->getPrimaryLocale(),
93  $journal->getId()
94  )
95  );
96  }
97 
102  function deleteById($journalId) {
103  $journalSettingsDao = DAORegistry::getDAO('JournalSettingsDAO');
104  $journalSettingsDao->deleteById($journalId);
105 
106  $sectionDao = DAORegistry::getDAO('SectionDAO');
107  $sectionDao->deleteByJournalId($journalId);
108 
109  $issueDao = DAORegistry::getDAO('IssueDAO');
110  $issueDao->deleteByJournalId($journalId);
111 
112  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
113  $emailTemplateDao->deleteEmailTemplatesByJournal($journalId);
114 
115  $rtDao = DAORegistry::getDAO('RTDAO');
116  $rtDao->deleteVersionsByJournal($journalId);
117 
118  $subscriptionDao = DAORegistry::getDAO('IndividualSubscriptionDAO');
119  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
120  $subscriptionDao = DAORegistry::getDAO('InstitutionalSubscriptionDAO');
121  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
122 
123  $subscriptionTypeDao = DAORegistry::getDAO('SubscriptionTypeDAO');
124  $subscriptionTypeDao->deleteSubscriptionTypesByJournal($journalId);
125 
126  $giftDao = DAORegistry::getDAO('GiftDAO');
127  $giftDao->deleteGiftsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
128 
129  $announcementDao = DAORegistry::getDAO('AnnouncementDAO');
130  $announcementDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
131 
132  $announcementTypeDao = DAORegistry::getDAO('AnnouncementTypeDAO');
133  $announcementTypeDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
134 
135  $articleDao = DAORegistry::getDAO('ArticleDAO');
136  $articleDao->deleteByContextId($journalId);
137 
138  $pluginSettingsDao = DAORegistry::getDAO('PluginSettingsDAO');
139  $pluginSettingsDao->deleteByContextId($journalId);
140 
141  $reviewFormDao = DAORegistry::getDAO('ReviewFormDAO');
142  $reviewFormDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
143 
144  parent::deleteById($journalId);
145  }
146 
151  function getTitles($enabledOnly = false) {
152  $journals = array();
153  $journalIterator = $this->getAll($enabledOnly);
154  while ($journal = $journalIterator->next()) {
155  $journals[$journal->getId()] = $journal->getLocalizedName();
156  }
157  return $journals;
158  }
159 
167  function deleteAllPubIds($journalId, $pubIdType) {
168  $pubObjectDaos = array('IssueDAO', 'ArticleDAO', 'ArticleGalleyDAO');
169  foreach($pubObjectDaos as $daoName) {
170  $dao = DAORegistry::getDAO($daoName);
171  $dao->deleteAllPubIds($journalId, $pubIdType);
172  }
173  }
174 
188  function anyPubIdExists($journalId, $pubIdType, $pubId,
189  $assocType = ASSOC_TYPE_ANY, $assocId = 0) {
190  $pubObjectDaos = array(
191  ASSOC_TYPE_ISSUE => 'IssueDAO',
192  ASSOC_TYPE_ARTICLE => 'ArticleDAO',
193  ASSOC_TYPE_GALLEY => 'ArticleGalleyDAO',
194  ASSOC_TYPE_ISSUE_GALLEY => 'IssueGalleyDAO',
195  );
196  foreach($pubObjectDaos as $daoAssocType => $daoName) {
197  $dao = DAORegistry::getDAO($daoName);
198  if ($assocType == $daoAssocType) {
199  $excludedId = $assocId;
200  } else {
201  $excludedId = 0;
202  }
203  if ($dao->pubIdExists($pubIdType, $pubId, $excludedId, $journalId)) return true;
204  }
205  return false;
206  }
207 
208  //
209  // Protected methods
210  //
215  protected function _getTableName() {
216  return 'journals';
217  }
218 
223  protected function _getSettingsTableName() {
224  return 'journal_settings';
225  }
226 
231  protected function _getPrimaryKeyColumn() {
232  return 'journal_id';
233  }
234 }
235 
236 ?>
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)
insertObject(&$journal)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208