public function load(ObjectManager $manager)
 {
     $PlayerSportsSkills1 = new PlayerSportsSkills();
     $PlayerSportsSkills1->setSkilllevelsId($manager->merge($this->getReference('Skilllevels1')));
     $PlayerSportsSkills1->setSportsId($manager->merge($this->getReference('Sports1')));
     $PlayerSportsSkills1->setPlayerId($manager->merge($this->getReference('Player1')));
     $manager->persist($PlayerSportsSkills1);
     $manager->flush();
     $PlayerSportsSkills2 = new PlayerSportsSkills();
     $PlayerSportsSkills2->setSkilllevelsId($manager->merge($this->getReference('Skilllevels2')));
     $PlayerSportsSkills2->setSportsId($manager->merge($this->getReference('Sports4')));
     $PlayerSportsSkills2->setPlayerId($manager->merge($this->getReference('Player1')));
     $manager->persist($PlayerSportsSkills2);
     $manager->flush();
 }
 public function insertPlayerData(\Symfony\Component\Form\Form $form)
 {
     $sportList = $form->get('sports')->getData();
     $this->created = time();
     $player = new Player();
     $gender = $form->get('gender')->getData();
     $player->setName($form->get('name')->getData());
     $player->setLastname($form->get('name')->getData());
     $player->setEmail($form->get('email')->getData());
     $player->setUsername($form->get('email')->getData());
     $player->setPassword(md5($form->get('password')->getData()));
     $player->setBirthday(strtotime($form->get('birthday')->getData()->format('d-m-Y')));
     $player->setSports(implode(':', $sportList));
     $player->setGender($gender->getId());
     $player->setActivityradius(10);
     //default
     $player->setCreated($this->created);
     $player->setPopularity('1');
     //default
     $player->setZipcode($form->get('zipcode')->getData());
     $player->setEvaluate('1');
     //can be modified in administration
     $player->setPlayerstatus(1);
     //can be modified in administration
     $player->setSkills('1:1:1');
     //default
     $player->setRegistered(0);
     $player->setOnline(0);
     $em = $this->getEntityManager();
     $em->persist($player);
     //populate player_sports_skills
     //cross reference table(entity) matches chosen sports with specific skills
     foreach ($sportList as $k => $v) {
         $pss = new PlayerSportsSkills();
         $pss->setPlayerId($player);
         $skill = $this->_em->getRepository("SportnetzwerkSpnBundle:Skilllevels")->findByName('pro');
         ///trigger_error(var_export($skill, true));
         $pss->setSkilllevelsId($skill[0]);
         $sport = $this->_em->getRepository("SportnetzwerkSpnBundle:Sports")->findById($v);
         $pss->setSportsId($sport[0]);
         $emLoop = $this->getEntityManager();
         $emLoop->persist($pss);
         $emLoop->flush();
         unset($pss);
     }
     $em->flush();
 }