Example #1
0
 public function addComment($parent_id, $article_id, $text)
 {
     $comment = new CommentDB();
     if (!$this->auth_user) {
         return false;
     }
     $comment->article_id = $article_id;
     $comment->user_id = $this->auth_user->id;
     $comment->parent_id = $parent_id;
     $comment->text = $text;
     try {
         $comment->save();
         /*не верно*/
         $comment_parent = new CommentDB();
         $comment_parent->load($parent_id);
         if ($comment_parent->isSaved() && $comment_parent->user_id != $this->auth_user->id) {
             $user = new UserDB();
             $user->load($comment_parent->user_id);
             $this->mail->send($user->email, array("user" => $user, "link" => $comment_parent->link), "comment_subscribe");
         }
         return json_encode(array("id" => $comment->id, "parent_id" => $comment->parent_id, "user_id" => $this->auth_user->id, "name" => $this->auth_user->name, "avatar" => $this->auth_user->avatar, "text" => $comment->text, "date" => $comment->date));
     } catch (Exception $e) {
         return false;
     }
 }