Ejemplo n.º 1
0
 /**
  * @Route("/generate", name="fakeEntityGenerator")
  * @Method("GET")
  */
 public function generateAction()
 {
     $faker = Factory::create();
     $em = $this->getDoctrine()->getManager();
     foreach ($this->countryNames as $countryName) {
         $country = new Country();
         $country->setName($countryName);
         $country->setFlag($countryName . '.png');
         $country->setDescription($faker->text(3000));
         $team = new Team();
         $team->setName($countryName);
         $team->setDescription($faker->text(3000));
         $team->setCountry($country);
         for ($i = 0; $i < 16; $i++) {
             $player = new Player();
             $player->setName($faker->name);
             $player->setDescription($faker->text(3000));
             $player->setTeam($team);
             $em->persist($player);
         }
         for ($i = 0; $i < 4; $i++) {
             $coach = new Coach();
             $coach->setName($faker->name);
             $coach->setDescription($faker->text(3000));
             $coach->setTeam($team);
             $em->persist($coach);
         }
         $em->persist($country);
         $em->persist($team);
     }
     $em->flush();
     return $this->redirectToRoute('homePage');
 }
Ejemplo n.º 2
0
 public function testSetName()
 {
     // new entity
     $team = new Team();
     // Use the setName method
     $team->setName("Hovedstyret");
     // Assert the result
     $this->assertEquals("Hovedstyret", $team->getName());
 }
Ejemplo n.º 3
0
 public function load(ObjectManager $manager)
 {
     $teams = array(array('name' => 'Equipo Temporal 1'), array('name' => 'Equipo de nuevos'), array('name' => 'Ayudantes para web'));
     foreach ($teams as $team) {
         $entity = new Team();
         $entity->setName($team['name']);
         $manager->persist($entity);
     }
     $manager->flush();
 }
Ejemplo n.º 4
0
 public function testSetTeam()
 {
     // new entity
     $wh = new WorkHistory();
     // dummy entity
     $team = new Team();
     $team->setName("Hovedstyret");
     // Use the setTeam method
     $wh->setTeam($team);
     // Assert the result
     $this->assertEquals($team, $wh->getTeam());
 }
Ejemplo n.º 5
0
 public function load(ObjectManager $manager)
 {
     $team1 = new Team();
     $team1->setDepartment($this->getReference('dep-1'));
     $team1->setName('Hovedstyret');
     $manager->persist($team1);
     $team2 = new Team();
     $team2->setDepartment($this->getReference('dep-1'));
     $team2->setName('IT');
     $manager->persist($team2);
     $manager->flush();
     $this->addReference('team-1', $team1);
     $this->addReference('team-2', $team2);
 }
Ejemplo n.º 6
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $io = new SymfonyStyle($input, $output);
     $em = $this->getContainer()->get('doctrine.orm.entity_manager');
     $file = $input->getArgument('file');
     $teams = json_decode(file_get_contents($file));
     foreach ($teams as $team) {
         $t = new Team();
         $t->setName($team->name);
         $t->setWsId($team->id);
         $em->persist($t);
     }
     $em->flush();
     $io->success('Added ' . count($teams) . ' teams.');
 }
Ejemplo n.º 7
0
 /**
  * @param $count
  * @return array
  */
 public function generateTeam($count)
 {
     $data = Factory::create();
     $teams = [];
     for ($i = 1; $i < $count + 1; $i++) {
         $team = new Team();
         $team->setCountry($data->country);
         $team->setName($data->company);
         for ($j = 0; $j < 23; $j++) {
             $player = $this->generatePlayer($team);
             $team->addPlayer($player);
         }
         for ($k = 0; $k < 7; $k++) {
             $trainer = $this->generateTrainer($team);
             $team->addTrainer($trainer);
         }
         $teams[$i] = $team;
     }
     return $teams;
 }
Ejemplo n.º 8
0
 public function getRegionTeams(Region $region)
 {
     $teams = $this->whoscored->loadStatistics('regionteams', array('id' => $region->getWsId()));
     foreach ($teams as $team) {
         if ($this->em->getRepository('AppBundle:Team')->findOneByWsId($team[0]) !== null) {
             continue;
         }
         $ret = new Team();
         $ret->setWsId($team[0]);
         $ret->setName($team[1]);
         $this->em->persist($ret);
         unset($ret);
     }
     $this->em->flush();
 }
Ejemplo n.º 9
0
 public function testRemoveTeam()
 {
     // new entity
     $department = new Department();
     $team1 = new Team();
     $team1->setName("Team1");
     $team2 = new Team();
     $team2->setName("Team2");
     $team3 = new Team();
     $team3->setName("Team3");
     // Use the addTeam method
     $department->addTeam($team1);
     $department->addTeam($team2);
     $department->addTeam($team3);
     // Remove $team1 from department
     $department->removeTeam($team1);
     // Teams are stored in an array
     $teams = $department->getTeams();
     // Loop through the array
     foreach ($teams as $team) {
         // Assert the result
         $this->assertNotEquals($team1, $team);
     }
 }
