Example #1
0
    private function saveComment($request)
    {
        $comment = new Comment();
        $user = $this->userSession->getUser();
        $user = $this->em->find("App\Model\User", $user->getId());
        $comment->setUser($user);
        $comment->setComment($request->get('comment'));
        $post = $this->em->find("App\Model\Post", $request->get('postId'));
        $post->setCommentsNum($post->getCommentsNum()+1);
        $comment->setPost($post);
        $comment->setPostedAt(new \DateTime('now'));
        $this->em->persist($comment);
        $this->em->flush();

        return $comment;
    }