Open Journal Systems  3.3.0
PendingRevisionsNotificationManager.inc.php
1 <?php
2 
16 import('lib.pkp.classes.notification.NotificationManagerDelegate');
17 import('lib.pkp.classes.workflow.WorkflowStageDAO');
18 
20 
25  function __construct($notificationType) {
26  parent::__construct($notificationType);
27  }
28 
32  public function getStyleClass($notification) {
33  return NOTIFICATION_STYLE_CLASS_WARNING;
34  }
35 
39  public function getNotificationUrl($request, $notification) {
40  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
41  $submission = $submissionDao->getById($notification->getAssocId());
42 
43  $stageData = $this->_getStageDataByType();
44  $operation = $stageData['path'];
45 
46  import('classes.core.Services');
47  return Services::get('submission')->getWorkflowUrlByUserRoles($submission, $notification->getUserId(), $stageData['path']);
48  }
49 
53  public function getNotificationMessage($request, $notification) {
54  $stageData = $this->_getStageDataByType();
55  AppLocale::requireComponents(LOCALE_COMPONENT_PKP_SUBMISSION); // For stage constants
56  $stageKey = $stageData['translationKey'];
57 
58  return __('notification.type.pendingRevisions', array('stage' => __($stageKey)));
59  }
60 
64  public function getNotificationContents($request, $notification) {
65  $stageData = $this->_getStageDataByType();
66  $stageId = $stageData['id'];
67  $submissionId = $notification->getAssocId();
68 
69  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
70  $submission = $submissionDao->getById($submissionId);
71  $reviewRoundDao = DAORegistry::getDAO('ReviewRoundDAO'); /* @var $reviewRoundDao ReviewRoundDAO */
72  $lastReviewRound = $reviewRoundDao->getLastReviewRoundBySubmissionId($submission->getId(), $stageId);
73 
74  import('lib.pkp.controllers.api.file.linkAction.AddRevisionLinkAction');
75  AppLocale::requireComponents(LOCALE_COMPONENT_APP_EDITOR); // editor.review.uploadRevision
76 
77  $uploadFileAction = new AddRevisionLinkAction(
78  $request, $lastReviewRound, array(ROLE_ID_AUTHOR)
79  );
80 
81  return $this->fetchLinkActionNotificationContent($uploadFileAction, $request);
82  }
83 
87  public function getNotificationTitle($notification) {
88  $stageData = $this->_getStageDataByType();
89  $stageKey = $stageData['translationKey'];
90  return __('notification.type.pendingRevisions.title', array('stage' => __($stageKey)));
91  }
92 
96  public function updateNotification($request, $userIds, $assocType, $assocId) {
97  $userId = current($userIds);
98  $submissionId = $assocId;
99  $stageData = $this->_getStageDataByType();
100  if ($stageData == null) return;
101  $expectedStageId = $stageData['id'];
102 
103  $editDecisionDao = DAORegistry::getDAO('EditDecisionDAO'); /* @var $editDecisionDao EditDecisionDAO */
104  $pendingRevisionDecision = $editDecisionDao->findValidPendingRevisionsDecision($submissionId, $expectedStageId, SUBMISSION_EDITOR_DECISION_PENDING_REVISIONS);
105  $removeNotifications = false;
106 
107  if ($pendingRevisionDecision) {
108  if ($editDecisionDao->responseExists($pendingRevisionDecision, $submissionId)) {
109  // Some user already uploaded a revision. Flag to delete any existing notification.
110  $removeNotifications = true;
111  } else {
112  $context = $request->getContext();
113  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
114  $notificationFactory = $notificationDao->getByAssoc(
115  ASSOC_TYPE_SUBMISSION,
116  $submissionId,
117  $userId,
118  NOTIFICATION_TYPE_EDITOR_DECISION_PENDING_REVISIONS,
119  $context->getId()
120  );
121  if ($notificationFactory->wasEmpty()) {
122  // Create or update a pending revision task notification.
123  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
124  $notificationDao->build(
125  $context->getId(),
126  NOTIFICATION_LEVEL_TASK,
127  $this->getNotificationType(),
128  ASSOC_TYPE_SUBMISSION,
129  $submissionId,
130  $userId
131  );
132  }
133  }
134  } else {
135  // No pending revision decision or other later decision overriden it.
136  // Flag to delete any existing notification.
137  $removeNotifications = true;
138  }
139 
140  if ($removeNotifications) {
141  $context = $request->getContext();
142  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
143  $notificationDao->deleteByAssoc(ASSOC_TYPE_SUBMISSION, $submissionId, $userId, $this->getNotificationType(), $context->getId());
144  $notificationDao->deleteByAssoc(ASSOC_TYPE_SUBMISSION, $submissionId, $userId, NOTIFICATION_TYPE_EDITOR_DECISION_PENDING_REVISIONS, $context->getId());
145  }
146  }
147 
148 
149  //
150  // Private helper methods.
151  //
157  private function _getStageDataByType() {
159 
160  switch ($this->getNotificationType()) {
161  case NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS:
162  return array_key_exists(WORKFLOW_STAGE_ID_INTERNAL_REVIEW, $stagesData) ? $stagesData[WORKFLOW_STAGE_ID_INTERNAL_REVIEW] : null;
163  case NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS:
164  return $stagesData[WORKFLOW_STAGE_ID_EXTERNAL_REVIEW];
165  default:
166  assert(false);
167  }
168  }
169 }
170 
171 
PendingRevisionsNotificationManager\getStyleClass
getStyleClass($notification)
Definition: PendingRevisionsNotificationManager.inc.php:32
AddRevisionLinkAction
An action to upload a revision of file currently under review.
Definition: AddRevisionLinkAction.inc.php:18
AppLocale\requireComponents
static requireComponents()
Definition: env1/MockAppLocale.inc.php:56
PendingRevisionsNotificationManager\getNotificationUrl
getNotificationUrl($request, $notification)
Definition: PendingRevisionsNotificationManager.inc.php:39
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
NotificationManagerDelegate
Abstract class to support notification manager delegates that provide default implementation to the i...
Definition: NotificationManagerDelegate.inc.php:21
PendingRevisionsNotificationManager\getNotificationTitle
getNotificationTitle($notification)
Definition: PendingRevisionsNotificationManager.inc.php:87
NotificationManagerDelegate\getNotificationType
getNotificationType()
Definition: NotificationManagerDelegate.inc.php:41
PendingRevisionsNotificationManager\__construct
__construct($notificationType)
Definition: PendingRevisionsNotificationManager.inc.php:25
PKPNotificationOperationManager\fetchLinkActionNotificationContent
fetchLinkActionNotificationContent($linkAction, $request)
Definition: PKPNotificationOperationManager.inc.php:304
PendingRevisionsNotificationManager\updateNotification
updateNotification($request, $userIds, $assocType, $assocId)
Definition: PendingRevisionsNotificationManager.inc.php:96
WorkflowStageDAO\getWorkflowStageKeysAndPaths
static getWorkflowStageKeysAndPaths()
Definition: WorkflowStageDAO.inc.php:92
PendingRevisionsNotificationManager\getNotificationContents
getNotificationContents($request, $notification)
Definition: PendingRevisionsNotificationManager.inc.php:64
PendingRevisionsNotificationManager
Pending revision notification types manager delegate.
Definition: PendingRevisionsNotificationManager.inc.php:19
PendingRevisionsNotificationManager\getNotificationMessage
getNotificationMessage($request, $notification)
Definition: PendingRevisionsNotificationManager.inc.php:53
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49