-
Notifications
You must be signed in to change notification settings - Fork 438
/
EmailReviewerForm.inc.php
98 lines (81 loc) · 3.09 KB
/
EmailReviewerForm.inc.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
<?php
/**
* @file controllers/grid/users/reviewer/form/EmailReviewerForm.inc.php
*
* Copyright (c) 2014-2021 Simon Fraser University
* Copyright (c) 2003-2021 John Willinsky
* Distributed under the GNU GPL v3. For full terms see the file docs/COPYING.
*
* @class EmailReviewerForm
* @ingroup controllers_grid_users_reviewer_form
*
* @brief Form for sending an email to a user
*/
import('lib.pkp.classes.form.Form');
class EmailReviewerForm extends Form {
/** @var ReviewAssignment The review assignment to use for this contact */
var $_reviewAssignment;
/** @var Submission */
var $_submission;
/**
* Constructor.
* @param ReviewAssignment $reviewAssignment The review assignment to use for this contact.
* @param Submission $submission The submission of this review assignment
*/
function __construct($reviewAssignment, $submission) {
parent::__construct('controllers/grid/users/reviewer/form/emailReviewerForm.tpl');
$this->_reviewAssignment = $reviewAssignment;
$this->_submission = $submission;
$this->addCheck(new FormValidator($this, 'subject', 'required', 'email.subjectRequired'));
$this->addCheck(new FormValidator($this, 'message', 'required', 'email.bodyRequired'));
$this->addCheck(new FormValidatorPost($this));
$this->addCheck(new FormValidatorCSRF($this));
}
/**
* Assign form data to user-submitted data.
* @see Form::readInputData()
*/
function readInputData() {
$this->readUserVars(array(
'subject',
'message',
));
}
/**
* Display the form.
* @param $requestArgs array Request parameters to bounce back with the form submission.
* @see Form::fetch
*/
function fetch($request, $template = null, $display = false, $requestArgs = array()) {
$userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
$user = $userDao->getById($this->_reviewAssignment->getReviewerId());
$templateMgr = TemplateManager::getManager($request);
$templateMgr->assign(array(
'userFullName' => $this->_reviewAssignment->getReviewerFullName(),
'requestArgs' => $requestArgs,
'reviewAssignmentId' => $this->_reviewAssignment->getId(),
));
return parent::fetch($request, $template, $display);
}
/**
* Send the email
*/
function execute(...$functionArgs) {
$userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
$toUser = $userDao->getById($this->_reviewAssignment->getReviewerId());
$request = Application::get()->getRequest();
$fromUser = $request->getUser();
import('lib.pkp.classes.mail.SubmissionMailTemplate');
$email = new SubmissionMailTemplate($this->_submission);
$email->addRecipient($toUser->getEmail(), $toUser->getFullName());
$email->setReplyTo($fromUser->getEmail(), $fromUser->getFullName());
$email->setSubject($this->getData('subject'));
$email->setBody($this->getData('message'));
$email->assignParams();
if (!$email->send()) {
import('classes.notification.NotificationManager');
$notificationMgr = new NotificationManager();
$notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('email.compose.error')));
}
}
}