* @param INotification $notification * @param string $languageCode The code of the language that should be used to prepare the notification * @return INotification * @throws UnknownNotificationException When the notification was not prepared by a notifier * @throws AlreadyProcessedException When the notification is not needed anymore and should be deleted * @since 9.0.0
(INotification $notification, string $languageCode)
| 74 | * @since 9.0.0 |
| 75 | */ |
| 76 | public function prepare(INotification $notification, string $languageCode): INotification |
| 77 | { |
| 78 | if ($notification->getApp() !== 'analytics') { |
| 79 | // Not my app => throw |
| 80 | throw new UnknownNotificationException('Unknown app'); |
| 81 | } |
| 82 | |
| 83 | // Read the language from the notification |
| 84 | $l = $this->l10nFactory->get('analytics', $languageCode); |
| 85 | $parsedSubject = ''; |
| 86 | |
| 87 | $parameters = $notification->getSubjectParameters(); |
| 88 | |
| 89 | switch ($notification->getObjectType()) { |
| 90 | case NotificationManager::SUBJECT_THRESHOLD: |
| 91 | $parsedSubject = $l->t("Report '{report}': {subject} reached the threshold of {rule} {value}"); |
| 92 | $link = $this->urlGenerator->linkToRouteAbsolute('analytics.page.main') . 'r/' . $notification->getObjectId(); |
| 93 | |
| 94 | $notification->setRichSubject( |
| 95 | $parsedSubject, |
| 96 | [ |
| 97 | 'report' => [ |
| 98 | 'type' => 'highlight', |
| 99 | 'id' => $notification->getObjectId(), |
| 100 | 'name' => $parameters['report'], |
| 101 | 'link' => $link, |
| 102 | ], |
| 103 | 'subject' => [ |
| 104 | 'type' => 'highlight', |
| 105 | 'id' => $notification->getObjectId(), |
| 106 | 'name' => $parameters['subject'], |
| 107 | ], |
| 108 | 'rule' => [ |
| 109 | 'type' => 'highlight', |
| 110 | 'id' => $notification->getObjectId(), |
| 111 | 'name' => $parameters['rule'], |
| 112 | ], |
| 113 | 'value' => [ |
| 114 | 'type' => 'highlight', |
| 115 | 'id' => $notification->getObjectId(), |
| 116 | 'name' => $parameters['value'], |
| 117 | ], |
| 118 | ] |
| 119 | ); |
| 120 | |
| 121 | break; |
| 122 | case NotificationManager::DATALOAD_ERROR: |
| 123 | $parsedSubject = $l->t("Error during data load \"{dataloadName}\" for data set \"{datasetName}\"" ); |
| 124 | $link = $this->urlGenerator->linkToRouteAbsolute('analytics.page.main') . 'd/' . $notification->getObjectId(); |
| 125 | |
| 126 | $notification->setRichSubject( |
| 127 | $parsedSubject, |
| 128 | [ |
| 129 | 'dataloadName' => [ |
| 130 | 'type' => 'highlight', |
| 131 | 'id' => $notification->getObjectId(), |
| 132 | 'name' => $parameters['dataloadName'], |
| 133 | ], |
no test coverage detected