Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PKPSubmissionSubmitStep1Form.inc.php
1 <?php
2 
16 import('lib.pkp.classes.submission.form.SubmissionSubmitForm');
17 
24  function PKPSubmissionSubmitStep1Form($context, $submission = null) {
25  parent::SubmissionSubmitForm($context, $submission, 1);
26 
27  // Validation checks for this form
28  $supportedSubmissionLocales = $context->getSupportedSubmissionLocales();
29  if (!is_array($supportedSubmissionLocales) || count($supportedSubmissionLocales) < 1) $supportedSubmissionLocales = array($context->getPrimaryLocale());
30  $this->addCheck(new FormValidatorInSet($this, 'locale', 'required', 'submission.submit.form.localeRequired', $supportedSubmissionLocales));
31  if ((boolean) $context->getSetting('copyrightNoticeAgree')) {
32  $this->addCheck(new FormValidator($this, 'copyrightNoticeAgree', 'required', 'submission.submit.copyrightNoticeAgreeRequired'));
33  }
34  $this->addCheck(new FormValidator($this, 'authorUserGroupId', 'required', 'user.authorization.userGroupRequired'));
35 
36  foreach ($context->getLocalizedSetting('submissionChecklist') as $key => $checklistItem) {
37  $this->addCheck(new FormValidator($this, "checklist-$key", 'required', 'submission.submit.checklistErrors'));
38  }
39  }
40 
45  function validate() {
46  if (!parent::validate()) return false;
47 
48  // Ensure that the user is in the specified authorUserGroupId
49  $authorUserGroupId = $this->getData('authorUserGroupId');
50  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
51  $request = Application::getRequest();
52  $context = $request->getContext();
53  $user = $request->getUser();
54  if (!$user) return false;
55 
56  $userGroups = $userGroupDao->getByUserId($user->getId(), $context->getId());
57  while ($userGroup = $userGroups->next()) {
58  if ($userGroup->getId() == $authorUserGroupId) return true;
59  }
60  return false;
61  }
62 
66  function fetch($request) {
67  $user = $request->getUser();
68  $templateMgr = TemplateManager::getManager($request);
69 
70  $templateMgr->assign(
71  'supportedSubmissionLocaleNames',
72  $this->context->getSupportedSubmissionLocaleNames()
73  );
74 
75  // if this context has a copyright notice that the author must agree to, present the form items.
76  if ((boolean) $this->context->getSetting('copyrightNoticeAgree')) {
77  $templateMgr->assign('copyrightNotice', $this->context->getLocalizedSetting('copyrightNotice'));
78  $templateMgr->assign('copyrightNoticeAgree', true);
79  }
80 
81  // Get list of user's author user groups. If its more than one, we'll need to display an author user group selector
82  $userGroupAssignmentDao = DAORegistry::getDAO('UserGroupAssignmentDAO');
83  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
84  $authorUserGroupAssignments = $userGroupAssignmentDao->getByUserId($user->getId(), $this->context->getId(), ROLE_ID_AUTHOR);
85  $userGroupNames = array();
86  if (!$authorUserGroupAssignments->wasEmpty()) {
87  while($authorUserGroupAssignment = $authorUserGroupAssignments->next()) {
88  $authorUserGroup = $userGroupDao->getById($authorUserGroupAssignment->getUserGroupId());
89  if ($userGroupDao->userGroupAssignedToStage($authorUserGroup->getId(), WORKFLOW_STAGE_ID_SUBMISSION)) {
90  $userGroupNames[$authorUserGroup->getId()] = $authorUserGroup->getLocalizedName();
91  }
92  }
93  $templateMgr->assign('authorUserGroupOptions', $userGroupNames);
94  } else {
95  // The user doesn't have any author user group assignments. They should be either a manager.
96  // Add all manager user groups
97  $managerUserGroupAssignments = $userGroupAssignmentDao->getByUserId($user->getId(), $this->context->getId(), ROLE_ID_MANAGER);
98  if($managerUserGroupAssignments) while($managerUserGroupAssignment = $managerUserGroupAssignments->next()) {
99  $managerUserGroup = $userGroupDao->getById($managerUserGroupAssignment->getUserGroupId());
100  $userGroupNames[$managerUserGroup->getId()] = $managerUserGroup->getLocalizedName();
101  }
102 
103  $templateMgr->assign('authorUserGroupOptions', $userGroupNames);
104  }
105 
106  return parent::fetch($request);
107  }
108 
112  function initData($data = array()) {
113  if (isset($this->submission)) {
114  $this->_data = $data + array(
115  'locale' => $this->submission->getLocale(),
116  'commentsToEditor' => $this->submission->getCommentsToEditor(),
117  );
118  } else {
119  $supportedSubmissionLocales = $this->context->getSupportedSubmissionLocales();
120  // Try these locales in order until we find one that's
121  // supported to use as a default.
122  $tryLocales = array(
123  $this->getFormLocale(), // Current form locale
124  AppLocale::getLocale(), // Current UI locale
125  $this->context->getPrimaryLocale(), // Context locale
126  $supportedSubmissionLocales[array_shift(array_keys($supportedSubmissionLocales))] // Fallback: first one on the list
127  );
128  $this->_data = $data;
129  foreach ($tryLocales as $locale) {
130  if (in_array($locale, $supportedSubmissionLocales)) {
131  // Found a default to use
132  $this->_data['locale'] = $locale;
133  break;
134  }
135  }
136  }
137  }
138 
142  function readInputData() {
143  $vars = array(
144  'authorUserGroupId', 'locale', 'copyrightNoticeAgree', 'commentsToEditor', 'copyrightNoticeAgree'
145  );
146  foreach ($this->context->getLocalizedSetting('submissionChecklist') as $key => $checklistItem) {
147  $vars[] = "checklist-$key";
148  }
149 
150  $this->readUserVars($vars);
151  }
152 
158  $this->submission->setLanguage(String::substr($this->submission->getLocale(), 0, 2));
159  $this->submission->setCommentsToEditor($this->getData('commentsToEditor'));
160  $this->submission->setLocale($this->getData('locale'));
161  }
162 
169  function execute($args, $request) {
170  $submissionDao = Application::getSubmissionDAO();
171 
172  if (isset($this->submission)) {
173  // Update existing submission
174  $this->setSubmissionData($this->submission);
175  if ($this->submission->getSubmissionProgress() <= $this->step) {
176  $this->submission->stampStatusModified();
177  $this->submission->setSubmissionProgress($this->step + 1);
178  }
179  $submissionDao->updateObject($this->submission);
180  } else {
181  // Create new submission
182  $this->submission = $submissionDao->newDataObject();
183  $user = $request->getUser();
184  $this->submission->setUserId($user->getId());
185  $this->submission->setContextId($this->context->getId());
186 
187  $this->setSubmissionData($this->submission);
188 
189  $this->submission->stampStatusModified();
190  $this->submission->setSubmissionProgress($this->step + 1);
191  $this->submission->setStageId(WORKFLOW_STAGE_ID_SUBMISSION);
192  $this->submission->setCopyrightNotice($this->context->getLocalizedSetting('copyrightNotice'), $this->getData('locale'));
193  // Insert the submission
194  $this->submissionId = $submissionDao->insertObject($this->submission);
195 
196  // Set user to initial author
197  $authorDao = DAORegistry::getDAO('AuthorDAO');
198  $author = $authorDao->newDataObject();
199  $author->setFirstName($user->getFirstName());
200  $author->setMiddleName($user->getMiddleName());
201  $author->setLastName($user->getLastName());
202  $author->setAffiliation($user->getAffiliation(null), null);
203  $author->setCountry($user->getCountry());
204  $author->setEmail($user->getEmail());
205  $author->setUrl($user->getUrl());
206  $author->setBiography($user->getBiography(null), null);
207  $author->setPrimaryContact(1);
208 
209  // Get the user group to display the submitter as
210  $authorUserGroupId = (int) $this->getData('authorUserGroupId');
211  $author->setUserGroupId($authorUserGroupId);
212 
213  $author->setSubmissionId($this->submissionId);
214  $authorDao->insertObject($author);
215 
216  // Assign the user author to the stage
217  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
218  $stageAssignmentDao->build($this->submissionId, $authorUserGroupId, $user->getId());
219  }
220 
221  return $this->submissionId;
222  }
223 }
224 
225 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
static substr($string, $start, $length=false)
Definition: String.inc.php:187
getFormLocale()
Definition: Form.inc.php:352
readUserVars($vars)
Definition: Form.inc.php:364
PKPSubmissionSubmitStep1Form($context, $submission=null)
getData($key)
Definition: Form.inc.php:210
Base class for author submit forms.
static getLocale()
static getSubmissionDAO()
Form for Step 1 of author submission: terms, conditions, etc.
Form validation check that checks if value is within a certain set.
Class to represent a form validation check.