Send a notification to a user about a message.

@param \Claroline\ForumBundle\Entity\Message $message
@param \Claroline\CoreBundle\Entity\User $user
438060
public function sendMessageNotification(Message $message, User $user)
    {
        $forum = $message->getSubject()->getCategory()->getForum();
        $notifications = $this->notificationRepo->findBy(array('forum' => $forum));
        $users = array();

        foreach ($notifications as $notification) {
            $users[] = $notification->getUser();
        }

        $title = $this->translator->trans(
            'forum_new_message',
            array('%forum%' => $forum->getResourceNode()->getName(), '%subject%' => $message->getSubject()->getTitle(), '%author%' => $message->getCreator()->getUsername()),
            'forum'
        );

        $url = $this->router->generate(
            'claro_forum_subjects', array('category' => $message->getSubject()->getCategory()->getId()), true
        );

        $body = "<a href='{$url}'>{$title}</a><hr>{$message->getContent()}";

        $this->mailManager->send($title, $body, $users);
    }
740746
protected function requestWrite(WebSocketTransportInterface $user, $message)
    {
        $stream = $this->getStream($user, $message->connection);

        if($stream){
            $this->logger->notice(sprintf("User %s writes %d bytes to connection %s", $user->getId(), strlen($message->data), $message->connection));
            $stream->write($message->data);
        }
    }
1046262
public function findAncestors(Message $message, User $user)
    {
        $dql = "
            SELECT m
            FROM Claroline\MessageBundle\Entity\Message m
            JOIN m.userMessages um
            JOIN um.user u
            WHERE m.lft BETWEEN m.lft AND m.rgt
            AND m.root = {$message->getRoot()}
            AND m.lvl <= {$message->getLvl()}
            AND (
                u.id = :userid
                OR m.user = :userid
            )
        ";

        $query = $this->_em->createQuery($dql);
        $query->setParameter('userid', $user->getId());

        return $query->getResult();
    }
49081
public function createNotification($message, $userId = '1')
    {
        $notification = $this->getEntityManager()->getEntity('Notification');
        $notification->set(array(
            'type' => 'message',
            'data' => array(
                'userId' => $userId,
            ),
            'userId' => $userId,
            'message' => $message
        ));
        $this->getEntityManager()->saveEntity($notification);
    }
579161
public function sendCreationEmailMessage(UserInterface $user, $password)
    {
        /** @var \Ekyna\Bundle\UserBundle\Model\UserInterface $user */
        $siteName  = $this->settingsManager->getParameter('general.site_name');
        $userName = sprintf('%s %s', $user->getFirstName(), $user->getLastName());
        $login = $user->getUsername();

        if (0 === strlen($password)) {
            return 0;
        }

        if (null === $loginUrl = $this->getLoginUrl($user)) {
            return 0;
        }

        $rendered = $this->templating->render(
            'EkynaUserBundle:Admin/User:creation_email.html.twig',
            [
                'username'  => $userName,
                'sitename'  => $siteName,
                'login_url' => $loginUrl,
                'login'     => $login,
                'password'  => $password,
            ]
        );

        $subject = $this->translator->trans(
            'ekyna_user.email.creation.subject',
            ['%sitename%' => $siteName]
        );

        return $this->sendEmail($rendered, $user->getEmail(), $userName, $subject);
    }
74945
public function notice(string $message, array $context = []){
        if($this->logger !== null){
            $this->logger->notice($message, $context);
        }

        if($this->messagePanel !== null){
            $this->messagePanel->addMessage($message, LogLevel::NOTICE);
        }
    }
1328175
public function addMessage(Message $message)
    {
        $message->setMessageBroker($this);
        $this->messages->attach($message);
    }
104007
public function continueUssdMenuProcess($user,$message){

        $menu = ussd_menu::find($user->menu_id);

        //check the user menu
        switch ($menu->type) {
            case 0:
                //authentication mini app

                break;
            case 1:
                //continue to another menu
                $response = self::continueUssdMenu($user,$message,$menu);
                break;
            case 2:
                //continue to a processs
                $response = self::continueSingleProcess($user,$message,$menu);
                break;
            case 3:
                //infomation mini app
                //
                self::infoMiniApp($user,$menu);
                break;
            default :
                self::resetUser($user);
                $response = "An error occurred";
                break;
        }

        return $response;

    }
