public function search() { $query = strtoupper(Input::get("q")); //query $team = strtoupper(Input::get("t")); //team $exclude = Input::get("e"); //id's A EXCLUIR DE LOS RESULTADOS $notInID[] = 0; $notInTR[] = 0; if (!is_null($exclude)) { //armo el arreglo con los resultados a excluir de la visual. foreach ($exclude as $e) { $notInID[] = $e; } } if ((int) $query > 0) { // BUSQUEDA POR CARNET O DOCUMENTO if ((int) $query < 999999) { // BUSQUEDA POR CARNET $socio_try = Socio::where('carnet', $query)->first(); if ($socio_try and in_array($socio_try->id, $notInID)) { // ES UN PELOTUDO Y BUSCA DE NUEVO UN JUGADOR return response()->json(['result' => 'Error', 'response' => ['title' => 'Jugador asociado', 'text' => 'El jugador <kbd>' . $socio_try->full_name . '</kbd> ya esta asociado a este club.']]); } else { $trayectoria = Trayectoria::with('socio')->with('club')->select('trayectorias.*')->join('socios', 'socios.id', '=', 'trayectorias.socio_id')->join('clubes', 'clubes.id', '=', 'trayectorias.club_id')->where('socios.carnet', $query)->whereNull('trayectorias.baja')->get(); //if (count($trayectoria)==0) { if ($trayectoria->isEmpty() or $trayectoria->first()->club_id == $team) { $results = Socio::with('persona.tipo_documento')->select('socios.*')->join('personas', 'personas.id', '=', 'socios.persona_id')->where('socios.carnet', $query)->whereNotIn('socios.id', $notInID)->limit('10')->get(); } else { return response()->json(['result' => 'Error', 'response' => ['title' => 'Jugador asociado', 'text' => 'El jugador con carnet <strong>' . $query . '</strong> (<var>' . $socio_try->full_name . '</var>) ya esta asociado a <strong>' . $trayectoria[0]->club->nombre . '</strong>']]); } } } else { //BUSQUEDA POR DOCUMENTO $socio_try = Socio::select('socios.*')->join('personas', 'personas.id', '=', 'socios.persona_id')->where('personas.documento', $query)->first(); //dd($socio_try,$notInID,in_array($socio_try->persona_id, $notInID )); if ($socio_try and in_array($socio_try->id, $notInID)) { // ES UN PELOTUDO Y BUSCA DE NUEVO UN JUGADOR return response()->json(['result' => 'Error', 'response' => ['title' => 'Jugador asociado', 'text' => 'El jugador <kbd>' . $socio_try->full_name . '</kbd> ya esta asociado a este club.']]); } else { $trayectoria = Trayectoria::with('socio.persona')->with('club')->whereNull('trayectorias.baja')->select('*')->join('socios', 'socios.id', '=', 'trayectorias.socio_id')->join('personas', 'personas.id', '=', 'socios.persona_id')->join('clubes', 'clubes.id', '=', 'trayectorias.club_id')->where("personas.documento", 'LIKE', '%' . $query . '%')->get(); //if (count($trayectoria)==0) { if ($trayectoria->isEmpty() or $trayectoria->first()->club_id == $team) { $results = Socio::with("persona.tipo_documento.pais")->select('socios.*')->join('personas', 'personas.id', '=', 'socios.persona_id')->where("documento", 'LIKE', '%' . $query . '%')->whereNotIn('socios.id', $notInID)->limit('10')->get(); } else { return response()->json(['result' => 'Error', 'response' => ['title' => 'Jugador asociado', 'text' => 'El jugador con documento <strong>' . $query . '</strong>(<var>' . $socio_try->full_name . '</var>) ya esta asociado a <strong>' . $trayectoria[0]->nombre . '</strong>']]); } } } } else { //BUSQUEDA POR NOMBRE Y APELLIDO $results = Socio::with("persona.tipo_documento.pais")->select('socios.*')->join('personas', 'personas.id', '=', 'socios.persona_id')->where(DB::raw('CONCAT(personas.nombre, " ", personas.apellido)'), 'LIKE', '%' . $query . '%')->whereNotIn('socios.id', $notInID)->orWhere(DB::raw('CONCAT(personas.apellido, " ", personas.nombre)'), 'LIKE', '%' . $query . '%')->whereNotIn('socios.id', $notInID)->limit('10')->get(); } foreach ($results as $socio) { $socio->edad_limite = $socio->edad_limite; $socio->persona->edad = $socio->persona->edad; // $socio->persona->inverse_full_name = $socio->persona->inverse_full_name; $socio->route_show = route('people.socios.show', $socio->id); } return response()->json(['result' => 'Ok', 'response' => $results]); }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(CreateSocioRequest $request) { $socio = new Socio(); $id = DB::transaction(function () use($request, $socio) { /* Al intentar poner un dni de un socio preexistente falla */ $id = $this->actualizarBD($request, $socio, 'socio'); // una vez insertado el socio, se lo asocia al club si es que se lo indicó $club_id = $request->get('club_id'); if ($club_id != '') { $trayectoria = new Trayectoria(); $trayectoria->socio_id = $socio->id; $trayectoria->club_id = $club_id; $trayectoria->save(); } return $id; }); return \Redirect::route('people.socios.show', $id); }
/** * * @return club objeto que representa el club actual */ public function getClubActualAttribute() { $club = null; $club_actual = Trayectoria::with('club')->where('socio_id', $this->id)->where('baja', NULL)->first(); if (!is_null($club_actual)) { $club = $club_actual->club; } return $club; }
/** * Devuelve todos los jugadores que actualmente estan vinculados al club * * @return collection $plantilla : */ public function getHistorialJugadoresAttribute() { $plantilla = Trayectoria::with('socio.persona')->select('trayectorias.*')->join('socios', 'socios.id', '=', 'trayectorias.socio_id')->join('personas', 'personas.id', '=', 'socios.persona_id')->where('trayectorias.club_id', $this->id)->orderBy('personas.apellido', 'ASC')->orderBy('personas.nombre', 'ASC')->orderBy('trayectorias.alta', 'ASC')->get(); return $plantilla; }
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, ) ));*/ } } }); }