@param NotificationInterface $notification
@param string       $message
@param bool         $flush

@return NotificationInterface
@throws \Doctrine\ORM\OptimisticLockException
320603
public function setMessage(NotificationInterface $notification, $message, $flush = false)
    {
        $notification->setMessage($message);
        $this->flush($flush);

        $event = new NotificationEvent($notification);
        $this->dispatcher->dispatch(MgiletNotificationEvents::MODIFIED, $event);

        return $notification;
    }
785795
protected function setNotificationsAsSent(array $notifications)
    {
        foreach ($notifications as $notification) {
            $notification->setSent(new \DateTime());
            $this->managerRegistry->getManager()->persist($notification);
        }
        $this->managerRegistry->getManager()->flush();
    }
373027
public function notify(NotificationInterface $notification)
    {
        $notified = false;
        $this->eventDispatcher->dispatch(Events::PRE_NOTIFY, new PreNotifyEvent($notification));

        foreach ($this->handlers as $handler) {
            if ($notification->getHandlerName() !== $handler->getName()) {
                continue;
            }
            $notified = $this->handle($notification, $handler) || $notified;
        }

        if ($this->throwIfNotNotified && ! $notified) {
            $message = 'No handler has been defined for '.\get_class($notification);
            if (\method_exists($notification, 'getConfig')) {
                $message .= ' ('.\json_encode($notification->getConfig()).')';
            }

            throw new NotificationFailedException($message);
        }

        $this->eventDispatcher->dispatch(Events::POST_NOTIFY, new PostNotifyEvent($notification));
    }
708707
public function send(NotifiableInterface $notifiable, Notification $notification)
    {
        /**
         * @var $message CloudPushMessage
         */
        $message = $notification->toCloudPush();
        $appRecipient = $notifiable->routeNotificationFor('cloudPush');
        if ($message->validate()) {
            $messageParams = [
                'AppKey' => $this->appKey,
                'Target' => $appRecipient['target'],
                'TargetValue' => $appRecipient['targetValue'],
                'Title' => $message->title,
                'Body' => $message->content,
            ];
            if (!empty($message->extParameters)) {
                $messageParams['ExtParameters'] = Json::encode($message->extParameters);
            }
            $this->aliyun->getCloudPush()->pushNoticeToAndroid($messageParams);
            $messageParams['ApnsEnv'] = YII_ENV_DEV ? 'DEV' : 'PRODUCT';
            $this->aliyun->getCloudPush()->pushNoticeToIOS($messageParams);
        } else {
            print_r($message->getErrors());
            exit;
        }
    }
373340
public function send(Notification $notification)
    {
        $message = $this->composeMessage($notification);
        $message->send($this->mailer);
    }
616627
public function markAsUnseen(NotifiableInterface $notifiable, NotificationInterface $notification, $flush = false)
    {
        $nn = $this->getNotifiableNotification($notifiable, $notification);
        if ($nn) {
            $nn->setSeen(false);
            $event = new NotificationEvent($notification, $notifiable);
            $this->dispatcher->dispatch(MgiletNotificationEvents::UNSEEN, $event);
            $this->flush($flush);
        } else {
            throw new EntityNotFoundException('The link between the notifiable and the notification has not been found');
        }
    }
221316
public function deleteNotification(NotificationInterface $notification, $flush = false)
    {
        $this->om->remove($notification);
        $this->flush($flush);

        $event = new NotificationEvent($notification);
        $this->dispatcher->dispatch(MgiletNotificationEvents::DELETED, $event);
    }
906549
public function notify(NotifyRequest $notification): Response
    {
        if ($this->appID !== null) {
            $notification->setApplicationIdentification($this->appID);
        }

        $response = $this->sendRequest($notification);
        return $response;

    }
520078
private function createMessageObject(string $type, string $message): Notification
    {
        $msg = new Notification();

        $msg->setType($type);
        $msg->setMessage($message);

        $this->handler->add($msg);

        return $msg;
    }
428699
public function buildNotifications(MessageInterface $message)
    {
        $notifications  = new \ArrayIterator();
        $recipientQueue = new \SplQueue();
        $recipientChunk = new \ArrayIterator();

        foreach ($message->getRecipientDeviceCollection() as $recipient) {
            $recipientChunk->append($recipient);

            if ($recipientChunk->count() >= $message->getMaxRecipientsPerMessage()) {
                $recipientQueue->enqueue($recipientChunk);
                $recipientChunk = new \ArrayIterator();
            }
        }

        if ($recipientChunk->count()) {
            $recipientQueue->enqueue($recipientChunk);
        }

        while (!$recipientQueue->isEmpty()) {
            $notification = $this->createNotification($recipientQueue->dequeue(), $message);
            $notifications->append($notification);
        }

        return $notifications;
    }
1108135
public static function mark_notification_as_read($notification, $timeread = null) {
        global $DB;

        if (is_null($timeread)) {
            $timeread = time();
        }

        if (is_null($notification->timeread)) {
            $updatenotification = new \stdClass();
            $updatenotification->id = $notification->id;
            $updatenotification->timeread = $timeread;

            $DB->update_record('notifications', $updatenotification);

            // Trigger event for reading a notification.
            \core\event\notification_viewed::create_from_ids(
                $notification->useridfrom,
                $notification->useridto,
                $notification->id
            )->trigger();
        }
    }
223547
public function publish($queue, MessageInterface $message)
    {
        $message->setQueue($queue);
        $this->getAdapter()->publish($queue, $message);
    }
1199025
public function getNotifierForMessage(Message $message): Notifier
    {
        foreach ($this->notifiers as $notifier) {
            if ($notifier->handles($message)) {
                return $notifier;
            }
        }
        throw new NotifierNotFoundException();
    }
657073
public function handle(NotificationInterface $notification, $level)
    {
        $this->memory[$level][] = $notification->message();

        return true;
    }
1064102
protected function handle(NotificationInterface $notification, NotificationHandlerInterface $handler): bool
    {
        if (! $handler->supports($notification)) {
            return false;
        }

        $cloned = clone $notification;

        $event = new NotifyEvent($cloned, $handler);
        $this->eventDispatcher->dispatch(Events::NOTIFY, $event);

        $handler->notify($cloned);

        foreach ($cloned->getResultSet()->all() as $result) {
            $notification->addResult($result);
        }

        return true;
    }
1182813
public function notify_message($message) {
        $n = new \core\output\notification($message, \core\output\notification::NOTIFY_INFO);
        return $this->render($n);
    }
1123923
public function send($notifiable, Notification $notification)
    {
        if (! $to = $notifiable->routeNotificationFor('plivo')) {
            return;
        }

        $message = $notification->toPlivo($notifiable);

        if (is_string($message)) {
            $message = new PlivoMessage($message);
        }

        $response = $this->plivo->send_message([
            'src' => $message->from ?: $this->from,
            'dst' => $to,
            'text' => trim($message->content),
        ]);

        if ($response['status'] !== 202) {
            throw CouldNotSendNotification::serviceRespondedWithAnError($response);
        }

        return $response;
    }