public function load(ObjectManager $manager) { $faker = Factory::create(); for ($i = 0; $i < 50; $i++) { static $id = 1; $post = new Post(); $post->setTitle($faker->sentence); $post->setAuthorEmail('*****@*****.**'); $post->setImageName("images/post/foto{$id}.jpg"); $post->setContent($faker->realText($maxNbChars = 5000, $indexSize = 2)); $marks = array(); for ($q = 0; $q < rand(1, 10); $q++) { $marks[] = rand(1, 5); } $post->setMarks($marks); $post->addMark(5); $manager->persist($post); $this->addReference("{$id}", $post); $id = $id + 1; $rand = rand(3, 7); for ($j = 0; $j < $rand; $j++) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setCreatedBy('user_user'); $comment->setContent($faker->realText($maxNbChars = 500, $indexSize = 2)); $comment->setPost($post); $post->getComments()->add($comment); $manager->persist($comment); $manager->flush(); } } $manager->flush(); }
private function loadPosts(ObjectManager $manager) { foreach (range(1, 30) as $i) { $post = new Post(); $post->setTitle('Sed ut perspiciatis unde'); $post->setAlias('Sed ut perspiciatis unde'); $post->setIntrotext('Sed ut perspicantium, tocto beatae vitae dicta sunt explicabo. '); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setBody('Sed ut is iste uasi architecto beatae vitae dicta sunt explicabo. '); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); $post->setState(1); $post->setImages('test.jpg'); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent('Sed ut perspiciatis undedasdadasd'); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } $manager->persist($post); } $manager->flush(); }
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(); }
private function loadPosts(ObjectManager $manager) { $category = new Category(); $category->setName('Improvements'); foreach (range(1, 5) as $i) { $post = new Post(); $post->setTitle($this->getRandomPostTitle()); $post->setSummary($this->getRandomPostSummary()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setContent($this->getPostContent()); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); $post->setState($this->getRandomState()); $post->setCategory($category); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent($this->getRandomCommentContent()); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } if (rand(0, 1)) { $vote = new Vote(); $vote->setAuthorEmail(rand(0, 1) ? '*****@*****.**' : '*****@*****.**'); $vote->setPost($post); $vote->setVote(rand(0, 1)); } $manager->persist($post); $category->addPost($post); } $manager->flush(); }
public function createNewCommentForm($slug, Comment $comment) { $em = $this->doctrine->getManager(); $post = $em->getRepository('AppBundle:Post')->findOneBy(['slug' => $slug]); //$comment = new Comment(); $comment->setPost($post); $form = $this->formFactory->create(CommentType::class, $comment, ['em' => $em, 'method' => Request::METHOD_POST]); $form->add('save', SubmitType::class, array('label' => 'Submit Comment', 'translation_domain' => 'messages', 'attr' => array('class' => "btn btn-primary"))); return $form; }
private function loadPosts(ObjectManager $manager) { foreach (range(1, 10) as $i) { $post = new Post(); $post->setTitle($this->getRandomPostTitle()); $post->setSummary($this->getRandomPostSummary()); $post->setSlug($this->container->get('slugger')->slugify($post->getTitle())); $post->setContent($this->getPostContent()); $post->setAuthorEmail('*****@*****.**'); $post->setPublishedAt(new \DateTime('now - ' . $i . 'days')); foreach (range(1, 5) as $j) { $comment = new Comment(); $comment->setAuthorEmail('*****@*****.**'); $comment->setPublishedAt(new \DateTime('now + ' . ($i + $j) . 'seconds')); $comment->setContent($this->getRandomCommentContent()); $comment->setPost($post); $manager->persist($comment); $post->addComment($comment); } $manager->persist($post); } $manager->flush(); }
public function getFrontShowElements(Request $request, $slug) { $em = $this->doctrine->getManager(); $post = $em->getRepository('AppBundle:Post')->findBySlug($slug); $user = $this->getUser(); if ($post[0] === null) { throw new NotFoundHttpException('Post not found'); } $comment = new Comment(); $comment->setPost($post[0]); $comment->setUser($user); $form = $this->formFactory->create(CommentType::class, $comment, ['method' => Request::METHOD_POST]); $form->add('save', SubmitType::class, array('label' => 'Submit Comment', 'attr' => array('class' => "btn btn-primary"))); if ($request->getMethod() == 'POST' && $user) { $form->handleRequest($request); if ($form->isValid()) { $em->persist($comment); $em->flush(); $url = $this->router->generate('show_post', ['slug' => $slug]); return new RedirectResponse($url, 301); } } return ['post' => $post, 'formComment' => $form->createView()]; }
/** * Creates a new comment from the submitted data. * * @Post("/comments/posts/{id}") * * @ApiDoc( * resource = true, * input = "AppBundle\Entity\Comment", * statusCodes = { * 201 = "Returned when a new resource is created", * 400 = "Returned when the form has errors" * } * ) * * @param Request $request * @param int $id * * * @return View */ public function newCommentAction(Request $request, $id) { $em = $this->getDoctrine()->getManager(); $post = $em->getRepository('AppBundle:Post')->find($id); $comment = new Comment(); $comment->setPost($post); $form = $this->createForm(new CommentRestType(), $comment); $form->submit($request); if ($form->isValid()) { $em->persist($comment); $em->flush(); return $this->routeRedirectView('api_v1_get_comment', array('id' => $comment->getId())); } $view = $this->view($form)->setTemplate('RestBundle:Comment:newComment.html.twig'); return $this->handleView($view); }
/** * {@inheritDoc} */ public function setPost(\AppBundle\Entity\Post $post = NULL) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setPost', array($post)); return parent::setPost($post); }
/** * Add comment * * @param Comment $comment */ public function addComment(Comment $comment) { $comment->setPost($this); $this->comments[] = $comment; }
/** * @param Comment $comment * * @return $this */ public function addComment(Comment $comment) { $this->comments[] = $comment; $comment->setPost($this); return $this; }
/** * Add comment * * @param \AppBundle\Entity\Comment $comment * @return Comment */ public function addComment(\AppBundle\Entity\Comment $comment) { $comment->setPost($this); $this->comments[] = $comment; return $this; }