public function createAction() { $request = $this->getRequest(); $requestData = $request->request->all(); $em = $this->getDoctrine()->getManager(); $response = new ResponseHelper($this); $pot = new Pot(); $pot->setManager($this->getUser()); $form = $this->createForm(new PotType(), $pot); $form->submit($request); if ($form->isValid()) { $em->persist($pot); $em->flush(); $participation = new Participation(); $participation->setUser($this->getUser()); $participation->setPot($pot); //Automatic acceptance and payment by manager $participation->setAcceptedAt(new \DateTime()); //$participation->setPaidAt(new \DateTime()); $em->persist($participation); $em->flush(); $response->setStatusCode(Response::HTTP_CREATED); $response->addHeader('Location', $this->generateUrl('pots_read', array('id' => $pot->getId()), true)); } else { $response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY); } return $response->renderResponse(); }
public function createAction() { $request = $this->getRequest(); $requestData = $request->request->all(); $em = $this->getDoctrine()->getManager(); $response = new ResponseHelper($this); $bet = new Bet(); $bet->setUser($this->getUser()); $form = $this->createForm(new BetType(), $bet); $form->submit($request); if ($form->isValid()) { $rep = $em->getRepository('EUMainBundle:Participation'); $participation = $rep->findOneBy(array('user' => $this->getUser(), 'pot' => $bet->getPot())); $rep = $em->getRepository('EUMainBundle:Bet'); $sameBet = $rep->findOneBy(array('user' => $this->getUser(), 'game' => $bet->getGame(), 'pot' => $bet->getPot())); if (!$bet->getGame()) { $response->setStatusCode(Response::HTTP_NOT_FOUND); } elseif (!$participation) { $response->setStatusCode(Response::HTTP_NOT_FOUND); } elseif ($bet->getGame()->hasStarted()) { $response->setStatusCode(Response::HTTP_LOCKED); } elseif (!$participation->isPaid()) { $response->setStatusCode(Response::HTTP_PAYMENT_REQUIRED); } elseif ($sameBet !== null) { $sameBet->updateBet($bet); $em->flush(); $response->setStatusCode(Response::HTTP_NO_CONTENT); } else { $em->persist($bet); $em->flush(); $response->setStatusCode(Response::HTTP_CREATED); $response->addHeader('Location', $this->generateUrl('bets_read', array('id' => $bet->getId()), true)); } } else { $response->setStatusCode(Response::HTTP_UNPROCESSABLE_ENTITY); } return $response->renderResponse(); }