Example #1
0
    /**
     * Creates a new Team entity.
     *
     */
    public function newAction(Request $request)
    {
        $userId = $request->attributes->get('user');
        $gameId = $request->attributes->get('game');
        $team = new Team();
        $user = $this->getDoctrine()->getRepository('AppBundle:User')->find($userId);
        $game = $this->getDoctrine()->getRepository('AppBundle:Game')->find($gameId);
        $team->setGame($game);
        $form = $this->createForm(new TeamType(), $team);
        $form->handleRequest($request);
        if ($form->isSubmitted() && $form->isValid()) {
            $em = $this->getDoctrine()->getManager();
            $query = $em->createQuery('SELECT p
			    FROM AppBundle:Player p
			    where p.game=' . $gameId . ' and p.user='******'SELECT p
			    FROM AppBundle:Application p
			    inner join AppBundle:Team t
			    with p.team=t.id
			    where p.user='******' and t.game=' . $players[0]->getGame()->getId());
            $applications = $query->getResult();
            foreach ($applications as $application) {
                $em->remove($application);
            }
            $em->persist($team);
            $em->persist($players[0]);
            $em->flush();
            return $this->redirectToRoute('team_show', array('id' => $team->getId()));
        }
        return $this->render('AppBundle:team:new.html.twig', array('team' => $team, 'game' => $game, 'form' => $form->createView()));
    }
Example #2
0
 /**
  * @param  Team $team
  */
 public function addTeam(\AppBundle\Entity\Team $team)
 {
     $team->setGame($this);
     $this->team[] = $team;
 }