public function actionBuscar($msg = null) { $form = new ValidarBusqueda(); $search = null; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { if (isset($form->x)) { $form->x = Html::encode($form->x); $sql = "select id_deporte,nombre_deporte from deporte " . "where nombre_deporte like '%{$form->x}%'"; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= " LIMIT {$pages->limit} OFFSET {$pages->offset} "; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $msg = "id deporte no valido"; } } else { $form->getErrors(); } } else { $table = Deporte::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "select id_deporte,nombre_deporte from deporte " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['msg' => $msg, "pages" => $pages, "model" => $model, "form" => $form, "search" => $search]); }
public function actionBuscar($msg = null) { $form = new ValidarBusqueda(); $search = null; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $sql = "select nombre,apellido,deportista.dni from persona " . "inner join deportista on persona.dni=deportista.dni " . "where deportista.dni like '%{$search}%' or nombre like'%{$search}%' or apellido like'%{$search}%'"; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= "limit {$pages->limit} offset {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { $table = Deportista::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "select nombre,apellido,deportista.dni from persona " . "inner join deportista on persona.dni=deportista.dni " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['msg' => $msg, 'model' => $model, 'search' => $search, 'pages' => $pages, 'form' => $form]); }
public function actionBuscar($msg = null) { $this->layout = "mainadmin"; $form = new ValidarBusqueda(); $search = null; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $sql = "select dni,nombre_usuario,privilegio from usuario " . "where dni like '%{$search}%' or nombre_usuario like '%{$search}%' or" . " privilegio like '%{$search}%' "; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= " LIMIT {$pages->limit} OFFSET {$pages->offset} "; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { $table = Users::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "select dni,nombre_usuario,privilegio from usuario " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['msg' => $msg, "pages" => $pages, "model" => $model, "form" => $form, "search" => $search]); }
public function actionBuscar($msg = null) { $this->menu(); $form = new ValidarBusqueda(); $search = null; $search_desde = null; $search_hasta = null; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $search_desde = Html::encode($form->desde); $search_hasta = Html::encode($form->hasta); if ($search == "" && $search_desde == "" && $search_hasta == "") { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento"; } elseif ($search == "" && $search_desde == "") { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento where evento.fecha BETWEEN '0000-00-00' and '{$search_hasta}'"; } elseif ($search == "" && $search_hasta == "") { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento where evento.fecha BETWEEN '{$search_desde}' and curdate()"; } elseif ($search == "") { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento where evento.fecha BETWEEN '{$search_desde}' and '{$search_hasta}'"; } elseif ($search != "" && $search_desde == "" && $search_hasta == "") { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento where nombre like '%{$search}%'"; } else { $sql = "select id_evento,id_deporte,nombre, fecha, condicion from evento where nombre like '%{$search}%' and evento.fecha BETWEEN '{$search_desde}' and '{$search_hasta}'"; } $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= " LIMIT {$pages->limit} OFFSET {$pages->offset} "; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { $table = Evento::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "select id_deporte, id_evento,nombre,fecha " . "from evento" . " " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['model' => $model, 'msg' => $msg, "pages" => $pages, "model" => $model, "form" => $form, "search" => $search]); }
public function actionBuscar($msg = null) { $form = new ValidarBusqueda(); $search = null; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $sql = "select DISTINCT id_comision, nombre_comision,dia,nombre_categoria,hora_inicio,hora_fin " . "from comision, categoria " . "where comision.id_categoria=categoria.id_categoria and " . "nombre_comision like '%{$search}%' or nombre_categoria like '%{$search}%' " . "or dia like '%{$search}%' or hora_inicio like '%{$search}%' or hora_fin like '%{$search}%'" . "group by comision.id_comision"; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= " LIMIT {$pages->limit} OFFSET {$pages->offset} "; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { $table = Comision::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "select id_comision, nombre_comision,dia,nombre_categoria,hora_inicio,hora_fin " . "from comision, categoria " . "where comision.id_categoria=categoria.id_categoria " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['model' => $model, 'msg' => $msg, "pages" => $pages, "model" => $model, "form" => $form, "search" => $search]); }
public function actionBuscarprueba($msg = null) { $this->layout = "mainprofe"; $profesor = Yii::$app->user->identity->id; $form = new ValidarBusqueda(); $search = null; $table = Deportista::find()->all(); foreach ($table as $valor) { $total[] = $valor['dni']; } $categoria = Categoria::find()->where(['id_profesor_titular' => $profesor])->orWhere(['id_profesor_suplente' => $profesor])->all(); foreach ($categoria as $valor) { $cate[] = $valor['id_categoria']; } $existentes = Deportista_cat::find()->where(["IN", 'id_categoria', $cate])->all(); foreach ($existentes as $val) { $existen[] = $val['dni']; } $dni = array_diff($total, $existen); if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $sql = "select deportista.dni,nombre,YEAR(CURDATE())-YEAR(deportista.fecha_nac) as 'edad' from persona,deportista " . "where persona.dni=deportista.dni " . "and deportista.dni like '%{$search}%' or nombre like'%{$search}%' "; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= "limit {$pages->limit} offset {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { if ($dni == null) { return $this->render("error", ['msg' => 'No se Encontraron Deportistas para Mostrar']); } $table = Deportista::find()->where(['IN', 'dni', $dni]); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $dni = implode(" ", $dni); $dni = str_replace(" ", ',', $dni); $sql = "select deportista.dni,persona.nombre,YEAR(CURDATE())-YEAR(deportista.fecha_nac) AS `edad` from persona,deportista " . " where deportista.dni in ({$dni}) and persona.dni=deportista.dni " . "LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } $categorias = ArrayHelper::map($categoria, 'id_categoria', 'nombre_categoria'); return $this->render("buscar_prueba", ['msg' => $msg, 'model' => $model, 'search' => $search, 'pages' => $pages, 'form' => $form, 'categorias' => $categorias]); }
public function actionBuscar($msg = null) { $form = new ValidarBusqueda(); $search = NULL; if ($form->load(Yii::$app->request->post())) { if ($form->validate()) { $search = Html::encode($form->q); $sql = "SELECT deporte.nombre_deporte,categoria.id_categoria,categoria.nombre_categoria,categoria.edad_minima,categoria.edad_maxima,sub1.prof_titular, sub2.prof_suplente FROM categoria\n INNER JOIN deporte ON deporte.id_deporte=categoria.id_deporte\n INNER JOIN \n (SELECT persona.nombre AS 'prof_titular',categoria.id_categoria FROM persona INNER JOIN categoria ON persona.dni=categoria.id_profesor_titular)AS sub1\n ON categoria.id_categoria=sub1.id_categoria\n INNER JOIN\n (SELECT persona.nombre AS 'prof_suplente',categoria.id_categoria FROM persona RIGHT JOIN categoria ON\n persona.dni=categoria.id_profesor_suplente)AS sub2\n ON categoria.id_categoria=sub2.id_categoria" . " where deporte.nombre_deporte like '%{$search}%'" . " or categoria.nombre_categoria like'%{$search}%'" . " or categoria.edad_minima like'%{$search}%'" . " or categoria.edad_maxima like'%{$search}%'" . " or sub1.prof_titular like'%{$search}%'" . " or sub2.prof_suplente like'%{$search}%'"; $command = Yii::$app->db->createCommand($sql)->query(); $count = clone $command; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql .= " LIMIT {$pages->limit} OFFSET {$pages->offset} "; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } else { $form->getErrors(); } } else { $table = Categoria::find(); $count = clone $table; $pages = new Pagination(["pageSize" => 10, "totalCount" => $count->count()]); $sql = "SELECT deporte.nombre_deporte,categoria.id_categoria,categoria.nombre_categoria,categoria.edad_minima,categoria.edad_maxima,sub1.prof_titular, sub2.prof_suplente FROM categoria\n INNER JOIN deporte ON deporte.id_deporte=categoria.id_deporte\n INNER JOIN \n (SELECT persona.nombre AS 'prof_titular',categoria.id_categoria FROM persona INNER JOIN categoria ON persona.dni=categoria.id_profesor_titular)AS sub1\n ON categoria.id_categoria=sub1.id_categoria\n INNER JOIN\n (SELECT persona.nombre AS 'prof_suplente',categoria.id_categoria FROM persona RIGHT JOIN categoria ON\n persona.dni=categoria.id_profesor_suplente)AS sub2\n ON categoria.id_categoria=sub2.id_categoria \n LIMIT {$pages->limit} OFFSET {$pages->offset}"; $command = Yii::$app->db->createCommand($sql)->queryAll(); $model = $command; } return $this->render("buscar", ['msg' => $msg, "pages" => $pages, "model" => $model, "form" => $form, "search" => $search]); }