public function load(ObjectManager $manager)
 {
     for ($i = 1; $i < 151; $i++) {
         $comment = new Comment();
         $comment->setUser('Hans Meier');
         $comment->setComment('Huh so funny');
         if ($i % 2 == 0) {
             $blog = 'blog-1';
         } else {
             $blog = 'blog-2';
         }
         $comment->setBlog($this->getReference($blog));
         $manager->persist($comment);
     }
     $manager->flush();
 }
Example #2
0
 /**
  * @param Comment $comment
  * @param Request $request
  *
  * @throws ItemResolvingException
  * @return CartItemInterface|void
  */
 public function resolve(Comment $comment, Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $postId = $request->query->get('post');
     $itemForm = $request->get('comment_front');
     if ($this->container->get('security.authorization_checker')->isGranted('IS_AUTHENTICATED_FULLY')) {
         $comment->setActor($this->container->get('security.token_storage')->getToken()->getUser());
     } else {
         //register user
         $actor = $this->createActor($itemForm);
         $comment->setActor($actor);
     }
     $postRepository = $em->getRepository('BlogBundle:Post');
     if (!$postId || !($post = $postRepository->find($postId))) {
         // no product id given, or product not found
         throw new \Exception('Requested post was not found');
     }
     // assign the product and quantity to the item
     $comment->setPost($post);
     $comment->setComment($itemForm['comment']);
     return $comment;
 }