/projects/Fantasy/webroot/integrar/old/Clases/fachadaInterface.php

https://github.com/danielvaleradp/--ngara
PHP | 150 lines | 132 code | 17 blank | 1 comment | 15 complexity | f7d421194cab07f942e046f5597af643 MD5 | raw file
  1. <?php
  2. require_once 'model/Jugador.php';
  3. require_once 'model/Equipo.php';
  4. require_once 'model/Estadio.php';
  5. require_once 'model/Roster.php';
  6. require_once 'model/tiene.php';
  7. require_once 'model/EstadisticaPitcheo.php';
  8. require_once 'model/EstadisticaBateo.php';
  9. require_once 'model/Usuario.php';
  10. require_once 'model/Perfil_Usuario.php';
  11. class fachadaInterface {
  12. protected static $casos_insert = array(
  13. 'Jugador',
  14. 'Equipo',
  15. 'Estadio',
  16. 'Roster',
  17. 'tiene'
  18. );
  19. protected static $casos_update = array(
  20. 'Jugador',
  21. 'Equipo',
  22. 'Estadio',
  23. 'Roster',
  24. 'tiene',
  25. 'Perfil_Usuario',
  26. 'Usuario'
  27. );
  28. protected static $casos_remove = array(
  29. 'Jugador',
  30. 'Equipo',
  31. 'Estadio',
  32. 'Roster',
  33. 'tiene',
  34. 'Perfil_Usuario',
  35. 'Usuario'
  36. );
  37. protected static $casos_select = array(
  38. 'Jugador',
  39. 'Equipo',
  40. 'Estadio',
  41. 'Roster',
  42. 'tiene',
  43. 'Perfil_Usuario',
  44. 'Usuario'
  45. );
  46. protected static $casos_retrieveAll = array(
  47. 'Jugador',
  48. 'Equipo',
  49. 'Estadio',
  50. 'Roster',
  51. 'tiene',
  52. 'Usuario'
  53. );
  54. protected static function do($action) {
  55. if (array_key_exists('TIPO', $_POST) && in_array($_POST['TIPO'], ${'casos_' . $action})) {
  56. $o = new $_POST['TIPO']($_POST);
  57. return call_user_func(array($o, $action));
  58. }
  59. return null;
  60. }
  61. public static function insert () { self::do(__FUNCTION__); }
  62. public static function select () { self::do(__FUNCTION__); }
  63. public static function update () { self::do(__FUNCTION__); }
  64. public static function remove () { self::do(__FUNCTION__); }
  65. public static function retrieveAll() { self::do(__FUNCTION__); }
  66. //De Toda la Gestion de Estadisticas se encarga el Jugador
  67. public function G_Estadistica(Jugador $Jugador) {
  68. $Jugador->G_Estadistica($_POST);
  69. }
  70. public static function consultarEstadisticas($obj) {
  71. $Res = array();
  72. unset($_POST); // WTF???
  73. switch (get_class($obj)):
  74. case "Jugador":
  75. $Res = $obj->selectSUMEstadisticas();
  76. break;
  77. case "Equipo":
  78. $_POST['TIPO'] = 'Jugador';
  79. $_POST['equipo'] = $obj->id;
  80. $Jugadores = self::retrieveAll();
  81. $i = 0;
  82. $j = 0;
  83. foreach ($Jugadores as $Jugador) {
  84. if ($Jugador->posicion == 'P') {
  85. $TmpP[$i] = self::consultarEstadisticas($Jugador);
  86. $i++;
  87. } else {
  88. $TmpB[$j] = self::consultarEstadisticas($Jugador);
  89. $j++;
  90. }
  91. }
  92. foreach ($TmpP as $i) {
  93. foreach ($i as $key => $value) {
  94. if (is_int($value)) {
  95. if (isset($Res[0][$key])) {
  96. $Res[0][$key] += $value;
  97. } else {
  98. $Res[0][$key] = $value;
  99. }
  100. }
  101. }
  102. }
  103. foreach ($TmpB as $i) {
  104. foreach ($i as $key => $value) {
  105. if (is_int($value)) {
  106. if (isset($Res[1][$key])) {
  107. $Res[1][$key] += $value;
  108. } else {
  109. $Res[1][$key] = $value;
  110. }
  111. }
  112. }
  113. }
  114. break;
  115. endswitch;
  116. return $Res;
  117. }
  118. public function CreateTable($id, $Matriz) {
  119. $n = count($Matriz);
  120. $m = count($Matriz[0]);
  121. echo '<table id="' . $id . '">';
  122. for ($i = 0; $i < $n; ++$i) {
  123. echo '<tr id="' . $id . '.' . $i . '">';
  124. for ($j = 0; $j < $m; ++$j) {
  125. if ($Matriz[$i][$j]!=null)
  126. echo '<td id="' $id . "." . $i . '.' . $j . '">' . $Matriz[$i][$j] . '</td>';
  127. }
  128. echo '</tr>';
  129. }
  130. echo '</table>';
  131. }
  132. }
  133. ?>