Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
AuthorForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 class AuthorForm extends Form {
21 
23  var $_author;
24 
27 
31  function AuthorForm($submission, $author, $submissionIdFieldName) {
32  parent::Form('controllers/grid/users/author/form/authorForm.tpl');
33  $this->setSubmission($submission);
34  $this->setAuthor($author);
35  $this->setSubmissionIdFieldName($submissionIdFieldName);
36 
37  // Validation checks for this form
38  $this->addCheck(new FormValidator($this, 'firstName', 'required', 'submission.submit.form.authorRequiredFields'));
39  $this->addCheck(new FormValidator($this, 'lastName', 'required', 'submission.submit.form.authorRequiredFields'));
40  $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'form.emailRequired'));
41  $this->addCheck(new FormValidatorUrl($this, 'url', 'optional', 'user.profile.form.urlInvalid'));
42  $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'submission.submit.form.contributorRoleRequired'));
43  $this->addCheck(new FormValidatorPost($this));
44  }
45 
46  //
47  // Getters and Setters
48  //
53  function getAuthor() {
54  return $this->_author;
55  }
56 
61  function setAuthor($author) {
62  $this->_author = $author;
63  }
64 
69  function getSubmission() {
70  return $this->_submission;
71  }
72 
77  function setSubmission($submission) {
78  $this->_submission = $submission;
79  }
80 
87  }
88 
93  function setSubmissionIdFieldName($submissionIdFieldName) {
94  $this->_submissionIdFieldName = $submissionIdFieldName;
95  }
96 
97 
98  //
99  // Overridden template methods
100  //
105  function initData() {
106  $author = $this->getAuthor();
107 
108  if ($author) {
109  $this->_data = array(
110  'authorId' => $author->getId(),
111  'firstName' => $author->getFirstName(),
112  'middleName' => $author->getMiddleName(),
113  'lastName' => $author->getLastName(),
114  'suffix' => $author->getSuffix(),
115  'affiliation' => $author->getAffiliation(AppLocale::getLocale()),
116  'country' => $author->getCountry(),
117  'email' => $author->getEmail(),
118  'url' => $author->getUrl(),
119  'userGroupId' => $author->getUserGroupId(),
120  'biography' => $author->getBiography(AppLocale::getLocale()),
121  'primaryContact' => $author->getPrimaryContact()
122  );
123  }
124  }
125 
130  function fetch($request) {
131  $author = $this->getAuthor();
132 
133  $templateMgr = TemplateManager::getManager($request);
134  $countryDao = DAORegistry::getDAO('CountryDAO');
135  $countries = $countryDao->getCountries();
136  $templateMgr->assign('countries', $countries);
137 
138  $router = $request->getRouter();
139  $context = $router->getContext($request);
140 
141  $userGroupDao = DAORegistry::getDAO('UserGroupDAO');
142  $authorUserGroups = $userGroupDao->getByRoleId($context->getId(), ROLE_ID_AUTHOR);
143  $templateMgr->assign('authorUserGroups', $authorUserGroups);
144 
145  $submission = $this->getSubmission();
146  $templateMgr->assign('submissionIdFieldName', $this->getSubmissionIdFieldName());
147  $templateMgr->assign('submissionId', $submission->getId());
148 
149  return parent::fetch($request);
150  }
151 
156  function readInputData() {
157  $this->readUserVars(array(
158  'authorId',
159  'firstName',
160  'middleName',
161  'lastName',
162  'suffix',
163  'affiliation',
164  'country',
165  'email',
166  'url',
167  'userGroupId',
168  'biography',
169  'primaryContact'
170  ));
171  }
172 
178  function execute() {
179  $authorDao = DAORegistry::getDAO('AuthorDAO');
180  $submission = $this->getSubmission();
181 
182  $author = $this->getAuthor();
183  if (!$author) {
184  // this is a new submission contributor
185  $author = new Author();
186  $author->setSubmissionId($submission->getId());
187  $existingAuthor = false;
188  } else {
189  $existingAuthor = true;
190  if ($submission->getId() !== $author->getSubmissionId()) fatalError('Invalid author!');
191  }
192 
193  $author->setFirstName($this->getData('firstName'));
194  $author->setMiddleName($this->getData('middleName'));
195  $author->setLastName($this->getData('lastName'));
196  $author->setSuffix($this->getData('suffix'));
197  $author->setAffiliation($this->getData('affiliation'), AppLocale::getLocale()); // localized
198  $author->setCountry($this->getData('country'));
199  $author->setEmail($this->getData('email'));
200  $author->setUrl($this->getData('url'));
201  $author->setUserGroupId($this->getData('userGroupId'));
202  $author->setBiography($this->getData('biography'), AppLocale::getLocale()); // localized
203  $author->setPrimaryContact(($this->getData('primaryContact') ? true : false));
204 
205  if ($existingAuthor) {
206  $authorDao->updateObject($author);
207  $authorId = $author->getId();
208  } else {
209  $authorId = $authorDao->insertObject($author);
210  }
211 
212  return $authorId;
213  }
214 }
215 
216 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setSubmission($submission)
Form validation check to make sure the form is POSTed.
Monograph author metadata class.
Definition: Author.inc.php:20
Form for adding/editing a author.
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
AuthorForm($submission, $author, $submissionIdFieldName)
Form validation check for email addresses.
getData($key)
Definition: Form.inc.php:210
static getLocale()
Form validation check for URLs.
setSubmissionIdFieldName($submissionIdFieldName)
Class to represent a form validation check.
setAuthor($author)
getSubmissionIdFieldName()
fetch($request)