Open Journal Systems  3.0.0
 All Classes Namespaces Functions Variables Groups Pages
EditorAction.inc.php
1 <?php
2 
16 import('lib.pkp.classes.submission.action.PKPAction');
17 
18 // Access decision actions constants.
19 import('classes.workflow.EditorDecisionActionsManager');
20 
21 class EditorAction extends PKPAction {
25  function EditorAction() {
26  parent::PKPAction();
27  }
28 
29  //
30  // Actions.
31  //
41  function recordDecision($request, $submission, $decision, $decisionLabels, $reviewRound = null, $stageId = null) {
42  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO');
43 
44  // Define the stage and round data.
45  if (!is_null($reviewRound)) {
46  $stageId = $reviewRound->getStageId();
47  } else {
48  if ($stageId == null) {
49  // We consider that the decision is being made for the current
50  // submission stage.
51  $stageId = $submission->getStageId();
52  }
53  }
54 
55  $editorAssigned = $stageAssignmentDao->editorAssignedToStage(
56  $submission->getId(),
57  $stageId
58  );
59 
60  // Sanity checks
61  if (!$editorAssigned || !isset($decisionLabels[$decision])) return false;
62 
63  $user = $request->getUser();
64  $editorDecision = array(
65  'editDecisionId' => null,
66  'editorId' => $user->getId(),
67  'decision' => $decision,
68  'dateDecided' => date(Core::getCurrentDate())
69  );
70 
71  $result = $editorDecision;
72  if (!HookRegistry::call('EditorAction::recordDecision', array(&$submission, &$editorDecision, &$result))) {
73  // Record the new decision
74  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO');
75  $editDecisionDao->updateEditorDecision($submission->getId(), $editorDecision, $stageId, $reviewRound);
76 
77  // Stamp the submission modified
78  $submission->setStatus(STATUS_QUEUED);
79  $submission->stampStatusModified();
80  $submissionDao = Application::getSubmissionDAO();
81  $submissionDao->updateObject($submission);
82 
83  // Add log entry
84  import('lib.pkp.classes.log.SubmissionLog');
85  import('lib.pkp.classes.log.PKPSubmissionEventLogEntry');
86  AppLocale::requireComponents(LOCALE_COMPONENT_APP_COMMON, LOCALE_COMPONENT_APP_EDITOR);
87  SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_EDITOR_DECISION, 'log.editor.decision', array('editorName' => $user->getFullName(), 'submissionId' => $submission->getId(), 'decision' => __($decisionLabels[$decision])));
88  }
89  return $result;
90  }
91 
98  function clearReview($request, $submissionId, $reviewId) {
99  $submissionDao = Application::getSubmissionDAO();
100  $submission = $submissionDao->getById($submissionId);
101  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
102  $userDao = DAORegistry::getDAO('UserDAO');
103 
104  $reviewAssignment = $reviewAssignmentDao->getById($reviewId);
105 
106  if (isset($reviewAssignment) && $reviewAssignment->getSubmissionId() == $submission->getId() && !HookRegistry::call('EditorAction::clearReview', array(&$submission, $reviewAssignment))) {
107  $reviewer = $userDao->getById($reviewAssignment->getReviewerId());
108  if (!isset($reviewer)) return false;
109  $reviewAssignmentDao->deleteById($reviewId);
110 
111  // Stamp the modification date
112  $submission->stampModified();
113  $submissionDao->updateObject($submission);
114 
115  $notificationDao = DAORegistry::getDAO('NotificationDAO');
116  $notificationDao->deleteByAssoc(
117  ASSOC_TYPE_REVIEW_ASSIGNMENT,
118  $reviewAssignment->getId(),
119  $reviewAssignment->getReviewerId(),
120  NOTIFICATION_TYPE_REVIEW_ASSIGNMENT
121  );
122 
123  // Insert a trivial notification to indicate the reviewer was removed successfully.
124  $currentUser = $request->getUser();
125  $notificationMgr = new NotificationManager();
126  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.removedReviewer')));
127 
128  // Update the review round status, if needed.
129  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO');
130  $reviewRound = $reviewRoundDao->getById($reviewAssignment->getReviewRoundId());
131  $reviewAssignments = $reviewAssignmentDao->getBySubmissionId($reviewRound->getSubmissionId(), $reviewRound->getId(), $reviewRound->getStageId());
132  $reviewRoundDao->updateStatus($reviewRound, $reviewAssignments);
133 
134  $notificationMgr->updateNotification(
135  $request,
136  array(NOTIFICATION_TYPE_ALL_REVIEWS_IN),
137  null,
138  ASSOC_TYPE_REVIEW_ROUND,
139  $reviewRound->getId()
140  );
141 
142  // Add log
143  import('lib.pkp.classes.log.SubmissionLog');
144  import('classes.log.SubmissionEventLogEntry');
145  SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_REVIEW_CLEAR, 'log.review.reviewCleared', array('reviewerName' => $reviewer->getFullName(), 'submissionId' => $submission->getId(), 'stageId' => $reviewAssignment->getStageId(), 'round' => $reviewAssignment->getRound()));
146 
147  return true;
148  } else return false;
149  }
150 
160  function addReviewer($request, $submission, $reviewerId, &$reviewRound, $reviewDueDate = null, $responseDueDate = null, $reviewMethod = null) {
161  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO');
162  $userDao = DAORegistry::getDAO('UserDAO');
163 
164  $reviewer = $userDao->getById($reviewerId);
165 
166  // Check to see if the requested reviewer is not already
167  // assigned to review this submission.
168 
169  $assigned = $reviewAssignmentDao->reviewerExists($reviewRound->getId(), $reviewerId);
170 
171  // Only add the reviewer if he has not already
172  // been assigned to review this submission.
173  $stageId = $reviewRound->getStageId();
174  $round = $reviewRound->getRound();
175  if (!$assigned && isset($reviewer) && !HookRegistry::call('EditorAction::addReviewer', array(&$submission, $reviewerId))) {
176  $reviewAssignment = new ReviewAssignment();
177  $reviewAssignment->setSubmissionId($submission->getId());
178  $reviewAssignment->setReviewerId($reviewerId);
179  $reviewAssignment->setDateAssigned(Core::getCurrentDate());
180  $reviewAssignment->setStageId($stageId);
181  $reviewAssignment->setRound($round);
182  $reviewAssignment->setReviewRoundId($reviewRound->getId());
183  if (isset($reviewMethod)) {
184  $reviewAssignment->setReviewMethod($reviewMethod);
185  }
186  $reviewAssignmentDao->insertObject($reviewAssignment);
187 
188  // Stamp modification date
189  $submission->stampStatusModified();
190  $submissionDao = Application::getSubmissionDAO();
191  $submissionDao->updateObject($submission);
192 
193  $this->setDueDates($request, $submission, $reviewAssignment, $reviewDueDate, $responseDueDate);
194 
195  // Add notification
196  $notificationMgr = new NotificationManager();
197  $notificationMgr->createNotification(
198  $request,
199  $reviewerId,
200  NOTIFICATION_TYPE_REVIEW_ASSIGNMENT,
201  $submission->getContextId(),
202  ASSOC_TYPE_REVIEW_ASSIGNMENT,
203  $reviewAssignment->getId(),
204  NOTIFICATION_LEVEL_TASK
205  );
206 
207  // Insert a trivial notification to indicate the reviewer was added successfully.
208  $currentUser = $request->getUser();
209  $notificationMgr = new NotificationManager();
210  $notificationMgr->createTrivialNotification($currentUser->getId(), NOTIFICATION_TYPE_SUCCESS, array('contents' => __('notification.addedReviewer')));
211 
212  // Update the review round status.
213  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
214  $reviewAssignments = $reviewAssignmentDao->getBySubmissionId($submission->getId(), $reviewRound->getId(), $stageId);
215  $reviewRoundDao->updateStatus($reviewRound, $reviewAssignments);
216 
217  $notificationMgr->updateNotification(
218  $request,
219  array(NOTIFICATION_TYPE_ALL_REVIEWS_IN),
220  null,
221  ASSOC_TYPE_REVIEW_ROUND,
222  $reviewRound->getId()
223  );
224 
225  // Add log
226  import('lib.pkp.classes.log.SubmissionLog');
227  import('lib.pkp.classes.log.PKPSubmissionEventLogEntry');
228  SubmissionLog::logEvent($request, $submission, SUBMISSION_LOG_REVIEW_ASSIGN, 'log.review.reviewerAssigned', array('reviewerName' => $reviewer->getFullName(), 'submissionId' => $submission->getId(), 'stageId' => $stageId, 'round' => $round));
229  }
230  }
231 
241  function setDueDates($request, $submission, $reviewAssignment, $reviewDueDate = null, $responseDueDate = null, $logEntry = false) {
242  $userDao = DAORegistry::getDAO('UserDAO');
243  $context = $request->getContext();
244 
245  $reviewer = $userDao->getById($reviewAssignment->getReviewerId());
246  if (!isset($reviewer)) return false;
247 
248  if ($reviewAssignment->getSubmissionId() == $submission->getId() && !HookRegistry::call('EditorAction::setDueDates', array(&$reviewAssignment, &$reviewer, &$reviewDueDate, &$responseDueDate))) {
249 
250  // Set the review due date
251  $defaultNumWeeks = $context->getSetting('numWeeksPerReview');
252  $reviewAssignment->setDateDue(DAO::formatDateToDB($reviewDueDate, $defaultNumWeeks, false));
253 
254  // Set the response due date
255  $defaultNumWeeks = $context->getSetting('numWeeksPerReponse');
256  $reviewAssignment->setDateResponseDue(DAO::formatDateToDB($responseDueDate, $defaultNumWeeks, false));
257 
258  // update the assignment (with both the new dates)
259  $reviewAssignment->stampModified();
260  $reviewAssignmentDao = DAORegistry::getDAO('ReviewAssignmentDAO'); /* @var $reviewAssignmentDao ReviewAssignmentDAO */
261  $reviewAssignmentDao->updateObject($reviewAssignment);
262 
263  // N.B. Only logging Date Due
264  if ($logEntry) {
265  // Add log
266  import('lib.pkp.classes.log.SubmissionLog');
267  import('classes.log.SubmissionEventLogEntry');
269  $request,
270  $submission,
271  SUBMISSION_LOG_REVIEW_SET_DUE_DATE,
272  'log.review.reviewDueDateSet',
273  array(
274  'reviewerName' => $reviewer->getFullName(),
275  'dueDate' => strftime(
276  Config::getVar('general', 'date_format_short'),
277  strtotime($reviewAssignment->getDateDue())
278  ),
279  'submissionId' => $submission->getId(),
280  'stageId' => $reviewAssignment->getStageId(),
281  'round' => $reviewAssignment->getRound()
282  )
283  );
284  }
285  }
286  }
287 
294  function assignDefaultStageParticipants($submission, $stageId, $request) {
295  }
296 
303  function incrementWorkflowStage($submission, $newStage, $request) {
304  // Change the submission's workflow stage.
305  $submission->setStageId($newStage);
306  $submissionDao = Application::getSubmissionDAO();
307  $submissionDao->updateObject($submission);
308 
309  // Assign the default users to the next workflow stage.
310  $this->assignDefaultStageParticipants($submission, $newStage, $request);
311  }
312 
313 }
314 
315 ?>
static & getDAO($name, $dbconn=null)
formatDateToDB($date, $defaultNumWeeks=null, $acceptPastDate=true)
Definition: DAO.inc.php:635
incrementWorkflowStage($submission, $newStage, $request)
static requireComponents()
setDueDates($request, $submission, $reviewAssignment, $reviewDueDate=null, $responseDueDate=null, $logEntry=false)
assignDefaultStageParticipants($submission, $stageId, $request)
static getVar($section, $key, $default=null)
Definition: Config.inc.php:35
static getSubmissionDAO()
static call($hookName, $args=null)
recordDecision($request, $submission, $decision, $decisionLabels, $reviewRound=null, $stageId=null)
Application-independent submission actions.
clearReview($request, $submissionId, $reviewId)
static logEvent($request, $submission, $eventType, $messageKey, $params=array())
Editor actions.
Describes review assignment properties.
addReviewer($request, $submission, $reviewerId, &$reviewRound, $reviewDueDate=null, $responseDueDate=null, $reviewMethod=null)
static getCurrentDate($ts=null)
Definition: Core.inc.php:95