Open Journal Systems  3.0.0
 All Data Structures 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->setAbstractWordCount($row['abstract_word_count']);
160 
161  $this->getDataObjectSettings('section_settings', 'section_id', $row['section_id'], $section);
162 
163  HookRegistry::call('SectionDAO::_fromRow', array(&$section, &$row));
164 
165  return $section;
166  }
167 
172  function getLocaleFieldNames() {
173  return array_merge(
174  parent::getLocaleFieldNames(),
175  array('abbrev', 'policy', 'identifyType')
176  );
177  }
178 
183  function updateLocaleFields($section) {
184  $this->updateDataObjectSettings('section_settings', $section, array(
185  'section_id' => $section->getId()
186  ));
187  }
188 
193  function insertObject($section) {
194  $this->update(
195  'INSERT INTO sections
196  (journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, hide_about, abstract_word_count)
197  VALUES
198  (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
199  array(
200  (int)$section->getJournalId(),
201  (int)$section->getReviewFormId(),
202  (float) $section->getSequence(),
203  $section->getMetaIndexed() ? 1 : 0,
204  $section->getMetaReviewed() ? 1 : 0,
205  $section->getAbstractsNotRequired() ? 1 : 0,
206  $section->getEditorRestricted() ? 1 : 0,
207  $section->getHideTitle() ? 1 : 0,
208  $section->getHideAuthor() ? 1 : 0,
209  $section->getHideAbout() ? 1 : 0,
210  (int) $section->getAbstractWordCount()
211  )
212  );
213 
214  $section->setId($this->getInsertId());
215  $this->updateLocaleFields($section);
216  return $section->getId();
217  }
218 
223  function updateObject($section) {
224  $this->update(
225  'UPDATE sections
226  SET
227  review_form_id = ?,
228  seq = ?,
229  meta_indexed = ?,
230  meta_reviewed = ?,
231  abstracts_not_required = ?,
232  editor_restricted = ?,
233  hide_title = ?,
234  hide_author = ?,
235  hide_about = ?,
236  abstract_word_count = ?
237  WHERE section_id = ?',
238  array(
239  (int)$section->getReviewFormId(),
240  (float) $section->getSequence(),
241  (int)$section->getMetaIndexed(),
242  (int)$section->getMetaReviewed(),
243  (int)$section->getAbstractsNotRequired(),
244  (int)$section->getEditorRestricted(),
245  (int)$section->getHideTitle(),
246  (int)$section->getHideAuthor(),
247  (int)$section->getHideAbout(),
248  $this->nullOrInt($section->getAbstractWordCount()),
249  (int)$section->getId()
250  )
251  );
252  $this->updateLocaleFields($section);
253  }
254 
260  function deleteById($sectionId, $contextId = null) {
261  $subEditorsDao = DAORegistry::getDAO('SubEditorsDAO');
262  $subEditorsDao->deleteBySectionId($sectionId, $contextId);
263 
264  // Remove articles from this section
265  $articleDao = DAORegistry::getDAO('ArticleDAO');
266  $articleDao->removeArticlesFromSection($sectionId);
267 
268  // Delete published article entries from this section -- they must
269  // be re-published.
270  $publishedArticleDao = DAORegistry::getDAO('PublishedArticleDAO');
271  $publishedArticleDao->deletePublishedArticlesBySectionId($sectionId);
272 
273  if (isset($contextId) && !$this->sectionExists($sectionId, $contextId)) return false;
274  $this->update('DELETE FROM section_settings WHERE section_id = ?', (int) $sectionId);
275  $this->update('DELETE FROM sections WHERE section_id = ?', (int) $sectionId);
276  }
277 
284  function deleteByJournalId($journalId) {
285  $this->deleteByContextId($journalId);
286  }
287 
293  function &getEditorSections($journalId) {
294  $returner = array();
295 
296  $result = $this->retrieve(
297  '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 = ?',
298  (int) $journalId
299  );
300 
301  while (!$result->EOF) {
302  $row = $result->GetRowAssoc(false);
303  $section = $this->_fromRow($row);
304  if (!isset($returner[$row['editor_id']])) {
305  $returner[$row['editor_id']] = array($section);
306  } else {
307  $returner[$row['editor_id']][] = $section;
308  }
309  $result->MoveNext();
310  }
311 
312  $result->Close();
313  return $returner;
314  }
315 
321  function getByIssueId($issueId) {
322  $result = $this->retrieve(
323  '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',
324  array((int) $issueId, (int) $issueId)
325  );
326 
327  $returner = array();
328  while (!$result->EOF) {
329  $row = $result->GetRowAssoc(false);
330  $returner[] = $this->_fromRow($row);
331  $result->MoveNext();
332  }
333 
334  $result->Close();
335  return $returner;
336  }
337 
342  function getByJournalId($journalId, $rangeInfo = null) {
343  return $this->getByContextId($journalId, $rangeInfo);
344  }
345 
352  function getByContextId($journalId, $rangeInfo = null) {
353  $result = $this->retrieveRange(
354  'SELECT * FROM sections WHERE journal_id = ? ORDER BY seq',
355  (int) $journalId, $rangeInfo
356  );
357 
358  return new DAOResultFactory($result, $this, '_fromRow');
359  }
360 
365  function getAll($rangeInfo = null) {
366  $result = $this->retrieveRange(
367  'SELECT * FROM sections ORDER BY journal_id, seq',
368  false, $rangeInfo
369  );
370 
371  return new DAOResultFactory($result, $this, '_fromRow');
372  }
373 
378  function getEmptyByJournalId($journalId) {
379  $result = $this->retrieve(
380  '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 = ?',
381  (int) $journalId
382  );
383 
384  $returner = array();
385  while (!$result->EOF) {
386  $returner[] = $result->fields[0];
387  $result->MoveNext();
388  }
389  $result->Close();
390  return $returner;
391  }
392 
397  function &getSectionTitles($journalId, $submittableOnly = false) {
398  $sections = array();
399 
400  $sectionsIterator = $this->getByJournalId($journalId);
401  while ($section = $sectionsIterator->next()) {
402  if ($submittableOnly) {
403  if (!$section->getEditorRestricted()) {
404  $sections[$section->getId()] = $section->getLocalizedTitle();
405  }
406  } else {
407  $sections[$section->getId()] = $section->getLocalizedTitle();
408  }
409  }
410 
411  return $sections;
412  }
413 
420  function sectionExists($sectionId, $journalId) {
421  $result = $this->retrieve(
422  'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
423  array((int) $sectionId, (int) $journalId)
424  );
425  $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
426 
427  $result->Close();
428  return $returner;
429  }
430 
435  function resequenceSections($journalId) {
436  $result = $this->retrieve(
437  'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
438  (int) $journalId
439  );
440 
441  for ($i=1; !$result->EOF; $i++) {
442  list($sectionId) = $result->fields;
443  $this->update(
444  'UPDATE sections SET seq = ? WHERE section_id = ?',
445  array(
446  $i,
447  $sectionId
448  )
449  );
450 
451  $result->MoveNext();
452  }
453  $result->Close();
454  }
455 
460  function getInsertId() {
461  return $this->_getInsertId('sections', 'section_id');
462  }
463 
468  function deleteCustomSectionOrdering($issueId) {
469  return $this->update(
470  'DELETE FROM custom_section_orders WHERE issue_id = ?', (int) $issueId
471  );
472  }
473 
479  function deleteCustomSection($issueId, $sectionId) {
480  $seq = $this->getCustomSectionOrder($issueId, $sectionId);
481 
482  $this->update(
483  'DELETE FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
484  array((int) $issueId, (int) $sectionId)
485  );
486 
487  // Reduce the section order of every successive section by one
488  $this->update(
489  'UPDATE custom_section_orders SET seq = seq - 1 WHERE issue_id = ? AND seq > ?',
490  array((int) $issueId, (float) $seq)
491  );
492  }
493 
498  function resequenceCustomSectionOrders($issueId) {
499  $result = $this->retrieve(
500  'SELECT section_id FROM custom_section_orders WHERE issue_id = ? ORDER BY seq',
501  (int) $issueId
502  );
503 
504  for ($i=1; !$result->EOF; $i++) {
505  list($sectionId) = $result->fields;
506  $this->update(
507  'UPDATE custom_section_orders SET seq = ? WHERE section_id = ? AND issue_id = ?',
508  array($i, $sectionId, (int) $issueId)
509  );
510 
511  $result->MoveNext();
512  }
513  $result->Close();
514  }
515 
521  function customSectionOrderingExists($issueId) {
522  $result = $this->retrieve(
523  'SELECT COUNT(*) FROM custom_section_orders WHERE issue_id = ?',
524  (int) $issueId
525  );
526  $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
527  $result->Close();
528  return $returner;
529  }
530 
537  function getCustomSectionOrder($issueId, $sectionId) {
538  $result = $this->retrieve(
539  'SELECT seq FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
540  array((int) $issueId, (int) $sectionId)
541  );
542 
543  $returner = null;
544  if (!$result->EOF) {
545  list($returner) = $result->fields;
546  }
547  $result->Close();
548  return $returner;
549  }
550 
556  function setDefaultCustomSectionOrders($issueId) {
557  $result = $this->retrieve(
558  'SELECT s.section_id FROM sections s, issues i WHERE i.journal_id = s.journal_id AND i.issue_id = ? ORDER BY seq',
559  (int) $issueId
560  );
561 
562  for ($i=1; !$result->EOF; $i++) {
563  list($sectionId) = $result->fields;
564  $this->insertCustomSectionOrder($issueId, $sectionId, $i);
565  $result->MoveNext();
566  }
567 
568  $result->Close();
569  }
570 
577  function insertCustomSectionOrder($issueId, $sectionId, $seq) {
578  $this->update(
579  'INSERT INTO custom_section_orders (section_id, issue_id, seq) VALUES (?, ?, ?)',
580  array((int) $sectionId,(int) $issueId, (float) $seq)
581  );
582  }
583 
591  function moveCustomSectionOrder($issueId, $sectionId, $newPos, $up) {
592  $this->update(
593  'UPDATE custom_section_orders SET seq = ? ' . ($up?'-':'+') . ' 0.5 WHERE issue_id = ? AND section_id = ?',
594  array((float) $newPos, (int) $issueId, (int) $sectionId)
595  );
596  $this->resequenceCustomSectionOrders($issueId);
597  }
598 }
599 
600 ?>
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)
_cacheMiss($cache, $id)
deleteByJournalId($journalId)
getByTitle($sectionTitle, $journalId, $locale=null)
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)
updateDataObjectSettings($tableName, $dataObject, $idArray)
Definition: DAO.inc.php:474
deleteCustomSectionOrdering($issueId)
Wrapper around ADORecordSet providing &quot;factory&quot; features for generating objects from DAOs...
deleteByContextId($contextId)
& getSectionTitles($journalId, $submittableOnly=false)
static getManager()
sectionExists($sectionId, $journalId)
getByJournalId($journalId, $rangeInfo=null)
getCustomSectionOrder($issueId, $sectionId)
getDataObjectSettings($tableName, $idFieldName, $idFieldValue, $dataObject)
Definition: DAO.inc.php:568
deleteById($sectionId, $contextId=null)
update($sql, $params=false, $callHooks=true, $dieOnError=true)
Definition: DAO.inc.php:208
updateObject($section)
deleteCustomSection($issueId, $sectionId)