Open Journal Systems  3.3.0
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 
28  protected function _getTableName() {
29  return 'sections';
30  }
31 
37  protected function _getContextIdColumnName() {
38  return 'journal_id';
39  }
40 
41  function _cacheMiss($cache, $id) {
42  $section = $this->getById($id, null, false);
43  $cache->setCache($id, $section);
44  return $section;
45  }
46 
47  function &_getCache() {
48  if (!isset($this->cache)) {
49  $cacheManager = CacheManager::getManager();
50  $this->cache = $cacheManager->getObjectCache('sections', 0, array($this, '_cacheMiss'));
51  }
52  return $this->cache;
53  }
54 
62  function getById($sectionId, $journalId = null, $useCache = false) {
63  if ($useCache) {
64  $cache = $this->_getCache();
65  $returner = $cache->get($sectionId);
66  if ($returner && $journalId != null && $journalId != $returner->getJournalId()) $returner = null;
67  return $returner;
68  }
69 
70  $sql = 'SELECT * FROM sections WHERE section_id = ?';
71  $params = array((int) $sectionId);
72  if ($journalId !== null) {
73  $sql .= ' AND journal_id = ?';
74  $params[] = (int) $journalId;
75  }
76  $result = $this->retrieve($sql, $params);
77 
78  $returner = null;
79  if ($result->RecordCount() != 0) {
80  $returner = $this->_fromRow($result->GetRowAssoc(false));
81  }
82  $result->Close();
83 
84  return $returner;
85  }
86 
94  function getByAbbrev($sectionAbbrev, $journalId, $locale = null) {
95  $params = array('abbrev', $sectionAbbrev, (int) $journalId);
96  if ($locale !== null) {
97  $params[] = $locale;
98  }
99 
100  $result = $this->retrieve(
101  'SELECT s.*
102  FROM sections s, section_settings l
103  WHERE l.section_id = s.section_id AND
104  l.setting_name = ? AND
105  l.setting_value = ? AND
106  s.journal_id = ?' .
107  ($locale!==null?' AND l.locale = ?':''),
108  $params
109  );
110 
111  $returner = null;
112  if ($result->RecordCount() != 0) {
113  $returner = $this->_fromRow($result->GetRowAssoc(false));
114  }
115 
116  $result->Close();
117  return $returner;
118  }
119 
127  function getByTitle($sectionTitle, $journalId, $locale = null) {
128  $params = array('title', $sectionTitle, (int) $journalId);
129  if ($locale !== null) {
130  $params[] = $locale;
131  }
132 
133  $result = $this->retrieve(
134  'SELECT s.*
135  FROM sections s, section_settings l
136  WHERE l.section_id = s.section_id AND
137  l.setting_name = ? AND
138  l.setting_value = ? AND
139  s.journal_id = ?' .
140  ($locale !== null?' AND l.locale = ?':''),
141  $params
142  );
143 
144  $returner = null;
145  if ($result->RecordCount() != 0) {
146  $returner = $this->_fromRow($result->GetRowAssoc(false));
147  }
148 
149  $result->Close();
150  return $returner;
151  }
152 
158  public function getBySubmissionId($submissionId) {
159  $result = $this->retrieve('SELECT sections.* FROM sections
160  JOIN submissions
161  ON (submissions.section_id = sections.section_id)
162  WHERE submissions.submission_id = ?',
163  array((int) $submissionId));
164 
165  $returner = null;
166  if ($result->RecordCount() != 0) {
167  $returner = $this->_fromRow($result->GetRowAssoc(false));
168  }
169  $result->Close();
170 
171  return $returner;
172  }
173 
177  function newDataObject() {
178  return new Section();
179  }
180 
186  function _fromRow($row) {
187  $section = parent::_fromRow($row);
188 
189  $section->setId($row['section_id']);
190  $section->setJournalId($row['journal_id']);
191  $section->setMetaIndexed($row['meta_indexed']);
192  $section->setMetaReviewed($row['meta_reviewed']);
193  $section->setAbstractsNotRequired($row['abstracts_not_required']);
194  $section->setHideTitle($row['hide_title']);
195  $section->setHideAuthor($row['hide_author']);
196  $section->setIsInactive($row['is_inactive']);
197  $section->setAbstractWordCount($row['abstract_word_count']);
198 
199  $this->getDataObjectSettings('section_settings', 'section_id', $row['section_id'], $section);
200 
201  HookRegistry::call('SectionDAO::_fromRow', array(&$section, &$row));
202 
203  return $section;
204  }
205 
210  function getLocaleFieldNames() {
211  return array_merge(
212  parent::getLocaleFieldNames(),
213  array('abbrev', 'identifyType')
214  );
215  }
216 
221  function updateLocaleFields($section) {
222  $this->updateDataObjectSettings('section_settings', $section, array(
223  'section_id' => $section->getId()
224  ));
225  }
226 
232  function insertObject($section) {
233  $this->update(
234  'INSERT INTO sections
235  (journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, is_inactive, abstract_word_count)
236  VALUES
237  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
238  array(
239  (int)$section->getJournalId(),
240  (int)$section->getReviewFormId(),
241  (float) $section->getSequence(),
242  $section->getMetaIndexed() ? 1 : 0,
243  $section->getMetaReviewed() ? 1 : 0,
244  $section->getAbstractsNotRequired() ? 1 : 0,
245  $section->getEditorRestricted() ? 1 : 0,
246  $section->getHideTitle() ? 1 : 0,
247  $section->getHideAuthor() ? 1 : 0,
248  $section->getIsInactive() ? 1 : 0,
249  (int) $section->getAbstractWordCount()
250  )
251  );
252 
253  $section->setId($this->getInsertId());
254  $this->updateLocaleFields($section);
255  return $section->getId();
256  }
257 
262  function updateObject($section) {
263  $this->update(
264  'UPDATE sections
265  SET
266  review_form_id = ?,
267  seq = ?,
268  meta_indexed = ?,
269  meta_reviewed = ?,
270  abstracts_not_required = ?,
271  editor_restricted = ?,
272  hide_title = ?,
273  hide_author = ?,
274  is_inactive = ?,
275  abstract_word_count = ?
276  WHERE section_id = ?',
277  array(
278  (int)$section->getReviewFormId(),
279  (float) $section->getSequence(),
280  (int)$section->getMetaIndexed(),
281  (int)$section->getMetaReviewed(),
282  (int)$section->getAbstractsNotRequired(),
283  (int)$section->getEditorRestricted(),
284  (int)$section->getHideTitle(),
285  (int)$section->getHideAuthor(),
286  (int)$section->getIsInactive(),
287  $this->nullOrInt($section->getAbstractWordCount()),
288  (int)$section->getId()
289  )
290  );
291  $this->updateLocaleFields($section);
292  }
293 
299  function deleteById($sectionId, $contextId = null) {
300  $subEditorsDao = DAORegistry::getDAO('SubEditorsDAO'); /* @var $subEditorsDao SubEditorsDAO */
301  $subEditorsDao->deleteBySubmissionGroupId($sectionId, ASSOC_TYPE_SECTION, $contextId);
302 
303  // Remove articles from this section
304  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
305  $submissionDao->removeSubmissionsFromSection($sectionId);
306 
307  if (isset($contextId) && !$this->sectionExists($sectionId, $contextId)) return false;
308  $this->update('DELETE FROM section_settings WHERE section_id = ?', (int) $sectionId);
309  $this->update('DELETE FROM sections WHERE section_id = ?', (int) $sectionId);
310  }
311 
318  function deleteByJournalId($journalId) {
319  $this->deleteByContextId($journalId);
320  }
321 
328  function getEditorSections($journalId) {
329  $returner = array();
330 
331  $result = $this->retrieve(
332  'SELECT s.*, se.user_id AS editor_id FROM subeditor_submission_group ssg, sections s WHERE ssg.assoc_id = s.section_id AND ssg.assoc_type = ? AND s.journal_id = ssg.context_id AND s.journal_id = ?',
333  (int) ASSOC_TYPE_SECTION,
334  (int) $journalId
335  );
336 
337  while (!$result->EOF) {
338  $row = $result->GetRowAssoc(false);
339  $section = $this->_fromRow($row);
340  if (!isset($returner[$row['editor_id']])) {
341  $returner[$row['editor_id']] = array($section);
342  } else {
343  $returner[$row['editor_id']][] = $section;
344  }
345  $result->MoveNext();
346  }
347 
348  $result->Close();
349  return $returner;
350  }
351 
358  function getByIssueId($issueId) {
359  import ('classes.submission.Submission'); // import STATUS_* constants
360  $issue = Services::get('issue')->get($issueId);
361  $allowedStatuses = [STATUS_PUBLISHED];
362  if (!$issue->getPublished()) {
363  $allowedStatuses[] = STATUS_SCHEDULED;
364  }
365  $submissionsIterator = Services::get('submission')->getMany([
366  'contextId' => $issue->getJournalId(),
367  'issueIds' => $issueId,
368  'status' => $allowedStatuses,
369  ]);
370  $sectionIds = [];
371  foreach ($submissionsIterator as $submission) {
372  $sectionIds[] = $submission->getCurrentPublication()->getData('sectionId');
373  }
374  if (empty($sectionIds)) {
375  return [];
376  }
377  $sectionIds = array_unique($sectionIds);
378  $result = $this->retrieve(
379  'SELECT s.*, COALESCE(o.seq, s.seq) AS section_seq
380  FROM sections s
381  LEFT JOIN custom_section_orders o ON (s.section_id = o.section_id AND o.issue_id = ?)
382  WHERE s.section_id IN (' . substr(str_repeat('?,', count($sectionIds)), 0, -1) . ')
383  ORDER BY section_seq',
384  array_merge([(int) $issueId], $sectionIds)
385  );
386 
387  $returner = array();
388  while (!$result->EOF) {
389  $row = $result->GetRowAssoc(false);
390  $returner[] = $this->_fromRow($row);
391  $result->MoveNext();
392  }
393 
394  $result->Close();
395  return $returner;
396  }
397 
405  function getByJournalId($journalId, $rangeInfo = null) {
406  return $this->getByContextId($journalId, $rangeInfo);
407  }
408 
417  function getByContextId($journalId, $rangeInfo = null, $submittableOnly = false) {
418  $result = $this->retrieveRange(
419  'SELECT * FROM sections WHERE journal_id = ? ' . ($submittableOnly ? ' AND editor_restricted = 0' : '') . ' ORDER BY seq',
420  (int) $journalId, $rangeInfo
421  );
422 
423  return new DAOResultFactory($result, $this, '_fromRow');
424  }
425 
431  function getAll($rangeInfo = null) {
432  $result = $this->retrieveRange(
433  'SELECT * FROM sections ORDER BY journal_id, seq',
434  false, $rangeInfo
435  );
436 
437  return new DAOResultFactory($result, $this, '_fromRow');
438  }
439 
445  function getEmptyByJournalId($journalId) {
446  $result = $this->retrieve(
447  '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 = ?',
448  (int) $journalId
449  );
450 
451  $returner = array();
452  while (!$result->EOF) {
453  $returner[] = $result->fields[0];
454  $result->MoveNext();
455  }
456  $result->Close();
457  return $returner;
458  }
459 
466  function sectionExists($sectionId, $journalId) {
467  $result = $this->retrieve(
468  'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
469  array((int) $sectionId, (int) $journalId)
470  );
471  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
472 
473  $result->Close();
474  return $returner;
475  }
476 
481  function resequenceSections($journalId) {
482  $result = $this->retrieve(
483  'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
484  (int) $journalId
485  );
486 
487  for ($i=1; !$result->EOF; $i++) {
488  list($sectionId) = $result->fields;
489  $this->update(
490  'UPDATE sections SET seq = ? WHERE section_id = ?',
491  array(
492  $i,
493  $sectionId
494  )
495  );
496 
497  $result->MoveNext();
498  }
499  $result->Close();
500  }
501 
506  function getInsertId() {
507  return $this->_getInsertId('sections', 'section_id');
508  }
509 
515  function deleteCustomSectionOrdering($issueId) {
516  return $this->update(
517  'DELETE FROM custom_section_orders WHERE issue_id = ?', (int) $issueId
518  );
519  }
520 
526  function deleteCustomSection($issueId, $sectionId) {
527  $seq = $this->getCustomSectionOrder($issueId, $sectionId);
528 
529  $this->update(
530  'DELETE FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
531  array((int) $issueId, (int) $sectionId)
532  );
533 
534  // Reduce the section order of every successive section by one
535  $this->update(
536  'UPDATE custom_section_orders SET seq = seq - 1 WHERE issue_id = ? AND seq > ?',
537  array((int) $issueId, (float) $seq)
538  );
539  }
540 
545  function resequenceCustomSectionOrders($issueId) {
546  $result = $this->retrieve(
547  'SELECT section_id FROM custom_section_orders WHERE issue_id = ? ORDER BY seq',
548  (int) $issueId
549  );
550 
551  for ($i=1; !$result->EOF; $i++) {
552  list($sectionId) = $result->fields;
553  $this->update(
554  'UPDATE custom_section_orders SET seq = ? WHERE section_id = ? AND issue_id = ?',
555  array($i, $sectionId, (int) $issueId)
556  );
557 
558  $result->MoveNext();
559  }
560  $result->Close();
561  }
562 
568  function customSectionOrderingExists($issueId) {
569  $result = $this->retrieve(
570  'SELECT COUNT(*) FROM custom_section_orders WHERE issue_id = ?',
571  (int) $issueId
572  );
573  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
574  $result->Close();
575  return $returner;
576  }
577 
584  function getCustomSectionOrder($issueId, $sectionId) {
585  $result = $this->retrieve(
586  'SELECT seq FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
587  array((int) $issueId, (int) $sectionId)
588  );
589 
590  $returner = null;
591  if (!$result->EOF) {
592  list($returner) = $result->fields;
593  }
594  $result->Close();
595  return $returner;
596  }
597 
603  function setDefaultCustomSectionOrders($issueId) {
604  $issueSections = $this->getByIssueId($issueId);
605  $i = 1;
606  foreach ($issueSections as $section) {
607  $this->insertCustomSectionOrder($issueId, $section->getId(), $i);
608  $i++;
609  }
610  }
611 
618  function insertCustomSectionOrder($issueId, $sectionId, $seq) {
619  $this->update(
620  'INSERT INTO custom_section_orders (section_id, issue_id, seq) VALUES (?, ?, ?)',
621  array((int) $sectionId,(int) $issueId, (float) $seq)
622  );
623  }
624 
631  function updateCustomSectionOrder($issueId, $sectionId, $seq) {
632  $this->update(
633  'UPDATE custom_section_orders SET seq = ? WHERE issue_id = ? AND section_id = ?',
634  array((float) $seq, (int) $issueId, (int) $sectionId)
635  );
636  }
637 }
SectionDAO\insertObject
insertObject($section)
Definition: SectionDAO.inc.php:232
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
SectionDAO\deleteCustomSection
deleteCustomSection($issueId, $sectionId)
Definition: SectionDAO.inc.php:526
SectionDAO\updateLocaleFields
updateLocaleFields($section)
Definition: SectionDAO.inc.php:221
SectionDAO\_fromRow
_fromRow($row)
Definition: SectionDAO.inc.php:186
DAO\retrieveRange
& retrieveRange($sql, $params=false, $dbResultRange=null, $callHooks=true)
Definition: DAO.inc.php:176
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
SectionDAO\getCustomSectionOrder
getCustomSectionOrder($issueId, $sectionId)
Definition: SectionDAO.inc.php:584
SectionDAO\resequenceCustomSectionOrders
resequenceCustomSectionOrders($issueId)
Definition: SectionDAO.inc.php:545
SectionDAO\deleteByJournalId
deleteByJournalId($journalId)
Definition: SectionDAO.inc.php:318
SectionDAO
Operations for retrieving and modifying Section objects.
Definition: SectionDAO.inc.php:20
SectionDAO\sectionExists
sectionExists($sectionId, $journalId)
Definition: SectionDAO.inc.php:466
SectionDAO\updateCustomSectionOrder
updateCustomSectionOrder($issueId, $sectionId, $seq)
Definition: SectionDAO.inc.php:631
SectionDAO\_cacheMiss
_cacheMiss($cache, $id)
Definition: SectionDAO.inc.php:41
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
SectionDAO\insertCustomSectionOrder
insertCustomSectionOrder($issueId, $sectionId, $seq)
Definition: SectionDAO.inc.php:618
SectionDAO\getByContextId
getByContextId($journalId, $rangeInfo=null, $submittableOnly=false)
Definition: SectionDAO.inc.php:417
SectionDAO\newDataObject
newDataObject()
Definition: SectionDAO.inc.php:177
SectionDAO\getByAbbrev
getByAbbrev($sectionAbbrev, $journalId, $locale=null)
Definition: SectionDAO.inc.php:94
SectionDAO\getInsertId
getInsertId()
Definition: SectionDAO.inc.php:506
SectionDAO\getEmptyByJournalId
getEmptyByJournalId($journalId)
Definition: SectionDAO.inc.php:445
SectionDAO\_getCache
& _getCache()
Definition: SectionDAO.inc.php:47
SectionDAO\$cache
$cache
Definition: SectionDAO.inc.php:21
SectionDAO\setDefaultCustomSectionOrders
setDefaultCustomSectionOrders($issueId)
Definition: SectionDAO.inc.php:603
CacheManager\getManager
static getManager()
Definition: CacheManager.inc.php:27
SectionDAO\_getContextIdColumnName
_getContextIdColumnName()
Definition: SectionDAO.inc.php:37
SectionDAO\getLocaleFieldNames
getLocaleFieldNames()
Definition: SectionDAO.inc.php:210
SectionDAO\customSectionOrderingExists
customSectionOrderingExists($issueId)
Definition: SectionDAO.inc.php:568
PKPSectionDAO
Operations for retrieving and modifying Section objects.
Definition: PKPSectionDAO.inc.php:17
SectionDAO\getById
getById($sectionId, $journalId=null, $useCache=false)
Definition: SectionDAO.inc.php:62
DAO\update
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:214
SectionDAO\getByIssueId
getByIssueId($issueId)
Definition: SectionDAO.inc.php:358
SectionDAO\getEditorSections
getEditorSections($journalId)
Definition: SectionDAO.inc.php:328
SectionDAO\deleteById
deleteById($sectionId, $contextId=null)
Definition: SectionDAO.inc.php:299
DAO\_getInsertId
_getInsertId($table='', $id='')
Definition: DAO.inc.php:255
DAO\getDataObjectSettings
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, $dataObject)
Definition: DAO.inc.php:582
SectionDAO\getByTitle
getByTitle($sectionTitle, $journalId, $locale=null)
Definition: SectionDAO.inc.php:127
SectionDAO\getByJournalId
getByJournalId($journalId, $rangeInfo=null)
Definition: SectionDAO.inc.php:405
SectionDAO\deleteCustomSectionOrdering
deleteCustomSectionOrdering($issueId)
Definition: SectionDAO.inc.php:515
SectionDAO\_getTableName
_getTableName()
Definition: SectionDAO.inc.php:28
PKPSectionDAO\deleteByContextId
deleteByContextId($contextId)
Definition: PKPSectionDAO.inc.php:77
SectionDAO\getBySubmissionId
getBySubmissionId($submissionId)
Definition: SectionDAO.inc.php:158
Section
Describes basic section properties.
Definition: Section.inc.php:19
DAO\updateDataObjectSettings
updateDataObjectSettings($tableName, $dataObject, $idArray)
Definition: DAO.inc.php:488
SectionDAO\updateObject
updateObject($section)
Definition: SectionDAO.inc.php:262
SectionDAO\getAll
getAll($rangeInfo=null)
Definition: SectionDAO.inc.php:431
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
SectionDAO\resequenceSections
resequenceSections($journalId)
Definition: SectionDAO.inc.php:481
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49