Ejemplo n.º 10
0
 /**
  * Creates a new Team entity.
  *
  * @Route("/team/new", name="team_new")
  * @Method({"GET", "POST"})
  */
 public function newAction(Request $request)
 {
     /** @var EntityManager $em */
     $em = $this->getDoctrine()->getManager();
     $maxTeamSize = 9;
     $minAge = 0;
     $maxAge = 100;
     $gender = Competitor::GENDER_BOTH;
     //$withCox = true;
     /** @var Race $race */
     $race = $request->get('race', null);
     if (!is_null($race)) {
         /** @var RaceRepository $raceRepo */
         $raceRepo = $em->getRepository('AppBundle:Race');
         /** @var Race|null $race */
         $race = $raceRepo->find(intval($race));
         if (!is_null($race)) {
             $maxTeamSize = $race->getTeamsize();
             $minAge = $race->getAgeMin();
             $maxAge = $race->getAgeMax();
             $gender = $race->getGender();
         }
     }
     // get all potential candidates
     /** @var MembershipRepository $memberRepo */
     $memberRepo = $em->getRepository('AppBundle:Membership');
     $memberships = $memberRepo->findAllCurrent($gender, $minAge, $maxAge);
     if (0 == count($memberships)) {
         $this->addFlash('error', 'Keine passenden Sportler gefunden, um neue Mannschaft anzulegen!');
         return $this->redirect($request->headers->get('referer'));
     } else {
         /** @var ClubRepository $clubRepo */
         $clubRepo = $em->getRepository('AppBundle:Club');
         $clubs = $clubRepo->findAll();
         usort($clubs, function ($a, $b) {
             /** @var Club $a */
             $left = $a->getCity() . '_' . $a->getAbbreviation();
             /** @var Club $b */
             $right = $b->getCity() . '_' . $b->getAbbreviation();
             return strcmp($left, $right);
         });
         // no model
         $data = array();
         $fb = $this->createFormBuilder($data);
         $fb->add('club', ChoiceType::class, array('label' => 'Meldender Club', 'required' => true, 'expanded' => false, 'multiple' => false, 'choices' => $clubs, 'choice_label' => function ($club, $key, $index) {
             /** @var Club $club */
             return $club->getName() . ' (' . $club->getCity() . ')';
         }, 'group_by' => function ($club, $key, $index) {
             /** @var Club $club */
             return substr($club->getCity(), 0, 1);
         }));
         // team members at the positions
         for ($i = 1; $i <= $maxTeamSize; $i++) {
             $fb->add('members_' . $i, ChoiceType::class, array('label' => 'Platz ' . $i, 'required' => true, 'expanded' => false, 'multiple' => false, 'choices' => $memberships, 'choice_label' => function ($m, $key, $index) use($gender) {
                 /** @var Membership $m */
                 /** @var Competitor $p */
                 $p = $m->getPerson();
                 $result = $p->getFirstName() . ' ' . strtoupper($p->getLastName()) . ' (' . $p->getYearOfBirth() . ', ' . $p->getAge();
                 if (Competitor::GENDER_BOTH == $gender) {
                     $result .= ', ' . $p->getGenderSymbol();
                 }
                 $result .= ')';
                 return $result;
             }, 'group_by' => function ($m, $key, $index) {
                 /** @var Membership $m*/
                 if (!empty(trim($m->getClub()->getShortname()))) {
                     return $m->getClub()->getShortname();
                 } else {
                     return $m->getClub()->getName();
                 }
             }));
         }
         $form = $fb->getForm();
         $form->handleRequest($request);
         if ($form->isSubmitted()) {
             $isGood = true;
             if (!$form->isValid()) {
                 foreach ($form->getErrors() as $error) {
                     $this->addFlash('error', $error->getMessage());
                 }
                 $isGood = false;
             }
             if ($isGood) {
                 /** @var Club $club */
                 $club = $form->get('club')->getData();
                 if (is_null($club)) {
                     $this->addFlash('error', 'Kein Club angegeben!');
                     $isGood = false;
                 }
             }
             $team = null;
             if ($isGood) {
                 $team = new Team();
                 $team->setClub($club);
                 $team->setName($club->getName());
                 $em->persist($team);
             }
             $found[] = array();
             for ($i = 1; $i <= $maxTeamSize; $i++) {
                 /** @var Membership $m */
                 $m = $form->get('members_' . $i)->getData();
                 if (is_null($m)) {
                     $this->addFlash('error', sprintf("Kein Sportler an Position %d angegeben!", $i));
                     $isGood = false;
                 } else {
                     if (in_array($m->getId(), $found)) {
                         $this->addFlash('error', sprintf("Sportler an Position %d mehrfach angegeben!", $i));
                         $isGood = false;
                     } else {
                         $found[] = $m->getId();
                         $posInTeam = new TeamPosition();
                         $posInTeam->setTeam($team)->setPosition($i)->setIsCox(false)->setMembership($m);
                         $em->persist($posInTeam);
                     }
                 }
             }
             if ($isGood) {
                 $em->flush();
                 $this->addFlash('notice', 'Mannschaft erfolgreich angelegt!');
             }
         }
         return $this->render('team/new.html.twig', array('race' => $race, 'form' => $form->createView()));
     }
 }
Ejemplo n.º 11
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();
 }
Ejemplo n.º 12
0
 /**
  * Creates a new Team entity.
  *
  * @Route("/create", name="team_create_ajax", options={"expose"=true})
  * @Method("POST")
  */
 public function createAction(Request $request)
 {
     $em = $this->getDoctrine()->getManager();
     $team = new Team();
     $team->setName($request->get('name'));
     $em->persist($team);
     $em->flush();
     $result = "";
     $response = new Response();
     $response->setContent(json_encode(array('result' => $result)));
     return $response;
 }