Exemple #1
0
 public function send(Notifications $notification)
 {
     if ($notification->getSent() == 'Y') {
         return;
     }
     //Get post and user via relationship ORM
     $post = $notification->post;
     $user = $notification->user;
     if ($notification->getType() != 'P') {
         $reply = $notification->reply;
     } else {
         $reply = true;
     }
     $url = $this->config->application->publicUrl;
     $sitename = '[ ' . $this->config->application->name . 'Forum ]';
     if ($post && $user && $reply) {
         $to = $user->getEmail();
         if ($to && $user->getNotifications() != 'N' && strpos($to, '@phalconbook.com') === false) {
             try {
                 if ($notification->getType() == Notifications::TYPE_POSTS) {
                     $content = $this->markdown->text($post->getContent());
                     $link = $url . '/posts/' . $post->getId() . '/' . $post->getSlug();
                 } else {
                     $reply = $notification->reply;
                     $content = $this->markdown->text($reply->getContent());
                     $link = $url . '/posts/' . $post->getId() . '/' . $post->getSlug() . '#C' . $reply->getId();
                 }
                 $params = ['name' => $user->getInforUser(), 'link' => $link, 'subject' => $sitename, 'content' => $content];
                 if (!$this->mail->send($to, 'sendspool', $params)) {
                     var_dump('false');
                 }
             } catch (\Exception $e) {
                 echo $e->getMessage(), PHP_EOL;
             }
         }
     }
     $notification->setSent('Y');
     if ($notification->save() == false) {
         foreach ($notification->getMessages() as $message) {
             echo $message->getMessage(), PHP_EOL;
         }
     }
 }