public function deleteAction($id)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Participation');
     $participation = $rep->find($id);
     $response = new ResponseHelper($this);
     if ($participation) {
         if ($participation->getUser() !== $this->getUser() && $participation->getAcceptedAt() !== null) {
             $response->setStatusCode(Response::HTTP_LOCKED);
         } elseif ($participation->getUser() !== $this->getUser() && $participation->getPot()->getManager() !== $this->getUser()) {
             $response->setStatusCode(Response::HTTP_LOCKED);
         } else {
             $pot = $participation->getPot();
             $em->remove($participation);
             $em->flush();
             $participations = $rep->findBy(array('pot' => $pot));
             if (sizeof($participations) == 0) {
                 $em->remove($pot);
             }
             $em->flush();
             $response->setStatusCode(Response::HTTP_NO_CONTENT);
         }
     } else {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         $response->setMessage('There is no participation with this ID in the database');
         $response->setMessageType('warning');
         $response->addMessageButton('default', $request->headers->get('referer') == '' ? $this->generateUrl('eu_main_homepage') : $request->headers->get('referer'), 'Back');
         $response->addMessageButton('warning', $this->generateUrl('eu_main_homepage'), 'Home');
     }
     return $response->renderResponse();
 }
Esempio n. 2
0
 public function listAction()
 {
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('ApplicationSonataUserBundle:User');
     $users = $rep->findAll();
     $response = new ResponseHelper($this, Response::HTTP_OK, $users);
     return $response->renderResponse();
 }
Esempio n. 3
0
 public function listBetsAction($id)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Game');
     $game = $rep->find($id);
     $response = new ResponseHelper($this);
     if ($game) {
         $rep = $em->getRepository('EUMainBundle:Bet');
         $bets = $rep->findBy(array('game' => $game));
         $response->setStatusCode(Response::HTTP_OK);
         $response->setData($bets);
     } else {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         $response->setMessage('There is no game with this ID in the database');
         $response->setMessageType('warning');
         $response->addMessageButton('default', $request->headers->get('referer') == '' ? $this->generateUrl('eu_main_homepage') : $request->headers->get('referer'), 'Back');
         $response->addMessageButton('warning', $this->generateUrl('eu_main_homepage'), 'Home');
     }
     return $response->renderResponse();
 }
Esempio n. 4
0
 public function deleteAction($id)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Bet');
     $bet = $rep->find($id);
     $response = new ResponseHelper($this);
     if ($bet) {
         if ($bet->getGame()->hasStarted()) {
             $response->setStatusCode(Response::HTTP_LOCKED);
         } else {
             $em->remove($bet);
             $em->flush();
             $response->setStatusCode(Response::HTTP_NO_CONTENT);
         }
     } else {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         $response->setMessage('There is no bet with this ID in the database');
         $response->setMessageType('warning');
         $response->addMessageButton('default', $request->headers->get('referer') == '' ? $this->generateUrl('eu_main_homepage') : $request->headers->get('referer'), 'Back');
         $response->addMessageButton('warning', $this->generateUrl('eu_main_homepage'), 'Home');
     }
     return $response->renderResponse();
 }
Esempio n. 5
0
 public function listBetsAction($id)
 {
     $request = $this->getRequest();
     $em = $this->getDoctrine()->getManager();
     $rep = $em->getRepository('EUMainBundle:Pot');
     $pot = $rep->find($id);
     $response = new ResponseHelper($this);
     if ($pot) {
         $rep = $em->getRepository('EUMainBundle:Bet');
         $bets = $rep->findBy(array('pot' => $pot, 'user' => $this->getUser()));
         $rep = $em->getRepository('EUMainBundle:Participation');
         $participations = $rep->findBy(array('pot' => $pot));
         $users = array();
         foreach ($participations as $p) {
             array_push($users, $p->getUser());
         }
         if (in_array($this->getUser(), $users)) {
             $response->setStatusCode(Response::HTTP_OK);
             $response->setData($bets);
         } else {
             $response->setStatusCode(Response::HTTP_LOCKED);
         }
     } else {
         $response->setStatusCode(Response::HTTP_NOT_FOUND);
         $response->setMessage('There is no pot with this ID in the database');
         $response->setMessageType('warning');
         $response->addMessageButton('default', $request->headers->get('referer') == '' ? $this->generateUrl('eu_main_homepage') : $request->headers->get('referer'), 'Back');
         $response->addMessageButton('warning', $this->generateUrl('eu_main_homepage'), 'Home');
     }
     return $response->renderResponse();
 }