Open Monograph Press  3.3.0
PromoteForm.inc.php
1 <?php
2 
16 import('lib.pkp.controllers.modals.editorDecision.form.EditorDecisionWithEmailForm');
17 
18 // Access decision actions constants.
19 import('classes.workflow.EditorDecisionActionsManager');
20 
22 
30  function __construct($submission, $decision, $stageId, $reviewRound = null) {
31  if (!in_array($decision, $this->_getDecisions())) {
32  fatalError('Invalid decision!');
33  }
34 
35  $this->setSaveFormOperation('savePromote');
36 
37  parent::__construct(
38  $submission, $decision, $stageId,
39  'controllers/modals/editorDecision/form/promoteForm.tpl',
40  $reviewRound
41  );
42 
43  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_MANAGER);
44  }
45 
46 
47  //
48  // Implement protected template methods from Form
49  //
53  function initData($actionLabels = array()) {
54  $request = Application::get()->getRequest();
55  $actionLabels = (new EditorDecisionActionsManager())->getActionLabels($request->getContext(), $this->getStageId(), $this->_getDecisions());
56 
57  $submission = $this->getSubmission();
58  $this->setData('stageId', $this->getStageId());
59 
60  // If payments are enabled for this stage/form, default to requiring them
61  $this->setData('requestPayment', true);
62 
63  return parent::initData($actionLabels);
64  }
65 
69  function readInputData() {
70  $this->readUserVars(array('requestPayment'));
71  parent::readInputData();
72  }
73 
77  function execute(...$functionParams) {
78  parent::execute(...$functionParams);
79 
80  $request = Application::get()->getRequest();
81 
82  // Retrieve the submission.
83  $submission = $this->getSubmission();
84 
85  // Get this form decision actions labels.
86  $actionLabels = (new EditorDecisionActionsManager())->getActionLabels($request->getContext(), $this->getStageId(), $this->_getDecisions());
87 
88  // Record the decision.
89  $reviewRound = $this->getReviewRound();
90  $decision = $this->getDecision();
91  import('lib.pkp.classes.submission.action.EditorAction');
92  $editorAction = new EditorAction();
93  $editorAction->recordDecision($request, $submission, $decision, $actionLabels, $reviewRound);
94 
95  // Identify email key and status of round.
96  import('lib.pkp.classes.file.SubmissionFileManager');
97  $submissionFileManager = new SubmissionFileManager($submission->getContextId(), $submission->getId());
98  switch ($decision) {
99  case SUBMISSION_EDITOR_DECISION_ACCEPT:
100  $emailKey = 'EDITOR_DECISION_ACCEPT';
101  $status = REVIEW_ROUND_STATUS_ACCEPTED;
102 
103  $this->_updateReviewRoundStatus($submission, $status, $reviewRound);
104 
105  // Move to the editing stage.
106  $editorAction->incrementWorkflowStage($submission, WORKFLOW_STAGE_ID_EDITING, $request);
107 
108  // Bring in the SUBMISSION_FILE_* constants.
109  import('lib.pkp.classes.submission.SubmissionFile');
110  // Bring in the Manager (we need it).
111  import('lib.pkp.classes.file.SubmissionFileManager');
112 
113  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
114 
115  $selectedFiles = $this->getData('selectedFiles');
116  if(is_array($selectedFiles)) {
117  foreach ($selectedFiles as $fileId) {
118  $revisionNumber = $submissionFileDao->getLatestRevisionNumber($fileId);
119  $submissionFileManager->copyFileToFileStage($fileId, $revisionNumber, SUBMISSION_FILE_FINAL, null, true);
120  }
121  }
122 
123  // Send email to the author.
124  $this->_sendReviewMailToAuthor($submission, $emailKey, $request);
125  break;
126 
127  case SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW:
128  $emailKey = 'EDITOR_DECISION_SEND_TO_EXTERNAL';
129  $status = REVIEW_ROUND_STATUS_SENT_TO_EXTERNAL;
130 
131  $this->_updateReviewRoundStatus($submission, $status, $reviewRound);
132 
133  // Move to the external review stage.
134  $editorAction->incrementWorkflowStage($submission, WORKFLOW_STAGE_ID_EXTERNAL_REVIEW, $request);
135 
136  // Create an initial external review round.
137  $this->_initiateReviewRound($submission, WORKFLOW_STAGE_ID_EXTERNAL_REVIEW, $request, REVIEW_ROUND_STATUS_PENDING_REVIEWERS);
138 
139  // Send email to the author.
140  $this->_sendReviewMailToAuthor($submission, $emailKey, $request);
141  break;
142  case SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION:
143  $emailKey = 'EDITOR_DECISION_SEND_TO_PRODUCTION';
144  // FIXME: this is copy-pasted from above, save the FILE_GALLEY.
145 
146  // Move to the editing stage.
147  $editorAction->incrementWorkflowStage($submission, WORKFLOW_STAGE_ID_PRODUCTION, $request);
148 
149  // Bring in the SUBMISSION_FILE_* constants.
150  import('lib.pkp.classes.submission.SubmissionFile');
151  // Bring in the Manager (we need it).
152  import('lib.pkp.classes.file.SubmissionFileManager');
153 
154  // Move the revisions to the next stage
155  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
156 
157  $selectedFiles = $this->getData('selectedFiles');
158  if(is_array($selectedFiles)) {
159  foreach ($selectedFiles as $fileId) {
160  $revisionNumber = $submissionFileDao->getLatestRevisionNumber($fileId);
161  $submissionFileManager->copyFileToFileStage($fileId, $revisionNumber, SUBMISSION_FILE_PRODUCTION_READY);
162  }
163  }
164  // Send email to the author.
165  $this->_sendReviewMailToAuthor($submission, $emailKey, $request);
166  break;
167  default:
168  fatalError('Unsupported decision!');
169  }
170 
171  if ($this->getData('requestPayment')) {
172  $context = $request->getContext();
173  $stageDecisions = (new EditorDecisionActionsManager())->getStageDecisions($context, $this->getStageId());
174  $decisionData = $stageDecisions[$decision];
175  if (isset($decisionData['paymentType'])) {
176  $paymentType = $decisionData['paymentType'];
177 
178  // Queue a payment.
179  $paymentManager = Application::getPaymentManager($context);
180  $queuedPayment = $paymentManager->createQueuedPayment($request, $paymentType, $request->getUser()->getId(), $submission->getId(), $decisionData['paymentAmount'], $decisionData['paymentCurrency']);
181  $paymentManager->queuePayment($queuedPayment);
182 
183  // Notify any authors that this needs payment.
184  $notificationMgr = new NotificationManager();
185  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
186  $stageAssignments = $stageAssignmentDao->getBySubmissionAndRoleId($submission->getId(), ROLE_ID_AUTHOR, null);
187  $userIds = array();
188  while ($stageAssignment = $stageAssignments->next()) {
189  if (!in_array($stageAssignment->getUserId(), $userIds)) {
190  $notificationMgr->createNotification($request, $stageAssignment->getUserId(), NOTIFICATION_TYPE_PAYMENT_REQUIRED,
191  $context->getId(), ASSOC_TYPE_QUEUED_PAYMENT, $queuedPayment->getId(), NOTIFICATION_LEVEL_TASK);
192  $userIds[] = $stageAssignment->getUserId();
193  }
194  }
195  }
196  }
197  }
198 
199  //
200  // Private functions
201  //
206  function _getDecisions() {
207  return array(
208  SUBMISSION_EDITOR_DECISION_EXTERNAL_REVIEW,
209  SUBMISSION_EDITOR_DECISION_ACCEPT,
210  SUBMISSION_EDITOR_DECISION_SEND_TO_PRODUCTION
211  );
212  }
213 }
214 
215 
SubmissionFileManager
Helper class for database-backed submission file management tasks.
Definition: SubmissionFileManager.inc.php:30
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PromoteForm\_getDecisions
_getDecisions()
Definition: PromoteForm.inc.php:206
PromoteForm\initData
initData($actionLabels=array())
Definition: PromoteForm.inc.php:53
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
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
Application\getPaymentManager
static getPaymentManager($context)
Definition: Application.inc.php:212
EditorDecisionWithEmailForm
Base class for the editor decision forms.
Definition: EditorDecisionWithEmailForm.inc.php:18
PromoteForm
Form for promoting a submission (to external review or editing)
Definition: PromoteForm.inc.php:21
PromoteForm\readInputData
readInputData()
Definition: PromoteForm.inc.php:69
EditorDecisionActionsManager
Wrapper class for create and assign editor decisions actions to template manager.
Definition: EditorDecisionActionsManager.inc.php:38
EditorDecisionWithEmailForm\_updateReviewRoundStatus
_updateReviewRoundStatus($submission, $status, $reviewRound=null)
Definition: EditorDecisionWithEmailForm.inc.php:180
EditorDecisionForm\getDecision
getDecision()
Definition: EditorDecisionForm.inc.php:73
EditorDecisionForm\_initiateReviewRound
_initiateReviewRound($submission, $stageId, $request, $status=null)
Definition: EditorDecisionForm.inc.php:150
PromoteForm\execute
execute(... $functionParams)
Definition: PromoteForm.inc.php:77
EditorDecisionWithEmailForm\_sendReviewMailToAuthor
_sendReviewMailToAuthor($submission, $emailKey, $request)
Definition: EditorDecisionWithEmailForm.inc.php:202
NotificationManager
Definition: NotificationManager.inc.php:19
EditorAction
Editor actions.
Definition: EditorAction.inc.php:19
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
fatalError
if(!function_exists('import')) fatalError($reason)
Definition: functions.inc.php:32
PromoteForm\__construct
__construct($submission, $decision, $stageId, $reviewRound=null)
Definition: PromoteForm.inc.php:30
EditorDecisionForm\getStageId
getStageId()
Definition: EditorDecisionForm.inc.php:89