Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
CreateReviewerForm.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.grid.users.reviewer.form.ReviewerForm');
17 
24  function CreateReviewerForm($submission, $reviewRound) {
25  parent::ReviewerForm($submission, $reviewRound);
26  $this->setTemplate('controllers/grid/users/reviewer/form/createReviewerForm.tpl');
27 
28  $this->addCheck(new FormValidator($this, 'firstname', 'required', 'user.profile.form.firstNameRequired'));
29  $this->addCheck(new FormValidator($this, 'lastname', 'required', 'user.profile.form.lastNameRequired'));
30  $this->addCheck(new FormValidatorCustom($this, 'username', 'required', 'user.register.form.usernameExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByUsername'), array(), true));
31  $this->addCheck(new FormValidatorAlphaNum($this, 'username', 'required', 'user.register.form.usernameAlphaNumeric'));
32  $this->addCheck(new FormValidatorEmail($this, 'email', 'required', 'user.profile.form.emailRequired'));
33  $this->addCheck(new FormValidatorCustom($this, 'email', 'required', 'user.register.form.emailExists', array(DAORegistry::getDAO('UserDAO'), 'userExistsByEmail'), array(), true));
34  $this->addCheck(new FormValidator($this, 'userGroupId', 'required', 'user.profile.form.usergroupRequired'));
35  }
36 
37 
42  function fetch($request) {
43  $searchByNameAction = $this->getSearchByNameAction($request);
44 
45  $this->setReviewerFormAction($searchByNameAction);
46  return parent::fetch($request);
47  }
48 
53  function readInputData() {
54  parent::readInputData();
55 
56  $this->readUserVars(array(
57  'firstname',
58  'middlename',
59  'lastname',
60  'affiliation',
61  'keywords',
62  'interestsTextOnly',
63  'username',
64  'email',
65  'skipEmail',
66  'userGroupId'
67  ));
68  }
69 
75  function execute($args, $request) {
76  $userDao = DAORegistry::getDAO('UserDAO');
77  $user = $userDao->newDataObject();
78 
79  $user->setFirstName($this->getData('firstname'));
80  $user->setMiddleName($this->getData('middlename'));
81  $user->setLastName($this->getData('lastname'));
82  $user->setEmail($this->getData('email'));
83 
84  $authDao = DAORegistry::getDAO('AuthSourceDAO');
85  $auth = $authDao->getDefaultPlugin();
86  $user->setAuthId($auth?$auth->getAuthId():0);
87  $user->setInlineHelp(1); // default new reviewers to having inline help visible
88 
89  $user->setUsername($this->getData('username'));
90  $password = Validation::generatePassword();
91 
92  if (isset($auth)) {
93  $user->setPassword($password);
94  // FIXME Check result and handle failures
95  $auth->doCreateUser($user);
96  $user->setAuthId($auth->authId);
97  $user->setPassword(Validation::encryptCredentials($user->getId(), Validation::generatePassword())); // Used for PW reset hash only
98  } else {
99  $user->setPassword(Validation::encryptCredentials($this->getData('username'), $password));
100  }
101 
102  $user->setDateRegistered(Core::getCurrentDate());
103  $reviewerId = $userDao->insertObject($user);
104 
105  // Set the reviewerId in the Form for the parent class to use
106  $this->setData('reviewerId', $reviewerId);
107 
108  // Insert the user interests
109  $interests = $this->getData('interestsKeywords') ? $this->getData('interestsKeywords') : $this->getData('interestsTextOnly');
110  import('lib.pkp.classes.user.InterestManager');
111  $interestManager = new InterestManager();
112  $interestManager->setInterestsForUser($user, $interests);
113 
114  // Assign the selected user group ID to the user
115  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
116  $userGroupId = (int) $this->getData('userGroupId');
117  $userGroupDao->assignUserToGroup($reviewerId, $userGroupId);
118 
119  if (!$this->getData('skipEmail')) {
120  // Send welcome email to user
121  import('lib.pkp.classes.mail.MailTemplate');
122  $mail = new MailTemplate('REVIEWER_REGISTER');
123  if ($mail->isEnabled()) {
124  $context = $request->getContext();
125  $mail->setReplyTo($context->getSetting('contactEmail'), $context->getSetting('contactName'));
126  $mail->assignParams(array('username' => $this->getData('username'), 'password' => $password, 'userFullName' => $user->getFullName()));
127  $mail->addRecipient($user->getEmail(), $user->getFullName());
128  $mail->send($request);
129  }
130  }
131 
132  return parent::execute($args, $request);
133  }
134 }
135 
136 ?>
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
Form validation check with a custom user function performing the validation check.
Form for creating and subsequently adding a reviewer to a submission.
readUserVars($vars)
Definition: Form.inc.php:364
setReviewerFormAction($action)
Form validation check for email addresses.
getData($key)
Definition: Form.inc.php:210
static generatePassword($length=8)
Form validation check for alphanumeric (plus interior dash/underscore) characters only...
Base Form for adding a reviewer to a submission. N.B. Requires a subclass to implement the &quot;reviewerI...
static encryptCredentials($username, $password, $encryption=false)
setTemplate($template)
Definition: Form.inc.php:121
Handle user interest functions.
Subclass of Mail for mailing a template email.
Class to represent a form validation check.
CreateReviewerForm($submission, $reviewRound)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95
getSearchByNameAction($request)