Ejemplo n.º 1
0
 /**
  * @param INotification $notification
  * @param string $languageCode The code of the language that should be used to prepare the notification
  * @return INotification
  */
 public function prepare(INotification $notification, $languageCode)
 {
     if ($notification->getApp() !== 'files_sharing') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->factory->get('files_sharing', $languageCode);
     switch ($notification->getSubject()) {
         // Deal with known subjects
         case 'remote_share':
             $params = $notification->getSubjectParameters();
             $notification->setParsedSubject((string) $l->t('You received %s as a remote share from %s', $params));
             // Deal with the actions for a known subject
             foreach ($notification->getActions() as $action) {
                 switch ($action->getLabel()) {
                     case 'accept':
                         $action->setParsedLabel((string) $l->t('Accept'));
                         break;
                     case 'decline':
                         $action->setParsedLabel((string) $l->t('Decline'));
                         break;
                 }
                 $notification->addParsedAction($action);
             }
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
Ejemplo n.º 2
0
 /**
  * @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() !== 'popularitycontestclient') {
         // Not my app => throw
         throw new \InvalidArgumentException();
     }
     // Read the language from the notification
     $l = $this->l10nFactory->get('popularitycontestclient', $languageCode);
     $notification->setParsedSubject((string) $l->t('Do you want to send monthly usage statistics to ownCloud?'));
     foreach ($notification->getActions() as $action) {
         if ($action->getLabel() === 'enable') {
             $action->setParsedLabel((string) $l->t('Yes'));
         } else {
             if ($action->getLabel() === 'disable') {
                 $action->setParsedLabel((string) $l->t('Not now'));
             }
         }
         $notification->addParsedAction($action);
     }
     return $notification;
 }
Ejemplo n.º 3
0
 /**
  * @dataProvider dataSetParsedSubjectInvalid
  * @param mixed $subject
  *
  * @expectedException \InvalidArgumentException
  */
 public function testSetParsedSubjectInvalid($subject)
 {
     $this->notification->setParsedSubject($subject);
 }