Open Journal Systems  3.3.0
RecommendationForm.inc.php
1 <?php
2 
16 import('lib.pkp.classes.form.Form');
17 
18 // Define review round and review stage id constants.
19 import('lib.pkp.classes.submission.reviewRound.ReviewRound');
20 
21 class RecommendationForm extends Form {
23  var $_submission;
24 
26  var $_stageId;
27 
29  var $_reviewRound;
30 
37  function __construct($submission, $stageId, $reviewRound) {
38  parent::__construct('controllers/modals/editorDecision/form/recommendationForm.tpl');
39  $this->_submission = $submission;
40  $this->_stageId = $stageId;
41  $this->_reviewRound = $reviewRound;
42 
43  // Validation checks for this form
44  $this->addCheck(new FormValidatorPost($this));
45  $this->addCheck(new FormValidatorCSRF($this));
46  }
47 
48  //
49  // Getters and Setters
50  //
55  function getSubmission() {
56  return $this->_submission;
57  }
58 
63  function getStageId() {
65  }
66 
71  function getReviewRound() {
73  }
74 
75  //
76  // Overridden template methods from Form
77  //
81  function initData() {
82  $submission = $this->getSubmission();
83 
84  // Get the decision making editors, the e-mail about the recommendation will be send to
85  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
86  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
87  $editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $this->getStageId());
88  $editorsStr = '';
89  $i = 0;
90  foreach ($editorsStageAssignments as $editorsStageAssignment) {
91  if (!$editorsStageAssignment->getRecommendOnly()) {
92  $editorFullName = $userDao->getUserFullName($editorsStageAssignment->getUserId());
93  $editorsStr .= ($i == 0) ? $editorFullName : ', ' . $editorFullName;
94  $i++;
95  }
96  }
97  // Get the editor recommendation e-mail template
98  import('lib.pkp.classes.mail.SubmissionMailTemplate');
99  $email = new SubmissionMailTemplate($submission, 'EDITOR_RECOMMENDATION');
100  $request = Application::get()->getRequest();
101  $router = $request->getRouter();
102  $dispatcher = $router->getDispatcher();
103  $user = $request->getUser();
104  $submissionUrl = $dispatcher->url($request, ROUTE_PAGE, null, 'workflow', 'index', array($submission->getId(), $this->getStageId()));
105  $emailParams = array(
106  'editors' => $editorsStr,
107  'submissionUrl' => $submissionUrl,
108  );
109  $email->assignParams($emailParams);
110  $email->replaceParams();
111 
112  // Get the recorded recommendations
113  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO'); /* @var $editDecisionDao EditDecisionDAO */
114  $editorRecommendations = $editDecisionDao->getEditorDecisions($submission->getId(), $this->getStageId(), null, $user->getId());
115 
116  // Set form data
117  $recommendationOptions = (new EditorDecisionActionsManager())->getRecommendationOptions($this->getStageId());
118  $data = array(
119  'submissionId' => $submission->getId(),
120  'stageId' => $this->getStageId(),
121  'reviewRoundId' => $this->getReviewRound()->getId(),
122  'editorRecommendations' => $editorRecommendations,
123  'recommendationOptions' => $recommendationOptions,
124  'editors' => $editorsStr,
125  'personalMessage' => $email->getBody(),
126  );
127  foreach($data as $key => $value) {
128  $this->setData($key, $value);
129  }
130  return parent::initData();
131  }
132 
136  function fetch($request, $template = null, $display = false) {
137  $templateMgr = TemplateManager::getManager($request);
138  $templateMgr->assign(array(
139  'allowedVariables' => [
140  'recommendation' => __('editor.submission.recommendation'),
141  ],
142  ));
143  return parent::fetch($request, $template, $display);
144  }
145 
149  function readInputData() {
150  $this->readUserVars(array('recommendation', 'personalMessage', 'skipEmail', 'skipDiscussion'));
151  parent::readInputData();
152  }
153 
157  function execute(...$functionParams) {
158  parent::execute(...$functionParams);
159 
160  // Record the recommendation.
161  $request = Application::get()->getRequest();
162  $submission = $this->getSubmission();
163  $reviewRound = $this->getReviewRound();
164  $recommendation = $this->getData('recommendation');
165 
166  // Record the recommendation
167  import('lib.pkp.classes.submission.action.EditorAction');
168  $editorAction = new EditorAction();
169  // Get editor action labels needed for the recording
170  $recommendationOptions = (new EditorDecisionActionsManager())->getRecommendationOptions($this->getStageId());
171  $actionLabels = array($recommendation => $recommendationOptions[$recommendation]);
172  $editorAction->recordDecision($request, $submission, $recommendation, $actionLabels, $reviewRound, $this->getStageId(), true);
173 
174  if (!$this->getData('skipEmail') || !$this->getData('skipDiscussion')) {
175  $router = $request->getRouter();
176  $user = $request->getUser();
177 
178  // Send the email to the decision making editors assigned to this submission.
179  import('lib.pkp.classes.mail.SubmissionMailTemplate');
180  $email = new SubmissionMailTemplate($submission, 'EDITOR_RECOMMENDATION', null, null, null, false);
181  $email->setBody($this->getData('personalMessage'));
182 
183  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
184  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
185  $editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $this->getStageId());
186  foreach ($editorsStageAssignments as $editorsStageAssignment) {
187  if (!$editorsStageAssignment->getRecommendOnly()) {
188  $editor = $userDao->getById($editorsStageAssignment->getUserId());
189  $editorFullName = $editor->getFullName();
190  $email->addRecipient($editor->getEmail(), $editorFullName);
191  }
192  }
193 
194  DAORegistry::getDAO('SubmissionEmailLogDAO'); // Load constants
195  $email->setEventType(SUBMISSION_EMAIL_EDITOR_RECOMMEND_NOTIFY);
196 
197  $dispatcher = $router->getDispatcher();
198  $submissionUrl = $dispatcher->url($request, ROUTE_PAGE, null, 'workflow', 'index', array($submission->getId(), $this->getStageId()));
199  $email->assignParams(array(
200  'editors' => $this->getData('editors'),
201  'editorialContactSignature' => $user->getContactSignature(),
202  'submissionUrl' => $submissionUrl,
203  'recommendation' => __($recommendationOptions[$recommendation]),
204  ));
205  if (!$this->getData('skipEmail')) {
206  if (!$email->send($request)) {
207  import('classes.notification.NotificationManager');
208  $notificationMgr = new NotificationManager();
209  $notificationMgr->createTrivialNotification($request->getUser()->getId(), NOTIFICATION_TYPE_ERROR, array('contents' => __('email.compose.error')));
210  }
211  }
212 
213  if (!$this->getData('skipDiscussion')) {
214  // Create a discussion
215  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
216  $query = $queryDao->newDataObject();
217  $query->setAssocType(ASSOC_TYPE_SUBMISSION);
218  $query->setAssocId($submission->getId());
219  $query->setStageId($this->getStageId());
220  $query->setSequence(REALLY_BIG_NUMBER);
221  $queryDao->insertObject($query);
222  $queryDao->resequence(ASSOC_TYPE_SUBMISSION, $submission->getId());
223 
224  // Add the decision making editors as discussion participants
225  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
226  $userDao = DAORegistry::getDAO('UserDAO'); /* @var $userDao UserDAO */
227  $discussionParticipantsIds = array();
228  $editorsStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submission->getId(), $this->getStageId());
229  foreach ($editorsStageAssignments as $editorsStageAssignment) {
230  if (!$editorsStageAssignment->getRecommendOnly()) {
231  if (!in_array($editorsStageAssignment->getUserId(), $discussionParticipantsIds)) {
232  $discussionParticipantsIds[] = $editorsStageAssignment->getUserId();
233  $queryDao->insertParticipant($query->getId(), $editorsStageAssignment->getUserId());
234  }
235  }
236  }
237 
238  $noteDao = DAORegistry::getDAO('NoteDAO'); /* @var $noteDao NoteDAO */
239  $note = $noteDao->newDataObject();
240  $note->setAssocType(ASSOC_TYPE_QUERY);
241  $note->setAssocId($query->getId());
242  $email->replaceParams();
243  $note->setContents($email->getBody());
244  $note->setTitle(__('editor.submission.recommendation'));
245  $note->setDateCreated(Core::getCurrentDate());
246  $note->setDateModified(Core::getCurrentDate());
247  $note->setUserId( $user->getId());
248  $noteDao->insertObject($note);
249 
250  // Add task
251  $notificationMgr = new NotificationManager();
252  foreach ($discussionParticipantsIds as $discussionParticipantsId) {
253  $notificationMgr->createNotification(
254  $request,
255  $discussionParticipantsId,
256  NOTIFICATION_TYPE_NEW_QUERY,
257  $request->getContext()->getId(),
258  ASSOC_TYPE_QUERY,
259  $query->getId(),
260  NOTIFICATION_LEVEL_TASK
261  );
262  }
263  }
264  }
265  }
266 
267 }
268 
269 
RecommendationForm
Editor recommendation form.
Definition: RecommendationForm.inc.php:21
RecommendationForm\initData
initData()
Definition: RecommendationForm.inc.php:90
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
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
FormValidatorPost
Form validation check to make sure the form is POSTed.
Definition: FormValidatorPost.inc.php:18
RecommendationForm\getStageId
getStageId()
Definition: RecommendationForm.inc.php:72
EditorDecisionActionsManager
Wrapper class for create and assign editor decisions actions to template manager.
Definition: EditorDecisionActionsManager.inc.php:33
RecommendationForm\readInputData
readInputData()
Definition: RecommendationForm.inc.php:158
RecommendationForm\getReviewRound
getReviewRound()
Definition: RecommendationForm.inc.php:80
PKPTemplateManager\getManager
static & getManager($request=null)
Definition: PKPTemplateManager.inc.php:1239
RecommendationForm\__construct
__construct($submission, $stageId, $reviewRound)
Definition: RecommendationForm.inc.php:46
RecommendationForm\$_stageId
$_stageId
Definition: RecommendationForm.inc.php:32
Core\getCurrentDate
static getCurrentDate($ts=null)
Definition: Core.inc.php:63
RecommendationForm\fetch
fetch($request, $template=null, $display=false)
Definition: RecommendationForm.inc.php:145
Form\addCheck
addCheck($formValidator)
Definition: Form.inc.php:395
RecommendationForm\getSubmission
getSubmission()
Definition: RecommendationForm.inc.php:64
NotificationManager
Definition: NotificationManager.inc.php:19
RecommendationForm\$_submission
$_submission
Definition: RecommendationForm.inc.php:26
FormValidatorCSRF
Form validation check to make sure the CSRF token is correct.
Definition: FormValidatorCSRF.inc.php:18
RecommendationForm\execute
execute(... $functionParams)
Definition: RecommendationForm.inc.php:166
Form
Class defining basic operations for handling HTML forms.
Definition: Form.inc.php:47
EditorAction
Editor actions.
Definition: EditorAction.inc.php:19
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
RecommendationForm\$_reviewRound
$_reviewRound
Definition: RecommendationForm.inc.php:38