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(); }
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(); }
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 load(ObjectManager $manager) { $faker = Factory::create(); for ($i = 1; $i <= 24; $i++) { $article = new Article(); // $article->setSlug('article' . $i); $article->setSummary($faker->sentences(10, true)); $article->setContent($faker->text(3000)); $article->setTitle($faker->sentence()); $slug = $this->container->get('app.slugger')->slugify($article->getTitle()); $article->setSlug($slug); $article->setAuthorEmail('*****@*****.**'); $article->setPathToImage('images/foto_' . $i . '.jpg'); for ($j = 1; $j <= 5; $j++) { $comment = new Comment(); $comment->setContent($faker->sentences(5, true)); //$comment->setPublishedAt(new \DateTime('now')); $comment->setArticle($article); $comment->setAuthorEmail('*****@*****.**'); $article->addComment($comment); $manager->persist($comment); } $manager->persist($article); $arrayId = array(); $k = rand(1, 10); while (count($arrayId) < $k) { $id = rand(1, 50); if (array_search($id, $arrayId) === false) { $arrayId[] = $id; $tagFromBase = $this->getReference("tag {$id}"); $article->addTag($tagFromBase); $tagFromBase->getArticles()->add($article); } } } $manager->flush(); }
public function getExampleCommentEntity() { $comment = new Comment(); $comment->setContent('Lorem ipsum dolor sit amet consectetur.'); $comment->setAuthorEmail('*****@*****.**'); return $comment; }