Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
JournalDAO.inc.php
1 <?php
2 
17 import ('classes.journal.Journal');
18 import('lib.pkp.classes.metadata.MetadataTypeDescription');
19 
20 define('JOURNAL_FIELD_TITLE', 1);
21 define('JOURNAL_FIELD_SEQUENCE', 2);
22 
23 class JournalDAO extends DAO {
29  function &getById($journalId) {
30  $result =& $this->retrieve(
31  'SELECT * FROM journals WHERE journal_id = ?',
32  (int) $journalId
33  );
34 
35  $returner = null;
36  if ($result->RecordCount() != 0) {
37  $returner =& $this->_returnJournalFromRow($result->GetRowAssoc(false));
38  }
39  $result->Close();
40  unset($result);
41  return $returner;
42  }
43 
47  function &getJournal($journalId) {
48  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
49  $returner =& $this->getById($journalId);
50  return $returner;
51  }
52 
58  function &getJournalByPath($path) {
59  $returner = null;
60  $result =& $this->retrieve(
61  'SELECT * FROM journals WHERE path = ?', $path
62  );
63 
64  if ($result->RecordCount() != 0) {
65  $returner =& $this->_returnJournalFromRow($result->GetRowAssoc(false));
66  }
67  $result->Close();
68  unset($result);
69  return $returner;
70  }
71 
77  function &_returnJournalFromRow(&$row) {
78  $journal = new Journal();
79  $journal->setId($row['journal_id']);
80  $journal->setPath($row['path']);
81  $journal->setSequence($row['seq']);
82  $journal->setEnabled($row['enabled']);
83  $journal->setPrimaryLocale($row['primary_locale']);
84 
85  HookRegistry::call('JournalDAO::_returnJournalFromRow', array(&$journal, &$row));
86 
87  return $journal;
88  }
89 
94  function insertJournal(&$journal) {
95  $this->update(
96  'INSERT INTO journals
97  (path, seq, enabled, primary_locale)
98  VALUES
99  (?, ?, ?, ?)',
100  array(
101  $journal->getPath(),
102  $journal->getSequence() == null ? 0 : $journal->getSequence(),
103  $journal->getEnabled() ? 1 : 0,
104  $journal->getPrimaryLocale()
105  )
106  );
107 
108  $journal->setId($this->getInsertJournalId());
109  return $journal->getId();
110  }
111 
116  function updateJournal(&$journal) {
117  return $this->update(
118  'UPDATE journals
119  SET
120  path = ?,
121  seq = ?,
122  enabled = ?,
123  primary_locale = ?
124  WHERE journal_id = ?',
125  array(
126  $journal->getPath(),
127  $journal->getSequence(),
128  $journal->getEnabled() ? 1 : 0,
129  $journal->getPrimaryLocale(),
130  $journal->getId()
131  )
132  );
133  }
134 
139  function deleteJournal(&$journal) {
140  return $this->deleteJournalById($journal->getId());
141  }
142 
147  function deleteJournalById($journalId) {
148  if (HookRegistry::call('JournalDAO::deleteJournalById', array(&$this, &$journalId))) return;
149 
150  $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
151  $journalSettingsDao->deleteSettingsByJournal($journalId);
152 
153  $sectionDao =& DAORegistry::getDAO('SectionDAO');
154  $sectionDao->deleteSectionsByJournal($journalId);
155 
156  $issueDao =& DAORegistry::getDAO('IssueDAO');
157  $issueDao->deleteIssuesByJournal($journalId);
158 
159  $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
160  $emailTemplateDao->deleteEmailTemplatesByJournal($journalId);
161 
162  $rtDao =& DAORegistry::getDAO('RTDAO');
163  $rtDao->deleteVersionsByJournal($journalId);
164 
165  $subscriptionDao =& DAORegistry::getDAO('IndividualSubscriptionDAO');
166  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
167  $subscriptionDao =& DAORegistry::getDAO('InstitutionalSubscriptionDAO');
168  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
169 
170  $subscriptionTypeDao =& DAORegistry::getDAO('SubscriptionTypeDAO');
171  $subscriptionTypeDao->deleteSubscriptionTypesByJournal($journalId);
172 
173  $giftDao =& DAORegistry::getDAO('GiftDAO');
174  $giftDao->deleteGiftsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
175 
176  $announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
177  $announcementDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
178 
179  $announcementTypeDao =& DAORegistry::getDAO('AnnouncementTypeDAO');
180  $announcementTypeDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
181 
182  $articleDao =& DAORegistry::getDAO('ArticleDAO');
183  $articleDao->deleteArticlesByJournalId($journalId);
184 
185  $roleDao =& DAORegistry::getDAO('RoleDAO');
186  $roleDao->deleteRoleByJournalId($journalId);
187 
188  $groupDao =& DAORegistry::getDAO('GroupDAO');
189  $groupDao->deleteGroupsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
190 
191  $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
192  $pluginSettingsDao->deleteSettingsByJournalId($journalId);
193 
194  $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
195  $reviewFormDao->deleteByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
196 
197  return $this->update(
198  'DELETE FROM journals WHERE journal_id = ?', $journalId
199  );
200  }
201 
212  function &getJournals($enabledOnly = false, $rangeInfo = null, $sortBy = JOURNAL_FIELD_SEQUENCE, $searchField = null, $searchMatch = null, $search = null) {
213  $joinSql = $whereSql = $orderBySql = '';
214  $params = array();
215  $needTitleJoin = false;
216 
217  // Handle sort conditions
218  switch ($sortBy) {
219  case JOURNAL_FIELD_TITLE:
220  $needTitleJoin = true;
221  $orderBySql = 'COALESCE(jsl.setting_value, jsl.setting_name)';
222  break;
223  case JOURNAL_FIELD_SEQUENCE:
224  $orderBySql = 'j.seq';
225  break;
226  }
227 
228  // Handle search conditions
229  switch ($searchField) {
230  case JOURNAL_FIELD_TITLE:
231  $needTitleJoin = true;
232  $whereSql .= ($whereSql?' AND ':'') . ' COALESCE(jsl.setting_value, jsl.setting_name) ';
233  switch ($searchMatch) {
234  case 'is':
235  $whereSql .= ' = ?';
236  $params[] = $search;
237  break;
238  case 'contains':
239  $whereSql .= ' LIKE ?';
240  $params[] = "%search%";
241  break;
242  default: // $searchMatch === 'startsWith'
243  $whereSql .= ' LIKE ?';
244  $params[] = "$search%";
245  break;
246  }
247  break;
248  }
249 
250  // If we need to join on the journal title (for sort or filter),
251  // include it.
252  if ($needTitleJoin) {
253  $joinSql .= ' LEFT JOIN journal_settings jspl ON (jspl.setting_name = ? AND jspl.locale = ? AND jspl.journal_id = j.journal_id) LEFT JOIN journal_settings jsl ON (jsl.setting_name = ? AND jsl.locale = ? AND jsl.journal_id = j.journal_id)';
254  $params = array_merge(
255  array(
256  'title',
258  'title',
260  ),
261  $params
262  );
263  }
264 
265  // Handle filtering conditions
266  if ($enabledOnly) $whereSql .= ($whereSql?'AND ':'') . 'j.enabled=1 ';
267 
268  // Clean up SQL strings
269  if ($whereSql) $whereSql = "WHERE $whereSql";
270  if ($orderBySql) $orderBySql = "ORDER BY $orderBySql";
271  $result =& $this->retrieveRange(
272  "SELECT j.*
273  FROM journals j
274  $joinSql
275  $whereSql
276  $orderBySql",
277  $params, $rangeInfo
278  );
279 
280  $returner = new DAOResultFactory($result, $this, '_returnJournalFromRow');
281  return $returner;
282  }
283 
288  function &getEnabledJournals($rangeInfo = null) {
289  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
290  $returner =& $this->getJournals(true, $rangeInfo);
291  return $returner;
292  }
293 
298  function &getJournalTitles($enabledOnly = false) {
299  $journals = array();
300 
301  $journalIterator =& $this->getJournals($enabledOnly);
302  while ($journal =& $journalIterator->next()) {
303  $journals[$journal->getId()] = $journal->getLocalizedTitle();
304  unset($journal);
305  }
306  unset($journalIterator);
307 
308  return $journals;
309  }
310 
316  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
317  $titles =& $this->getJournalTitles(true);
318  return $titles;
319  }
320 
326  function journalExistsByPath($path) {
327  $result =& $this->retrieve(
328  'SELECT COUNT(*) FROM journals WHERE path = ?', $path
329  );
330  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
331 
332  $result->Close();
333  unset($result);
334 
335  return $returner;
336  }
337 
345  function deleteAllPubIds($journalId, $pubIdType) {
346  $pubObjectDaos = array('IssueDAO', 'ArticleDAO', 'ArticleGalleyDAO', 'SuppFileDAO');
347  foreach($pubObjectDaos as $daoName) {
348  $dao =& DAORegistry::getDAO($daoName);
349  $dao->deleteAllPubIds($journalId, $pubIdType);
350  unset($dao);
351  }
352  }
353 
367  function anyPubIdExists($journalId, $pubIdType, $pubId,
368  $assocType = ASSOC_TYPE_ANY, $assocId = 0) {
369  $pubObjectDaos = array(
370  ASSOC_TYPE_ISSUE => 'IssueDAO',
371  ASSOC_TYPE_ARTICLE => 'ArticleDAO',
372  ASSOC_TYPE_GALLEY => 'ArticleGalleyDAO',
373  ASSOC_TYPE_ISSUE_GALLEY => 'IssueGalleyDAO',
374  ASSOC_TYPE_SUPP_FILE => 'SuppFileDAO'
375  );
376  foreach($pubObjectDaos as $daoAssocType => $daoName) {
377  $dao =& DAORegistry::getDAO($daoName);
378  if ($assocType == $daoAssocType) {
379  $excludedId = $assocId;
380  } else {
381  $excludedId = 0;
382  }
383  if ($dao->pubIdExists($pubIdType, $pubId, $excludedId, $journalId)) return true;
384  unset($dao);
385  }
386  return false;
387  }
388 
392  function resequenceJournals() {
393  $result =& $this->retrieve(
394  'SELECT journal_id FROM journals ORDER BY seq'
395  );
396 
397  for ($i=1; !$result->EOF; $i++) {
398  list($journalId) = $result->fields;
399  $this->update(
400  'UPDATE journals SET seq = ? WHERE journal_id = ?',
401  array(
402  $i,
403  $journalId
404  )
405  );
406 
407  $result->moveNext();
408  }
409 
410  $result->close();
411  unset($result);
412  }
413 
418  function getInsertJournalId() {
419  return $this->getInsertId('journals', 'journal_id');
420  }
421 }
422 
423 ?>
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
deleteJournalById($journalId)
& getJournalTitles($enabledOnly=false)
deleteAllPubIds($journalId, $pubIdType)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Describes basic journal properties.
Definition: Journal.inc.php:26
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
anyPubIdExists($journalId, $pubIdType, $pubId, $assocType=ASSOC_TYPE_ANY, $assocId=0)
Operations for retrieving and modifying Journal objects.
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
updateJournal(&$journal)
& _returnJournalFromRow(&$row)
& getJournal($journalId)
& getJournalByPath($path)
journalExistsByPath($path)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
getVar($section, $key, $default=null)
Definition: Config.inc.php:34
& getDAO($name, $dbconn=null)
& getEnabledJournals($rangeInfo=null)
deleteJournal(&$journal)
& getById($journalId)
call($hookName, $args=null)
& getEnabledJournalTitles()
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
& getJournals($enabledOnly=false, $rangeInfo=null, $sortBy=JOURNAL_FIELD_SEQUENCE, $searchField=null, $searchMatch=null, $search=null)
insertJournal(&$journal)