/** * Controller of games main page * * @param Request $request * @param int $id_partida * @return RedirectResponse|\Symfony\Component\HttpFoundation\Response */ public function partidaAction(Request $request, $id_partida) { //$this->denyAccessUnlessGranted('ROLE_USER', null, 'Unable to access this page!'); //Security control. Check user roles. $securityContext = $this->get('security.authorization_checker'); if (false === $securityContext->isGranted('ROLE_USER')) { return new RedirectResponse($this->container->get('router')->generate('base_homepage')); } //set language $locale = $request->get('_locale'); $request->setLocale($locale); $request->getSession()->set('_locale', $locale); $router = $this->container->get('router'); /** @var User $user */ $user = $this->getUser(); $user_id = $user->getId(); $gravatar = $this->getGravatar($user->getEmail()); /** @var ObjectManager $em */ $em = $this->getDoctrine()->getManager(); try { /** @var Partida $partida */ $partida = $em->getRepository('BaseBundle:Partida')->findOneById($id_partida); /** @var UserPartida $userPartida */ $userPartida = $em->getRepository('BaseBundle:UserPartida')->findByIDS($user_id, $id_partida); if (new \DateTime('NOW') < $partida->getFin()) { $partidaLogic = new PartidaLogic(); //consultar el resto de jugadores $jugadores = $em->getRepository('BaseBundle:UserPartida')->findAllFriends($id_partida); //consultar ofertas pendientes $oferta_recibida = $em->getRepository('BaseBundle:Ofertas')->findRecievedOffers($user_id, $id_partida, OfertaLogic::NOTRATADA); $oferta_recibida_enCurso = $partidaLogic->checkInProgress($oferta_recibida, $em); //consultar ofertas enviadas en curso. $oferta_enviada = $em->getRepository('BaseBundle:Ofertas')->findSentOffers($user_id, $id_partida, OfertaLogic::NOTRATADA); $oferta_enviada_enCurso = $partidaLogic->checkInProgress($oferta_enviada, $em); $acceptReject = $this->createForm(new AcceptRejectDealType()); $delForm = $this->createForm(new DeleteDealType()); //guardar en sesion el valor de partida $session = $this->container->get('session'); $session->set('id_partida', $id_partida); /* Grafica de linea para usuario */ $graphics = new GraphicsLogic(); $evolucion = $partidaLogic->partidaEvolution($em, $user_id, $partida); $lineChart = $graphics->linesUserJsArray($evolucion); return $this->render('BaseBundle:Partida:partida.html.twig', array('partida' => $partida, 'userPartida' => $userPartida, 'jugadores' => $jugadores, 'oferta_recibida' => $oferta_recibida_enCurso, 'oferta_enviada' => $oferta_enviada_enCurso, 'acceptReject' => $acceptReject->createView(), 'delForm' => $delForm->createView(), 'lineChart' => $lineChart, 'gravatar' => $gravatar)); } } catch (\Exception $e) { return new RedirectResponse($router->generate('base_homepage')); } }