Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
SectionDAO.inc.php
1 <?php
2 
17 import ('classes.journal.Section');
18 import ('lib.pkp.classes.context.PKPSectionDAO');
19 
20 class SectionDAO extends PKPSectionDAO {
21  var $cache;
22 
23  function SectionDAO() {
24  parent::PKPSectionDAO();
25  }
26 
27  function _cacheMiss($cache, $id) {
28  $section = $this->getById($id, null, false);
29  $cache->setCache($id, $section);
30  return $section;
31  }
32 
33  function &_getCache() {
34  if (!isset($this->cache)) {
35  $cacheManager = CacheManager::getManager();
36  $this->cache = $cacheManager->getObjectCache('sections', 0, array($this, '_cacheMiss'));
37  }
38  return $this->cache;
39  }
40 
48  function getById($sectionId, $journalId = null, $useCache = false) {
49  if ($useCache) {
50  $cache = $this->_getCache();
51  $returner = $cache->get($sectionId);
52  if ($returner && $journalId != null && $journalId != $returner->getJournalId()) $returner = null;
53  return $returner;
54  }
55 
56  $sql = 'SELECT * FROM sections WHERE section_id = ?';
57  $params = array((int) $sectionId);
58  if ($journalId !== null) {
59  $sql .= ' AND journal_id = ?';
60  $params[] = (int) $journalId;
61  }
62  $result = $this->retrieve($sql, $params);
63 
64  $returner = null;
65  if ($result->RecordCount() != 0) {
66  $returner = $this->_fromRow($result->GetRowAssoc(false));
67  }
68  $result->Close();
69 
70  return $returner;
71  }
72 
79  function getByAbbrev($sectionAbbrev, $journalId, $locale = null) {
80  $params = array('abbrev', $sectionAbbrev, (int) $journalId);
81  if ($locale !== null) {
82  $params[] = $locale;
83  }
84 
85  $result = $this->retrieve(
86  'SELECT s.*
87  FROM sections s, section_settings l
88  WHERE l.section_id = s.section_id AND
89  l.setting_name = ? AND
90  l.setting_value = ? AND
91  s.journal_id = ?' .
92  ($locale!==null?' AND l.locale = ?':''),
93  $params
94  );
95 
96  $returner = null;
97  if ($result->RecordCount() != 0) {
98  $returner = $this->_fromRow($result->GetRowAssoc(false));
99  }
100 
101  $result->Close();
102  return $returner;
103  }
104 
110  function getByTitle($sectionTitle, $journalId, $locale = null) {
111  $params = array('title', $sectionTitle, (int) $journalId);
112  if ($locale !== null) {
113  $params[] = $locale;
114  }
115 
116  $result = $this->retrieve(
117  'SELECT s.*
118  FROM sections s, section_settings l
119  WHERE l.section_id = s.section_id AND
120  l.setting_name = ? AND
121  l.setting_value = ? AND
122  s.journal_id = ?' .
123  ($locale !== null?' AND l.locale = ?':''),
124  $params
125  );
126 
127  $returner = null;
128  if ($result->RecordCount() != 0) {
129  $returner = $this->_fromRow($result->GetRowAssoc(false));
130  }
131 
132  $result->Close();
133  return $returner;
134  }
135 
139  function newDataObject() {
140  return new Section();
141  }
142 
148  function _fromRow($row) {
149  $section = parent::_fromRow($row);
150 
151  $section->setId($row['section_id']);
152  $section->setJournalId($row['journal_id']);
153  $section->setMetaIndexed($row['meta_indexed']);
154  $section->setMetaReviewed($row['meta_reviewed']);
155  $section->setAbstractsNotRequired($row['abstracts_not_required']);
156  $section->setHideTitle($row['hide_title']);
157  $section->setHideAuthor($row['hide_author']);
158  $section->setHideAbout($row['hide_about']);
159  $section->setDisableComments($row['disable_comments']);
160  $section->setAbstractWordCount($row['abstract_word_count']);
161 
162  $this->getDataObjectSettings('section_settings', 'section_id', $row['section_id'], $section);
163 
164  HookRegistry::call('SectionDAO::_fromRow', array(&$section, &$row));
165 
166  return $section;
167  }
168 
173  function getLocaleFieldNames() {
174  return array_merge(
175  parent::getLocaleFieldNames(),
176  array('abbrev', 'policy', 'identifyType')
177  );
178  }
179 
184  function updateLocaleFields($section) {
185  $this->updateDataObjectSettings('section_settings', $section, array(
186  'section_id' => $section->getId()
187  ));
188  }
189 
194  function insertObject($section) {
195  $this->update(
196  'INSERT INTO sections
197  (journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, hide_about, disable_comments, abstract_word_count)
198  VALUES
199  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
200  array(
201  (int)$section->getJournalId(),
202  (int)$section->getReviewFormId(),
203  (float) $section->getSequence(),
204  $section->getMetaIndexed() ? 1 : 0,
205  $section->getMetaReviewed() ? 1 : 0,
206  $section->getAbstractsNotRequired() ? 1 : 0,
207  $section->getEditorRestricted() ? 1 : 0,
208  $section->getHideTitle() ? 1 : 0,
209  $section->getHideAuthor() ? 1 : 0,
210  $section->getHideAbout() ? 1 : 0,
211  $section->getDisableComments() ? 1 : 0,
212  (int) $section->getAbstractWordCount()
213  )
214  );
215 
216  $section->setId($this->getInsertId());
217  $this->updateLocaleFields($section);
218  return $section->getId();
219  }
220 
225  function updateObject($section) {
226  $this->update(
227  'UPDATE sections
228  SET
229  review_form_id = ?,
230  seq = ?,
231  meta_indexed = ?,
232  meta_reviewed = ?,
233  abstracts_not_required = ?,
234  editor_restricted = ?,
235  hide_title = ?,
236  hide_author = ?,
237  hide_about = ?,
238  disable_comments = ?,
239  abstract_word_count = ?
240  WHERE section_id = ?',
241  array(
242  (int)$section->getReviewFormId(),
243  (float) $section->getSequence(),
244  (int)$section->getMetaIndexed(),
245  (int)$section->getMetaReviewed(),
246  (int)$section->getAbstractsNotRequired(),
247  (int)$section->getEditorRestricted(),
248  (int)$section->getHideTitle(),
249  (int)$section->getHideAuthor(),
250  (int)$section->getHideAbout(),
251  (int)$section->getDisableComments(),
252  $this->nullOrInt($section->getAbstractWordCount()),
253  (int)$section->getId()
254  )
255  );
256  $this->updateLocaleFields($section);
257  }
258 
264  function deleteById($sectionId, $contextId = null) {
265  $sectionEditorsDao = DAORegistry::getDAO('SectionEditorsDAO');
266  $sectionEditorsDao->deleteBySectionId($sectionId, $contextId);
267 
268  // Remove articles from this section
269  $articleDao = DAORegistry::getDAO('ArticleDAO');
270  $articleDao->removeArticlesFromSection($sectionId);
271 
272  // Delete published article entries from this section -- they must
273  // be re-published.
274  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
275  $publishedArticleDao->deletePublishedArticlesBySectionId($sectionId);
276 
277  if (isset($contextId) && !$this->sectionExists($sectionId, $contextId)) return false;
278  $this->update('DELETE FROM section_settings WHERE section_id = ?', (int) $sectionId);
279  $this->update('DELETE FROM sections WHERE section_id = ?', (int) $sectionId);
280  }
281 
288  function deleteByJournalId($journalId) {
289  $this->deleteByContextId($journalId);
290  }
291 
297  function &getEditorSections($journalId) {
298  $returner = array();
299 
300  $result = $this->retrieve(
301  'SELECT s.*, se.user_id AS editor_id FROM section_editors se, sections s WHERE se.section_id = s.section_id AND s.journal_id = se.journal_id AND s.journal_id = ?',
302  (int) $journalId
303  );
304 
305  while (!$result->EOF) {
306  $row = $result->GetRowAssoc(false);
307  $section = $this->_fromRow($row);
308  if (!isset($returner[$row['editor_id']])) {
309  $returner[$row['editor_id']] = array($section);
310  } else {
311  $returner[$row['editor_id']][] = $section;
312  }
313  $result->MoveNext();
314  }
315 
316  $result->Close();
317  return $returner;
318  }
319 
325  function getByIssueId($issueId) {
326  $result = $this->retrieve(
327  'SELECT DISTINCT s.*, COALESCE(o.seq, s.seq) AS section_seq FROM sections s, published_submissions pa, submissions a LEFT JOIN custom_section_orders o ON (a.section_id = o.section_id AND o.issue_id = ?) WHERE s.section_id = a.section_id AND pa.submission_id = a.submission_id AND pa.issue_id = ? ORDER BY section_seq',
328  array((int) $issueId, (int) $issueId)
329  );
330 
331  $returner = array();
332  while (!$result->EOF) {
333  $row = $result->GetRowAssoc(false);
334  $returner[] = $this->_fromRow($row);
335  $result->MoveNext();
336  }
337 
338  $result->Close();
339  return $returner;
340  }
341 
346  function getByJournalId($journalId, $rangeInfo = null) {
347  return $this->getByContextId($journalId, $rangeInfo);
348  }
349 
356  function getByContextId($journalId, $rangeInfo = null) {
357  $result = $this->retrieveRange(
358  'SELECT * FROM sections WHERE journal_id = ? ORDER BY seq',
359  (int) $journalId, $rangeInfo
360  );
361 
362  return new DAOResultFactory($result, $this, '_fromRow');
363  }
364 
369  function getAll($rangeInfo = null) {
370  $result = $this->retrieveRange(
371  'SELECT * FROM sections ORDER BY journal_id, seq',
372  false, $rangeInfo
373  );
374 
375  return new DAOResultFactory($result, $this, '_fromRow');
376  }
377 
382  function getEmptyByJournalId($journalId) {
383  $result = $this->retrieve(
384  'SELECT s.section_id FROM sections s LEFT JOIN submissions a ON (a.section_id = s.section_id) WHERE a.section_id IS NULL AND s.journal_id = ?',
385  (int) $journalId
386  );
387 
388  $returner = array();
389  while (!$result->EOF) {
390  $returner[] = $result->fields[0];
391  $result->MoveNext();
392  }
393  $result->Close();
394  return $returner;
395  }
396 
401  function &getSectionTitles($journalId, $submittableOnly = false) {
402  $sections = array();
403 
404  $sectionsIterator = $this->getByJournalId($journalId);
405  while ($section = $sectionsIterator->next()) {
406  if ($submittableOnly) {
407  if (!$section->getEditorRestricted()) {
408  $sections[$section->getId()] = $section->getLocalizedTitle();
409  }
410  } else {
411  $sections[$section->getId()] = $section->getLocalizedTitle();
412  }
413  }
414 
415  return $sections;
416  }
417 
424  function sectionExists($sectionId, $journalId) {
425  $result = $this->retrieve(
426  'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
427  array((int) $sectionId, (int) $journalId)
428  );
429  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
430 
431  $result->Close();
432  return $returner;
433  }
434 
439  function resequenceSections($journalId) {
440  $result = $this->retrieve(
441  'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
442  (int) $journalId
443  );
444 
445  for ($i=1; !$result->EOF; $i++) {
446  list($sectionId) = $result->fields;
447  $this->update(
448  'UPDATE sections SET seq = ? WHERE section_id = ?',
449  array(
450  $i,
451  $sectionId
452  )
453  );
454 
455  $result->MoveNext();
456  }
457  $result->Close();
458  }
459 
464  function getInsertId() {
465  return $this->_getInsertId('sections', 'section_id');
466  }
467 
472  function deleteCustomSectionOrdering($issueId) {
473  return $this->update(
474  'DELETE FROM custom_section_orders WHERE issue_id = ?', (int) $issueId
475  );
476  }
477 
483  function deleteCustomSection($issueId, $sectionId) {
484  $seq = $this->getCustomSectionOrder($issueId, $sectionId);
485 
486  $this->update(
487  'DELETE FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
488  array((int) $issueId, (int) $sectionId)
489  );
490 
491  // Reduce the section order of every successive section by one
492  $this->update(
493  'UPDATE custom_section_orders SET seq = seq - 1 WHERE issue_id = ? AND seq > ?',
494  array((int) $issueId, (float) $seq)
495  );
496  }
497 
502  function resequenceCustomSectionOrders($issueId) {
503  $result = $this->retrieve(
504  'SELECT section_id FROM custom_section_orders WHERE issue_id = ? ORDER BY seq',
505  (int) $issueId
506  );
507 
508  for ($i=1; !$result->EOF; $i++) {
509  list($sectionId) = $result->fields;
510  $this->update(
511  'UPDATE custom_section_orders SET seq = ? WHERE section_id = ? AND issue_id = ?',
512  array($i, $sectionId, (int) $issueId)
513  );
514 
515  $result->MoveNext();
516  }
517  $result->Close();
518  }
519 
525  function customSectionOrderingExists($issueId) {
526  $result = $this->retrieve(
527  'SELECT COUNT(*) FROM custom_section_orders WHERE issue_id = ?',
528  (int) $issueId
529  );
530  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
531  $result->Close();
532  return $returner;
533  }
534 
541  function getCustomSectionOrder($issueId, $sectionId) {
542  $result = $this->retrieve(
543  'SELECT seq FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
544  array((int) $issueId, (int) $sectionId)
545  );
546 
547  $returner = null;
548  if (!$result->EOF) {
549  list($returner) = $result->fields;
550  }
551  $result->Close();
552  return $returner;
553  }
554 
560  function setDefaultCustomSectionOrders($issueId) {
561  $result = $this->retrieve(
562  'SELECT s.section_id FROM sections s, issues i WHERE i.journal_id = s.journal_id AND i.issue_id = ? ORDER BY seq',
563  (int) $issueId
564  );
565 
566  for ($i=1; !$result->EOF; $i++) {
567  list($sectionId) = $result->fields;
568  $this->insertCustomSectionOrder($issueId, $sectionId, $i);
569  $result->MoveNext();
570  }
571 
572  $result->Close();
573  }
574 
581  function insertCustomSectionOrder($issueId, $sectionId, $seq) {
582  $this->update(
583  'INSERT INTO custom_section_orders (section_id, issue_id, seq) VALUES (?, ?, ?)',
584  array((int) $sectionId,(int) $issueId, (float) $seq)
585  );
586  }
587 
595  function moveCustomSectionOrder($issueId, $sectionId, $newPos, $up) {
596  $this->update(
597  'UPDATE custom_section_orders SET seq = ? ' . ($up?'-':'+') . ' 0.5 WHERE issue_id = ? AND section_id = ?',
598  array((float) $newPos, (int) $issueId, (int) $sectionId)
599  );
600  $this->resequenceCustomSectionOrders($issueId);
601  }
602 }
603 
604 ?>
static & getDAO($name, $dbconn=null)
insertObject($section)
getByContextId($journalId, $rangeInfo=null)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:84
getAll($rangeInfo=null)
Describes basic section properties.
Definition: Section.inc.php:19
updateLocaleFields($section)
getEmptyByJournalId($journalId)
Operations for retrieving and modifying Section objects.
getByAbbrev($sectionAbbrev, $journalId, $locale=null)
resequenceCustomSectionOrders($issueId)
deleteByJournalId($journalId)
getByTitle($sectionTitle, $journalId, $locale=null)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:474
getById($sectionId, $journalId=null, $useCache=false)
setDefaultCustomSectionOrders($issueId)
insertCustomSectionOrder($issueId, $sectionId, $seq)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:174
customSectionOrderingExists($issueId)
& getEditorSections($journalId)
_getInsertId($table= '', $id= '')
Definition: DAO.inc.php:249
resequenceSections($journalId)
nullOrInt($value)
Definition: DAO.inc.php:430
Operations for retrieving and modifying Section objects.
moveCustomSectionOrder($issueId, $sectionId, $newPos, $up)
getByIssueId($issueId)
static call($hookName, $args=null)
deleteCustomSectionOrdering($issueId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteByContextId($contextId)
& getSectionTitles($journalId, $submittableOnly=false)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, &$dataObject)
Definition: DAO.inc.php:567
sectionExists($sectionId, $journalId)
getByJournalId($journalId, $rangeInfo=null)
getCustomSectionOrder($issueId, $sectionId)
deleteById($sectionId, $contextId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
updateObject($section)
deleteCustomSection($issueId, $sectionId)