コード例 #1
0
ファイル: Notifier.php プロジェクト: rchicoli/owncloud-core
 /**
  * Remove the notification and prevent rendering, when the update is installed
  *
  * @param INotification $notification
  * @param string $installedVersion
  * @throws \InvalidArgumentException When the update is already installed
  */
 protected function updateAlreadyInstalledCheck(INotification $notification, $installedVersion)
 {
     if (version_compare($notification->getObjectId(), $installedVersion, '<=')) {
         $this->notificationManager->markProcessed($notification);
         throw new \InvalidArgumentException();
     }
 }
コード例 #2
0
ファイル: Notifier.php プロジェクト: GitHubUser4234/core
 /**
  * @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();
             if ($params[0] !== $params[1] && $params[1] !== null) {
                 $notification->setParsedSubject((string) $l->t('You received "/%3$s" as a remote share from %1$s (on behalf of %2$s)', $params));
             } else {
                 $notification->setParsedSubject((string) $l->t('You received "/%3$s" as a remote share from %1$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'))->setPrimary(true);
                         break;
                     case 'decline':
                         $action->setParsedLabel((string) $l->t('Decline'));
                         break;
                 }
                 $notification->addParsedAction($action);
             }
             return $notification;
         default:
             // Unknown subject => Unknown notification => throw
             throw new \InvalidArgumentException();
     }
 }
コード例 #3
0
ファイル: notificationtest.php プロジェクト: farukuzun/core-1
 public function testAddActionSecondParsedPrimary()
 {
     /** @var \OCP\Notification\IAction|\PHPUnit_Framework_MockObject_MockObject $action */
     $action = $this->getMockBuilder('OCP\\Notification\\IAction')->disableOriginalConstructor()->getMock();
     $action->expects($this->exactly(2))->method('isValidParsed')->willReturn(true);
     $action->expects($this->exactly(2))->method('isPrimary')->willReturn(true);
     $this->assertSame($this->notification, $this->notification->addParsedAction($action));
     $this->setExpectedException('\\InvalidArgumentException');
     $this->notification->addParsedAction($action);
 }
コード例 #4
0
ファイル: Manager.php プロジェクト: GitHubUser4234/core
 /**
  * @param INotification $notification
  * @return null
  * @throws \InvalidArgumentException When the notification is not valid
  * @since 8.2.0
  */
 public function notify(INotification $notification)
 {
     if (!$notification->isValid()) {
         throw new \InvalidArgumentException('The given notification is invalid');
     }
     $apps = $this->getApps();
     foreach ($apps as $app) {
         try {
             $app->notify($notification);
         } catch (\InvalidArgumentException $e) {
         }
     }
 }
コード例 #5
0
ファイル: Handler.php プロジェクト: drognisep/Portfolio-Site
 /**
  * Turn a notification into an input statement
  *
  * @param IQueryBuilder $sql
  * @param INotification $notification
  */
 protected function sqlInsert(IQueryBuilder $sql, INotification $notification)
 {
     $sql->setValue('app', $sql->createParameter('app'))->setParameter('app', $notification->getApp());
     $sql->setValue('user', $sql->createParameter('user'))->setParameter('user', $notification->getUser());
     $sql->setValue('timestamp', $sql->createParameter('timestamp'))->setParameter('timestamp', $notification->getDateTime()->getTimestamp());
     $sql->setValue('object_type', $sql->createParameter('objectType'))->setParameter('objectType', $notification->getObjectType());
     $sql->setValue('object_id', $sql->createParameter('objectId'))->setParameter('objectId', $notification->getObjectId());
     $sql->setValue('subject', $sql->createParameter('subject'))->setParameter('subject', $notification->getSubject());
     $sql->setValue('subject_parameters', $sql->createParameter('subject_parameters'))->setParameter('subject_parameters', json_encode($notification->getSubjectParameters()));
     $sql->setValue('message', $sql->createParameter('message'))->setParameter('message', $notification->getMessage());
     $sql->setValue('message_parameters', $sql->createParameter('message_parameters'))->setParameter('message_parameters', json_encode($notification->getMessageParameters()));
     $sql->setValue('link', $sql->createParameter('link'))->setParameter('link', $notification->getLink());
     $actions = [];
     foreach ($notification->getActions() as $action) {
         /** @var IAction $action */
         $actions[] = ['label' => $action->getLabel(), 'link' => $action->getLink(), 'type' => $action->getRequestType(), 'primary' => $action->isPrimary()];
     }
     $sql->setValue('actions', $sql->createParameter('actions'))->setParameter('actions', json_encode($actions));
 }
コード例 #6
0
 /**
  * @param int $notificationId
  * @param INotification $notification
  * @return array
  */
 protected function notificationToArray($notificationId, INotification $notification)
 {
     $data = ['notification_id' => $notificationId, 'app' => $notification->getApp(), 'user' => $notification->getUser(), 'datetime' => $notification->getDateTime()->format('c'), 'object_type' => $notification->getObjectType(), 'object_id' => $notification->getObjectId(), 'subject' => $notification->getParsedSubject(), 'message' => $notification->getParsedMessage(), 'link' => $notification->getLink(), 'actions' => []];
     foreach ($notification->getParsedActions() as $action) {
         $data['actions'][] = $this->actionToArray($action);
     }
     return $data;
 }