/** * Get the ranking and other visual statistics of a game * * @param Request $request * @param int $id_partida * @return \Symfony\Component\HttpFoundation\Response|AccessDeniedException */ public function statisticsAction(Request $request, $id_partida) { $locale = $request->get('_locale'); $request->setLocale($locale); $request->getSession()->set('_locale', $locale); //Security control. Check user roles. $response = $this->checkSecurity($request); if ($response instanceof RedirectResponse) { return $response; } /** @var User $admin */ $admin = $this->getUser(); $admin_id = $admin->getId(); $gravatar = $this->getGravatar($admin->getEmail()); $em = $this->getDoctrine()->getManager(); try { /** @var Partida $partida */ $partida = $em->getRepository('BaseBundle:Partida')->isMyAdminGame($id_partida, $admin_id); $form = $this->createFormBuilder()->getForm(); $form->handleRequest($request); if ($form->isValid() && $request->isMethod('POST')) { $now = new \DateTime('now'); $partida->setFin($now); $em->flush(); } //pasar a ms para Angular $fin = $partida->getFin()->getTimestamp() * 1000; //la partida está en curso? new \DateTime('NOW') >= $partida->getFin() ? $terminado = PartidaLogic::TERMINADO : ($terminado = PartidaLogic::ENCURSO); $ranking = $em->getRepository('BaseBundle:UserPartida')->getRanking($id_partida); $graphics = new GraphicsLogic(); $adminLogic = new AdminLogic(); /*-------tarta------*/ $rankingFutlitidadStats = $graphics->donutJsArray($ranking, 'fUtilidad'); $rankingAluRojaStats = $graphics->donutJsArray($ranking, 'aluRojaActual'); $rankingAluBlancaStats = $graphics->donutJsArray($ranking, 'aluBlancaActual'); /*-------barras en detalle---*/ $ofertasMod = $adminLogic->barChartGraphics($em, $id_partida); //creamos el array para graficar los ratios $lineChart = $graphics->linesRatioJsArray($ofertasMod); //creamos el array para graficar las alubias $barChart = $graphics->barBeansJsArray($ofertasMod); return $this->render('BaseBundle:Admin:stats.html.twig', array('ranking' => $ranking, 'partida' => $partida, 'terminado' => $terminado, 'fin' => $fin, 'rankingFutilidadStats' => $rankingFutlitidadStats, 'rankingAluRojaStats' => $rankingAluRojaStats, 'rankingAluBlancaStats' => $rankingAluBlancaStats, 'lineChart' => $lineChart, 'barChart' => $barChart, 'gravatar' => $gravatar, 'form' => $form->createView())); } catch (\Exception $e) { return new AccessDeniedException('You shall not pass!'); } }
/** * 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')); } }