Пример #1
0
 /**
  * @param int    $ideaId
  * @param string $content
  * @param bool   $isPrivate
  *
  * @return Comment
  * @throws \Exception
  */
 public function comment($ideaId, $content, $isPrivate)
 {
     $idea = $this->getIdea($ideaId);
     if ($idea instanceof Idea === false) {
         throw new \Exception("Unknown Idea[id={$ideaId}] aka 'I have no idea!'");
     }
     $user = $this->getAuthenticatedUser();
     $this->ensureAuthenticated($user);
     $comment = new Comment();
     $comment->setIdea($idea);
     $comment->setContent($content);
     $comment->setUser($user);
     $comment->setPrivate($isPrivate);
     $comment->setCreatedAt(new \DateTime());
     $this->entityManager->persist($comment);
     $this->entityManager->flush($comment);
     return $comment;
 }