Newscoop\Services\EmailService::sendCommentNotification PHP Method

sendCommentNotification() public method

Send comment notification
public sendCommentNotification ( Comment $comment, Article $article, array $authors, User $user = null ) : void
$comment Newscoop\Entity\Comment
$article Newscoop\Entity\Article
$authors array
$user Newscoop\Entity\User
return void
    public function sendCommentNotification(Comment $comment, Article $article, array $authors, User $user = null)
    {
        $publicationService = $this->container->get('newscoop_newscoop.publication_service');
        $templatesService = $this->container->get('newscoop.templates.service');
        $placeholdersService = $this->container->get('newscoop.placeholders.service');
        $preferencesService = $this->container->get('preferences');
        $translator = $this->container->get('translator');
        $emails = array_unique(array_filter(array_map(function ($author) {
            return $author->getEmail();
        }, $authors)));
        $publication = $publicationService->getPublication();
        $moderatorTo = $this->getModeratorEmailIfModerationEnabled($publication, $user);
        $moderatorTo ? $emails['moderator'] = $moderatorTo : null;
        $moderatorFrom = $publication->getModeratorFrom();
        if (empty($emails)) {
            return;
        }
        $smarty = $templatesService->getSmarty();
        $uri = \CampSite::GetURIInstance();
        if ($user) {
            $smarty->assign('username', $user->getUsername());
        } else {
            $smarty->assign('username', $translator->trans('anonymous'));
        }
        $smarty->assign('comment', $comment);
        $smarty->assign('article', new \MetaArticle($article->getLanguageId(), $article->getNumber()));
        $smarty->assign('publication', $uri->getBase());
        $smarty->assign('site', $uri->getBase());
        $smarty->assign('articleLink', \ShortURL::GetURI($article->getPublicationId(), $article->getLanguageId(), $article->getIssueId(), $article->getSectionId(), $article->getNumber()));
        $message = $templatesService->fetchTemplate("email_comment-notify.tpl");
        $this->send($placeholdersService->get('subject'), $message, $emails, $moderatorFrom ?: $preferencesService->EmailFromAddress);
    }