Open Monograph Press  1.1
 All Classes Namespaces Functions Variables Groups Pages
SignoffNotificationManager.inc.php
1 <?php
2 
16 import('lib.pkp.classes.notification.NotificationManagerDelegate');
17 
19 
24  function SignoffNotificationManagerDelegate($notificationType) {
25  parent::NotificationManagerDelegate($notificationType);
26  }
27 
28  public function getNotificationTitle($notification) {
29  return __('notification.type.signoff');
30  }
31 
35  public function getNotificationMessage($request, $notification) {
36  AppLocale::requireComponents(LOCALE_COMPONENT_APP_SUBMISSION);
37  return __('submission.upload.signoff');
38  }
39 
43  public function getNotificationContents($request, $notification) {
44  $notificationMessage = $this->getNotificationMessage($request, $notification);
45  switch($notification->getType()) {
46  case NOTIFICATION_TYPE_SIGNOFF_COPYEDIT:
47  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
48  return $this->_getSignoffNotificationContents($request, $notification, 'SIGNOFF_COPYEDITING', $notificationMessage);
49  case NOTIFICATION_TYPE_SIGNOFF_PROOF:
50  assert($notification->getAssocType() == ASSOC_TYPE_SUBMISSION && is_numeric($notification->getAssocId()));
51  return $this->_getSignoffNotificationContents($request, $notification, 'SIGNOFF_PROOFING', $notificationMessage);
52  }
53  }
54 
55  public function getStyleClass($notification) {
56  return NOTIFICATION_STYLE_CLASS_WARNING;
57  }
58 
62  public function updateNotification($request, $userIds, $assocType, $assocId) {
63  $notificationType = $this->getNotificationType();
64 
65  if (is_null($notificationType)) {
66  return false;
67  }
68 
69  $context = $request->getContext();
70  $contextId = $context->getId();
71  $submissionId = $assocId;
72  $userId = current($userIds);
73 
74  // Check for an existing NOTIFICATION_TYPE_SIGNOFF_...
75  $notificationDao = DAORegistry::getDAO('NotificationDAO');
76  $notificationFactory = $notificationDao->getByAssoc(
77  ASSOC_TYPE_SUBMISSION,
78  $submissionId,
79  $userId,
80  $notificationType,
81  $contextId
82  );
83 
84  // Check for any active signoff with the $symbolic value.
85  $symbolic = $this->_getSymbolicByType();
86  $submissionFileSignOffDao = DAORegistry::getDAO('SubmissionFileSignoffDAO');
87  $signoffFactory = $submissionFileSignOffDao->getAllBySubmission($submissionId, $symbolic, $userId);
88  $activeSignoffs = false;
89  if (!$signoffFactory->wasEmpty()) {
90  // Loop through signoffs and check for active ones on this context.
91  while (!$signoffFactory->eof()) {
92  $workingSignoff = $signoffFactory->next();
93  if (!$workingSignoff->getDateCompleted()) {
94  $activeSignoffs = true;
95  break;
96  }
97  }
98  }
99 
100  // Decide if we need to create or delete a notification.
101  if (!$activeSignoffs && !$notificationFactory->wasEmpty()) {
102  // No signoff but found notification, delete it.
103  $notification = $notificationFactory->next();
104  $notificationDao->deleteObject($notification);
105  } else if ($activeSignoffs && $notificationFactory->wasEmpty()) {
106  // At least one signoff not completed and no notification, create one.
107  $this->createNotification(
108  $request,
109  $userId,
110  $notificationType,
111  $contextId,
112  ASSOC_TYPE_SUBMISSION,
113  $submissionId,
114  NOTIFICATION_LEVEL_TASK
115  );
116  }
117  }
118 
119 
120  //
121  // Helper methods.
122  //
131  private function _getSignoffNotificationContents($request, $notification, $symbolic, $message) {
132  $submissionId = $notification->getAssocId();
133 
134  // Get the stage id, based on symbolic.
135  $signoffDao = DAORegistry::getDAO('SignoffDAO');
136  $stageId = $signoffDao->getStageIdBySymbolic($symbolic);
137 
138  import('lib.pkp.controllers.api.signoff.linkAction.AddSignoffFileLinkAction');
139  $signoffFileLinkAction = new AddSignoffFileLinkAction(
140  $request, $submissionId,
141  $stageId, $symbolic, null,
142  $message, $message
143  );
144 
145  return $this->fetchLinkActionNotificationContent($signoffFileLinkAction, $request);
146  }
147 
152  private function _getSymbolicByType() {
153  switch ($this->getNotificationType()) {
154  case NOTIFICATION_TYPE_SIGNOFF_COPYEDIT:
155  return 'SIGNOFF_COPYEDITING';
156  case NOTIFICATION_TYPE_SIGNOFF_PROOF:
157  return 'SIGNOFF_PROOFING';
158  default:
159  return null;
160  }
161  }
162 }
163 
164 ?>
static & getDAO($name, $dbconn=null)
static requireComponents()
Signoff notification types manager delegate.
Class for signoff file upload actions.
updateNotification($request, $userIds, $assocType, $assocId)
Abstract class to support notification manager delegates that provide default implementation to the i...
getNotificationMessage($request, $notification)
getNotificationContents($request, $notification)