/**
  * The extension can translate a given message to the requested languages.
  * If no translation is available false is to be returned.
  *
  * @param string $app
  * @param string $text
  * @param array $params
  * @param boolean $stripPath
  * @param boolean $highlightParams
  * @param string $languageCode
  * @return string|false
  */
 public function translate($app, $text, $params, $stripPath, $highlightParams, $languageCode)
 {
     if ($app === 'announcementcenter') {
         $l = $this->languageFactory->get('announcementcenter', $languageCode);
         list(, $id) = explode('#', $text);
         try {
             $announcement = $this->manager->getAnnouncement($id, $highlightParams);
         } catch (\InvalidArgumentException $e) {
             return (string) $l->t('Announcement does not exist anymore', $params);
         }
         if (strpos($text, 'announcementmessage#') === 0) {
             return $announcement['message'];
         }
         if ($highlightParams) {
             $params[] = '<strong>' . $announcement['subject'] . '</strong>';
         } else {
             $params[] = $announcement['subject'];
         }
         if ($announcement['author'] === $this->activityManager->getCurrentUserId()) {
             array_shift($params);
             return (string) $l->t('You announced %s', $params);
         }
         return (string) $l->t('%s announced %s', $params);
     }
     return false;
 }
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  * @throws \InvalidArgumentException When the notification was not prepared by a notifier
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'announcementcenter') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->l10nFactory->get('announcementcenter', $languageCode);
     switch ($notification->getSubject()) {
         // Deal with known subjects
         case 'announced':
             $params = $notification->getSubjectParameters();
             $announcement = $this->manager->getAnnouncement($notification->getObjectId(), false);
             $params[] = $this->prepareMessage($announcement['subject']);
             $notification->setParsedMessage($this->prepareMessage($announcement['message']))->setParsedSubject((string) $l->t('%1$s announced “%2$s”', $params));
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
 public function testAnnouncement()
 {
     $subject = 'subject' . "\n<html>";
     $message = 'message' . "\n<html>";
     $author = 'author';
     $time = time() - 10;
     $announcement = $this->manager->announce($subject, $message, $author, $time);
     $this->assertInternalType('int', $announcement['id']);
     $this->assertGreaterThan(0, $announcement['id']);
     $this->assertSame('subject &lt;html&gt;', $announcement['subject']);
     $this->assertSame('message<br />&lt;html&gt;', $announcement['message']);
     $this->assertSame('author', $announcement['author']);
     $this->assertSame($time, $announcement['time']);
     $this->assertEquals($announcement, $this->manager->getAnnouncement($announcement['id']));
     $this->assertEquals($announcement, $this->manager->getAnnouncement($announcement['id']));
     $this->assertEquals([$announcement], $this->manager->getAnnouncements(1));
     $this->manager->delete($announcement['id']);
     try {
         $this->manager->getAnnouncement($announcement['id']);
         $this->fail('Failed to delete the announcement');
     } catch (\InvalidArgumentException $e) {
         $this->assertInstanceOf('InvalidArgumentException', $e);
     }
 }