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; }
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.'); } }
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; }
/** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { $torneo_club = TorneoClub::findOrFail($id); $this->webpage['whereAmI'] = $this->BreadcrumbRoot($torneo_club); $this->webpage['tab_title'] = $torneo_club->full_name; $estados_suspensiones = EstadoSuspension::get(); $categorias = Categoria::get(); $tipos_suspensiones = TipoSuspension::where("entidad", 4)->orWhere("entidad", null)->get(); $torneo_club->partidos = $torneo_club->partidos_clubes->pluck('partido'); $this->data = array_merge(['webpage' => $this->webpage, 'torneo_club' => $torneo_club, 'tipos_sanciones' => $tipos_suspensiones, 'estados_sanciones' => $estados_suspensiones, 'estados' => $estados_suspensiones, 'categorias' => $categorias], $this->data); return view('admin.seasons.torneos_clubes.show', $this->data); }
public function save() { $result = DB::transaction(function () { $result = array("result" => '', 'response' => ''); $result["result"] = 'nothing2do'; //respuesta para el resultado por defecto si no debo realizar ningun cambio $equipo = Input::get("e"); //arreglo de id de socios $torneo_id = Input::get("torneo_id"); //id del torneo $torneo_club_id = Input::get("t"); //torneo_club_id $torneo_club = TorneoClub::where('id', $torneo_club_id)->first(); $tr = new Trayectoria(); $jugadores_actuales = []; $plantel = []; $i = 0; // ================== $director_tecnico = TorneoTecnico::where('torneo_club_id', $torneo_club->id)->get(); foreach ($director_tecnico as $tecnico) { $tecnico->forceDelete(); } $dt = Input::get("dt"); $socio_dt = Socio::where('id', $dt)->first(); if ($socio_dt) { $director_tecnico = TorneoTecnico::firstOrNew(['tecnico_id' => $dt, 'torneo_club_id' => $torneo_club->id]); $director_tecnico->save(); } // ================== //$trayectoria_club = $tr::where('club_id',$torneo_club->club_id)->whereNull('baja')->select('socio_id')->get(); $jugadores_club_categoria = TorneoPlantel::with('jugador.jugador')->select('torneos_planteles.*')->join('temporadas_planteles', 'torneos_planteles.jugador_id', '=', 'temporadas_planteles.id')->join('torneos_clubes', 'torneos_planteles.torneo_club_id', '=', 'torneos_clubes.id')->join('socios', 'socios.id', '=', 'temporadas_planteles.jugador_id')->where('torneos_planteles.torneo_club_id', $torneo_club_id)->get(); $habia_jugadores = count($jugadores_club_categoria); if ($habia_jugadores) { foreach ($jugadores_club_categoria as $p) { $jugadores_actuales[] = $p->jugador->jugador_id; } $i = array_intersect($jugadores_actuales, $equipo); //Interseccion de jugadores cargados y seleccionados $insertar = array_diff($equipo, $i); //SOCIOS a insertar en la tabla $remover = array_diff($jugadores_actuales, $i); //SOCIOS a remover de la tabla } else { $insertar = $equipo; } $torneo = Torneo::where("id", $torneo_id)->first(); if (isset($remover)) { foreach ($remover as $p) { //elimino los jugadores que fueron removidos de la interface. /* $result = $tr::where('socio_id', $p)->whereNull('baja')->first(); $result->forceDelete(); */ $jugador_temporada = TemporadaPlantel::where('temporada_id', $torneo->temporada_id)->where('jugador_id', $p)->first(); $jugador_torneo = TorneoPlantel::where('jugador_id', $jugador_temporada->id)->where('torneo_club_id', $torneo_club->id)->first(); if ($jugador_torneo) { $jugador_torneo->forceDelete(); } if ($jugador_temporada) { $jugador_temporada->forceDelete(); } //$result = DB::table('trayectorias')->where('socio_id', $p)->softDeletes(); } } if (count($insertar)) { foreach ($insertar as $p) { //creo el arreglo asociativo de los nuevos jugadores $plantel[] = array('alta' => date("Y-m-d"), 'alta_tipo' => 1, 'socio_id' => $p, 'club_id' => $torneo_club->club_id); $jugador_temporada = TemporadaPlantel::firstOrNew(['temporada_id' => $torneo->temporada_id, 'jugador_id' => $p]); $jugador_temporada->save(); $jugador_torneo = TorneoPlantel::firstOrNew(['jugador_id' => $jugador_temporada->id, 'torneo_club_id' => $torneo_club->id]); $jugador_torneo->save(); } } $result_ldbf = ($jugador_temporada and $jugador_torneo); // $result_trayectoria = (count($plantel)) ? DB::table('trayectorias')->insert($plantel) : true; //inserto los socios o si solo removi devuelvo verdadero if ($result_ldbf) { $result["result"] = "Ok"; $result["response"] = $result_ldbf; } else { $result["result"] = "Error"; if ($jugador_temporada) { $error = '***Error al agregar a la temporada***'; } if ($jugador_torneo) { $error = '***Error al agregar al torneo***'; } $result["response"] = $error; } $this->jugadores_compartidos($torneo_club, $torneo); return $result; }); return response()->json($result); }