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;
         }
     }
 }
Exemple #2
0
 /**
  * Set Notify users that always want notifications via Queueing jobs
  *
  * @param integer $userId      user want notification
  * @param integer $postId      [description]
  * @param integer $postReplyId [description]
  * @param string  $type        Such as Comment, reply...
  *
  * @return integet|bool
  */
 public function setNotification($userId, $postId, $postReplyId, $type)
 {
     $notification = new Notifications();
     $notification->setUsersId($userId);
     $notification->setPostsId($postId);
     $notification->setPostsReplyId($postReplyId);
     $notification->setType($type);
     if (!$notification->save()) {
         $messages = $notification->getMessages();
         error_log('setNotification error' . __LINE__ . $messages[0]);
         return false;
     }
     return $notification->getId();
 }