Open Preprint 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  $this->addCheck(new FormValidator($this, 'path', 'required', 'manager.setup.form.section.pathRequired'));
37  $journal = $request->getJournal();
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  return parent::fetch($request, $template, $display);
117  }
118 
122  function readInputData() {
123  parent::readInputData();
124  $this->readUserVars(array('abbrev', 'path', 'description', 'policy', 'identifyType', 'isInactive', 'metaIndexed', 'abstractsNotRequired', 'editorRestriction', 'wordCount'));
125  }
126 
131  function getLocaleFieldNames() {
132  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
133  return $sectionDao->getLocaleFieldNames();
134  }
135 
140  function execute(...$functionArgs) {
141  $sectionDao = DAORegistry::getDAO('SectionDAO'); /* @var $sectionDao SectionDAO */
142  $request = Application::get()->getRequest();
143  $journal = $request->getJournal();
144 
145  // Get or create the section object
146  if ($this->getSectionId()) {
147  $section = $sectionDao->getById($this->getSectionId(), $journal->getId());
148  } else {
149  import('classes.journal.Section');
150  $section = $sectionDao->newDataObject();
151  $section->setJournalId($journal->getId());
152  }
153 
154  // Populate/update the section object from the form
155  $section->setTitle($this->getData('title'), null); // Localized
156  $section->setAbbrev($this->getData('abbrev'), null); // Localized
157  $section->setPath($this->getData('path'));
158  $section->setDescription($this->getData('description'), null); // Localized
159  $section->setIsInactive($this->getData('isInactive') ? 1 : 0);
160  $section->setMetaIndexed($this->getData('metaIndexed') ? 0 : 1); // #2066: Inverted
161  $section->setAbstractsNotRequired($this->getData('abstractsNotRequired') ? 1 : 0);
162  $section->setIdentifyType($this->getData('identifyType'), null); // Localized
163  $section->setEditorRestricted($this->getData('editorRestriction') ? 1 : 0);
164  $section->setPolicy($this->getData('policy'), null); // Localized
165  $section->setAbstractWordCount($this->getData('wordCount'));
166 
167  // Insert or update the section in the DB
168  if ($this->getSectionId()) {
169  $sectionDao->updateObject($section);
170  } else {
171  $section->setSequence(REALLY_BIG_NUMBER);
172  $this->setSectionId($sectionDao->insertObject($section));
173  $sectionDao->resequenceSections($journal->getId());
174  }
175 
176  return parent::execute(...$functionArgs);
177  }
178 }
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:131
SectionForm\execute
execute(... $functionArgs)
Definition: SectionForm.inc.php:140
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:1226
FormValidator
Class to represent a form validation check.
Definition: FormValidator.inc.php:23
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
SectionForm\readInputData
readInputData()
Definition: SectionForm.inc.php:122
SectionForm\validate
validate($callHooks=true)
Definition: SectionForm.inc.php:86
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49