Exemplo n.º 1
0
 public function armarPartidosInterzonalesFechas($id_torneo)
 {
     $torneo = Torneo::where("id", $id_torneo)->first();
     $partidos_interzonales = [];
     if (!is_null($torneo)) {
         $partidos_interzonales = array("torneo" => $torneo);
         $torneo_fase = TorneoFase::where("torneo_id", $id_torneo)->first();
         if ($torneo_fase->exists() and $torneo_fase->cant_grupos == 2) {
             $torneo_grupos = TorneoGrupo::where("fase_id", $torneo_fase->id)->get();
             $grupo1 = $torneo_grupos['0'];
             $grupo2 = $torneo_grupos['1'];
             $club_grupos1 = TorneoGrupoClub::with("torneo_club.club")->where("grupo_id", $grupo1->id)->get();
             $club_grupos2 = TorneoGrupoClub::with("torneo_club.club")->where("grupo_id", $grupo2->id)->get();
             $equipos = [];
             foreach ($club_grupos1 as $key => $club_grupo) {
                 //$equipos1 []=  $club_grupo->torneo_club->club;
                 $equipos1[] = $club_grupo->torneo_club;
             }
             foreach ($club_grupos2 as $key => $club_grupo) {
                 $equipos2[] = $club_grupo->torneo_club;
                 //$equipos2 []=  $club_grupo->torneo_club->club;
             }
             $cant_equipos1 = $grupo1->cant_equipos;
             $cant_equipos2 = $grupo2->cant_equipos;
             $partidos = [];
             for ($j = 0; $j < $cant_equipos1; $j++) {
                 for ($k = 0; $k < $cant_equipos2; $k++) {
                     //$this->crearPartidoIdaYVuelta($partidos, $iPartido, $equipo, $equipos[$k] );
                     //$this->crearPartidoClub($equipos[$j],$equipos[$k])
                     $partidos[] = ["l" => $equipos1[$j], "v" => $equipos2[$k]];
                 }
             }
             $partidos_interzonales["partidos"][] = ["grupo" => 'interzonales', "partidos" => $partidos];
         } else {
             $partidos_interzonales["partidos"][] = '';
         }
     }
     return $partidos_interzonales;
 }
Exemplo n.º 2
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.');
     }
 }