コード例 #1
0
 public function load(ObjectManager $manager)
 {
     $faker = \Faker\Factory::create();
     $game = new Game();
     $game->setDate($faker->dateTime());
     $game->setTeam1($this->getReference("team-1"));
     $game->setTeam2($this->getReference("team-2"));
     $game->setScoreTeam1($faker->numberBetween(0, 10));
     $game->setScoreTeam2($faker->numberBetween(0, 10));
     $manager->persist($game);
     $manager->flush();
     $this->addReference("game-1", $game);
     $game = new Game();
     $game->setDate($faker->dateTime());
     $game->setTeam1($this->getReference("team-3"));
     $game->setTeam2($this->getReference("team-4"));
     $game->setScoreTeam1($faker->numberBetween(0, 10));
     $game->setScoreTeam2($faker->numberBetween(0, 10));
     $manager->persist($game);
     $manager->flush();
     $this->addReference("game-2", $game);
     $game = new Game();
     $game->setDate($faker->dateTime());
     $game->setTeam1($this->getReference("team-5"));
     $game->setTeam2($this->getReference("team-6"));
     $game->setScoreTeam1($faker->numberBetween(0, 10));
     $game->setScoreTeam2($faker->numberBetween(0, 10));
     $manager->persist($game);
     $manager->flush();
     $this->addReference("game-3", $game);
     $game = new Game();
     $game->setDate($faker->dateTime());
     $game->setTeam1($this->getReference("team-7"));
     $game->setTeam2($this->getReference("team-8"));
     $game->setScoreTeam1($faker->numberBetween(0, 10));
     $game->setScoreTeam2($faker->numberBetween(0, 10));
     $manager->persist($game);
     $manager->flush();
     $this->addReference("game-4", $game);
 }
コード例 #2
0
 /**
  * @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');
 }
コード例 #3
0
 public function load(\Doctrine\Common\Persistence\ObjectManager $manager)
 {
     $faker = \Faker\Factory::create();
     $userManager = $this->container->get('fos_user.user_manager');
     $addPlayer = function ($i, $team) use($manager, $userManager, $faker) {
         /** @var User $user */
         $user = $userManager->createUser();
         $user->setUsername('player' . $i);
         $user->setEmail('player' . $i . '@mailinator.com');
         $user->setPlainPassword('123456');
         $user->setEnabled(true);
         $user->setRoles(array('ROLE_USER', 'ROLE_PLAYER'));
         //            $user->setGcmRegistrationId($faker->uuid);
         $userManager->updateUser($user, true);
         $player = new Player();
         $player->setActive(true);
         $player->setAlias($faker->name);
         $player->setUser($user);
         $this->addReference('player' . $i, $player);
         $player->setImage($this->getReference('image' . rand(1, 19)));
         $manager->persist($player);
         $team->addPlayer($player);
     };
     $team1 = new Team();
     $team1->setActive(true);
     $team1->setName($faker->word);
     $manager->persist($team1);
     for ($i = 1; $i <= 5; $i++) {
         $addPlayer($i, $team1);
     }
     $team2 = new Team();
     $team2->setActive(true);
     $team2->setName($faker->word);
     $manager->persist($team2);
     for ($i = 6; $i <= 10; $i++) {
         $addPlayer($i, $team2);
     }
     $game = new Game();
     $game->setTeam1($team1);
     $game->setTeam2($team2);
     $game->setActive(true);
     $endTime = new DateTime();
     $endTime->add(new DateInterval('PT15M'));
     $game->setEndTimeStamp($endTime);
     $this->addReference('game', $game);
     $manager->persist($team1);
     $manager->persist($team2);
     $queue = new Team();
     $queue->setActive(true);
     $queue->setName('queue');
     $manager->persist($queue);
     $manager->persist($game);
     for ($i = 1; $i < 10; $i++) {
         $team = new Team();
         $team->setName($faker->word);
         $team->setActive(true);
         $team->setPoints(rand(10, 400));
         $manager->persist($team);
     }
     for ($i = 11; $i < 20; $i++) {
         /** @var User $user */
         $user = $userManager->createUser();
         $user->setUsername('player' . $i);
         $user->setEmail('player' . $i . '@mailinator.com');
         $user->setPlainPassword('123456');
         $user->setEnabled(true);
         $user->setRoles(array('ROLE_USER', 'ROLE_PLAYER'));
         $userManager->updateUser($user, true);
         $player = new Player();
         $player->setActive(true);
         $player->setAlias($faker->name);
         $player->setUser($user);
         $this->addReference('player' . $i, $player);
         $player->setImage($this->getReference('image' . rand(1, 19)));
         $manager->persist($player);
     }
     $manager->flush();
 }