Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace Gi33\Bundle\FantasyBundle\Controller;
- use Symfony\Component\HttpFoundation\Request;
- use Symfony\Bundle\FrameworkBundle\Controller\Controller;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
- use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
- /**
- * Equipo controller.
- *
- * @Route("/home")
- */
- class HomeController extends Controller {
- /**
- * Lists all Equipo entities.
- *
- * @Route("/", name="home")
- * @Method("GET")
- * @Template()
- */
- public function indexAction() {
- $mobileDetector = $this -> get('mobile_detect.mobile_detector');
- $isMobile = $mobileDetector -> isMobile();
- $isTablet = $mobileDetector -> isTablet();
- if ($isMobile && !$isTablet) {
- return $this -> redirect($this -> generateUrl('mobil'));
- } else if ($isTablet && $isMobile) {
- $uUser = $this -> get("session") -> get("user_info");
- $tieneequipo = false;
- if (count($uUser)) {
- $tieneequipo = true;
- }
- return $this -> render('Gi33FantasyBundle:Home:index.html.twig', array("tieneequipo", $tieneequipo));
- } else {
- $uUser = $this -> get("session") -> get("user_info");
- $tieneequipo = false;
- if (count($uUser)) {
- $tieneequipo = true;
- }
- return $this -> render('Gi33FantasyBundle:Home:index.html.twig', array("tieneequipo", $tieneequipo));
- }
- }
- /**
- * Lists all Equipo entities.
- *
- * @Route("/m", name="mobil")
- * @Method("GET")
- * @Template()
- */
- public function mobilAction(Request $request) {
- // $listRanking = $this->listRanking($request->get("rows"), $request->get("page"));
- $listRanking = array();
- $listRanking["participantes"] = 10;
- $listRanking["cantActual"] = 10;
- $cantidadParticipantes = $listRanking["participantes"];
- $cantidadActual = $listRanking["cantActual"];
- $listRanking["usuarios"] = 0;
- $totalpaginas = $cantidadParticipantes / $cantidadActual;
- $totalpaginasgeneral = $totalpaginas;
- $paginaplus = $request -> get("page") + 1;
- $paginaminus = $request -> get("page") - 1;
- if ($totalpaginas >= 4) {
- $totalpaginas = 4;
- }
- $page = $request -> get("page");
- return $this -> render('Gi33FantasyBundle:Home:mobil.html.twig', array("listarray" => $listRanking, "total" => $totalpaginas, "page" => $page, "totalgenral" => $totalpaginasgeneral, "paginacionplus" => $paginaplus, "paginaminus" => $paginaminus));
- }
- /**
- * Lists all Equipo entities.
- *
- * @Route("/playerlist", name="playerlist")
- * @Method("GET")
- * @Template()
- */
- public function playerlistAction() {
- return $this -> render('Gi33FantasyBundle:Home:jugadores.html.twig');
- }
- /**
- * Lists all Equipo entities.
- *
- * @Route("/crear-equipo", name="crearequipo")
- * @Method("GET")
- * @Template()
- */
- public function detalleAction() {
- $mobileDetector = $this -> get('mobile_detect.mobile_detector');
- $isMobile = $mobileDetector -> isMobile();
- $uUser = $this -> get("session") -> get("user_info");
- if (count($uUser["equipo"]) == 0 || !$uUser["equipo"]) {
- //return $this->redirect($this->generateUrl('home'));
- if ($isMobile) {
- return $this -> render('Gi33FantasyBundle:Home:detallesm.html.twig');
- } else {
- return $this -> render('Gi33FantasyBundle:Home:detalles.html.twig');
- }
- } else {
- return $this -> redirect($this -> generateUrl('home'));
- //return $this->render('Gi33FantasyBundle:Home:detalles.html.twig');
- }
- }
- private function getRanking($list_id) {
- $api_base_url = $this -> container -> getParameter('gi33_fantasy.api_base_url');
- $api_url = "{$api_base_url}listusers/{$list_id}";
- $ch = curl_init();
- curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
- curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($ch, CURLOPT_URL, $api_url);
- $response = curl_exec($ch);
- curl_close($ch);
- $response = json_decode($response);
- return $response;
- }
- public function listRanking($rowsr, $pager) {
- $em = $this -> getDoctrine() -> getManager();
- $gamRanking = $this -> getRanking(4);
- $request = $this -> getRequest();
- $result = array();
- $torneo = 1;
- $cont = 0;
- $rows = $request -> get("rows");
- $page = $request -> get("page");
- $offset = 0;
- $flagE = false;
- $usuarios = "";
- $totalU = count($gamRanking);
- if ($rows && $page) {
- if ($page > 0) {
- $offset = ($page - 1) * $rows;
- }
- $gamRanking = array_slice($gamRanking, $offset, $rows);
- }
- foreach ($gamRanking as $gamUser) {
- $eU = $em -> getRepository('Gi33FantasyBundle:EquipoUsuario') -> findEquipoUsuarioByEmail($gamUser -> user -> email, $torneo);
- if ($eU) {
- ++$cont;
- $result["usuarios"][] = array("posicion" => $gamUser -> userPosition, "nombre" => $eU -> getUsuario() -> getNombre(), "equipo" => $eU -> getNombre(), "puntos" => $gamUser -> user -> points, "diffPos" => $eU -> getUsuario() -> getPosicionAnterior() - $gamUser -> userPosition);
- } else {
- $flagE = true;
- $usuarios .= " " . $gamUser -> user -> email . " ";
- }
- }
- if (!$flagE) {
- $result["participantes"] = $totalU;
- $result["cantActual"] = $cont;
- $result["pagina"] = $page;
- } else {
- $result = array("status" => false, "code" => 109, "msg" => "Los usuarios {$usuarios} de gamification, no están registrados en el sistema");
- }
- /*
- $em = $this->getDoctrine()->getManager();
- $gamRanking = $this->getRanking(4);
- $result = array();
- $torneo = 1;
- $cont = 0;
- $rows=$rowsr;
- $page=$pager;
- $flagE = false;
- $usuarios = "";
- $totalU = count($gamRanking);
- if($rows && $page){
- $gamRanking = array_slice($gamRanking, $page, $rows);
- }
- foreach ($gamRanking as $gamUser) {
- $eU = $em->getRepository('Gi33FantasyBundle:EquipoUsuario')->findEquipoUsuarioByEmail($gamUser->user->email, $torneo);
- if($eU){
- ++$cont;
- $result["usuarios"][] = array(
- "posicion" => $gamUser->userPosition,
- "nombre" => $eU->getUsuario()->getNombre(),
- "equipo" => $eU->getNombre(),
- "puntos" => $gamUser->user->points,
- "diffPos" => $eU->getUsuario()->getPosicionAnterior() - $gamUser->userPosition
- );
- }else{
- $flagE = true;
- $usuarios .= " " .$gamUser->user->email." ";
- }
- }
- if(!$flagE){
- $result["participantes"] = $totalU;
- $result["cantActual"] = $cont;
- $result["pagina"] = $page;
- }else{
- $result = array("status" => false, "code" => 109, "msg" => "Los usuarios {$usuarios} de gamification, no están registrados en el sistema");
- }
- */
- return $result;
- }
- /**
- * Lists all Equipo entities.
- *
- * @Route("/ranking", name="ranking")
- * @Method("GET")
- * @Template()
- */
- public function rankingAction(Request $request) {
- $listRanking = $this -> listRanking($request -> get("rows"), $request -> get("page"));
- $cantidadParticipantes = $listRanking["participantes"];
- $cantidadActual = $listRanking["cantActual"];
- $totalpaginas = $cantidadParticipantes / $cantidadActual;
- $totalpaginasgeneral = $totalpaginas;
- $paginaplus = $request -> get("page") + 1;
- $paginaminus = $request -> get("page") - 1;
- if ($totalpaginas >= 4) {
- $totalpaginas = 4;
- }
- $page = $request -> get("page");
- return $this -> render('Gi33FantasyBundle:Home:ranking.html.twig', array("listarray" => $listRanking, "total" => $totalpaginas, "page" => $page, "totalgenral" => $totalpaginasgeneral, "paginacionplus" => $paginaplus, "paginaminus" => $paginaminus));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement