Example #1
0
 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();
 }