public function generateLeaguePlayers(League $league)
 {
     // Begin with functioning gen new league
     // optimize later with raw sql and multi inserts.
     $players = $this->em->getRepository('DraftBundle:Player')->findAll();
     foreach ($players as $player) {
         $leaguePlayer = new League_Player();
         $leaguePlayer->setLeague($league);
         $leaguePlayer->setPlayer($player);
         $this->em->persist($leaguePlayer);
     }
     $this->em->flush();
 }
 public function processForm(Player $player, $isNew = true)
 {
     $parameters = $this->get('request')->request->all();
     if ($isNew) {
         $statusCode = 201;
     } else {
         $statusCode = 204;
     }
     $form = $this->createForm(new PlayerType(), $player);
     $form->submit($parameters);
     $view = View::create($player, $statusCode);
     if ($form->isValid()) {
         $player->setUpdatedAt(new \DateTime());
         $em = $this->getDoctrine()->getManager();
         $em->persist($player);
         /*
          * now build the league players in each league
          * but only if new.
          */
         if ($isNew) {
             $leagues = $em->getRepository('DraftBundle:League')->findAll();
             //todo make this more efficient and async if necessary
             foreach ($leagues as $league) {
                 $leaguePlayer = new League_Player();
                 $leaguePlayer->setPlayer($player);
                 $leaguePlayer->setLeague($league);
                 $em->persist($leaguePlayer);
             }
         }
         $em->flush();
         return $this->handleView($view);
     }
     return $this->handleView($view->setData($form)->setStatusCode(400));
 }