예제 #1
0
 private function createTorneosClubes($cant_grupos, $torneo, $request)
 {
     $mensajes = new Collection();
     $torneos_clubes = new Collection();
     for ($i = 1; $i <= $cant_grupos; $i++) {
         $equipos_grupo = $request->get("grupo_" . $i);
         $cant_equipos = sizeof($equipos_grupo);
         for ($j = 0; $j < $cant_equipos; $j++) {
             $club_id = $equipos_grupo[$j];
             // corroboro que el club no este participando ya del torneo
             $existe_en_torneo = $torneos_clubes->where('club_id', $club_id);
             if ($existe_en_torneo->isEmpty()) {
                 $torneo_club = new TorneoClub();
                 //$torneo_club->pseudonimo = chr($j+96);
                 $torneo_club->club_id = $club_id;
                 $torneo_club->torneo_id = $torneo->id;
                 $torneo_club->save();
                 $torneos_clubes->push($torneo_club);
                 // Me fijo si el club esta jugando en otra division, de la misma categoría, en alguno de los restantes torneos de la misma temporada.
                 $existe_instancia = TorneoClub::with('club')->with('torneo.division')->select('torneos_clubes.*')->join('clubes', 'clubes.id', '=', 'torneos_clubes.club_id')->join('torneos', 'torneos.id', '=', 'torneos_clubes.torneo_id')->join('tipos_torneos', 'tipos_torneos.id', '=', 'torneos.tipo_torneo_id')->join('temporadas', 'temporadas.id', '=', 'torneos.temporada_id')->join('divisiones', 'divisiones.id', '=', 'torneos.division_id')->join('categorias', 'categorias.id', '=', 'divisiones.categoria_id')->where('clubes.id', $club_id)->where('torneos.id', '!=', $torneo->id)->where('temporadas.id', '=', $torneo->temporada_id)->where('divisiones.id', '!=', $torneo->division_id)->where('categorias.id', '=', $torneo->categoria->id)->first();
                 if ($existe_instancia) {
                     $error_msg = '';
                     $error_msg .= ' El Club ' . $existe_instancia->club->full_name;
                     $error_msg .= ' esta jugando el ' . $existe_instancia->torneo->full_name;
                     $error_msg .= ' en ' . $existe_instancia->torneo->division->full_name . '.';
                     $mensajes->push($error_msg);
                 }
             }
         }
     }
     $cant_equipos_ingresados = $torneos_clubes->count();
     $cant_max = $torneo->tipo_torneo->cant_equipos;
     $cant_min = 0;
     if ($cant_equipos_ingresados > $cant_max or $cant_equipos_ingresados < $cant_min) {
         $error_msg = 'Se ingresaron mas equipos de los que el tipo de torneo define. ';
         $mensajes->push($error_msg);
     }
     //return $cant_equipos_ingresados;
     //return $torneos_clubes;
     return $mensajes;
 }
예제 #2
0
파일: Club.php 프로젝트: emitategh/aabcehmt
 public function participoEnTorneo($temporada_id, $categoria_id, $tipo_torneo_id)
 {
     $participacion = TorneoClub::with('club')->select('torneos_clubes.*')->join('clubes', 'clubes.id', '=', 'torneos_clubes.club_id')->join('torneos', 'torneos.id', '=', 'torneos_clubes.torneo_id')->join('temporadas', 'temporadas.id', '=', 'torneos.temporada_id')->join('divisiones', 'divisiones.id', '=', 'torneos.division_id')->join('categorias', 'categorias.id', '=', 'divisiones.categoria_id')->where('clubes.id', $this->id)->where('temporadas.id', $temporada_id)->where('categorias.id', $categoria_id)->where('torneos.tipo_torneo_id', $tipo_torneo_id)->first();
     return $participacion;
 }
