コード例 #1
0
 /**
  * Recherche une entrée de la bd.
  *
  * @return Response
  */
 public function recherche()
 {
     //TODO: mettre cette logique dans index()
     $routeActionName = 'ParticipantsController@index';
     $listeRecherches = ParticipantsController::getListeRecherches();
     $listeFiltres = ParticipantsController::getListeFiltres();
     $infosTri = ParticipantsController::getInfosTri();
     $input = Input::all();
     $valeurFiltre = $input['listeFiltres'];
     $valeurRecherche = $input['entreeRecherche'];
     if ($valeurRecherche != '') {
         if ($valeurFiltre == 0) {
             $participants = Participant::where('nom', 'like', $valeurRecherche . '%')->get();
         } elseif ($valeurFiltre == 1) {
             $participants = Participant::where('prenom', 'like', $valeurRecherche . '%')->get();
         } elseif ($valeurFiltre == 2) {
             if (is_numeric($valeurRecherche)) {
                 $participants = Participant::where('numero', $valeurRecherche)->get();
             } else {
                 $participants = new \Illuminate\Database\Eloquent\Collection();
             }
         } elseif ($valeurFiltre == 3) {
             $region = Region::where('nom_court', '=', $valeurRecherche)->first();
             if ($region) {
                 $participants = $region->participants()->get();
             } else {
                 $participants = new \Illuminate\Database\Eloquent\Collection();
             }
         } else {
             $participants = Participant::all();
         }
     } else {
         $participants = Participant::all();
     }
     $participants = ParticipantsController::trierColonnes($participants);
     return View::make('participants.index', compact('participants', 'routeActionName', 'infosTri', 'listeFiltres', 'listeRecherches', 'valeurFiltre', 'valeurRecherche'));
 }