00001 <?php
00002
00016
00017
00018
00019 import ('journal.Section');
00020
00021 class SectionDAO extends DAO {
00027 function &getSection($sectionId, $journalId = null) {
00028 $sql = 'SELECT * FROM sections WHERE section_id = ?';
00029 $params = array($sectionId);
00030 if ($journalId !== null) {
00031 $sql .= ' AND journal_id = ?';
00032 $params[] = $journalId;
00033 }
00034 $result = &$this->retrieve($sql, $params);
00035
00036 $returner = null;
00037 if ($result->RecordCount() != 0) {
00038 $returner = &$this->_returnSectionFromRow($result->GetRowAssoc(false));
00039 }
00040
00041 $result->Close();
00042 unset($result);
00043
00044 return $returner;
00045 }
00046
00053 function &getSectionByAbbrev($sectionAbbrev, $journalId, $locale = null) {
00054 $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 = ?';
00055 $params = array('abbrev', $sectionAbbrev, $journalId);
00056 if ($locale !== null) {
00057 $sql .= ' AND l.locale = ?';
00058 $params[] = $locale;
00059 }
00060
00061 $result = &$this->retrieve($sql, $params);
00062
00063 $returner = null;
00064 if ($result->RecordCount() != 0) {
00065 $returner = &$this->_returnSectionFromRow($result->GetRowAssoc(false));
00066 }
00067
00068 $result->Close();
00069 unset($result);
00070
00071 return $returner;
00072 }
00073
00079 function &getSectionByTitle($sectionTitle, $journalId, $locale = null) {
00080 $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 = ?';
00081 $params = array('title', $sectionTitle, $journalId);
00082 if ($locale !== null) {
00083 $sql .= ' AND l.locale = ?';
00084 $params[] = $locale;
00085 }
00086
00087 $result = &$this->retrieve($sql, $params);
00088
00089 $returner = null;
00090 if ($result->RecordCount() != 0) {
00091 $returner = &$this->_returnSectionFromRow($result->GetRowAssoc(false));
00092 }
00093
00094 $result->Close();
00095 unset($result);
00096
00097 return $returner;
00098 }
00099
00107 function &getSectionByTitleAndAbbrev($sectionTitle, $sectionAbbrev, $journalId, $locale) {
00108 $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 = ?';
00109 $params = array('title', 'abbrev', $sectionTitle, $sectionAbbrev, $journalId);
00110 if ($locale !== null) {
00111 $sql .= ' AND l1.locale = ? AND l2.locale = ?';
00112 $params[] = $locale;
00113 $params[] = $locale;
00114 }
00115
00116 $result = &$this->retrieve($sql, $params);
00117
00118 $returner = null;
00119 if ($result->RecordCount() != 0) {
00120 $returner = &$this->_returnSectionFromRow($result->GetRowAssoc(false));
00121 }
00122
00123 $result->Close();
00124 unset($result);
00125
00126 return $returner;
00127 }
00128
00134 function &_returnSectionFromRow(&$row) {
00135 $section = &new Section();
00136 $section->setSectionId($row['section_id']);
00137 $section->setJournalId($row['journal_id']);
00138 $section->setReviewFormId($row['review_form_id']);
00139 $section->setSequence($row['seq']);
00140 $section->setMetaIndexed($row['meta_indexed']);
00141 $section->setMetaReviewed($row['meta_reviewed']);
00142 $section->setAbstractsNotRequired($row['abstracts_not_required']);
00143 $section->setEditorRestricted($row['editor_restricted']);
00144 $section->setHideTitle($row['hide_title']);
00145 $section->setHideAuthor($row['hide_author']);
00146 $section->setHideAbout($row['hide_about']);
00147 $section->setDisableComments($row['disable_comments']);
00148
00149 $this->getDataObjectSettings('section_settings', 'section_id', $row['section_id'], $section);
00150
00151 HookRegistry::call('SectionDAO::_returnSectionFromRow', array(&$section, &$row));
00152
00153 return $section;
00154 }
00155
00160 function getLocaleFieldNames() {
00161 return array('title', 'abbrev', 'policy', 'identifyType');
00162 }
00163
00168 function updateLocaleFields(&$section) {
00169 $this->updateDataObjectSettings('section_settings', $section, array(
00170 'section_id' => $section->getSectionId()
00171 ));
00172 }
00173
00178 function insertSection(&$section) {
00179 $this->update(
00180 'INSERT INTO sections
00181 (journal_id, review_form_id, seq, meta_indexed, meta_reviewed, abstracts_not_required, editor_restricted, hide_title, hide_author, hide_about, disable_comments)
00182 VALUES
00183 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)',
00184 array(
00185 $section->getJournalId(),
00186 $section->getReviewFormId(),
00187 $section->getSequence() == null ? 0 : $section->getSequence(),
00188 $section->getMetaIndexed() ? 1 : 0,
00189 $section->getMetaReviewed() ? 1 : 0,
00190 $section->getAbstractsNotRequired() ? 1 : 0,
00191 $section->getEditorRestricted() ? 1 : 0,
00192 $section->getHideTitle() ? 1 : 0,
00193 $section->getHideAuthor() ? 1 : 0,
00194 $section->getHideAbout() ? 1 : 0,
00195 $section->getDisableComments() ? 1 : 0
00196 )
00197 );
00198
00199 $section->setSectionId($this->getInsertSectionId());
00200 $this->updateLocaleFields($section);
00201 return $section->getSectionId();
00202 }
00203
00208 function updateSection(&$section) {
00209 $returner = $this->update(
00210 'UPDATE sections
00211 SET
00212 review_form_id = ?,
00213 seq = ?,
00214 meta_indexed = ?,
00215 meta_reviewed = ?,
00216 abstracts_not_required = ?,
00217 editor_restricted = ?,
00218 hide_title = ?,
00219 hide_author = ?,
00220 hide_about = ?,
00221 disable_comments = ?
00222 WHERE section_id = ?',
00223 array(
00224 $section->getReviewFormId(),
00225 $section->getSequence(),
00226 $section->getMetaIndexed(),
00227 $section->getMetaReviewed(),
00228 $section->getAbstractsNotRequired(),
00229 $section->getEditorRestricted(),
00230 $section->getHideTitle(),
00231 $section->getHideAuthor(),
00232 $section->getHideAbout(),
00233 $section->getDisableComments(),
00234 $section->getSectionId()
00235 )
00236 );
00237 $this->updateLocaleFields($section);
00238 return $returner;
00239 }
00240
00245 function deleteSection(&$section) {
00246 return $this->deleteSectionById($section->getSectionId(), $section->getJournalId());
00247 }
00248
00254 function deleteSectionById($sectionId, $journalId = null) {
00255 $sectionEditorsDao = &DAORegistry::getDAO('SectionEditorsDAO');
00256 $sectionEditorsDao->deleteEditorsBySectionId($sectionId, $journalId);
00257
00258
00259 $articleDao = &DAORegistry::getDAO('ArticleDAO');
00260 $articleDao->removeArticlesFromSection($sectionId);
00261
00262
00263
00264 $publishedArticleDao = &DAORegistry::getDAO('PublishedArticleDAO');
00265 $publishedArticleDao->deletePublishedArticlesBySectionId($sectionId);
00266
00267 if (isset($journalId) && !$this->sectionExists($sectionId, $journalId)) return false;
00268 $this->update('DELETE FROM section_settings WHERE section_id = ?', array($sectionId));
00269 return $this->update('DELETE FROM sections WHERE section_id = ?', array($sectionId));
00270 }
00271
00278 function deleteSectionsByJournal($journalId) {
00279 $sections =& $this->getJournalSections($journalId);
00280 while (($section =& $sections->next())) {
00281 $this->deleteSection($section);
00282 unset($section);
00283 }
00284 }
00285
00291 function &getEditorSections($journalId) {
00292 $returner = array();
00293
00294 $result = &$this->retrieve(
00295 '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 = ?',
00296 $journalId
00297 );
00298
00299 while (!$result->EOF) {
00300 $row = $result->GetRowAssoc(false);
00301 $section = &$this->_returnSectionFromRow($row);
00302 if (!isset($returner[$row['editor_id']])) {
00303 $returner[$row['editor_id']] = array($section);
00304 } else {
00305 $returner[$row['editor_id']][] = $section;
00306 }
00307 $result->moveNext();
00308 }
00309
00310 $result->Close();
00311 unset($result);
00312
00313 return $returner;
00314 }
00315
00321 function &getSectionsForIssue($issueId) {
00322 $returner = array();
00323
00324 $result = &$this->retrieve(
00325 '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',
00326 array($issueId, $issueId)
00327 );
00328
00329 while (!$result->EOF) {
00330 $row = $result->GetRowAssoc(false);
00331 $returner[] = &$this->_returnSectionFromRow($row);
00332 $result->moveNext();
00333 }
00334
00335 $result->Close();
00336 unset($result);
00337
00338 return $returner;
00339 }
00340
00345 function &getJournalSections($journalId, $rangeInfo = null) {
00346 $result = &$this->retrieveRange(
00347 'SELECT * FROM sections WHERE journal_id = ? ORDER BY seq',
00348 $journalId, $rangeInfo
00349 );
00350
00351 $returner = &new DAOResultFactory($result, $this, '_returnSectionFromRow');
00352 return $returner;
00353 }
00354
00359 function &getSectionTitles($journalId, $submittableOnly = false) {
00360 $sections = array();
00361
00362 $sectionsIterator =& $this->getJournalSections($journalId);
00363 while (($section =& $sectionsIterator->next())) {
00364 if ($submittableOnly) {
00365 if (!$section->getEditorRestricted()) {
00366 $sections[$section->getSectionId()] = $section->getSectionTitle();
00367 }
00368 } else {
00369 $sections[$section->getSectionId()] = $section->getSectionTitle();
00370 }
00371 unset($section);
00372 }
00373
00374 return $sections;
00375 }
00376
00383 function sectionExists($sectionId, $journalId) {
00384 $result = &$this->retrieve(
00385 'SELECT COUNT(*) FROM sections WHERE section_id = ? AND journal_id = ?',
00386 array($sectionId, $journalId)
00387 );
00388 $returner = isset($result->fields[0]) && $result->fields[0] == 1 ? true : false;
00389
00390 $result->Close();
00391 unset($result);
00392
00393 return $returner;
00394 }
00395
00400 function resequenceSections($journalId) {
00401 $result = &$this->retrieve(
00402 'SELECT section_id FROM sections WHERE journal_id = ? ORDER BY seq',
00403 $journalId
00404 );
00405
00406 for ($i=1; !$result->EOF; $i++) {
00407 list($sectionId) = $result->fields;
00408 $this->update(
00409 'UPDATE sections SET seq = ? WHERE section_id = ?',
00410 array(
00411 $i,
00412 $sectionId
00413 )
00414 );
00415
00416 $result->moveNext();
00417 }
00418
00419 $result->close();
00420 unset($result);
00421 }
00422
00427 function getInsertSectionId() {
00428 return $this->getInsertId('sections', 'section_id');
00429 }
00430
00435 function deleteCustomSectionOrdering($issueId) {
00436 return $this->update(
00437 'DELETE FROM custom_section_orders WHERE issue_id = ?', $issueId
00438 );
00439 }
00440
00445 function resequenceCustomSectionOrders($issueId) {
00446 $result = &$this->retrieve(
00447 'SELECT section_id FROM custom_section_orders WHERE issue_id = ? ORDER BY seq',
00448 $issueId
00449 );
00450
00451 for ($i=1; !$result->EOF; $i++) {
00452 list($sectionId) = $result->fields;
00453 $this->update(
00454 'UPDATE custom_section_orders SET seq = ? WHERE section_id = ? AND issue_id = ?',
00455 array($i, $sectionId, $issueId)
00456 );
00457
00458 $result->moveNext();
00459 }
00460
00461 $result->close();
00462 unset($result);
00463 }
00464
00470 function customSectionOrderingExists($issueId) {
00471 $result = &$this->retrieve(
00472 'SELECT COUNT(*) FROM custom_section_orders WHERE issue_id = ?',
00473 $issueId
00474 );
00475 $returner = isset($result->fields[0]) && $result->fields[0] == 0 ? false : true;
00476
00477 $result->Close();
00478 unset($result);
00479
00480 return $returner;
00481 }
00482
00489 function getCustomSectionOrder($issueId, $sectionId) {
00490 $result = &$this->retrieve(
00491 'SELECT seq FROM custom_section_orders WHERE issue_id = ? AND section_id = ?',
00492 array($issueId, $sectionId)
00493 );
00494
00495 $returner = null;
00496 if (!$result->EOF) {
00497 list($returner) = $result->fields;
00498 }
00499 $result->Close();
00500 unset($result);
00501
00502 return $returner;
00503 }
00504
00510 function setDefaultCustomSectionOrders($issueId) {
00511 $result = &$this->retrieve(
00512 'SELECT s.section_id FROM sections s, issues i WHERE i.journal_id = s.journal_id AND i.issue_id = ? ORDER BY seq',
00513 $issueId
00514 );
00515
00516 for ($i=1; !$result->EOF; $i++) {
00517 list($sectionId) = $result->fields;
00518 $this->insertCustomSectionOrder($issueId, $sectionId, $i);
00519 $result->moveNext();
00520 }
00521
00522 $result->close();
00523 unset($result);
00524 }
00525
00532 function insertCustomSectionOrder($issueId, $sectionId, $seq) {
00533 $this->update(
00534 'INSERT INTO custom_section_orders (section_id, issue_id, seq) VALUES (?, ?, ?)',
00535 array(
00536 $sectionId,
00537 $issueId,
00538 $seq
00539 )
00540 );
00541 }
00542
00550 function moveCustomSectionOrder($issueId, $sectionId, $newPos, $up) {
00551 $this->update(
00552 'UPDATE custom_section_orders SET seq = ? ' . ($up?'-':'+') . ' 0.5 WHERE issue_id = ? AND section_id = ?',
00553 array($newPos, $issueId, $sectionId)
00554 );
00555 $this->resequenceCustomSectionOrders($issueId);
00556 }
00557 }
00558
00559 ?>