/**
  * @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;
 }
示例#2
0
 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();
 }
 public function load(ObjectManager $manager)
 {
     $comment = new Comment();
     $comment->setUser('symfony');
     $comment->setComment('To make a long story short. You can\'t go wrong by choosing Symfony!');
     $comment->setBlog($manager->merge($this->getReference('blog-1')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('David');
     $comment->setComment('To make a long story short. Make sure that you make the right selection!');
     $comment->setBlog($manager->merge($this->getReference('blog-1')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Dade');
     $comment->setComment('Donec dui enim, facilisis id sollicitudin sed, ullamcorper id lacus. Mauris eros felis, tincidunt elementum iaculis eu, iaculis sit amet sapien.');
     $comment->setBlog($manager->merge($this->getReference('blog-2')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Kate');
     $comment->setComment('Etiam eget diam pretium, auctor neque sit amet, pulvinar nibh?');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 06:15:20'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Dade');
     $comment->setComment('Name your stakes.');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 06:18:35'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Kate');
     $comment->setComment('If I win, you give me ice cream.');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 06:22:53'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Dade');
     $comment->setComment('Ice Cream?');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 06:25:15'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Kate');
     $comment->setComment('Yes! Chocolate, with sprinkles, and whip cream...');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 06:46:08'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Dade');
     $comment->setComment('And if I win?');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 10:22:46'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Kate');
     $comment->setComment('I still get ice cream!');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-23 11:08:08'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Dade');
     $comment->setComment('Everyone wins!');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-24 18:56:01'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Kate');
     $comment->setComment('Deal!');
     $comment->setBlog($manager->merge($this->getReference('blog-3')));
     $comment->setCreated(new \DateTime('2011-07-25 22:28:42'));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Stanley');
     $comment->setComment('It\'s not gonna end like this.');
     $comment->setBlog($manager->merge($this->getReference('blog-4')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Gabriel');
     $comment->setComment('Oh, come on, Stan. Not everything ends the way you think it should. Besides, audiences love happy endings.');
     $comment->setBlog($manager->merge($this->getReference('blog-4')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Mile');
     $comment->setComment('Doesn\'t Bill Gates have something like that?');
     $comment->setBlog($manager->merge($this->getReference('blog-5')));
     $manager->persist($comment);
     $comment = new Comment();
     $comment->setUser('Gary');
     $comment->setComment('Bill Who?');
     $comment->setBlog($manager->merge($this->getReference('blog-5')));
     $manager->persist($comment);
     $manager->flush();
 }