Open Journal Systems  2.4.3
 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  $journalSettingsDao =& DAORegistry::getDAO('JournalSettingsDAO');
149  $journalSettingsDao->deleteSettingsByJournal($journalId);
150 
151  $sectionDao =& DAORegistry::getDAO('SectionDAO');
152  $sectionDao->deleteSectionsByJournal($journalId);
153 
154  $issueDao =& DAORegistry::getDAO('IssueDAO');
155  $issueDao->deleteIssuesByJournal($journalId);
156 
157  $emailTemplateDao =& DAORegistry::getDAO('EmailTemplateDAO');
158  $emailTemplateDao->deleteEmailTemplatesByJournal($journalId);
159 
160  $rtDao =& DAORegistry::getDAO('RTDAO');
161  $rtDao->deleteVersionsByJournal($journalId);
162 
163  $subscriptionDao =& DAORegistry::getDAO('IndividualSubscriptionDAO');
164  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
165  $subscriptionDao =& DAORegistry::getDAO('InstitutionalSubscriptionDAO');
166  $subscriptionDao->deleteSubscriptionsByJournal($journalId);
167 
168  $subscriptionTypeDao =& DAORegistry::getDAO('SubscriptionTypeDAO');
169  $subscriptionTypeDao->deleteSubscriptionTypesByJournal($journalId);
170 
171  $giftDao =& DAORegistry::getDAO('GiftDAO');
172  $giftDao->deleteGiftsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
173 
174  $announcementDao =& DAORegistry::getDAO('AnnouncementDAO');
175  $announcementDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
176 
177  $announcementTypeDao =& DAORegistry::getDAO('AnnouncementTypeDAO');
178  $announcementTypeDao->deleteByAssoc(ASSOC_TYPE_JOURNAL, $journalId);
179 
180  $articleDao =& DAORegistry::getDAO('ArticleDAO');
181  $articleDao->deleteArticlesByJournalId($journalId);
182 
183  $roleDao =& DAORegistry::getDAO('RoleDAO');
184  $roleDao->deleteRoleByJournalId($journalId);
185 
186  $groupDao =& DAORegistry::getDAO('GroupDAO');
187  $groupDao->deleteGroupsByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
188 
189  $pluginSettingsDao =& DAORegistry::getDAO('PluginSettingsDAO');
190  $pluginSettingsDao->deleteSettingsByJournalId($journalId);
191 
192  $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
193  $reviewFormDao->deleteByAssocId(ASSOC_TYPE_JOURNAL, $journalId);
194 
195  return $this->update(
196  'DELETE FROM journals WHERE journal_id = ?', $journalId
197  );
198  }
199 
210  function &getJournals($enabledOnly = false, $rangeInfo = null, $sortBy = JOURNAL_FIELD_SEQUENCE, $searchField = null, $searchMatch = null, $search = null) {
211  $joinSql = $whereSql = $orderBySql = '';
212  $params = array();
213  $needTitleJoin = false;
214 
215  // Handle sort conditions
216  switch ($sortBy) {
217  case JOURNAL_FIELD_TITLE:
218  $needTitleJoin = true;
219  $orderBySql = 'COALESCE(jsl.setting_value, jsl.setting_name)';
220  break;
221  case JOURNAL_FIELD_SEQUENCE:
222  $orderBySql = 'j.seq';
223  break;
224  }
225 
226  // Handle search conditions
227  switch ($searchField) {
228  case JOURNAL_FIELD_TITLE:
229  $needTitleJoin = true;
230  $whereSql .= ($whereSql?' AND ':'') . ' COALESCE(jsl.setting_value, jsl.setting_name) ';
231  switch ($searchMatch) {
232  case 'is':
233  $whereSql .= ' = ?';
234  $params[] = $search;
235  break;
236  case 'contains':
237  $whereSql .= ' LIKE ?';
238  $params[] = "%search%";
239  break;
240  default: // $searchMatch === 'startsWith'
241  $whereSql .= ' LIKE ?';
242  $params[] = "$search%";
243  break;
244  }
245  break;
246  }
247 
248  // If we need to join on the journal title (for sort or filter),
249  // include it.
250  if ($needTitleJoin) {
251  $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)';
252  $params = array_merge(
253  array(
254  'title',
256  'title',
258  ),
259  $params
260  );
261  }
262 
263  // Handle filtering conditions
264  if ($enabledOnly) $whereSql .= ($whereSql?'AND ':'') . 'j.enabled=1 ';
265 
266  // Clean up SQL strings
267  if ($whereSql) $whereSql = "WHERE $whereSql";
268  if ($orderBySql) $orderBySql = "ORDER BY $orderBySql";
269  $result =& $this->retrieveRange(
270  "SELECT j.*
271  FROM journals j
272  $joinSql
273  $whereSql
274  $orderBySql",
275  $params, $rangeInfo
276  );
277 
278  $returner = new DAOResultFactory($result, $this, '_returnJournalFromRow');
279  return $returner;
280  }
281 
286  function &getEnabledJournals($rangeInfo = null) {
287  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
288  $returner =& $this->getJournals(true, $rangeInfo);
289  return $returner;
290  }
291 
296  function &getJournalTitles($enabledOnly = false) {
297  $journals = array();
298 
299  $journalIterator =& $this->getJournals($enabledOnly);
300  while ($journal =& $journalIterator->next()) {
301  $journals[$journal->getId()] = $journal->getLocalizedTitle();
302  unset($journal);
303  }
304  unset($journalIterator);
305 
306  return $journals;
307  }
308 
314  if (Config::getVar('debug', 'deprecation_warnings')) trigger_error('Deprecated function.');
315  $titles =& $this->getJournalTitles(true);
316  return $titles;
317  }
318 
324  function journalExistsByPath($path) {
325  $result =& $this->retrieve(
326  'SELECT COUNT(*) FROM journals WHERE path = ?', $path
327  );
328  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
329 
330  $result->Close();
331  unset($result);
332 
333  return $returner;
334  }
335 
343  function deleteAllPubIds($journalId, $pubIdType) {
344  $pubObjectDaos = array('IssueDAO', 'ArticleDAO', 'ArticleGalleyDAO', 'SuppFileDAO');
345  foreach($pubObjectDaos as $daoName) {
346  $dao =& DAORegistry::getDAO($daoName);
347  $dao->deleteAllPubIds($journalId, $pubIdType);
348  unset($dao);
349  }
350  }
351 
365  function anyPubIdExists($journalId, $pubIdType, $pubId,
366  $assocType = ASSOC_TYPE_ANY, $assocId = 0) {
367  $pubObjectDaos = array(
368  ASSOC_TYPE_ISSUE => 'IssueDAO',
369  ASSOC_TYPE_ARTICLE => 'ArticleDAO',
370  ASSOC_TYPE_GALLEY => 'ArticleGalleyDAO',
371  ASSOC_TYPE_ISSUE_GALLEY => 'IssueGalleyDAO',
372  ASSOC_TYPE_SUPP_FILE => 'SuppFileDAO'
373  );
374  foreach($pubObjectDaos as $daoAssocType => $daoName) {
375  $dao =& DAORegistry::getDAO($daoName);
376  if ($assocType == $daoAssocType) {
377  $excludedId = $assocId;
378  } else {
379  $excludedId = 0;
380  }
381  if ($dao->pubIdExists($pubIdType, $pubId, $excludedId, $journalId)) return true;
382  unset($dao);
383  }
384  return false;
385  }
386 
390  function resequenceJournals() {
391  $result =& $this->retrieve(
392  'SELECT journal_id FROM journals ORDER BY seq'
393  );
394 
395  for ($i=1; !$result->EOF; $i++) {
396  list($journalId) = $result->fields;
397  $this->update(
398  'UPDATE journals SET seq = ? WHERE journal_id = ?',
399  array(
400  $i,
401  $journalId
402  )
403  );
404 
405  $result->moveNext();
406  }
407 
408  $result->close();
409  unset($result);
410  }
411 
416  function getInsertJournalId() {
417  return $this->getInsertId('journals', 'journal_id');
418  }
419 }
420 
421 ?>
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)