00001 <?php
00002
00015
00016
00017
00018 import('form.Form');
00019
00020 class SectionForm extends Form {
00021
00023 var $sectionId;
00024
00028 var $includeSectionEditor;
00029
00033 var $omitSectionEditor;
00034
00038 var $sectionEditors;
00039
00044 function SectionForm($sectionId = null) {
00045 parent::Form('manager/sections/sectionForm.tpl');
00046
00047 $journal =& Request::getJournal();
00048 $this->sectionId = $sectionId;
00049
00050
00051 $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'manager.sections.form.titleRequired'));
00052 $this->addCheck(new FormValidatorLocale($this, 'abbrev', 'required', 'manager.sections.form.abbrevRequired'));
00053 $this->addCheck(new FormValidatorPost($this));
00054 $this->addCheck(new FormValidatorCustom($this, 'reviewFormId', 'optional', 'manager.sections.form.reviewFormId', array(DAORegistry::getDAO('ReviewFormDAO'), 'reviewFormExists'), array($journal->getJournalId())));
00055
00056 $this->includeSectionEditor = $this->omitSectionEditor = null;
00057
00058
00059 $roleDao =& DAORegistry::getDAO('RoleDAO');
00060 $this->sectionEditors =& $roleDao->getUsersByRoleId(ROLE_ID_SECTION_EDITOR, $journal->getJournalId());
00061 $this->sectionEditors =& $this->sectionEditors->toArray();
00062 }
00063
00069 function includeSectionEditor($sectionEditorId) {
00070 foreach ($this->sectionEditors as $key => $junk) {
00071 if ($this->sectionEditors[$key]->getUserId() == $sectionEditorId) {
00072 $this->includeSectionEditor =& $this->sectionEditors[$key];
00073 }
00074 }
00075 }
00076
00081 function omitSectionEditor($sectionEditorId) {
00082 foreach ($this->sectionEditors as $key => $junk) {
00083 if ($this->sectionEditors[$key]->getUserId() == $sectionEditorId) {
00084 $this->omitSectionEditor =& $this->sectionEditors[$key];
00085 }
00086 }
00087 }
00088
00093 function getLocaleFieldNames() {
00094 $sectionDao =& DAORegistry::getDAO('SectionDAO');
00095 return $sectionDao->getLocaleFieldNames();
00096 }
00097
00101 function display() {
00102 $journal =& Request::getJournal();
00103 $templateMgr = &TemplateManager::getManager();
00104
00105 $templateMgr->assign('sectionId', $this->sectionId);
00106 $templateMgr->assign('commentsEnabled', $journal->getSetting('enableComments'));
00107 $templateMgr->assign('helpTopicId','journal.managementPages.sections');
00108
00109 $reviewFormDao =& DAORegistry::getDAO('ReviewFormDAO');
00110 $reviewForms =& $reviewFormDao->getJournalActiveReviewForms($journal->getJournalId());
00111 $reviewFormOptions = array();
00112 while ($reviewForm =& $reviewForms->next()) {
00113 $reviewFormOptions[$reviewForm->getReviewFormId()] = $reviewForm->getReviewFormTitle();
00114 }
00115 $templateMgr->assign_by_ref('reviewFormOptions', $reviewFormOptions);
00116
00117 parent::display();
00118 }
00119
00123 function initData() {
00124 if (isset($this->sectionId)) {
00125 $journal = &Request::getJournal();
00126 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00127 $section = &$sectionDao->getSection($this->sectionId, $journal->getJournalId());
00128
00129 if ($section == null) {
00130 unset($this->sectionId);
00131 } else {
00132 $sectionEditorsDao =& DAORegistry::getDAO('SectionEditorsDAO');
00133 $this->_data = array(
00134 'title' => $section->getTitle(null),
00135 'abbrev' => $section->getAbbrev(null),
00136 'reviewFormId' => $section->getReviewFormId(),
00137 'metaIndexed' => !$section->getMetaIndexed(),
00138 'metaReviewed' => !$section->getMetaReviewed(),
00139 'abstractsNotRequired' => $section->getAbstractsNotRequired(),
00140 'identifyType' => $section->getIdentifyType(null),
00141 'editorRestriction' => $section->getEditorRestricted(),
00142 'hideTitle' => $section->getHideTitle(),
00143 'hideAuthor' => $section->getHideAuthor(),
00144 'hideAbout' => $section->getHideAbout(),
00145 'disableComments' => $section->getDisableComments(),
00146 'policy' => $section->getPolicy(null),
00147 'assignedEditors' => $sectionEditorsDao->getEditorsBySectionId($journal->getJournalId(), $this->sectionId),
00148 'unassignedEditors' => $sectionEditorsDao->getEditorsNotInSection($journal->getJournalId(), $this->sectionId)
00149 );
00150 }
00151 }
00152 }
00153
00157 function readInputData() {
00158 $this->readUserVars(array('title', 'abbrev', 'policy', 'reviewFormId', 'identifyType', 'metaIndexed', 'metaReviewed', 'abstractsNotRequired', 'editorRestriction', 'hideTitle', 'hideAuthor', 'hideAbout', 'disableComments'));
00159 $assignedEditorIds = Request::getUserVar('assignedEditorIds');
00160 if (empty($assignedEditorIds)) $assignedEditorIds = array();
00161 elseif (!is_array($assignedEditorIds)) $assignedEditorIds = array($assignedEditorIds);
00162
00163 $assignedEditors = $unassignedEditors = array();
00164
00165 foreach ($this->sectionEditors as $key => $junk) {
00166 $sectionEditor =& $this->sectionEditors[$key];
00167 $userId = $sectionEditor->getUserId();
00168
00169 $isIncludeEditor = $this->includeSectionEditor && $this->includeSectionEditor->getUserId() == $userId;
00170 $isOmitEditor = $this->omitSectionEditor && $this->omitSectionEditor->getUserId() == $userId;
00171 if ((in_array($userId, $assignedEditorIds) || $isIncludeEditor) && !$isOmitEditor) {
00172 $assignedEditors[] = array(
00173 'user' => &$sectionEditor,
00174 'canReview' => (Request::getUserVar('canReview' . $userId)?1:0),
00175 'canEdit' => (Request::getUserVar('canEdit' . $userId)?1:0)
00176 );
00177 } else {
00178 $unassignedEditors[] =& $sectionEditor;
00179 }
00180
00181 unset($sectionEditor);
00182 }
00183
00184 $this->setData('assignedEditors', $assignedEditors);
00185 $this->setData('unassignedEditors', $unassignedEditors);
00186 }
00187
00191 function execute() {
00192 $journal = &Request::getJournal();
00193 $journalId = $journal->getJournalId();
00194
00195 $sectionDao = &DAORegistry::getDAO('SectionDAO');
00196
00197 if (isset($this->sectionId)) {
00198 $section = &$sectionDao->getSection($this->sectionId, $journalId);
00199 }
00200
00201 if (!isset($section)) {
00202 $section = &new Section();
00203 $section->setJournalId($journalId);
00204 $section->setSequence(REALLY_BIG_NUMBER);
00205 }
00206
00207 $section->setTitle($this->getData('title'), null);
00208 $section->setAbbrev($this->getData('abbrev'), null);
00209 $section->setReviewFormId($this->getData('reviewFormId'));
00210 $section->setMetaIndexed($this->getData('metaIndexed') ? 0 : 1);
00211 $section->setMetaReviewed($this->getData('metaReviewed') ? 0 : 1);
00212 $section->setAbstractsNotRequired($this->getData('abstractsNotRequired') ? 1 : 0);
00213 $section->setIdentifyType($this->getData('identifyType'), null);
00214 $section->setEditorRestricted($this->getData('editorRestriction') ? 1 : 0);
00215 $section->setHideTitle($this->getData('hideTitle') ? 1 : 0);
00216 $section->setHideAuthor($this->getData('hideAuthor') ? 1 : 0);
00217 $section->setHideAbout($this->getData('hideAbout') ? 1 : 0);
00218 $section->setDisableComments($this->getData('disableComments') ? 1 : 0);
00219 $section->setPolicy($this->getData('policy'), null);
00220
00221 if ($section->getSectionId() != null) {
00222 $sectionDao->updateSection($section);
00223 $sectionId = $section->getSectionId();
00224
00225 } else {
00226 $sectionId = $sectionDao->insertSection($section);
00227 $sectionDao->resequenceSections($journalId);
00228 }
00229
00230
00231 $assignedEditorIds = Request::getUserVar('assignedEditorIds');
00232 if (empty($assignedEditorIds)) $assignedEditorIds = array();
00233 elseif (!is_array($assignedEditorIds)) $assignedEditorIds = array($assignedEditorIds);
00234 $sectionEditorsDao = &DAORegistry::getDAO('SectionEditorsDAO');
00235 $sectionEditorsDao->deleteEditorsBySectionId($sectionId, $journalId);
00236 foreach ($this->sectionEditors as $key => $junk) {
00237 $sectionEditor =& $this->sectionEditors[$key];
00238 $userId = $sectionEditor->getUserId();
00239
00240
00241
00242
00243 if (in_array($userId, $assignedEditorIds)) $sectionEditorsDao->insertEditor(
00244 $journalId,
00245 $sectionId,
00246 $userId,
00247 Request::getUserVar('canReview' . $userId),
00248 Request::getUserVar('canEdit' . $userId)
00249 );
00250 unset($sectionEditor);
00251 }
00252 }
00253 }
00254
00255 ?>