16 import(
'lib.pkp.classes.form.Form');
29 parent::__construct(
'controllers/grid/users/author/form/authorForm.tpl');
38 $this->
addCheck(
new FormValidatorLocale($this,
'givenName',
'required',
'user.profile.form.givenNameRequired', $this->defaultLocale));
39 $this->
addCheck(
new FormValidatorCustom($this,
'familyName',
'optional',
'user.profile.form.givenNameRequired.locale',
function($familyName) use ($form) {
40 $givenNames = $form->getData(
'givenName');
41 foreach ($familyName as $locale => $value) {
42 if (!empty($value) && empty($givenNames[$locale])) {
50 $this->
addCheck(
new FormValidator($this,
'userGroupId',
'required',
'submission.submit.form.contributorRoleRequired'));
72 $this->_author = $author;
88 $this->_publication = $publication;
102 $this->_data = array(
103 'authorId' => $author->getId(),
104 'givenName' => $author->getGivenName(
null),
105 'familyName' => $author->getFamilyName(
null),
106 'preferredPublicName' => $author->getPreferredPublicName(
null),
107 'affiliation' => $author->getAffiliation(
null),
108 'country' => $author->getCountry(),
109 'email' => $author->getEmail(),
110 'userUrl' => $author->getUrl(),
111 'orcid' => $author->getOrcid(),
112 'userGroupId' => $author->getUserGroupId(),
113 'biography' => $author->getBiography(
null),
114 'primaryContact' => $this->getPublication()->getData(
'primaryContactId') === $author->getId(),
115 'includeInBrowse' => $author->getIncludeInBrowse(),
119 $this->_data = array(
'includeInBrowse' =>
true);
122 return parent::initData();
128 function fetch($request, $template =
null, $display =
false) {
130 $authorUserGroups = $userGroupDao->getByRoleId($request->getContext()->getId(), ROLE_ID_AUTHOR);
132 $isoCodes = new \Sokil\IsoCodes\IsoCodesFactory();
133 $countries = array();
134 foreach ($isoCodes->getCountries() as $country) {
135 $countries[$country->getAlpha2()] = $country->getLocalName();
139 $templateMgr->assign(array(
140 'submissionId' => $publication->getData(
'submissionId'),
141 'publicationId' => $publication->getId(),
142 'countries' => $countries,
143 'authorUserGroups' => $authorUserGroups,
146 return parent::fetch($request, $template, $display);
158 'preferredPublicName',
182 $this->_author = $authorDao->newDataObject();
184 $author->setData(
'publicationId', $publication->getId());
185 $author->setData(
'seq', count($publication->getData(
'authors')));
186 $existingAuthor =
false;
188 $existingAuthor =
true;
189 if ($publication->getId() !== $author->getData(
'publicationId'))
fatalError(
'Invalid author!');
192 $author->setGivenName($this->
getData(
'givenName'),
null);
193 $author->setFamilyName($this->
getData(
'familyName'),
null);
194 $author->setPreferredPublicName($this->
getData(
'preferredPublicName'),
null);
195 $author->setAffiliation($this->
getData(
'affiliation'),
null);
196 $author->setCountry($this->
getData(
'country'));
197 $author->setEmail($this->
getData(
'email'));
198 $author->setUrl($this->
getData(
'userUrl'));
199 $author->setOrcid($this->
getData(
'orcid'));
200 $author->setUserGroupId($this->
getData(
'userGroupId'));
201 $author->setBiography($this->
getData(
'biography'),
null);
202 $author->setIncludeInBrowse(($this->
getData(
'includeInBrowse') ?
true :
false));
205 parent::execute(...$functionParams);
207 if ($existingAuthor) {
208 $authorDao->updateObject($author);
209 $authorId = $author->getId();
211 $authorId = $authorDao->insertObject($author);
214 if ($this->
getData(
'primaryContact')) {
215 $submission =
Services::get(
'submission')->get($publication->getData(
'submissionId'));
216 $context =
Services::get(
'context')->get($submission->getData(
'contextId'));
217 $params = [
'primaryContactId' => $authorId];
219 VALIDATE_ACTION_EDIT,
221 $context->getData(
'supportedLocales'),
222 $publication->getData(
'locale')
224 if (!empty($errors)) {
225 throw new Exception(
'Invalid primary contact ID. This author can not be a primary contact.');