Open Journal Systems  3.3.0
PKPEditingProductionStatusNotificationManager.inc.php
1 <?php
2 
16 import('lib.pkp.classes.notification.NotificationManagerDelegate');
17 
19 
24  function __construct($notificationType) {
25  parent::__construct($notificationType);
26  }
27 
31  public function getNotificationMessage($request, $notification) {
32  switch ($notification->getType()) {
33  case NOTIFICATION_TYPE_ASSIGN_COPYEDITOR:
34  return __('notification.type.assignCopyeditors');
35  case NOTIFICATION_TYPE_AWAITING_COPYEDITS:
36  return __('notification.type.awaitingCopyedits');
37  case NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER:
38  return __('notification.type.assignProductionUser');
39  case NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS:
40  return __('notification.type.awaitingRepresentations');
41  default:
42  assert(false);
43  }
44  }
45 
49  public function getNotificationUrl($request, $notification) {
50  $dispatcher = Application::get()->getDispatcher();
51  $contextDao = Application::getContextDAO();
52  $context = $contextDao->getById($notification->getContextId());
53 
54  switch ($notification->getType()) {
55  case NOTIFICATION_TYPE_ASSIGN_COPYEDITOR:
56  case NOTIFICATION_TYPE_AWAITING_COPYEDITS:
57  case NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER:
58  case NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS:
59  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
60  return $dispatcher->url($request, ROUTE_PAGE, $context->getPath(), 'workflow', 'access', $notification->getAssocId());
61  default:
62  assert(false);
63  }
64  }
65 
69  public function getStyleClass($notification) {
70  return NOTIFICATION_STYLE_CLASS_INFORMATION;
71  }
72 
76  public function updateNotification($request, $userIds, $assocType, $assocId) {
77  $context = $request->getContext();
78  $contextId = $context->getId();
79 
80  assert($assocType == ASSOC_TYPE_SUBMISSION);
81  $submissionId = $assocId;
82  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
83  $submission = $submissionDao->getById($submissionId);
84 
85  $stageAssignmentDao = DAORegistry::getDAO('StageAssignmentDAO'); /* @var $stageAssignmentDao StageAssignmentDAO */
86  $editorStageAssignments = $stageAssignmentDao->getEditorsAssignedToStage($submissionId, $submission->getStageId());
87 
88  // Get the copyediting and production discussions
89  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
90  $editingQueries = $queryDao->getByAssoc(ASSOC_TYPE_SUBMISSION, $submissionId, WORKFLOW_STAGE_ID_EDITING);
91  $productionQueries = $queryDao->getByAssoc(ASSOC_TYPE_SUBMISSION, $submissionId, WORKFLOW_STAGE_ID_PRODUCTION);
92 
93  // Get the copyedited files
94  $submissionFileDao = DAORegistry::getDAO('SubmissionFileDAO'); /* @var $submissionFileDao SubmissionFileDAO */
95  import('lib.pkp.classes.submission.SubmissionFile');
96  $copyeditedFiles = $submissionFileDao->getLatestRevisions($submissionId, SUBMISSION_FILE_COPYEDIT);
97 
98  // Get representations
99  $representationDao = Application::getRepresentationDAO();
100  $representations = $representationDao->getByPublicationId($submission->getLatestPublication()->getId());
101 
102  $notificationType = $this->getNotificationType();
103 
104  foreach ($editorStageAssignments as $editorStageAssignment) {
105  switch ($submission->getStageId()) {
106  case WORKFLOW_STAGE_ID_PRODUCTION:
107  if ($notificationType == NOTIFICATION_TYPE_ASSIGN_COPYEDITOR || $notificationType == NOTIFICATION_TYPE_AWAITING_COPYEDITS) {
108  // Remove 'assign a copyeditor' and 'awaiting copyedits' notification
109  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
110  } else {
111  // If there is a representation
112  if (!$representations->wasEmpty()) {
113  // Remove 'assign a production user' and 'awaiting representations' notification
114  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
115  } else {
116  // If a production user is assigned i.e. there is a production discussion
117  if (!$productionQueries->wasEmpty()) {
118  if ($notificationType == NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS) {
119  // Add 'awaiting representations' notification
120  $this->_createNotification(
121  $request,
122  $submissionId,
123  $editorStageAssignment->getUserId(),
124  $notificationType,
125  $contextId
126  );
127  } elseif ($notificationType == NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER) {
128  // Remove 'assign a production user' notification
129  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
130  }
131  } else {
132  if ($notificationType == NOTIFICATION_TYPE_ASSIGN_PRODUCTIONUSER) {
133  // Add 'assign a user' notification
134  $this->_createNotification(
135  $request,
136  $submissionId,
137  $editorStageAssignment->getUserId(),
138  $notificationType,
139  $contextId
140  );
141  } elseif ($notificationType == NOTIFICATION_TYPE_AWAITING_REPRESENTATIONS) {
142  // Remove 'awaiting representations' notification
143  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
144  }
145  }
146  }
147  }
148  break;
149  case WORKFLOW_STAGE_ID_EDITING:
150  if (!empty($copyeditedFiles)) {
151  // Remove 'assign a copyeditor' and 'awaiting copyedits' notification
152  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
153  } else {
154  // If a copyeditor is assigned i.e. there is a copyediting discussion
155  if (!$editingQueries->wasEmpty()) {
156  if ($notificationType == NOTIFICATION_TYPE_AWAITING_COPYEDITS) {
157  // Add 'awaiting copyedits' notification
158  $this->_createNotification(
159  $request,
160  $submissionId,
161  $editorStageAssignment->getUserId(),
162  $notificationType,
163  $contextId
164  );
165  } elseif ($notificationType == NOTIFICATION_TYPE_ASSIGN_COPYEDITOR) {
166  // Remove 'assign a copyeditor' notification
167  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
168  }
169  } else {
170  if ($notificationType == NOTIFICATION_TYPE_ASSIGN_COPYEDITOR) {
171  // Add 'assign a copyeditor' notification
172  $this->_createNotification(
173  $request,
174  $submissionId,
175  $editorStageAssignment->getUserId(),
176  $notificationType,
177  $contextId
178  );
179  } elseif ($notificationType == NOTIFICATION_TYPE_AWAITING_COPYEDITS) {
180  // Remove 'awaiting copyedits' notification
181  $this->_removeNotification($submissionId, $editorStageAssignment->getUserId(), $notificationType, $contextId);
182  }
183  }
184  }
185  break;
186  }
187  }
188  }
189 
190  //
191  // Helper methods.
192  //
200  function _removeNotification($submissionId, $userId, $notificationType, $contextId) {
201  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
202  $notificationDao->deleteByAssoc(
203  ASSOC_TYPE_SUBMISSION,
204  $submissionId,
205  $userId,
206  $notificationType,
207  $contextId
208  );
209  }
210 
219  function _createNotification($request, $submissionId, $userId, $notificationType, $contextId) {
220  $notificationDao = DAORegistry::getDAO('NotificationDAO'); /* @var $notificationDao NotificationDAO */
221  $notificationFactory = $notificationDao->getByAssoc(
222  ASSOC_TYPE_SUBMISSION,
223  $submissionId,
224  $userId,
225  $notificationType,
226  $contextId
227  );
228  if ($notificationFactory->wasEmpty()) {
229  $notificationMgr = new NotificationManager();
230  $notificationMgr->createNotification(
231  $request,
232  $userId,
233  $notificationType,
234  $contextId,
235  ASSOC_TYPE_SUBMISSION,
236  $submissionId,
237  NOTIFICATION_LEVEL_NORMAL,
238  null,
239  true
240  );
241  }
242  }
243 
244 }
245 
246 
Application\getContextDAO
static getContextDAO()
Definition: Application.inc.php:137
PKPEditingProductionStatusNotificationManager\_removeNotification
_removeNotification($submissionId, $userId, $notificationType, $contextId)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:200
Application\getRepresentationDAO
static getRepresentationDAO()
Definition: Application.inc.php:162
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
PKPEditingProductionStatusNotificationManager\_createNotification
_createNotification($request, $submissionId, $userId, $notificationType, $contextId)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:219
NotificationManagerDelegate
Abstract class to support notification manager delegates that provide default implementation to the i...
Definition: NotificationManagerDelegate.inc.php:21
NotificationManagerDelegate\getNotificationType
getNotificationType()
Definition: NotificationManagerDelegate.inc.php:41
PKPEditingProductionStatusNotificationManager\getNotificationMessage
getNotificationMessage($request, $notification)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:31
PKPEditingProductionStatusNotificationManager\updateNotification
updateNotification($request, $userIds, $assocType, $assocId)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:76
PKPEditingProductionStatusNotificationManager
Editing and productionstatus notifications types manager delegate.
Definition: PKPEditingProductionStatusNotificationManager.inc.php:18
PKPEditingProductionStatusNotificationManager\getNotificationUrl
getNotificationUrl($request, $notification)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:49
NotificationManager
Definition: NotificationManager.inc.php:19
PKPApplication\get
static get()
Definition: PKPApplication.inc.php:235
PKPEditingProductionStatusNotificationManager\getStyleClass
getStyleClass($notification)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:69
PKPEditingProductionStatusNotificationManager\__construct
__construct($notificationType)
Definition: PKPEditingProductionStatusNotificationManager.inc.php:24