예제 #1
0
 public function load(ObjectManager $manager)
 {
     $faker = Factory::create();
     for ($i = 1; $i <= 24; $i++) {
         $team = new Team();
         $team->setInfo($faker->text(2000));
         $country = $this->getReference("country {$i}");
         $team->setCountry($country);
         $this->setReference("team {$i}", $team);
         $manager->persist($team);
         $manager->flush();
         for ($k = 1; $k <= 11; $k++) {
             $player = new Player();
             $player->setFirstName($faker->firstNameMale);
             $player->setLastName($faker->lastName);
             $player->setBiography($faker->text(200));
             $player->setDateOfBirthday($faker->date('Y-m-d'));
             $player->setTeam($team);
             $team->getPlayers()->add($player);
             $manager->persist($player);
         }
         // the same for coaches
         for ($k = 1; $k <= 5; $k++) {
             $coach = new Coach();
             $coach->setName($faker->name);
             $coach->setBiography($faker->text(200));
             $coach->setTeam($team);
             $team->getCoaches()->add($coach);
             $manager->persist($coach);
         }
     }
     $manager->flush();
 }
예제 #2
0
 public function generateCoach()
 {
     $faker = Factory::create();
     $coach = new Coach();
     $em = $this->getDoctrine()->getManager();
     for ($i = 0; $i < 10; $i++) {
         $coach->setFirstName($faker->firstNameMale);
         $coach->setLastName($faker->lastName);
         $coach->setBirthDay($faker->dateTime);
         $coach->setBiography($faker->text);
         $em->persist($coach);
     }
     $em->flush();
     $this->redirectToRoute('homepage');
 }
예제 #3
0
 /**
  * @Route("/admin/insert/coach/{id}", name="coach_insert_admin", requirements={"id" : "\d+"})
  *
  */
 public function generateCoachAction($id)
 {
     $teams = $this->getDoctrine()->getRepository('AppBundle:Team')->find($id);
     if (!$teams) {
         throw $this->createNotFoundException('Not found');
     }
     $faker = Factory::create();
     $em = $this->getDoctrine()->getManager();
     $coach = new Coach();
     $coach->setTeam($teams);
     $coach->setFirstName($faker->firstNameMale);
     $coach->setLastName($faker->lastName);
     $coach->setBirthDay($faker->dateTime);
     $coach->setBiography($faker->text);
     $em->persist($coach);
     $em->flush();
     $this->addFlash('notice', 'Add coach!');
     return $this->forward('AppBundle:Admin:show');
 }