Open Journal Systems  3.3.0
SectionForm.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.settings.sections.form.PKPSectionForm');
17 
18 class SectionForm extends PKPSectionForm {
19 
25  function __construct($request, $sectionId = null) {
26  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION);
27  parent::__construct(
28  $request,
29  'controllers/grid/settings/sections/form/sectionForm.tpl',
30  $sectionId
31  );
32 
33  // Validation checks for this form
34  $this->addCheck(new FormValidatorLocale($this, 'title', 'required', 'manager.setup.form.section.nameRequired'));
35  $this->addCheck(new FormValidatorLocale($this, 'abbrev', 'required', 'manager.sections.form.abbrevRequired'));
36  $journal = $request->getJournal();
37  $this->addCheck(new FormValidatorCustom($this, 'reviewFormId', 'optional', 'manager.sections.form.reviewFormId', array(DAORegistry::getDAO('ReviewFormDAO'), 'reviewFormExists'), array(ASSOC_TYPE_JOURNAL, $journal->getId())));
38  }
39 
43  function initData() {
44  $request = Application::get()->getRequest();
45  $journal = $request->getJournal();
46 
47  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
48  $sectionId = $this->getSectionId();
49  if ($sectionId) {
50  $section = $sectionDao->getById($sectionId, $journal->getId());
51  }
52 
53  if (isset($section)) {
54  $this->setData(array(
55  'title' => $section->getTitle(null), // Localized
56  'abbrev' => $section->getAbbrev(null), // Localized
57  'reviewFormId' => $section->getReviewFormId(),
58  'isInactive' => $section->getIsInactive(),
59  'metaIndexed' => !$section->getMetaIndexed(), // #2066: Inverted
60  'metaReviewed' => !$section->getMetaReviewed(), // #2066: Inverted
61  'abstractsNotRequired' => $section->getAbstractsNotRequired(),
62  'identifyType' => $section->getIdentifyType(null), // Localized
63  'editorRestriction' => $section->getEditorRestricted(),
64  'hideTitle' => $section->getHideTitle(),
65  'hideAuthor' => $section->getHideAuthor(),
66  'policy' => $section->getPolicy(null), // Localized
67  'wordCount' => $section->getAbstractWordCount(),
68  'assignedSubeditors' => Services::get('user')->getIds([
69  'contextId' => Application::get()->getRequest()->getContext()->getId(),
70  'roleIds' => ROLE_ID_SUB_EDITOR,
71  'assignedToSection' => (int) $this->getSectionId(),
72  ]),
73  ));
74  } else {
75  $this->setData([
76  'assignedSubeditors' => [],
77  ]);
78  }
79 
80  parent::initData();
81  }
82 
86  function validate($callHooks = true) {
87  // Validate if it can be inactive
88  if ($this->getData('isInactive')) {
89  $request = Application::get()->getRequest();
90  $context = $request->getContext();
91  $sectionId = $this->getSectionId();
92 
93  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
94  $sectionsIterator = $sectionDao->getByContextId($context->getId());
95  $activeSectionsCount = 0;
96  while ($section = $sectionsIterator->next()) {
97  if (!$section->getIsInactive() && ($sectionId != $section->getId())) {
98  $activeSectionsCount++;
99  }
100  }
101  if ($activeSectionsCount < 1 && $this->getData('isInactive')) {
102  $this->addError('isInactive', __('manager.sections.confirmDeactivateSection.error'));
103  }
104  }
105 
106  return parent::validate($callHooks);
107  }
108 
112  function fetch($request, $template = null, $display = false) {
113  $templateMgr = TemplateManager::getManager($request);
114  $templateMgr->assign('sectionId', $this->getSectionId());
115 
116  $journal = $request->getJournal();
117 
118  $reviewFormDao = DAORegistry::getDAO('ReviewFormDAO'); /* @var $reviewFormDao ReviewFormDAO */
119  $reviewForms = $reviewFormDao->getActiveByAssocId(ASSOC_TYPE_JOURNAL, $journal->getId());
120  $reviewFormOptions = array();
121  while ($reviewForm = $reviewForms->next()) {
122  $reviewFormOptions[$reviewForm->getId()] = $reviewForm->getLocalizedTitle();
123  }
124  $templateMgr->assign('reviewFormOptions', $reviewFormOptions);
125 
126  return parent::fetch($request, $template, $display);
127  }
128 
132  function readInputData() {
133  parent::readInputData();
134  $this->readUserVars(array('abbrev', 'policy', 'reviewFormId', 'identifyType', 'isInactive', 'metaIndexed', 'metaReviewed', 'abstractsNotRequired', 'editorRestriction', 'hideTitle', 'hideAuthor', 'wordCount'));
135  }
136 
141  function getLocaleFieldNames() {
142  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
143  return $sectionDao->getLocaleFieldNames();
144  }
145 
150  function execute(...$functionArgs) {
151  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
152  $request = Application::get()->getRequest();
153  $journal = $request->getJournal();
154 
155  // Get or create the section object
156  if ($this->getSectionId()) {
157  $section = $sectionDao->getById($this->getSectionId(), $journal->getId());
158  } else {
159  import('classes.journal.Section');
160  $section = $sectionDao->newDataObject();
161  $section->setJournalId($journal->getId());
162  }
163 
164  // Populate/update the section object from the form
165  $section->setTitle($this->getData('title'), null); // Localized
166  $section->setAbbrev($this->getData('abbrev'), null); // Localized
167  $reviewFormId = $this->getData('reviewFormId');
168  if ($reviewFormId === '') $reviewFormId = null;
169  $section->setReviewFormId($reviewFormId);
170  $section->setIsInactive($this->getData('isInactive') ? 1 : 0);
171  $section->setMetaIndexed($this->getData('metaIndexed') ? 0 : 1); // #2066: Inverted
172  $section->setMetaReviewed($this->getData('metaReviewed') ? 0 : 1); // #2066: Inverted
173  $section->setAbstractsNotRequired($this->getData('abstractsNotRequired') ? 1 : 0);
174  $section->setIdentifyType($this->getData('identifyType'), null); // Localized
175  $section->setEditorRestricted($this->getData('editorRestriction') ? 1 : 0);
176  $section->setHideTitle($this->getData('hideTitle') ? 1 : 0);
177  $section->setHideAuthor($this->getData('hideAuthor') ? 1 : 0);
178  $section->setPolicy($this->getData('policy'), null); // Localized
179  $section->setAbstractWordCount($this->getData('wordCount'));
180 
181  // Insert or update the section in the DB
182  if ($this->getSectionId()) {
183  $sectionDao->updateObject($section);
184  } else {
185  $section->setSequence(REALLY_BIG_NUMBER);
186  $this->setSectionId($sectionDao->insertObject($section));
187  $sectionDao->resequenceSections($journal->getId());
188  }
189 
190  return parent::execute(...$functionArgs);
191  }
192 }
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PKPSectionForm
Form for adding/editing a section.
Definition: PKPSectionForm.inc.php:18
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
FormValidatorLocale
Class to represent a form validation check for localized fields.
Definition: FormValidatorLocale.inc.php:16
SectionForm\fetch
fetch($request, $template=null, $display=false)
Definition: SectionForm.inc.php:112
Form\setData
setData($key, $value=null)
Definition: Form.inc.php:229
SectionForm\initData
initData()
Definition: SectionForm.inc.php:43
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
SectionForm
Form for adding/editing a section.
Definition: SectionForm.inc.php:18
Form\getData
getData($key)
Definition: Form.inc.php:220
SectionForm\getLocaleFieldNames
getLocaleFieldNames()
Definition: SectionForm.inc.php:141
SectionForm\execute
execute(... $functionArgs)
Definition: SectionForm.inc.php:150
Form\addError
addError($field, $message)
Definition: Form.inc.php:404
PKPSectionForm\setSectionId
setSectionId($sectionId)
Definition: PKPSectionForm.inc.php:80
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
SectionForm\__construct
__construct($request, $sectionId=null)
Definition: SectionForm.inc.php:25
PKPSectionForm\getSectionId
getSectionId()
Definition: PKPSectionForm.inc.php:72
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
FormValidatorCustom
Form validation check with a custom user function performing the validation check.
Definition: FormValidatorCustom.inc.php:18
SectionForm\readInputData
readInputData()
Definition: SectionForm.inc.php:132
SectionForm\validate
validate($callHooks=true)
Definition: SectionForm.inc.php:86
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49