/** * @Route("/admin/insert/game/", name="game_insert_admin") * */ public function generateGameAction() { $teams = $this->getDoctrine()->getRepository('AppBundle:Team')->findAll(); if (!$teams) { throw $this->createNotFoundException('Not found'); } $count = 0; $arr = array(); foreach ($teams as $team) { $arr[$count] = $team; $count++; } $faker = Factory::create(); $em = $this->getDoctrine()->getManager(); for ($i = 0; $i < 20; $i++) { $game = new Game(); $game->setDateGame($faker->dateTime); $goals1 = rand(0, 5); $goals2 = rand(0, 5); $team1 = $arr[rand(0, $count - 1)]; $team2 = $arr[rand(0, $count - 1)]; $game->setGoals1($goals1); $game->setGoals2($goals2); $game->setTeam1($team1->getCountry()); $game->setTeam2($team2->getCountry()); $game->setTeam1Id($team1); $game->setTeam2Id($team2); $em->persist($game); } $em->flush(); $this->addFlash('notice', 'Add games!'); return $this->forward('AppBundle:Admin:show'); }