Open Journal Systems  2.4.4
 All Classes Namespaces Functions Variables Groups Pages
SectionDAO.inc.php
1 <?php
2 
17 import ('classes.journal.Section');
18 
19 class SectionDAO extends DAO {
20  var $cache;
21 
22  function _cacheMiss(&$cache, $id) {
23  $section =& $this->getSection($id, null, false);
24  $cache->setCache($id, $section);
25  return $section;
26  }
27 
28  function &_getCache() {
29  if (!isset($this->cache)) {
30  $cacheManager =& CacheManager::getManager();
31  $this->cache =& $cacheManager->getObjectCache('sections', 0, array(&$this, '_cacheMiss'));
32  }
33  return $this->cache;
34  }
35 
43  function &getSection($sectionId, $journalId = null, $useCache = false) {
44  if ($useCache) {
45  $cache =& $this->_getCache();
46  $returner = $cache->get($sectionId);
47  if ($returner && $journalId != null && $journalId != $returner->getJournalId()) $returner = null;
48  return $returner;
49  }
50 
51  $sql = 'SELECT * FROM sections WHERE section_id = ?';
52  $params = array($sectionId);
53  if ($journalId !== null) {
54  $sql .= ' AND journal_id = ?';
55  $params[] = $journalId;
56  }
57  $result =& $this->retrieve($sql, $params);
58 
59  $returner = null;
60  if ($result->RecordCount() != 0) {
61  $returner =& $this->_returnSectionFromRow($result->GetRowAssoc(false));
62  }
63 
64  $result->Close();
65  unset($result);
66 
67  return $returner;
68  }
69 
76  function &getSectionByAbbrev($sectionAbbrev, $journalId, $locale = null) {
77  $sql = 'SELECT s.* FROM sections s, section_settings l WHERE l.section_id = s.section_id AND l.setting_name = ? AND l.setting_value = ? AND s.journal_id = ?';
78  $params = array('abbrev', $sectionAbbrev, $journalId);
79  if ($locale !== null) {
80  $sql .= ' AND l.locale = ?';
81  $params[] = $locale;
82  }
83 
84  $result =& $this->retrieve($sql, $params);
85 
86  $returner = null;
87  if ($result->RecordCount() != 0) {
88  $returner =& $this->_returnSectionFromRow($result->GetRowAssoc(false));
89  }
90 
91  $result->Close();
92  unset($result);
93 
94  return $returner;
95  }
96 
102  function &getSectionByTitle($sectionTitle, $journalId, $locale = null) {
103  $sql = 'SELECT s.* FROM sections s, section_settings l WHERE l.section_id = s.section_id AND l.setting_name = ? AND l.setting_value = ? AND s.journal_id = ?';
104  $params = array('title', $sectionTitle, $journalId);
105  if ($locale !== null) {
106  $sql .= ' AND l.locale = ?';
107  $params[] = $locale;
108  }
109 
110  $result =& $this->retrieve($sql, $params);
111 
112  $returner = null;
113  if ($result->RecordCount() != 0) {
114  $returner =& $this->_returnSectionFromRow($result->GetRowAssoc(false));
115  }
116 
117  $result->Close();
118  unset($result);
119 
120  return $returner;
121  }
122 
130  function &getSectionByTitleAndAbbrev($sectionTitle, $sectionAbbrev, $journalId, $locale) {
131  $sql = 'SELECT s.* FROM sections s, section_settings l1, section_settings l2 WHERE l1.section_id = s.section_id AND l2.section_id = s.section_id AND l1.setting_name = ? AND l2.setting_name = ? AND l1.setting_value = ? AND l2.setting_value = ? AND s.journal_id = ?';
132  $params = array('title', 'abbrev', $sectionTitle, $sectionAbbrev, $journalId);
133  if ($locale !== null) {
134  $sql .= ' AND l1.locale = ? AND l2.locale = ?';
135  $params[] = $locale;
136  $params[] = $locale;
137  }
138 
139  $result =& $this->retrieve($sql, $params);
140 
141  $returner = null;
142  if ($result->RecordCount() != 0) {
143  $returner =& $this->_returnSectionFromRow($result->GetRowAssoc(false));
144  }
145 
146  $result->Close();
147  unset($result);
148 
149  return $returner;
150  }
151 
157  function &_returnSectionFromRow(&$row) {
158  $section = new Section();
159  $section->setId($row['section_id']);
160  $section->setJournalId($row['journal_id']);
161  $section->setReviewFormId($row['review_form_id']);
162  $section->setSequence($row['seq']);
163  $section->setMetaIndexed($row['meta_indexed']);
164  $section->setMetaReviewed($row['meta_reviewed']);
165  $section->setAbstractsNotRequired($row['abstracts_not_required']);
166  $section->setEditorRestricted($row['editor_restricted']);
167  $section->setHideTitle($row['hide_title']);
168  $section->setHideAuthor($row['hide_author']);
169  $section->setHideAbout($row['hide_about']);
170  $section->setDisableComments($row['disable_comments']);
171  $section->setAbstractWordCount($row['abstract_word_count']);
172 
173  $this->getDataObjectSettings('section_settings', 'section_id', $row['section_id'], $section);
174 
175  HookRegistry::call('SectionDAO::_returnSectionFromRow', array(&$section, &$row));
176 
177  return $section;
178  }
179 
184  function getLocaleFieldNames() {
185  return array('title', 'abbrev', 'policy', 'identifyType');
186  }
187 
192  function updateLocaleFields(&$section) {
193  $this->updateDataObjectSettings('section_settings', $section, array(
194  'section_id' => $section->getId()
195  ));
196  }
197 
202  function insertSection(&$section) {
203  $this->update(
204  'INSERT INTO sections
205  (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)
206  VALUES
207  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
208  array(
209  (int)$section->getJournalId(),
210  (int)$section->getReviewFormId(),
211  (float) $section->getSequence(),
212  $section->getMetaIndexed() ? 1 : 0,
213  $section->getMetaReviewed() ? 1 : 0,
214  $section->getAbstractsNotRequired() ? 1 : 0,
215  $section->getEditorRestricted() ? 1 : 0,
216  $section->getHideTitle() ? 1 : 0,
217  $section->getHideAuthor() ? 1 : 0,
218  $section->getHideAbout() ? 1 : 0,
219  $section->getDisableComments() ? 1 : 0,
220  (int) $section->getAbstractWordCount()
221  )
222  );
223 
224  $section->setId($this->getInsertSectionId());
225  $this->updateLocaleFields($section);
226  return $section->getId();
227  }
228 
233  function updateSection(&$section) {
234  $returner = $this->update(
235  'UPDATE sections
236  SET
237  review_form_id = ?,
238  seq = ?,
239  meta_indexed = ?,
240  meta_reviewed = ?,
241  abstracts_not_required = ?,
242  editor_restricted = ?,
243  hide_title = ?,
244  hide_author = ?,
245  hide_about = ?,
246  disable_comments = ?,
247  abstract_word_count = ?
248  WHERE section_id = ?',
249  array(
250  (int)$section->getReviewFormId(),
251  (float) $section->getSequence(),
252  (int)$section->getMetaIndexed(),
253  (int)$section->getMetaReviewed(),
254  (int)$section->getAbstractsNotRequired(),
255  (int)$section->getEditorRestricted(),
256  (int)$section->getHideTitle(),
257  (int)$section->getHideAuthor(),
258  (int)$section->getHideAbout(),
259  (int)$section->getDisableComments(),
260  $this->nullOrInt($section->getAbstractWordCount()),
261  (int)$section->getId()
262  )
263  );
264  $this->updateLocaleFields($section);
265  return $returner;
266  }
267 
272  function deleteSection(&$section) {
273  return $this->deleteSectionById($section->getId(), $section->getJournalId());
274  }
275 
281  function deleteSectionById($sectionId, $journalId = null) {
282  $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO');
283  $sectionEditorsDao->deleteEditorsBySectionId($sectionId, $journalId);
284 
285  // Remove articles from this section
286  $articleDao =& DAORegistry::getDAO('ArticleDAO');
287  $articleDao->removeArticlesFromSection($sectionId);
288 
289  // Delete published article entries from this section -- they must
290  // be re-published.
291  $publishedArticleDao =& DAORegistry::getDAO('PublishedArticleDAO');
292  $publishedArticleDao->deletePublishedArticlesBySectionId($sectionId);
293 
294  if (isset($journalId) && !$this->sectionExists($sectionId, $journalId)) return false;
295  $this->update('DELETE FROM section_settings WHERE section_id = ?', array($sectionId));
296  return $this->update('DELETE FROM sections WHERE section_id = ?', array($sectionId));
297  }
298 
305  function deleteSectionsByJournal($journalId) {
306  $sections =& $this->getJournalSections($journalId);
307  while (($section =& $sections->next())) {
308  $this->deleteSection($section);
309  unset($section);
310  }
311  }
312 
318  function &getEditorSections($journalId) {
319  $returner = array();
320 
321  $result =& $this->retrieve(
322  '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 = ?',
323  $journalId
324  );
325 
326  while (!$result->EOF) {
327  $row = $result->GetRowAssoc(false);
328  $section =& $this->_returnSectionFromRow($row);
329  if (!isset($returner[$row['editor_id']])) {
330  $returner[$row['editor_id']] = array($section);
331  } else {
332  $returner[$row['editor_id']][] = $section;
333  }
334  $result->moveNext();
335  }
336 
337  $result->Close();
338  unset($result);
339 
340  return $returner;
341  }
342 
348  function &getSectionsForIssue($issueId) {
349  $returner = array();
350 
351  $result =& $this->retrieve(
352  'SELECT DISTINCT s.*, COALESCE(o.seq, s.seq) AS section_seq FROM sections s, published_articles pa, articles 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.article_id = a.article_id AND pa.issue_id = ? ORDER BY section_seq',
353  array($issueId, $issueId)
354  );
355 
356  while (!$result->EOF) {
357  $row = $result->GetRowAssoc(false);
358  $returner[] =& $this->_returnSectionFromRow($row);
359  $result->moveNext();
360  }
361 
362  $result->Close();
363  unset($result);
364 
365  return $returner;
366  }
367 
372  function &getJournalSections($journalId, $rangeInfo = null) {
373  $result =& $this->retrieveRange(
374  'SELECT * FROM sections WHERE journal_id = ? ORDER BY seq',
375  $journalId, $rangeInfo
376  );
377 
378  $returner = new DAOResultFactory($result, $this, '_returnSectionFromRow');
379  return $returner;
380  }
381 
386  function &getSections($rangeInfo = null) {
387  $result =& $this->retrieveRange(
388  'SELECT * FROM sections ORDER BY journal_id, seq',
389  false, $rangeInfo
390  );
391 
392  $returner = new DAOResultFactory($result, $this, '_returnSectionFromRow');
393  return $returner;
394  }
395 
400  function getJournalEmptySectionIds($journalId) {
401  $returner = array();
402 
403  $result =& $this->retrieve(
404  'SELECT s.section_id FROM sections s LEFT JOIN articles a ON (a.section_id = s.section_id) WHERE a.section_id IS NULL AND s.journal_id = ?',
405  (int) $journalId
406  );
407 
408  while (!$result->EOF) {
409  $returner[] = $result->fields[0];
410  $result->moveNext();
411  }
412 
413  $result->Close();
414  unset($result);
415 
416  return $returner;
417  }
418 
423  function &getSectionTitles($journalId, $submittableOnly = false) {
424  $sections = array();
425 
426  $sectionsIterator =& $this->getJournalSections($journalId);
427  while (($section =& $sectionsIterator->next())) {
428  if ($submittableOnly) {
429  if (!$section->getEditorRestricted()) {
430  $sections[$section->getId()] = $section->getLocalizedTitle();
431  }
432  } else {
433  $sections[$section->getId()] = $section->getLocalizedTitle();
434  }
435  unset($section);
436  }
437 
438  return $sections;
439  }
440 
447  function sectionExists($sectionId, $journalId) {
448  $result =& $this->retrieve(
449  'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
450  array($sectionId, $journalId)
451  );
452  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
453 
454  $result->Close();
455  unset($result);
456 
457  return $returner;
458  }
459 
464  function resequenceSections($journalId) {
465  $result =& $this->retrieve(
466  'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
467  $journalId
468  );
469 
470  for ($i=1; !$result->EOF; $i++) {
471  list($sectionId) = $result->fields;
472  $this->update(
473  'UPDATE sections SET seq = ? WHERE section_id = ?',
474  array(
475  $i,
476  $sectionId
477  )
478  );
479 
480  $result->moveNext();
481  }
482 
483  $result->close();
484  unset($result);
485  }
486 
491  function getInsertSectionId() {
492  return $this->getInsertId('sections', 'section_id');
493  }
494 
499  function deleteCustomSectionOrdering($issueId) {
500  return $this->update(
501  'DELETE FROM custom_section_orders WHERE issue_id = ?', $issueId
502  );
503  }
504 
510  function deleteCustomSection($issueId, $sectionId) {
511  $sequence = $this->getCustomSectionOrder($issueId, $sectionId);
512 
513  $this->update(
514  'DELETE FROM custom_section_orders WHERE issue_id = ? AND section_id = ?', array($issueId, $sectionId)
515  );
516 
517  // Reduce the section order of every successive section by one
518  $this->update(
519  'UPDATE custom_section_orders SET seq = seq - 1 WHERE issue_id = ? AND seq > ?', array($issueId, $sequence)
520  );
521  }
522 
527  function resequenceCustomSectionOrders($issueId) {
528  $result =& $this->retrieve(
529  'SELECT section_id FROM custom_section_orders WHERE issue_id = ? ORDER BY seq',
530  $issueId
531  );
532 
533  for ($i=1; !$result->EOF; $i++) {
534  list($sectionId) = $result->fields;
535  $this->update(
536  'UPDATE custom_section_orders SET seq = ? WHERE section_id = ? AND issue_id = ?',
537  array($i, $sectionId, $issueId)
538  );
539 
540  $result->moveNext();
541  }
542 
543  $result->close();
544  unset($result);
545  }
546 
552  function customSectionOrderingExists($issueId) {
553  $result =& $this->retrieve(
554  'SELECT COUNT(*) FROM custom_section_orders WHERE issue_id = ?',
555  $issueId
556  );
557  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
558 
559  $result->Close();
560  unset($result);
561 
562  return $returner;
563  }
564 
571  function getCustomSectionOrder($issueId, $sectionId) {
572  $result =& $this->retrieve(
573  'SELECT seq FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
574  array($issueId, $sectionId)
575  );
576 
577  $returner = null;
578  if (!$result->EOF) {
579  list($returner) = $result->fields;
580  }
581  $result->Close();
582  unset($result);
583 
584  return $returner;
585  }
586 
592  function setDefaultCustomSectionOrders($issueId) {
593  $result =& $this->retrieve(
594  'SELECT s.section_id FROM sections s, issues i WHERE i.journal_id = s.journal_id AND i.issue_id = ? ORDER BY seq',
595  $issueId
596  );
597 
598  for ($i=1; !$result->EOF; $i++) {
599  list($sectionId) = $result->fields;
600  $this->insertCustomSectionOrder($issueId, $sectionId, $i);
601  $result->moveNext();
602  }
603 
604  $result->close();
605  unset($result);
606  }
607 
614  function insertCustomSectionOrder($issueId, $sectionId, $seq) {
615  $this->update(
616  'INSERT INTO custom_section_orders (section_id, issue_id, seq) VALUES (?, ?, ?)',
617  array(
618  $sectionId,
619  $issueId,
620  $seq
621  )
622  );
623  }
624 
632  function moveCustomSectionOrder($issueId, $sectionId, $newPos, $up) {
633  $this->update(
634  'UPDATE custom_section_orders SET seq = ? ' . ($up?'-':'+') . ' 0.5 WHERE issue_id = ? AND section_id = ?',
635  array($newPos, $issueId, $sectionId)
636  );
637  $this->resequenceCustomSectionOrders($issueId);
638  }
639 }
640 
641 ?>
& getJournalSections($journalId, $rangeInfo=null)
Operations for retrieving and modifying objects from a database.
Definition: DAO.inc.php:29
& _returnSectionFromRow(&$row)
updateSection(&$section)
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:83
Describes basic section properties.
Definition: Section.inc.php:17
getInsertId($table= '', $id= '', $callHooks=true)
Definition: DAO.inc.php:252
resequenceCustomSectionOrders($issueId)
updateDataObjectSettings($tableName, &$dataObject, $idArray)
Definition: DAO.inc.php:460
setDefaultCustomSectionOrders($issueId)
insertCustomSectionOrder($issueId, $sectionId, $seq)
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
& getSectionsForIssue($issueId)
customSectionOrderingExists($issueId)
& getEditorSections($journalId)
getJournalEmptySectionIds($journalId)
resequenceSections($journalId)
Operations for retrieving and modifying Section objects.
moveCustomSectionOrder($issueId, $sectionId, $newPos, $up)
deleteCustomSectionOrdering($issueId)
deleteSectionById($sectionId, $journalId=null)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
& getSections($rangeInfo=null)
& getDAO($name, $dbconn=null)
& getSection($sectionId, $journalId=null, $useCache=false)
& getSectionByTitle($sectionTitle, $journalId, $locale=null)
updateLocaleFields(&$section)
deleteSection(&$section)
call($hookName, $args=null)
& getSectionTitles($journalId, $submittableOnly=false)
insertSection(&$section)
& getSectionByAbbrev($sectionAbbrev, $journalId, $locale=null)
sectionExists($sectionId, $journalId)
getCustomSectionOrder($issueId, $sectionId)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:211
deleteCustomSection($issueId, $sectionId)
& getSectionByTitleAndAbbrev($sectionTitle, $sectionAbbrev, $journalId, $locale)
deleteSectionsByJournal($journalId)