657153
protected function sendNotifications(Collection $users, $subject, $view = null, array $data = []): void
    {
        foreach ($users->all() as $user) {
            $this->sendNotification($user, $subject, $view, $data);
        }
    }
742759
public function activate(User $user)
    {
        $this->authorize(UsersPolicy::PERMISSION_UPDATE);

        try {
            ($active = $user->isActive()) ? $user->deactivate() : $user->activate();

            $message = $this->transNotification(
                $active ? 'disabled' : 'enabled',
                ['name' => $user->full_name],
                $user->toArray()
            );

            return $this->jsonResponseSuccess(compact('message'));
        }
        catch (\Exception $e) {
            return $this->jsonResponseError(['message' => $e->getMessage()], 500);
        }
    }
12067
public function getUserNotificationsList(User $user, $page = 1, $maxResult = -1, $isRss = false, $notificationParameters = null, $category = null)
    {
        $query = $this->getUserNotifications($user, $page, $maxResult, $isRss, $notificationParameters, false, $category);
        $adapter = new DoctrineORMAdapter($query, false);
        $pager = new Pagerfanta($adapter);
        $pager->setMaxPerPage($maxResult);

        try {
            $pager->setCurrentPage($page);
        } catch (NotValidCurrentPageException $e) {
            throw new NotFoundHttpException();
        }
        $notifications = $this->renderNotifications($pager->getCurrentPageResults());

        return [
            'pager' => $pager,
            'notificationViews' => $notifications['views'],
            'colors' => $notifications['colors'],
        ];
    }
373127
public function sendMessage(Message $message)
    {
        $payload = $this->preparePayload($message);

        $encoded = json_encode($payload, JSON_UNESCAPED_UNICODE);

        if ($encoded === false) {
            throw new RuntimeException(sprintf('JSON encoding error %s: %s', json_last_error(), json_last_error_msg()));
        }

        $this->guzzle->post($this->endpoint, ['body' => $encoded]);
    }
311917
protected function sendEmailNotification($subject, $message)
    {
        $superUsers = UsersManagerApi::getInstance()->getUsersHavingSuperUserAccess();

        foreach ($superUsers as $superUser) {
            $mail = new Mail();
            $mail->setDefaultFromPiwik();
            $mail->addTo($superUser['email']);
            $mail->setSubject($subject);
            $mail->setWrappedHtmlBody($message);
            $mail->send();
        }
    }
321395
public function unsubscribe(Forum $forum, User $user)
    {
        $this->om->startFlushSuite();
        $notification = $this->notificationRepo->findOneBy(array('forum' => $forum, 'user' => $user));
        $this->om->remove($notification);
        $this->dispatch(new UnsubscribeForumEvent($forum));
        $this->om->endFlushSuite();
    }
1020276
private function getUserMessages(Message $message)
    {
        $currentUser = $this->tokenStorage->getToken()->getUser();

        return $this->om->getRepository(UserMessage::class)->findBy(['message' => $message, 'user' => $currentUser]);
    }
1078872
public function sendCreationMessage(User $user)
    {
        $locale = $user->getLocale();
        $content = $this->contentManager->getTranslatedContent(array('type' => 'claro_mail_registration'));
        $displayedLocale = isset($content[$locale]) ? $locale : $this->ch->getParameter('locale_language');
        $body = $content[$displayedLocale]['content'];
        $subject = $content[$displayedLocale]['title'];
        $url =
            $this->container->get('request')->getSchemeAndHttpHost()
            . $this->router->generate('claro_security_validate_email', array('hash' => $user->getEmailValidationHash()));
        $validationLink = $this->translator->trans('email_validation_url_display', array('%url%' => $url), 'platform');

        $body = str_replace('%first_name%', $user->getFirstName(), $body);
        $body = str_replace('%last_name%', $user->getLastName(), $body);
        $body = str_replace('%username%', $user->getUsername(), $body);
        $body = str_replace('%password%', $user->getPlainPassword(), $body);
        $body = str_replace('%validation_mail%', $validationLink, $body);
        $subject = str_replace('%platform_name%', $this->ch->getParameter('name'), $subject);

        return $this->send($subject, $body, array($user), null, array(), true);
    }
162683
public function sendActivationMail($user)
    {
        if ($user->activated || !$this->shouldSend($user)) {
            return;
        }
        $userToken = $this->createActivation($user);
        //$userToken = User::find($user->id);
        $user->notify(new ConfirmEmailNotification($userToken));
    }