Advertisement
Guest User

Untitled

a guest
May 25th, 2015
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.49 KB | None | 0 0
  1. <?php
  2.  
  3. namespace Gi33\Bundle\FantasyBundle\Controller;
  4.  
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Bundle\FrameworkBundle\Controller\Controller;
  7. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
  8. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
  9. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Template;
  10.  
  11. /**
  12. * Equipo controller.
  13. *
  14. * @Route("/home")
  15. */
  16. class HomeController extends Controller {
  17.  
  18. /**
  19. * Lists all Equipo entities.
  20. *
  21. * @Route("/", name="home")
  22. * @Method("GET")
  23. * @Template()
  24. */
  25. public function indexAction() {
  26.  
  27. $mobileDetector = $this -> get('mobile_detect.mobile_detector');
  28. $isMobile = $mobileDetector -> isMobile();
  29. $isTablet = $mobileDetector -> isTablet();
  30.  
  31. if ($isMobile && !$isTablet) {
  32.  
  33. return $this -> redirect($this -> generateUrl('mobil'));
  34. } else if ($isTablet && $isMobile) {
  35.  
  36. $uUser = $this -> get("session") -> get("user_info");
  37.  
  38. $tieneequipo = false;
  39. if (count($uUser)) {
  40. $tieneequipo = true;
  41. }
  42.  
  43. return $this -> render('Gi33FantasyBundle:Home:index.html.twig', array("tieneequipo", $tieneequipo));
  44.  
  45. } else {
  46.  
  47. $uUser = $this -> get("session") -> get("user_info");
  48.  
  49. $tieneequipo = false;
  50. if (count($uUser)) {
  51. $tieneequipo = true;
  52. }
  53.  
  54. return $this -> render('Gi33FantasyBundle:Home:index.html.twig', array("tieneequipo", $tieneequipo));
  55.  
  56. }
  57.  
  58. }
  59.  
  60. /**
  61. * Lists all Equipo entities.
  62. *
  63. * @Route("/m", name="mobil")
  64. * @Method("GET")
  65. * @Template()
  66. */
  67. public function mobilAction(Request $request) {
  68.  
  69. // $listRanking = $this->listRanking($request->get("rows"), $request->get("page"));
  70.  
  71. $listRanking = array();
  72. $listRanking["participantes"] = 10;
  73. $listRanking["cantActual"] = 10;
  74.  
  75. $cantidadParticipantes = $listRanking["participantes"];
  76.  
  77. $cantidadActual = $listRanking["cantActual"];
  78. $listRanking["usuarios"] = 0;
  79. $totalpaginas = $cantidadParticipantes / $cantidadActual;
  80. $totalpaginasgeneral = $totalpaginas;
  81. $paginaplus = $request -> get("page") + 1;
  82. $paginaminus = $request -> get("page") - 1;
  83. if ($totalpaginas >= 4) {
  84. $totalpaginas = 4;
  85. }
  86. $page = $request -> get("page");
  87.  
  88. return $this -> render('Gi33FantasyBundle:Home:mobil.html.twig', array("listarray" => $listRanking, "total" => $totalpaginas, "page" => $page, "totalgenral" => $totalpaginasgeneral, "paginacionplus" => $paginaplus, "paginaminus" => $paginaminus));
  89.  
  90. }
  91.  
  92. /**
  93. * Lists all Equipo entities.
  94. *
  95. * @Route("/playerlist", name="playerlist")
  96. * @Method("GET")
  97. * @Template()
  98. */
  99. public function playerlistAction() {
  100. return $this -> render('Gi33FantasyBundle:Home:jugadores.html.twig');
  101. }
  102.  
  103. /**
  104. * Lists all Equipo entities.
  105. *
  106. * @Route("/crear-equipo", name="crearequipo")
  107. * @Method("GET")
  108. * @Template()
  109. */
  110. public function detalleAction() {
  111.  
  112. $mobileDetector = $this -> get('mobile_detect.mobile_detector');
  113. $isMobile = $mobileDetector -> isMobile();
  114.  
  115. $uUser = $this -> get("session") -> get("user_info");
  116. if (count($uUser["equipo"]) == 0 || !$uUser["equipo"]) {
  117. //return $this->redirect($this->generateUrl('home'));
  118.  
  119. if ($isMobile) {
  120. return $this -> render('Gi33FantasyBundle:Home:detallesm.html.twig');
  121.  
  122. } else {
  123. return $this -> render('Gi33FantasyBundle:Home:detalles.html.twig');
  124.  
  125. }
  126.  
  127. } else {
  128. return $this -> redirect($this -> generateUrl('home'));
  129. //return $this->render('Gi33FantasyBundle:Home:detalles.html.twig');
  130. }
  131. }
  132.  
  133. private function getRanking($list_id) {
  134.  
  135. $api_base_url = $this -> container -> getParameter('gi33_fantasy.api_base_url');
  136. $api_url = "{$api_base_url}listusers/{$list_id}";
  137. $ch = curl_init();
  138. curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/json'));
  139. curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
  140. curl_setopt($ch, CURLOPT_URL, $api_url);
  141. $response = curl_exec($ch);
  142. curl_close($ch);
  143. $response = json_decode($response);
  144. return $response;
  145. }
  146.  
  147. public function listRanking($rowsr, $pager) {
  148.  
  149. $em = $this -> getDoctrine() -> getManager();
  150. $gamRanking = $this -> getRanking(4);
  151.  
  152. $request = $this -> getRequest();
  153.  
  154. $result = array();
  155. $torneo = 1;
  156. $cont = 0;
  157. $rows = $request -> get("rows");
  158. $page = $request -> get("page");
  159. $offset = 0;
  160. $flagE = false;
  161. $usuarios = "";
  162.  
  163. $totalU = count($gamRanking);
  164.  
  165. if ($rows && $page) {
  166. if ($page > 0) {
  167. $offset = ($page - 1) * $rows;
  168. }
  169.  
  170. $gamRanking = array_slice($gamRanking, $offset, $rows);
  171. }
  172.  
  173. foreach ($gamRanking as $gamUser) {
  174.  
  175. $eU = $em -> getRepository('Gi33FantasyBundle:EquipoUsuario') -> findEquipoUsuarioByEmail($gamUser -> user -> email, $torneo);
  176.  
  177. if ($eU) {
  178. ++$cont;
  179. $result["usuarios"][] = array("posicion" => $gamUser -> userPosition, "nombre" => $eU -> getUsuario() -> getNombre(), "equipo" => $eU -> getNombre(), "puntos" => $gamUser -> user -> points, "diffPos" => $eU -> getUsuario() -> getPosicionAnterior() - $gamUser -> userPosition);
  180. } else {
  181. $flagE = true;
  182. $usuarios .= " " . $gamUser -> user -> email . " ";
  183. }
  184. }
  185.  
  186. if (!$flagE) {
  187. $result["participantes"] = $totalU;
  188. $result["cantActual"] = $cont;
  189. $result["pagina"] = $page;
  190. } else {
  191. $result = array("status" => false, "code" => 109, "msg" => "Los usuarios {$usuarios} de gamification, no están registrados en el sistema");
  192. }
  193. /*
  194.  
  195. $em = $this->getDoctrine()->getManager();
  196. $gamRanking = $this->getRanking(4);
  197.  
  198. $result = array();
  199. $torneo = 1;
  200. $cont = 0;
  201. $rows=$rowsr;
  202. $page=$pager;
  203.  
  204. $flagE = false;
  205. $usuarios = "";
  206.  
  207. $totalU = count($gamRanking);
  208.  
  209. if($rows && $page){
  210. $gamRanking = array_slice($gamRanking, $page, $rows);
  211. }
  212.  
  213. foreach ($gamRanking as $gamUser) {
  214.  
  215. $eU = $em->getRepository('Gi33FantasyBundle:EquipoUsuario')->findEquipoUsuarioByEmail($gamUser->user->email, $torneo);
  216.  
  217. if($eU){
  218. ++$cont;
  219. $result["usuarios"][] = array(
  220. "posicion" => $gamUser->userPosition,
  221. "nombre" => $eU->getUsuario()->getNombre(),
  222. "equipo" => $eU->getNombre(),
  223. "puntos" => $gamUser->user->points,
  224. "diffPos" => $eU->getUsuario()->getPosicionAnterior() - $gamUser->userPosition
  225. );
  226. }else{
  227.  
  228. $flagE = true;
  229. $usuarios .= " " .$gamUser->user->email." ";
  230. }
  231. }
  232.  
  233. if(!$flagE){
  234. $result["participantes"] = $totalU;
  235. $result["cantActual"] = $cont;
  236. $result["pagina"] = $page;
  237. }else{
  238. $result = array("status" => false, "code" => 109, "msg" => "Los usuarios {$usuarios} de gamification, no están registrados en el sistema");
  239. }
  240.  
  241. */
  242. return $result;
  243. }
  244.  
  245. /**
  246. * Lists all Equipo entities.
  247. *
  248. * @Route("/ranking", name="ranking")
  249. * @Method("GET")
  250. * @Template()
  251. */
  252. public function rankingAction(Request $request) {
  253.  
  254. $listRanking = $this -> listRanking($request -> get("rows"), $request -> get("page"));
  255.  
  256. $cantidadParticipantes = $listRanking["participantes"];
  257. $cantidadActual = $listRanking["cantActual"];
  258.  
  259. $totalpaginas = $cantidadParticipantes / $cantidadActual;
  260. $totalpaginasgeneral = $totalpaginas;
  261. $paginaplus = $request -> get("page") + 1;
  262. $paginaminus = $request -> get("page") - 1;
  263. if ($totalpaginas >= 4) {
  264. $totalpaginas = 4;
  265. }
  266. $page = $request -> get("page");
  267. return $this -> render('Gi33FantasyBundle:Home:ranking.html.twig', array("listarray" => $listRanking, "total" => $totalpaginas, "page" => $page, "totalgenral" => $totalpaginasgeneral, "paginacionplus" => $paginaplus, "paginaminus" => $paginaminus));
  268.  
  269. }
  270.  
  271. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement