Open Journal Systems  3.3.0
EditorDecisionWithEmailForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.controllers.modals.editorDecision.form.EditorDecisionForm');
17 
19 
22 
23  //
24  // Getters and Setters
25  //
30  function getSaveFormOperation() {
32  }
33 
38  function setSaveFormOperation($saveFormOperation) {
39  $this->_saveFormOperation = $saveFormOperation;
40  }
41 
42  //
43  // Implement protected template methods from Form
44  //
49  function initData($actionLabels = array()) {
50  $request = Application::get()->getRequest();
51  $context = $request->getContext();
52  $router = $request->getRouter();
53  $dispatcher = $router->getDispatcher();
54 
55  $submission = $this->getSubmission();
56  $user = $request->getUser();
57 
58  import('lib.pkp.classes.mail.SubmissionMailTemplate');
59  $emailKeys = array(
60  SUBMISSION_EDITOR_DECISION_ACCEPT => 'EDITOR_DECISION_ACCEPT',
61  SUBMISSION_EDITOR_DECISION_DECLINE => 'EDITOR_DECISION_DECLINE',
62  SUBMISSION_EDITOR_DECISION_INITIAL_DECLINE => 'EDITOR_DECISION_INITIAL_DECLINE',
63  SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW => 'EDITOR_DECISION_SEND_TO_EXTERNAL',
64  SUBMISSION_EDITOR_DECISION_RESUBMIT => 'EDITOR_DECISION_RESUBMIT',
65  SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS => 'EDITOR_DECISION_REVISIONS',
66  SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION => 'EDITOR_DECISION_SEND_TO_PRODUCTION',
67  );
68 
69  $email = new SubmissionMailTemplate($submission, $emailKeys[$this->getDecision()]);
70 
71  $submissionUrl = $dispatcher->url($request, ROUTE_PAGE, null, 'authorDashboard', 'submission', $submission->getId());
72  $email->assignParams(array(
73  'authorName' => $submission->getAuthorString(),
74  'submissionUrl' => $submissionUrl,
75  ));
76  $email->replaceParams();
77 
78  // If we are in review stage we need a review round.
79  $reviewRound = $this->getReviewRound();
80  if (is_a($reviewRound, 'ReviewRound')) {
81  $this->setData('reviewRoundId', $reviewRound->getId());
82  }
83 
84  $data = array(
85  'submissionId' => $submission->getId(),
86  'decision' => $this->getDecision(),
87  'authorName' => $submission->getAuthorString(),
88  'personalMessage' => $email->getBody(),
89  'actionLabel' => $actionLabels[$this->getDecision()]
90  );
91  foreach($data as $key => $value) {
92  $this->setData($key, $value);
93  }
94 
95  return parent::initData();
96  }
97 
101  function readInputData() {
102  $this->readUserVars(array('personalMessage', 'selectedAttachments', 'skipEmail', 'selectedLibraryFiles'));
103  parent::readInputData();
104  }
105 
109  function fetch($request, $template = null, $display = false) {
110 
111  $templateMgr = TemplateManager::getManager($request);
112 
113  // On the review stage, determine if any reviews are available for import
114  $stageId = $this->getStageId();
115  if ($stageId == WORKFLOW_STAGE_ID_INTERNAL_REVIEW || $stageId == WORKFLOW_STAGE_ID_EXTERNAL_REVIEW) {
116  $reviewsAvailable = false;
117  $submission = $this->getSubmission();
118  $reviewRound = $this->getReviewRound();
119  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
120  $reviewAssignments = $reviewAssignmentDao->getBySubmissionId($submission->getId(), $reviewRound->getId());
121  foreach ($reviewAssignments as $reviewAssignment) {
122  if ($reviewAssignment->getDateCompleted() != null) {
123  $reviewsAvailable = true;
124  break;
125  }
126  }
127 
128  $templateMgr->assign('reviewsAvailable', $reviewsAvailable);
129 
130  // Retrieve a URL to fetch the reviews
131  if ($reviewsAvailable) {
132  $router = $request->getRouter();
133  $this->setData(
134  'peerReviewUrl',
135  $router->url(
136  $request, null, null,
137  'importPeerReviews', null,
138  array(
139  'submissionId' => $submission->getId(),
140  'stageId' => $stageId,
141  'reviewRoundId' => $reviewRound->getId()
142  )
143  )
144  );
145 
146  }
147  }
148 
149  // When this form is being used in review stages, we need a different
150  // save operation to allow the EditorDecisionHandler authorize the review
151  // round object.
152  if ($this->getSaveFormOperation()) {
153  $templateMgr = TemplateManager::getManager($request);
154  $templateMgr->assign('saveFormOperation', $this->getSaveFormOperation());
155  }
156 
157  $templateMgr->assign('allowedVariables', $this->_getAllowedVariables($request));
158  $templateMgr->assign('allowedVariablesType', $this->_getAllowedVariablesType());
159 
160  return parent::fetch($request, $template, $display);
161  }
162 
163 
164  //
165  // Private helper methods
166  //
177  function _updateReviewRoundStatus($submission, $status, $reviewRound = null) {
178  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
179  if (!$reviewRound) {
180  $reviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId());
181  }
182 
183  // If we don't have a review round, it's because the submission is being
184  // accepted without starting any of the review stages. In that case we
185  // do nothing.
186  if (is_a($reviewRound, 'ReviewRound')) {
187  $reviewRoundDao->updateStatus($reviewRound, $status);
188  }
189  }
190 
199  function _sendReviewMailToAuthor($submission, $emailKey, $request) {
200  // Send personal message to author.
201  import('lib.pkp.classes.mail.SubmissionMailTemplate');
202  $email = new SubmissionMailTemplate($submission, $emailKey, null, null, null, false);
203  $email->setBody($this->getData('personalMessage'));
204 
205  // Get submission authors in the same way as for the email template form,
206  // that editor sees. This also ensures that the recipient list is not empty.
207  $authors = $submission->getAuthors(true);
208  foreach($authors as $author) {
209  $email->addRecipient($author->getEmail(), $author->getFullName());
210  }
211 
212  DAORegistry::getDAO('SubmissionEmailLogDAO'); // Load constants
213  $email->setEventType(SUBMISSION_EMAIL_EDITOR_NOTIFY_AUTHOR);
214 
215  // Get review round.
216  $reviewRound = $this->getReviewRound();
217 
218  if(is_a($reviewRound, 'ReviewRound')) {
219  // Retrieve review indexes.
220  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
221  $reviewIndexes = $reviewAssignmentDao->getReviewIndexesForRound($submission->getId(), $reviewRound->getId());
222  assert(is_array($reviewIndexes));
223 
224  // Add a review index for review attachments not associated with
225  // a review assignment (i.e. attachments uploaded by the editor).
226  $lastIndex = end($reviewIndexes);
227  $reviewIndexes[-1] = $lastIndex + 1;
228 
229  // Attach the selected reviewer attachments to the email.
230  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
231  $selectedAttachments = $this->getData('selectedAttachments');
232  if(is_array($selectedAttachments)) {
233  foreach ($selectedAttachments as $fileId) {
234 
235  // Retrieve the submission file.
236  $submissionFile = $submissionFileDao->getLatestRevision($fileId);
237  assert(is_a($submissionFile, 'SubmissionFile'));
238 
239  // Check the association information.
240  if($submissionFile->getAssocType() == ASSOC_TYPE_REVIEW_ASSIGNMENT) {
241  // The review attachment has been uploaded by a reviewer.
242  $reviewAssignmentId = $submissionFile->getAssocId();
243  assert(is_numeric($reviewAssignmentId));
244  } else {
245  // The review attachment has been uploaded by the editor.
246  $reviewAssignmentId = -1;
247  }
248 
249  // Identify the corresponding review index.
250  assert(isset($reviewIndexes[$reviewAssignmentId]));
251  $reviewIndex = $reviewIndexes[$reviewAssignmentId];
252  assert(!is_null($reviewIndex));
253 
254  // Add the attachment to the email.
255  $email->addAttachment(
256  $submissionFile->getFilePath(),
257  PKPString::enumerateAlphabetically($reviewIndex).'-'.$submissionFile->getOriginalFileName()
258  );
259 
260  // Update submission file to set viewable as true, so author
261  // can view the file on their submission summary page.
262  $submissionFile->setViewable(true);
263  $submissionFileDao->updateObject($submissionFile);
264  }
265  }
266  }
267 
268  // Attach the selected Library files as attachments to the email.
269  import('classes.file.LibraryFileManager');
270  $libraryFileDao = DAORegistry::getDAO('LibraryFileDAO'); /* @var $libraryFileDao LibraryFileDAO */
271  $selectedLibraryFilesAttachments = $this->getData('selectedLibraryFiles');
272  if(is_array($selectedLibraryFilesAttachments)) {
273  foreach ($selectedLibraryFilesAttachments as $fileId) {
274  // Retrieve the Library file.
275  $libraryFile = $libraryFileDao->getById($fileId);
276  assert(is_a($libraryFile, 'LibraryFile'));
277 
278  $libraryFileManager = new LibraryFileManager($libraryFile->getContextId());
279 
280  // Add the attachment to the email.
281  $email->addAttachment($libraryFile->getFilePath(), $libraryFile->getOriginalFileName());
282  }
283  }
284 
285  // Send the email.
286  if (!$this->getData('skipEmail')) {
287  $router = $request->getRouter();
288  $dispatcher = $router->getDispatcher();
289  $context = $request->getContext();
290  $user = $request->getUser();
291  $email->assignParams(array(
292  'submissionUrl' => $dispatcher->url($request, ROUTE_PAGE, null, 'authorDashboard', 'submission', $submission->getId()),
293  'contextName' => $context->getLocalizedName(),
294  'authorName' => $submission->getAuthorString(),
295  'editorialContactSignature' => $user->getContactSignature(),
296  ));
297  if (!$email->send($request)) {
298  import('classes.notification.NotificationManager');
299  $notificationMgr = new NotificationManager();
300  $notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('email.compose.error')));
301  }
302  }
303  }
304 
310  function _getAllowedVariables($request) {
311  $router = $request->getRouter();
312  $dispatcher = $router->getDispatcher();
313  $submission = $this->getSubmission();
314  $user = $request->getUser();
315  return array(
316  'submissionUrl' => __('common.url'),
317  'contextName' => $request->getContext()->getLocalizedName(),
318  'editorialContactSignature' => strip_tags($user->getContactSignature(), "<br>"),
319  'submissionTitle' => strip_tags($submission->getLocalizedTitle()),
320  'authorName' => strip_tags($submission->getAuthorString()),
321  );
322  }
323 
329  function _getAllowedVariablesType() {
330  return array(
331  'contextName' => INSERT_TAG_VARIABLE_TYPE_PLAIN_TEXT,
332  'editorialContactSignature' => INSERT_TAG_VARIABLE_TYPE_PLAIN_TEXT,
333  'submissionTitle' => INSERT_TAG_VARIABLE_TYPE_PLAIN_TEXT,
334  'authorName' => INSERT_TAG_VARIABLE_TYPE_PLAIN_TEXT,
335  );
336  }
337 }
338 
339 
EditorDecisionWithEmailForm\_getAllowedVariablesType
_getAllowedVariablesType()
Definition: EditorDecisionWithEmailForm.inc.php:332
EditorDecisionForm\getSubmission
getSubmission()
Definition: EditorDecisionForm.inc.php:81
EditorDecisionWithEmailForm\setSaveFormOperation
setSaveFormOperation($saveFormOperation)
Definition: EditorDecisionWithEmailForm.inc.php:41
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
EditorDecisionForm\getReviewRound
getReviewRound()
Definition: EditorDecisionForm.inc.php:97
SubmissionMailTemplate
Subclass of MailTemplate for sending emails related to submissions.
Definition: SubmissionMailTemplate.inc.php:20
Form\setData
setData($key, $value=null)
Definition: Form.inc.php:229
Form\readUserVars
readUserVars($vars)
Definition: Form.inc.php:378
Form\getData
getData($key)
Definition: Form.inc.php:220
EditorDecisionWithEmailForm\readInputData
readInputData()
Definition: EditorDecisionWithEmailForm.inc.php:104
EditorDecisionWithEmailForm\initData
initData($actionLabels=array())
Definition: EditorDecisionWithEmailForm.inc.php:52
EditorDecisionWithEmailForm\fetch
fetch($request, $template=null, $display=false)
Definition: EditorDecisionWithEmailForm.inc.php:112
EditorDecisionWithEmailForm
Base class for the editor decision forms.
Definition: EditorDecisionWithEmailForm.inc.php:18
EditorDecisionWithEmailForm\$_saveFormOperation
$_saveFormOperation
Definition: EditorDecisionWithEmailForm.inc.php:24
EditorDecisionWithEmailForm\_updateReviewRoundStatus
_updateReviewRoundStatus($submission, $status, $reviewRound=null)
Definition: EditorDecisionWithEmailForm.inc.php:180
EditorDecisionForm\getDecision
getDecision()
Definition: EditorDecisionForm.inc.php:73
EditorDecisionWithEmailForm\getSaveFormOperation
getSaveFormOperation()
Definition: EditorDecisionWithEmailForm.inc.php:33
Form\initData
initData()
Definition: Form.inc.php:240
LibraryFileManager
Wrapper class for uploading files to a site/context' library directory.
Definition: LibraryFileManager.inc.php:18
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
EditorDecisionWithEmailForm\_sendReviewMailToAuthor
_sendReviewMailToAuthor($submission, $emailKey, $request)
Definition: EditorDecisionWithEmailForm.inc.php:202
EditorDecisionWithEmailForm\_getAllowedVariables
_getAllowedVariables($request)
Definition: EditorDecisionWithEmailForm.inc.php:313
NotificationManager
Definition: NotificationManager.inc.php:19
EditorDecisionForm
Base class for the editor decision forms.
Definition: EditorDecisionForm.inc.php:21
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
EditorDecisionForm\getStageId
getStageId()
Definition: EditorDecisionForm.inc.php:89
PKPString\enumerateAlphabetically
static enumerateAlphabetically($steps)
Definition: PKPString.inc.php:473