Example #1
0
 /**
  * Genera el torneo y los partidos para imprimir el fixture de la fecha.
  *
  * @param  int  $id torneo id
  * @return \Illuminate\Http\Response
  */
 public function posiciones_pdf(Request $request)
 {
     $torneo_id = $request->get('torneo_id');
     $torneo = Torneo::with('temporada')->with('division.categoria.genero')->with('fases.grupos.clubes.torneo_club.club')->with('fechas.partidos.clubes.torneo_grupo_club.torneo_grupo.fase')->with('fechas.partidos.clubes.torneo_grupo_club.torneo_club.club')->with('clubes.club')->findOrFail($torneo_id);
     $this->data = array_merge(['torneo' => $torneo, 'temporada' => $torneo->temporada, 'division' => $torneo->division, 'categoria' => $torneo->division->categoria, 'clubes' => $torneo->clubes, 'fases' => $torneo->fases->sortBy('orden')], $this->data);
     /*
             $fecha = TorneoFecha::with('torneo')->findOrFail($fecha_id);
             $partidos = Partido::with('fecha')->with('estadio')->where('fecha_id', $fecha_id)->get();
     
             $this->data = array_merge([ 'torneo' => $fecha->torneo, 'partidos' => $partidos , 'fecha' => $fecha->orden ]);
     */
     $pdf = \PDF::loadView('admin.pdf.posiciones', $this->data);
     return $pdf->stream('goleadores.pdf');
 }
 public function SeedPlantillas()
 {
     DB::transaction(function () {
         $socios = Socio::all();
         $socios_cant = $socios->count();
         $socios_temporada_cant = 0;
         $torneo = Torneo::with('temporada')->with('division.categoria.genero')->with('fases.grupos.clubes.torneo_club.club')->with('fechas.partidos.clubes.torneo_grupo_club.torneo_grupo.fase')->with('fechas.partidos.clubes.torneo_grupo_club.torneo_club.club')->with('clubes.jugadores')->with('clubes.club')->findOrFail(1);
         $cant_jugadores = 20;
         $torneo_clubes = $torneo->clubes;
         foreach ($torneo_clubes as $torneo_club) {
             for ($i = 0; $i < $cant_jugadores and $socios_temporada_cant < $socios_cant; $i++) {
                 $encontre = 0;
                 while (!$encontre) {
                     $socio = $socios->random();
                     $encontre = !$socio->participoEnTorneo($torneo->id);
                 }
                 $trayectoria = new Trayectoria();
                 $trayectoria->socio_id = $socio->id;
                 $trayectoria->club_id = $torneo_club->club->id;
                 $trayectoria->save();
                 $temporada_plantel = new TemporadaPlantel();
                 $temporada_plantel->jugador_id = $socio->id;
                 $temporada_plantel->temporada_id = $torneo_club->torneo->temporada->id;
                 $temporada_plantel->save();
                 $torneo_plantel = new TorneoPlantel();
                 $torneo_plantel->jugador_id = $temporada_plantel->id;
                 $torneo_plantel->torneo_club_id = $torneo_club->id;
                 $torneo_plantel->save();
                 /*DB::table('trayectorias')->insert(array(
                                         array (
                                             "socio_id"  => $socio->id,
                                             "club_id"   => $torneo_club->club->id,
                                         ),
                                     ));
                 
                                     DB::table('temporadas_planteles')->insert(array(
                                         array (
                                             "id"            => $temporadas_plantel_id,
                                             "jugador_id"    => $socio_id,
                                             "temporada_id"  => 1,
                                         )
                                     ));
                 
                                     DB::table('torneos_planteles')->insert(array(
                                         array (
                                             "id" => $torneos_plantele_id,
                                             "jugador_id" => $temporadas_plantel_id,
                                             "torneo_club_id" => $club_torneo,
                                         )
                                     ));*/
             }
         }
     });
 }
Example #3
0
 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);
 }
 public function jugadoresEquipoParticipante($id_torneo, $id_equipo)
 {
     $torneo = Torneo::findOrFail($id_torneo);
     return $torneo->plantillas->where('pivot.eqp_id', intval($id_equipo))->unique();
 }