示例#1
0
 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();
 }
示例#2
0
文件: Bet.php 项目: Euro2016/Euro2016
 public function updateBet(\EU\MainBundle\Entity\Bet $bet)
 {
     $this->score1 = $bet->getScore1();
     $this->score2 = $bet->getScore2();
 }