예제 #3
0
 public function crearTorneoFase($torneo, $torneo_fase)
 {
     $tipo_torneo = $torneo->tipo_torneo;
     if (is_null($torneo_fase)) {
         $tipo_torneo_fase_actual = $tipo_torneo->fases->where('fase_numero', 1)->first();
         $tipo_torneo_fase_siguiente = $tipo_torneo_fase_actual;
     } else {
         $tipo_torneo_fase_actual = $tipo_torneo->fases->where('fase_numero', $torneo_fase->fase_numero)->first();
         $tipo_torneo_fase_siguiente = $tipo_torneo_fase_actual->fase_siguiente;
     }
     if (!is_null($tipo_torneo_fase_siguiente)) {
         $new_toreno_fase = TorneoFase::firstOrCreate(['fase_numero' => $tipo_torneo_fase_siguiente->fase_numero, 'torneo_id' => $torneo->id, 'tipo_fase_id' => $tipo_torneo_fase_siguiente->tipo_fase_id]);
         $new_toreno_fase->cant_equipos = $torneo_fase->cant_clasificados;
         $new_toreno_fase->fase_anterior_id = $torneo_fase->id;
         $new_toreno_fase->nombre = $tipo_torneo_fase_siguiente->tipo_fase->nombre;
         $new_toreno_fase->ida_y_vuelta = $tipo_torneo_fase_siguiente->ida_y_vuelta;
         $new_toreno_fase->gol_visitante = $tipo_torneo_fase_siguiente->gol_visitante;
         $new_toreno_fase->cant_grupos = $tipo_torneo_fase_siguiente->cant_grupos;
         $new_toreno_fase->cant_interzonales = $tipo_torneo_fase_siguiente->cant_interzonales;
         $new_toreno_fase->cant_clasificados = $tipo_torneo_fase_siguiente->cant_clasificados;
         $new_toreno_fase->tipo_partido_definicion_id = $tipo_torneo_fase_siguiente->tipo_partido_definicion_id;
         $new_toreno_fase->save();
         for ($i = 1; $i <= $new_toreno_fase->cant_grupos; $i++) {
             $new_torneo_grupo = new TorneoGrupo();
             $new_torneo_grupo->orden = $i;
             $new_torneo_grupo->cant_equipos = $new_toreno_fase->cant_equipos_x_grupo;
             $new_torneo_grupo->fase_id = $new_toreno_fase->id;
             $new_torneo_grupo->save();
             $equipos_grupo = $grupos[$i]->equipos_grupo;
             for ($j = 1; $j <= $new_torneo_grupo->cant_equipos; $j++) {
                 $club_id = $equipos_grupo[$j];
                 $torneo_club = TorneoClub::with('club')->where('club_id', $club_id)->where('torneo_id', $torneo->id)->first();
                 $new_torneo_grupo_club = TorneoGrupoClub::firstOrCreate(['grupo_id' => $new_torneo_grupo->id, 'torneo_club_id' => $torneo_club_->id]);
             }
         }
         dd($tipo_torneo_fase_siguiente, $new_toreno_fase, $new_toreno_fase->grupos);
     } else {
         die('Forbidden.');
     }
 }
예제 #4
0
 public function jugadores_compartidos($torneo_club, $torneo)
 {
     $categorias = Categoria::where('id', '!=', $torneo->categoria->id)->get();
     $club_id = $torneo_club->club_id;
     $torneos_clubes = TorneoClub::with('torneo.temporada')->with('torneo.division.categoria')->with('torneo.tipo_torneo')->with('jugadores.jugador.jugador')->select('torneos_clubes.*')->join('clubes', 'clubes.id', '=', 'torneos_clubes.club_id')->join('torneos', 'torneos.id', '=', 'torneos_clubes.torneo_id')->join('divisiones', 'divisiones.id', '=', 'torneos.division_id')->join('categorias', 'categorias.id', '=', 'divisiones.categoria_id')->join('temporadas', 'temporadas.id', '=', 'torneos.temporada_id')->where('clubes.id', '=', $club_id)->where('torneos.id', '!=', $torneo->id)->where('torneos.tipo_torneo_id', '=', $torneo->tipo_torneo_id)->where('temporadas.id', '=', $torneo->temporada_id)->where('categorias.id', '!=', $torneo->categoria->id)->get();
     $mi_lista = $torneo_club->lista_buena_fe->pluck('jugador')->pluck('jugador')->pluck('id');
     foreach ($torneos_clubes as $club_en_otra_categoria) {
         $lista_buena_fe = $club_en_otra_categoria->lista_buena_fe->pluck('jugador')->pluck('jugador')->pluck('id');
         $jugadores_para_mi = $lista_buena_fe->diff($mi_lista);
         $jugadores_para_el_otro = $mi_lista->diff($lista_buena_fe);
         foreach ($jugadores_para_mi as $jugador) {
             if ($this::validar_categoria_jugador($jugador, $torneo->categoria->id)) {
                 $jugador_temporada = TemporadaPlantel::firstOrNew(['temporada_id' => $torneo->temporada_id, 'jugador_id' => $jugador]);
                 $jugador_temporada->save();
                 $jugador_torneo = TorneoPlantel::firstOrNew(['jugador_id' => $jugador_temporada->id, 'torneo_club_id' => $torneo_club->id]);
                 $jugador_torneo->save();
             }
         }
         //dd($club_en_otra_categoria);
         foreach ($jugadores_para_el_otro as $jugador) {
             if ($this::validar_categoria_jugador($jugador, $club_en_otra_categoria->torneo->categoria->id)) {
                 $jugador_temporada = TemporadaPlantel::firstOrNew(['temporada_id' => $torneo->temporada_id, 'jugador_id' => $jugador]);
                 $jugador_temporada->save();
                 $jugador_torneo = TorneoPlantel::firstOrNew(['jugador_id' => $jugador_temporada->id, 'torneo_club_id' => $club_en_otra_categoria->id]);
                 $jugador_torneo->save();
             }
         }
     }
 }