/** * @Route("/comment", name="Comment") */ public function commentAction(Request $request) { $user = $this->getUser(); $comment = new Comment(); $now = new DateTime(); $doodle_id = $request->get('id'); $text = $request->get('comment'); $doodle = $this->getDoctrine()->getRepository('AppBundle:Doodle')->find($doodle_id); $comment->setUser($user); $comment->setDoodle($doodle); $comment->setCreated($now); $comment->setText($text); if ($user) { $comment->setAuthor($user->username); } else { $comment->setAuthor('Anonymous'); } $em = $this->getDoctrine()->getManager(); $em->persist($comment); $em->flush(); $data = ['message' => 'Success!', 'id' => $doodle_id, 'text' => $text]; $response = new Response(json_encode(['response' => $data])); $response->headers->set('Content-Type', 'application/json'); return $response; }
public function load(ObjectManager $manager) { // TODO: Implement load() method. $category = new Category(); $category->setName('Default'); $manager->persist($category); foreach (range(1, 100) as $i) { $post = new Post(); $post->setTitle($this->getPostTitle()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setImage('post.jpeg'); $post->setContent($this->getPostContent()); $post->setAuthor('gunyem'); $post->setCreated(new \DateTime('now - ' . $i . 'days')); $post->setUpdated(new \DateTime('now - ' . $i . 'days')); $post->setCategory($category); foreach (range(1, 10) as $j) { $comment = new Comment(); $comment->setPost($post); $comment->setContent($this->getPostTitle()); $comment->setAuthor('gunyem'); $comment->setCreated(new \DateTime('now + ' . ($i + $j) . 'seconds')); $manager->persist($comment); $post->createComment($comment); } $manager->persist($post); } $manager->flush(); }
/** * @param ObjectManager $manager */ public function load(ObjectManager $manager) { $comment = new Comment(); $comment->setAuthor($this->getReference('user')); $comment->setContent('Commentaire babla bla bla Beer'); $comment->setArticle($this->getReference('article')); $manager->persist($comment); $manager->flush(); $this->addReference('comment', $comment); }
public function addNewCommentToArticle($article, Comment $comment, $author) { if ($author !== null) { $comment->setAuthor($author); } $comment->setArticle($article); $em = $this->doctrine->getManager(); $em->persist($comment); $em->flush(); }
public function load(ObjectManager $manager) { for ($i = 0; $i < 40; $i++) { $article = new Article(); $article->setTitle('News' . $i); $article->setContent('This is default content'); $article->setDatetime(new \DateTime('- ' . rand(1, 4) . ' day')); $commentA = new Comment(); $commentA->setAuthor('Author'); $commentA->setContent('Comment .... default'); $manager->persist($commentA); $article->addComment($commentA); $commentB = new Comment(); $commentB->setAuthor('Author' . $i); $commentB->setContent('Comment .... default'); $manager->persist($commentB); $article->addComment($commentB); $manager->persist($article); } $manager->flush(); }
/** * {@inheritDoc} */ public function setAuthor(\AppBundle\Entity\User $author = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setAuthor', array($author)); return parent::setAuthor($author); }
/** * Add comment * * @param Comment $comment * * @return User */ public function addComment(Comment $comment) { $this->comments[] = $comment; $comment->setAuthor($this); return $this; }
/** * @Route("id{id}/writeComment", name="commentFormAction") */ public function commentAction($id, Request $request) { $comment = new Comment(); $comment->setText($request->get('_comment')); $comment->setAuthor($this->getUser()); $user = $this->getDoctrine()->getRepository('AppBundle:User')->find($id); $comment->setUser($user); $em = $this->getDoctrine()->getManager(); $em->persist($this->getUser()); $em->persist($user); $em->persist($comment); $em->flush(); return $this->redirectToRoute('userPage', array('id' => $id)); }