/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { $distancia_total = Registro::getDistanciaTotal(); if (is_object($distancia_total)) { $distancia_total = '0'; } $tops = Registro::select()->whereNull('tutti')->orderBy('distancia', 'DESC')->orderBy('updated_at', 'DESC')->take(5)->get(); $lugar = ['Primer', 'Segundo', 'Tercer', 'Cuarto', 'Quinto']; $i = 0; foreach ($tops as $key => $top) { if ($top->imagen) { $top->orientacion = self::imageOrientation($top->imagen); } else { $top->orientacion = null; } $top->lugar = $lugar[$i]; $i++; } $count = Registro::select()->whereNull('tutti')->count(); $skip = 5; $limit = $count - $skip; $corredores = Registro::select()->whereNull('tutti')->skip($skip)->take(20)->orderBy('distancia', 'DESC')->orderBy('updated_at', 'DESC')->get(); foreach ($corredores as $key => $corredor) { if ($corredor->imagen) { $corredor->orientacion = $this->imageOrientation($corredor->imagen); } else { $corredor->imagen = 'http://12kchocho.org.mx/img/avatarchocho.png'; $corredor->orientacion = null; } } if (Request::ajax()) { return Response::json($corredores); } else { return view('index')->with(compact('corredores', 'tops', 'distancia_total', 'filename')); } }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // Busca o registro pelo id e deleta do banco de dados $registro = Registro::find($id)->delete(); // Cria a msg para exibir para o usuário flash('Registro excluído com sucesso'); // Redireciona para a index return redirect()->route('registros.index'); }
public function corredores(Request $request) { $pagina = $request->input('page'); $count = Registro::select()->whereNull('tutti')->count(); $skip = 5 + 20 * ($pagina - 1); $limit = 20; $corredores = Registro::select()->whereNull('tutti')->skip($skip)->take($limit)->orderBy('distancia', 'DESC')->orderBy('created_at', 'DESC')->get(); foreach ($corredores as $key => $corredor) { if ($corredor->imagen) { $corredor->orientacion = $this->imageOrientation($corredor->imagen); } else { $corredor->imagen = 'http://12kchocho.org.mx/img/avatarchocho.png'; $corredor->orientacion = null; } } return $corredores->toJson(); }
public function actionMostrar() { /*$table = new Registro; $model = $table->find()->all(); $form =new FormMostrar; $buscar= null; if ($form->load(Yii::$app->request->get())) { if ($form->validate()) { $buscar = Html::encode($form->b); $query = "SELECT * FROM registra WHERE id_reg LIKE '%$buscar%' OR "; $query .= "nombre LIKE '%$buscar%'OR apellido LIKE '%$buscar%' OR CI LIKE '%$buscar%' OR email LIKE '%$buscar%' OR usuario LIKE '%$buscar%' OR clave LIKE '%$buscar%'"; $model = $table->findBySql($query)->all(); }else{ $form->getErrors(); } }*/ $form = new FormMostrar(); $buscar = null; if ($form->load(Yii::$app->request->get())) { if ($form->validate()) { $buscar = Html::encode($form->b); $table = Registro::find()->where(["like", "id_reg", $buscar])->orwhere(["like", "nombre", $buscar])->orwhere(["like", "apellido", $buscar])->orwhere(["like", "CI", $buscar]); $count = clone $table; $pages = new Pagination(["pageSize" => 1, "totalCount" => $count->count()]); $model = $table->offset($pages->offset)->limit($pages->limit)->all(); } else { $form->getErrors(); } } else { $table = Registro::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 1, "totalCount" => $count->count()]); $model = $table->offset($pages->offset)->limit($pages->limit)->all(); } return $this->render("mostrar", ["model" => $model, "form" => $form, "buscar" => $buscar, "pages" => $pages]); }