Esempio n. 1
0
 public function actionEliminar()
 {
     $msg = null;
     $id;
     if (!isset($_REQUEST['confirmar']) && isset($_REQUEST['id'])) {
         $id = $_REQUEST['id'];
         $tabla = Evento::find()->where(['id_categoria' => $id]);
         if ($tabla->count() != 0) {
             $msg = "existen eventos registrados con esta categoria";
         }
         $tabla = Deportista_cat::find()->where(['id_categoria' => $id]);
         if ($tabla->count() != 0) {
             $msg .= "<br>" . "existen Deportistas registrados con esta categoria";
         }
         $tabla = Comision::find()->where(['id_categoria' => $id]);
         if ($tabla->count() != 0) {
             $msg .= "<br>" . "existen Comisiones registrados con esta categoria";
         }
         if ($msg != null) {
             return $this->render("confirmar", ['msg' => $msg, 'id' => $id]);
         } else {
             if (Categoria::deleteAll($id)) {
                 $msg = "Categoria eliminado con exito";
             } else {
                 $msg = "ocurrio un error";
             }
         }
     } else {
         if (isset($_REQUEST['confirmar'])) {
             if (Categoria::deleteAll($_REQUEST['id'])) {
                 $msg = "Categoria eliminado con exito";
             } else {
                 $msg = "ocurrio un error";
             }
         }
     }
     return $this->render("eliminar", ['msg' => $msg]);
 }
Esempio n. 2
0
 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]);
 }