Open Journal Systems  3.3.0
QueryNotificationManager.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 getNotificationTitle($notification) {
32  switch ($notification->getType()) {
33  case NOTIFICATION_TYPE_NEW_QUERY:
34  assert(false);
35  break;
36  case NOTIFICATION_TYPE_QUERY_ACTIVITY:
37  assert(false);
38  break;
39  default: assert(false);
40  }
41  }
42 
46  public function getNotificationMessage($request, $notification) {
47  assert($notification->getAssocType() == ASSOC_TYPE_QUERY);
48  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
49  $query = $queryDao->getById($notification->getAssocId());
50 
51  $headNote = $query->getHeadNote();
52  assert(isset($headNote));
53 
54  switch($notification->getType()) {
55  case NOTIFICATION_TYPE_NEW_QUERY:
56  $user = $headNote->getUser();
57  return __('submission.query.new', array(
58  'creatorName' => $user->getFullName(),
59  'noteContents' => substr(PKPString::html2text($headNote->getContents()), 0, 200),
60  'noteTitle' => substr($headNote->getTitle(), 0, 200),
61  ));
62  case NOTIFICATION_TYPE_QUERY_ACTIVITY:
63  $notes = $query->getReplies(null, NOTE_ORDER_ID, SORT_DIRECTION_DESC);
64  $latestNote = $notes->next();
65  $user = $latestNote->getUser();
66  $notes->close();
67  return __('submission.query.activity', array(
68  'responderName' => $user->getFullName(),
69  'noteContents' => substr(PKPString::html2text($latestNote->getContents()), 0, 200),
70  'noteTitle' => substr($headNote->getTitle(), 0, 200),
71  ));
72  default: assert(false);
73  }
74  }
75 
81  protected function getQuerySubmission($query) {
82  $submissionDao = DAORegistry::getDAO('SubmissionDAO'); /* @var $submissionDao SubmissionDAO */
83  switch ($query->getAssocType()) {
84  case ASSOC_TYPE_SUBMISSION:
85  return $submissionDao->getById($query->getAssocId());
86  case ASSOC_TYPE_REPRESENTATION:
87  $representationDao = Application::getRepresentationDAO();
88  $representation = $representationDao->getById($query->getAssocId());
89  $publication = Services::get('publication')->get($representation->getData('publicationId'));
90  return Services::get('submission')->get($publication->getData('submissionId'));
91  }
92  assert(false);
93  }
94 
98  public function getNotificationUrl($request, $notification) {
99  assert($notification->getAssocType() == ASSOC_TYPE_QUERY);
100  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
101  $query = $queryDao->getById($notification->getAssocId());
102  assert(is_a($query, 'Query'));
103  $submission = $this->getQuerySubmission($query);
104 
105  import('classes.core.Services');
106  return Services::get('submission')->getWorkflowUrlByUserRoles($submission, $notification->getUserId());
107  }
108 
112  public function getNotificationContents($request, $notification) {
113  assert($notification->getAssocType() == ASSOC_TYPE_QUERY);
114  $queryDao = DAORegistry::getDAO('QueryDAO'); /* @var $queryDao QueryDAO */
115  $query = $queryDao->getById($notification->getAssocId());
116  assert(is_a($query, 'Query'));
117 
118  $submission = $this->getQuerySubmission($query);
119  assert(is_a($submission, 'Submission'));
120 
121  switch($notification->getType()) {
122  case NOTIFICATION_TYPE_NEW_QUERY:
123  return __(
124  'submission.query.new.contents',
125  array(
126  'queryTitle' => $query->getHeadNote()->getTitle(),
127  'submissionTitle' => $submission->getLocalizedTitle(),
128  )
129  );
130  case NOTIFICATION_TYPE_QUERY_ACTIVITY:
131  return __(
132  'submission.query.activity.contents',
133  array(
134  'queryTitle' => $query->getHeadNote()->getTitle(),
135  'submissionTitle' => $submission->getLocalizedTitle(),
136  )
137  );
138  default: assert(false);
139  }
140  }
141 
145  public function getStyleClass($notification) {
146  return NOTIFICATION_STYLE_CLASS_WARNING;
147  }
148 }
149 
150 
Application\getRepresentationDAO
static getRepresentationDAO()
Definition: Application.inc.php:162
DAORegistry\getDAO
static & getDAO($name, $dbconn=null)
Definition: DAORegistry.inc.php:57
QueryNotificationManager
Query notification types manager delegate.
Definition: QueryNotificationManager.inc.php:18
NotificationManagerDelegate
Abstract class to support notification manager delegates that provide default implementation to the i...
Definition: NotificationManagerDelegate.inc.php:21
QueryNotificationManager\getNotificationMessage
getNotificationMessage($request, $notification)
Definition: QueryNotificationManager.inc.php:46
QueryNotificationManager\__construct
__construct($notificationType)
Definition: QueryNotificationManager.inc.php:24
QueryNotificationManager\getNotificationContents
getNotificationContents($request, $notification)
Definition: QueryNotificationManager.inc.php:112
PKPString\html2text
static html2text($html)
Definition: PKPString.inc.php:395
QueryNotificationManager\getNotificationTitle
getNotificationTitle($notification)
Definition: QueryNotificationManager.inc.php:31
QueryNotificationManager\getNotificationUrl
getNotificationUrl($request, $notification)
Definition: QueryNotificationManager.inc.php:98
QueryNotificationManager\getQuerySubmission
getQuerySubmission($query)
Definition: QueryNotificationManager.inc.php:81
PKPServices\get
static get($service)
Definition: PKPServices.inc.php:49
QueryNotificationManager\getStyleClass
getStyleClass($notification)
Definition: QueryNotificationManager.inc.php:145