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