Open Preprint 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', 'description')
214  );
215  }
216 
222  return array_merge(
223  parent::getAdditionalFieldNames(),
224  array('path')
225  );
226  }
227 
232  function updateLocaleFields($section) {
233  $this->updateDataObjectSettings('section_settings', $section, array(
234  'section_id' => $section->getId()
235  ));
236  }
237 
243  function insertObject($section) {
244  $this->update(
245  'INSERT INTO sections
246  (journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, is_inactive, abstract_word_count)
247  VALUES
248  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
249  array(
250  (int)$section->getJournalId(),
251  (int)$section->getReviewFormId(),
252  (float) $section->getSequence(),
253  $section->getMetaIndexed() ? 1 : 0,
254  $section->getMetaReviewed() ? 1 : 0,
255  $section->getAbstractsNotRequired() ? 1 : 0,
256  $section->getEditorRestricted() ? 1 : 0,
257  $section->getHideTitle() ? 1 : 0,
258  $section->getHideAuthor() ? 1 : 0,
259  $section->getIsInactive() ? 1 : 0,
260  (int) $section->getAbstractWordCount()
261  )
262  );
263 
264  $section->setId($this->getInsertId());
265  $this->updateLocaleFields($section);
266  return $section->getId();
267  }
268 
273  function updateObject($section) {
274  $this->update(
275  'UPDATE sections
276  SET
277  review_form_id = ?,
278  seq = ?,
279  meta_indexed = ?,
280  meta_reviewed = ?,
281  abstracts_not_required = ?,
282  editor_restricted = ?,
283  hide_title = ?,
284  hide_author = ?,
285  is_inactive = ?,
286  abstract_word_count = ?
287  WHERE section_id = ?',
288  array(
289  (int)$section->getReviewFormId(),
290  (float) $section->getSequence(),
291  (int)$section->getMetaIndexed(),
292  (int)$section->getMetaReviewed(),
293  (int)$section->getAbstractsNotRequired(),
294  (int)$section->getEditorRestricted(),
295  (int)$section->getHideTitle(),
296  (int)$section->getHideAuthor(),
297  (int)$section->getIsInactive(),
298  $this->nullOrInt($section->getAbstractWordCount()),
299  (int)$section->getId()
300  )
301  );
302  $this->updateLocaleFields($section);
303  }
304 
310  function deleteById($sectionId, $contextId = null) {
311  $subEditorsDao = DAORegistry::getDAO('SubEditorsDAO');
312  $subEditorsDao->deleteBySubmissionGroupId($sectionId, ASSOC_TYPE_SECTION, $contextId);
313 
314  // Remove articles from this section
315  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
316  $submissionDao->removeSubmissionsFromSection($sectionId);
317 
318  if (isset($contextId) && !$this->sectionExists($sectionId, $contextId)) return false;
319  $this->update('DELETE FROM section_settings WHERE section_id = ?', (int) $sectionId);
320  $this->update('DELETE FROM sections WHERE section_id = ?', (int) $sectionId);
321  }
322 
329  function deleteByJournalId($journalId) {
330  $this->deleteByContextId($journalId);
331  }
332 
339  function getEditorSections($journalId) {
340  $returner = array();
341 
342  $result = $this->retrieve(
343  '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 = ?',
344  (int) ASSOC_TYPE_SECTION,
345  (int) $journalId
346  );
347 
348  while (!$result->EOF) {
349  $row = $result->GetRowAssoc(false);
350  $section = $this->_fromRow($row);
351  if (!isset($returner[$row['editor_id']])) {
352  $returner[$row['editor_id']] = array($section);
353  } else {
354  $returner[$row['editor_id']][] = $section;
355  }
356  $result->MoveNext();
357  }
358 
359  $result->Close();
360  return $returner;
361  }
362 
369  function getByJournalId($journalId, $rangeInfo = null) {
370  return $this->getByContextId($journalId, $rangeInfo);
371  }
372 
381  function getByContextId($journalId, $rangeInfo = null, $submittableOnly = false) {
382  $result = $this->retrieveRange(
383  'SELECT * FROM sections WHERE journal_id = ? ' . ($submittableOnly ? ' AND editor_restricted = 0' : '') . ' ORDER BY seq',
384  (int) $journalId, $rangeInfo
385  );
386 
387  return new DAOResultFactory($result, $this, '_fromRow');
388  }
389 
395  function getAll($rangeInfo = null) {
396  $result = $this->retrieveRange(
397  'SELECT * FROM sections ORDER BY journal_id, seq',
398  false, $rangeInfo
399  );
400 
401  return new DAOResultFactory($result, $this, '_fromRow');
402  }
403 
409  function getEmptyByJournalId($journalId) {
410  $result = $this->retrieve(
411  '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 = ?',
412  (int) $journalId
413  );
414 
415  $returner = array();
416  while (!$result->EOF) {
417  $returner[] = $result->fields[0];
418  $result->MoveNext();
419  }
420  $result->Close();
421  return $returner;
422  }
423 
430  function sectionExists($sectionId, $journalId) {
431  $result = $this->retrieve(
432  'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
433  array((int) $sectionId, (int) $journalId)
434  );
435  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
436 
437  $result->Close();
438  return $returner;
439  }
440 
445  function resequenceSections($journalId) {
446  $result = $this->retrieve(
447  'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
448  (int) $journalId
449  );
450 
451  for ($i=1; !$result->EOF; $i++) {
452  list($sectionId) = $result->fields;
453  $this->update(
454  'UPDATE sections SET seq = ? WHERE section_id = ?',
455  array(
456  $i,
457  $sectionId
458  )
459  );
460 
461  $result->MoveNext();
462  }
463  $result->Close();
464  }
465 
470  function getInsertId() {
471  return $this->_getInsertId('sections', 'section_id');
472  }
473 
474 }
SectionDAO\insertObject
insertObject($section)
Definition: SectionDAO.inc.php:243
SectionDAO\getAdditionalFieldNames
getAdditionalFieldNames()
Definition: SectionDAO.inc.php:221
DAOResultFactory
Wrapper around ADORecordSet providing "factory" features for generating objects from DAOs.
Definition: DAOResultFactory.inc.php:21
SectionDAO\updateLocaleFields
updateLocaleFields($section)
Definition: SectionDAO.inc.php:232
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\deleteByJournalId
deleteByJournalId($journalId)
Definition: SectionDAO.inc.php:329
SectionDAO
Operations for retrieving and modifying Section objects.
Definition: SectionDAO.inc.php:20
SectionDAO\sectionExists
sectionExists($sectionId, $journalId)
Definition: SectionDAO.inc.php:430
SectionDAO\_cacheMiss
_cacheMiss($cache, $id)
Definition: SectionDAO.inc.php:41
DAO\retrieve
& retrieve($sql, $params=false, $callHooks=true)
Definition: DAO.inc.php:85
SectionDAO\getByContextId
getByContextId($journalId, $rangeInfo=null, $submittableOnly=false)
Definition: SectionDAO.inc.php:381
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:470
SectionDAO\getEmptyByJournalId
getEmptyByJournalId($journalId)
Definition: SectionDAO.inc.php:409
SectionDAO\_getCache
& _getCache()
Definition: SectionDAO.inc.php:47
SectionDAO\$cache
$cache
Definition: SectionDAO.inc.php:21
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
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\getEditorSections
getEditorSections($journalId)
Definition: SectionDAO.inc.php:339
SectionDAO\deleteById
deleteById($sectionId, $contextId=null)
Definition: SectionDAO.inc.php:310
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:369
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:273
SectionDAO\getAll
getAll($rangeInfo=null)
Definition: SectionDAO.inc.php:395
HookRegistry\call
static call($hookName, $args=null)
Definition: HookRegistry.inc.php:86
SectionDAO\resequenceSections
resequenceSections($journalId)
Definition: SectionDAO.inc.php:445