Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
ReviewerForm.inc.php
1 <?php
2 
17 import('lib.pkp.classes.form.Form');
18 
19 class ReviewerForm extends Form {
22 
25 
28 
31 
37  function ReviewerForm($submission, $reviewRound) {
38  parent::Form('controllers/grid/users/reviewer/form/defaultReviewerForm.tpl');
39  $this->setSubmission($submission);
40  $this->setReviewRound($reviewRound);
41 
42  // Validation checks for this form
43  $this->addCheck(new FormValidator($this, 'responseDueDate', 'required', 'editor.review.errorAddingReviewer'));
44  $this->addCheck(new FormValidator($this, 'reviewDueDate', 'required', 'editor.review.errorAddingReviewer'));
45 
46  $this->addCheck(new FormValidatorPost($this));
47 
48  import('lib.pkp.classes.mail.SubmissionMailTemplate');
49  }
50 
51  //
52  // Getters and Setters
53  //
58  function getSubmissionId() {
59  $submission = $this->getSubmission();
60  return $submission->getId();
61  }
62 
67  function getSubmission() {
68  return $this->_submission;
69  }
70 
75  function getReviewRound() {
76  return $this->_reviewRound;
77  }
78 
83  function setSubmission($submission) {
84  $this->_submission = $submission;
85  }
86 
91  function setReviewRound($reviewRound) {
92  $this->_reviewRound = $reviewRound;
93  }
94 
99  function setReviewerFormAction($action) {
100  $this->_reviewerFormActions[$action->getId()] = $action;
101  }
102 
107  function setUserRoles($userRoles) {
108  $this->_userRoles = $userRoles;
109  }
110 
115  function getUserRoles() {
116  return $this->_userRoles;
117  }
118 
125  }
126  //
127  // Overridden template methods
128  //
134  function initData($args, $request) {
135  $reviewerId = (int) $request->getUserVar('reviewerId');
136  $context = $request->getContext();
137  $reviewRound = $this->getReviewRound();
138  $submission = $this->getSubmission();
139 
140  // The reviewer id has been set
141  if (!empty($reviewerId)) {
142  if ($this->_isValidReviewer($context, $submission, $reviewRound, $reviewerId)) {
143  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
144  $reviewer = $userDao->getById($reviewerId);
145  $this->setData('userNameString', sprintf('%s (%s)', $reviewer->getFullname(), $reviewer->getUsername()));
146  }
147  }
148 
149  // Get review assignment related data;
150  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
151  $reviewAssignment = $reviewAssignmentDao->getReviewAssignment($reviewRound->getId(), $reviewerId, $reviewRound->getRound());
152 
153  // Get the review method (open, blind, or double-blind)
154  if (isset($reviewAssignment) && $reviewAssignment->getReviewMethod() != false) {
155  $reviewMethod = $reviewAssignment->getReviewMethod();
156  } else {
157  // Set default value.
158  $reviewMethod = SUBMISSION_REVIEW_METHOD_BLIND;
159  }
160 
161  // Get the response/review due dates or else set defaults
162  if (isset($reviewAssignment) && $reviewAssignment->getDueDate() != null) {
163  $reviewDueDate = strftime(Config::getVar('general', 'date_format_short'), strtotime($reviewAssignment->getDueDate()));
164  } else {
165  $numWeeks = max((int) $context->getSetting('numWeeksPerReview'), 4);
166  $reviewDueDate = strftime(Config::getVar('general', 'date_format_short'), strtotime('+' . $numWeeks . ' week'));
167  }
168  if (isset($reviewAssignment) && $reviewAssignment->getResponseDueDate() != null) {
169  $responseDueDate = strftime(Config::getVar('general', 'date_format_short'), strtotime($reviewAssignment->getResponseDueDate()));
170  } else {
171  $numWeeks = max((int) $context->getSetting('numWeeksPerResponse'), 3);
172  $responseDueDate = strftime(Config::getVar('general', 'date_format_short'), strtotime('+' . $numWeeks . ' week'));
173  }
174 
175  // Get the currently selected reviewer selection type to show the correct tab if we're re-displaying the form
176  $selectionType = (int) $request->getUserVar('selectionType');
177  $stageId = $reviewRound->getStageId();
178 
179  $this->setData('submissionId', $this->getSubmissionId());
180  $this->setData('stageId', $stageId);
181  $this->setData('reviewMethod', $reviewMethod);
182  $this->setData('reviewRoundId', $reviewRound->getId());
183  $this->setData('reviewerId', $reviewerId);
184 
185  $context = $request->getContext();
186  $templateKey = $this->_getMailTemplateKey($context);
187  $template = new SubmissionMailTemplate($submission, $templateKey);
188  if ($template) {
189  $user = $request->getUser();
190  $dispatcher = $request->getDispatcher();
191  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_REVIEWER); // reviewer.step1.requestBoilerplate
192  $template->assignParams(array(
193  'contextUrl' => $dispatcher->url($request, ROUTE_PAGE, $context->getPath()),
194  'editorialContactSignature' => $user->getContactSignature(),
195  'signatureFullName' => $user->getFullname(),
196  'messageToReviewer' => __('reviewer.step1.requestBoilerplate'),
197  ));
198  }
199  $this->setData('personalMessage', $template->getBody() . "\n" . $context->getSetting('emailSignature'));
200  $this->setData('responseDueDate', $responseDueDate);
201  $this->setData('reviewDueDate', $reviewDueDate);
202  $this->setData('selectionType', $selectionType);
203  }
204 
210  function fetch($request) {
211  // Get the review method options.
212  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
213  $reviewMethods = $reviewAssignmentDao->getReviewMethodsTranslationKeys();
214  $submission = $this->getSubmission();
215 
216  $templateMgr = TemplateManager::getManager($request);
217  $templateMgr->assign('reviewMethods', $reviewMethods);
218  $templateMgr->assign('reviewerActions', $this->getReviewerFormActions());
219 
220  // Allow the default template
221  $templateKeys[] = $this->_getMailTemplateKey($request->getContext());
222 
223  // Determine if the current user can use any custom templates defined.
224  $user = $request->getUser();
225  $roleDao = DAORegistry::getDAO('RoleDAO');
226 
227  $userRoles = $roleDao->getByUserId($user->getId(), $submission->getContextId());
228  foreach ($userRoles as $userRole) {
229  if (in_array($userRole->getId(), array(ROLE_ID_MANAGER, ROLE_ID_SUB_EDITOR, ROLE_ID_ASSISTANT))) {
230  $emailTemplateDao = DAORegistry::getDAO('EmailTemplateDAO');
231  $customTemplates = $emailTemplateDao->getCustomTemplateKeys(Application::getContextAssocType(), $submission->getContextId());
232  $templateKeys = array_merge($templateKeys, $customTemplates);
233  break;
234  }
235  }
236 
237  foreach ($templateKeys as $templateKey) {
238  $template = new SubmissionMailTemplate($submission, $templateKey, null, null, null, false);
239  $template->assignParams(array());
240  $templates[$templateKey] = $template->getSubject();
241  }
242 
243  $templateMgr->assign('templates', $templates);
244 
245  // Get the reviewer user groups for the create new reviewer/enroll existing user tabs
246  $context = $request->getContext();
247  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
248  $reviewRound = $this->getReviewRound();
249  $reviewerUserGroups = $userGroupDao->getUserGroupsByStage($context->getId(), $reviewRound->getStageId(), false, false, ROLE_ID_REVIEWER);
250  $userGroups = array();
251  while($userGroup = $reviewerUserGroups->next()) {
252  $userGroups[$userGroup->getId()] = $userGroup->getLocalizedName();
253  }
254 
255  $this->setData('userGroups', $userGroups);
256  return parent::fetch($request);
257  }
258 
263  function readInputData() {
264  $this->readUserVars(array(
265  'selectionType',
266  'submissionId',
267  'template',
268  'personalMessage',
269  'responseDueDate',
270  'reviewDueDate',
271  'reviewMethod',
272  'skipEmail',
273  'keywords',
274  'interestsTextOnly',
275  'reviewRoundId',
276  'stageId',
277  'selectedFiles',
278  ));
279 
280  $keywords = $this->getData('keywords');
281  if ($keywords != null && is_array($keywords['interests'])) {
282  // The interests are coming in encoded -- Decode them for DB storage
283  $this->setData('interestsKeywords', array_map('urldecode', $keywords['interests']));
284  }
285  }
286 
292  function execute($args, $request) {
293  $submission = $this->getSubmission();
294  $context = $request->getContext();
295 
296  $currentReviewRound = $this->getReviewRound();
297  $stageId = $currentReviewRound->getStageId();
298  $reviewDueDate = $this->getData('reviewDueDate');
299  $responseDueDate = $this->getData('responseDueDate');
300 
301  // Get reviewer id and validate it.
302  $reviewerId = (int) $this->getData('reviewerId');
303 
304  if (!$this->_isValidReviewer($context, $submission, $currentReviewRound, $reviewerId)) {
305  fatalError('Invalid reviewer id.');
306  }
307 
308  $reviewMethod = (int) $this->getData('reviewMethod');
309 
310  import('lib.pkp.classes.submission.action.EditorAction');
311  $editorAction = new EditorAction();
312  $editorAction->addReviewer($request, $submission, $reviewerId, $currentReviewRound, $reviewDueDate, $responseDueDate, $reviewMethod);
313 
314  // Get the reviewAssignment object now that it has been added.
315  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
316  $reviewAssignment = $reviewAssignmentDao->getReviewAssignment($currentReviewRound->getId(), $reviewerId, $currentReviewRound->getRound(), $stageId);
317  $reviewAssignment->setDateNotified(Core::getCurrentDate());
318  $reviewAssignment->setCancelled(0);
319  $reviewAssignment->stampModified();
320  $reviewAssignmentDao->updateObject($reviewAssignment);
321 
322  // Grant access for this review to all selected files.
323  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO');
324  import('lib.pkp.classes.submission.SubmissionFile'); // File constants
325  $submissionFiles = $submissionFileDao->getLatestNewRevisionsByReviewRound($currentReviewRound, SUBMISSION_FILE_REVIEW_FILE);
326  $selectedFiles = (array) $this->getData('selectedFiles');
327  $reviewFilesDao = DAORegistry::getDAO('ReviewFilesDAO');
328  foreach ($submissionFiles as $submissionFile) {
329  if (in_array($submissionFile->getFileId(), $selectedFiles)) {
330  $reviewFilesDao->grant($reviewAssignment->getId(), $submissionFile->getFileId());
331  }
332  }
333 
334 
335  // Notify the reviewer via email.
336  import('lib.pkp.classes.mail.SubmissionMailTemplate');
337  $templateKey = $keywords = $this->getData('template');
338  $mail = new SubmissionMailTemplate($submission, $templateKey, null, null, null, false);
339 
340  if ($mail->isEnabled() && !$this->getData('skipEmail')) {
341  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
342  $reviewer = $userDao->getById($reviewerId);
343  $user = $request->getUser();
344  $mail->addRecipient($reviewer->getEmail(), $reviewer->getFullName());
345  $mail->setBody($this->getData('personalMessage'));
346  $dispatcher = $request->getDispatcher();
347 
348  // Set the additional arguments for the one click url
349  $reviewUrlArgs = array('submissionId' => $this->getSubmissionId());
350  if ($context->getSetting('reviewerAccessKeysEnabled')) {
351  import('lib.pkp.classes.security.AccessKeyManager');
352  $accessKeyManager = new AccessKeyManager();
353  $expiryDays = $context->getSetting('numWeeksPerReview') + 4 * 7;
354  $accessKey = $accessKeyManager->createKey($context->getId(), $reviewerId, $reviewAssignment->getId(), $expiryDays);
355  $reviewUrlArgs = array_merge($reviewUrlArgs, array('reviewId' => $reviewAssignment->getId(), 'key' => $accessKey));
356  }
357 
358  // Assign the remaining parameters
359  $paramArray = array(
360  'reviewerName' => $reviewer->getFullName(),
361  'responseDueDate' => $responseDueDate,
362  'reviewDueDate' => $reviewDueDate,
363  'reviewerUserName' => $reviewer->getUsername(),
364  'submissionReviewUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'reviewer', 'submission', null, $reviewUrlArgs)
365  );
366  $mail->assignParams($paramArray);
367  $mail->send($request);
368  }
369 
370  return $reviewAssignment;
371  }
372 
373 
374  //
375  // Protected methods.
376  //
383  function getSearchByNameAction($request) {
384  $reviewRound = $this->getReviewRound();
385 
386  $actionArgs['submissionId'] = $this->getSubmissionId();
387  $actionArgs['stageId'] = $reviewRound->getStageId();
388  $actionArgs['reviewRoundId'] = $reviewRound->getId();
389  $actionArgs['selectionType'] = REVIEWER_SELECT_SEARCH_BY_NAME;
390 
391  return new LinkAction(
392  'addReviewer',
393  new AjaxAction($request->url(null, null, 'reloadReviewerForm', null, $actionArgs)),
394  __('editor.submission.returnToSimpleSearch'),
395  'return'
396  );
397  }
398 
399 
400  //
401  // Private helper methods
402  //
411  function _isValidReviewer($context, $submission, $reviewRound, $reviewerId) {
412  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
413  $reviewerFactory = $userDao->getReviewersNotAssignedToSubmission($context->getId(), $submission->getId(), $reviewRound);
414  $reviewersArray = $reviewerFactory->toAssociativeArray();
415  if (array_key_exists($reviewerId, $reviewersArray)) {
416  return true;
417  } else {
418  return false;
419  }
420  }
421 
429  function _getMailTemplateKey($context) {
430  $templateKey = 'REVIEW_REQUEST';
431  if ($context->getSetting('reviewerAccessKeysEnabled')) {
432  $templateKey = 'REVIEW_REQUEST_ONECLICK';
433  }
434 
435  return $templateKey;
436  }
437 }
438 
439 ?>
Subclass of MailTemplate for sending emails related to submissions.
static & getDAO($name, $dbconn=null)
addCheck($formValidator)
Definition: Form.inc.php:396
setData($key, $value)
Definition: Form.inc.php:219
ReviewerForm($submission, $reviewRound)
Form validation check to make sure the form is POSTed.
static requireComponents()
setSubmission($submission)
readUserVars($vars)
Definition: Form.inc.php:364
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
setReviewerFormAction($action)
_isValidReviewer($context, $submission, $reviewRound, $reviewerId)
getData($key)
Definition: Form.inc.php:210
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
Class defining operations for AccessKey management.
initData($args, $request)
setReviewRound($reviewRound)
setUserRoles($userRoles)
Class defining an AJAX action.
_getMailTemplateKey($context)
static getContextAssocType()
Base Form for adding a reviewer to a submission. N.B. Requires a subclass to implement the &quot;reviewerI...
Editor actions.
Class to represent a form validation check.
execute($args, $request)
Base class defining an action that can be performed by the user in the user interface.
static getCurrentDate($ts=null)
Definition: Core.inc.php:95
getSearchByNameAction($request)