/**
  * Reacts to topic reply events. When a topic is replied to, we want to
  * update the counts on the topic as well as send emails notifying the
  * thread participants of a new post.
  *
  * @param TopicEventInterface $event
  */
 public function onReplyToTopic(TopicEventInterface $event)
 {
     /** @var $topic \Rhapsody\SocialBundle\Model\TopicInterface */
     $topic = $event->getTopic();
     /** @var $post \Rhapsody\SocialBundle\Model\PostInterface */
     $post = $event->getPost();
     /** @var $author \Symfony\Component\Security\Core\User\UserInterface */
     $author = $event->getUser();
     // ** Count the number of posts and replies for a given topic.
     $this->topicManager->updateCounts($topic);
     // ** The URL for viewing the forum post.
     $url = $this->router->generate('rhapsody_forum_topic_view', array('topic' => $topic->getId()), UrlGeneratorInterface::ABSOLUTE_URL);
     $users = $this->topicManager->findUsersByTopic($topic);
     foreach ($users as $user) {
         // **
         // Only send the comment email to people OTHER THAN the person who
         // actually posted the comment. Why do they need to know they posted
         // a comment? They already do! They just posted it! [SWQ]
         if ($user->getId() !== $author->getId()) {
             /** @var $user \Symfony\Component\Security\Core\User\UserInterface */
             $email = $user->email;
             if (!empty($email)) {
                 $data = array('author' => $author, 'topic' => $topic, 'post' => $post, 'url' => $url, 'user' => $user);
                 /** @var $message \Application\LorecallBundle\Model\Messaging\MessageTemplate */
                 $message = EmailTemplate::newInstance()->setTemplate($this->templateFactory->getTopicReplyEmailTemplate())->setTo($email)->setFrom($this->senderEmail, $this->senderName);
                 $this->mailer->sendMessage($message, $data);
             }
         }
     }
 }
 /**
  * Notify the collection of <code>$users</code> of something that has
  * happened on the platform. The email that is sent is composed from the
  * <code>$data</code> and rendered into the <code>$template</code> before
  * the mail is sent.
  *
  * @param string $template the email template.
  * @param array $data the data to pass into the construction of the email
  *     message.
  * @param array $users the filtered collection of users to notify.
  */
 public function notify($template, $data = array(), $users = array())
 {
     foreach ($users as $user) {
         $email = $user->email;
         if (!empty($email)) {
             $data['user'] = $user;
             /** @var $message \Rhapsody\SocialBundle\Mailer\MessageTemplate */
             $message = EmailTemplate::newInstance()->setTemplate($template)->setTo($email)->setFrom($this->mailer->getSenderEmail(), $this->mailer->getSenderName());
             $this->mailer->sendMessage($message, $data);
         }
     }
 }