示例#1
0
 /**
  * {@inheritdoc}
  */
 public function notify(NotificationInterface $notification, array $users)
 {
     $userNotifications = [];
     foreach ($users as $user) {
         try {
             $user = is_object($user) ? $user : $this->userProvider->loadUserByUsername($user);
             $userNotifications[] = $this->userNotifFactory->createUserNotification($notification, $user);
         } catch (UsernameNotFoundException $e) {
             continue;
         }
     }
     $this->notificationSaver->save($notification);
     $this->userNotifsSaver->saveAll($userNotifications);
     return $this;
 }
 /**
  * Send a user notification to given users
  *
  * @param array  $users   Users which have to be notified
  *                        ['userName', ...] or [UserInterface, ...]
  * @param string $message Message which has to be sent
  * @param string $type    success (default) | warning | error
  * @param array  $options ['route' => '', 'routeParams' => [], 'messageParams' => [], 'context => '']
  *
  * @return NotificationManager
  */
 public function notify(array $users, $message, $type = 'success', array $options = [])
 {
     $notification = $this->notificationFactory->createNotification($message, $type, $options);
     $userNotifications = [];
     foreach ($users as $user) {
         try {
             $user = is_object($user) ? $user : $this->userProvider->loadUserByUsername($user);
             $userNotifications[] = $this->userNotifFactory->createUserNotification($notification, $user);
         } catch (UsernameNotFoundException $e) {
             continue;
         }
     }
     $this->em->persist($notification);
     foreach ($userNotifications as $userNotification) {
         $this->em->persist($userNotification);
     }
     $this->em->flush($notification);
     $this->em->flush($userNotifications);
     return $this;
 }