Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
PendingRevisionsNotificationManager.inc.php
1 <?php
2 
16 import('lib.pkp.classes.notification.managerDelegate.RevisionsNotificationManager');
17 
19 
24  function PendingRevisionsNotificationManager($notificationType) {
25  parent::RevisionsNotificationManager($notificationType);
26  }
27 
31  public function getNotificationUrl($request, $notification) {
32  $submissionDao = Application::getSubmissionDAO();
33  $submission = $submissionDao->getById($notification->getAssocId());
34 
35  import('lib.pkp.controllers.grid.submissions.SubmissionsListGridCellProvider');
36  list($page, $operation) = SubmissionsListGridCellProvider::getPageAndOperationByUserRoles($request, $submission);
37 
38  if ($page == 'workflow') {
39  $stageData = $this->_getStageDataByType();
40  $operation = $stageData['path'];
41  }
42 
43  $router = $request->getRouter();
44  $dispatcher = $router->getDispatcher();
45  $contextDao = Application::getContextDAO();
46  $context = $contextDao->getById($submission->getContextId());
47  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), $page, $operation, $submission->getId());
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 = Application::getSubmissionDAO();
70  $submission = $submissionDao->getById($submissionId);
71  $reviewRoundDao = DAORegistry::getDAO('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  $expectedStageId = $stageData['id'];
101 
102  $pendingRevisionDecision = $this->findValidPendingRevisionsDecision($submissionId, $expectedStageId);
103  $removeNotifications = false;
104 
105  if ($pendingRevisionDecision) {
106  if ($this->responseExists($pendingRevisionDecision, $submissionId)) {
107  // Some user already uploaded a revision. Flag to delete any existing notification.
108  $removeNotifications = true;
109  } else {
110  // Create or update a pending revision task notification.
111  $context = $request->getContext();
112  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
113  $notificationDao->build(
114  $context->getId(),
115  NOTIFICATION_LEVEL_TASK,
116  $this->getNotificationType(),
117  ASSOC_TYPE_SUBMISSION,
118  $submissionId,
119  $userId
120  );
121  }
122  } else {
123  // No pending revision decision or other later decision overriden it.
124  // Flag to delete any existing notification.
125  $removeNotifications = true;
126  }
127 
128  if ($removeNotifications) {
129  $context = $request->getContext();
130  $notificationDao = DAORegistry::getDAO('NotificationDAO');
131  $notificationDao->deleteByAssoc(ASSOC_TYPE_SUBMISSION, $submissionId, $userId, $this->getNotificationType(), $context->getId());
132  }
133  }
134 
135 
136  //
137  // Private helper methods.
138  //
144  private function _getStageDataByType() {
145  $userGroupDao = DAORegistry::getDAO('UserGroupDAO'); /* @var $userGroupDao UserGroupDAO */
146  $stagesData = $userGroupDao->getWorkflowStageKeysAndPaths();
147 
148  switch ($this->getNotificationType()) {
149  case NOTIFICATION_TYPE_PENDING_INTERNAL_REVISIONS:
150  return $stagesData[WORKFLOW_STAGE_ID_INTERNAL_REVIEW];
151  case NOTIFICATION_TYPE_PENDING_EXTERNAL_REVISIONS:
152  return $stagesData[WORKFLOW_STAGE_ID_EXTERNAL_REVIEW];
153  default:
154  assert(false);
155  }
156  }
157 }
158 
159 ?>
static & getDAO($name, $dbconn=null)
Pending revision notification types manager delegate.
static requireComponents()
An action to upload a revision of file currently under review.
static getSubmissionDAO()
findValidPendingRevisionsDecision($submissionId, $expectedStageId)
updateNotification($request, $userIds, $assocType, $assocId)
static getPageAndOperationByUserRoles($request, $submission, $userId=null)
Base class for revision notification types manager delegate.
static getContextDAO()