コード例 #1
0
ファイル: ComisionController.php プロジェクト: lucho314/cae
 public function actionModificar()
 {
     $msg = null;
     $model = new ValidarComision();
     if (Yii::$app->request->get()) {
         $id = Html::encode($_GET["id_comision"]);
         if ((int) $id) {
             $table = Deportista::find();
             $model->id_comision = $_REQUEST['id_comision'];
             $table = Comision::findOne($model->id_comision);
             $model->nombre_comision = $table->nombre_comision;
             $model->dia = $table->dia;
             $model->categoria = $table->id_categoria;
             $model->hora_fin = $table->hora_fin;
             $model->hora_inicio = $table->hora_inicio;
         }
     }
     if ($model->load(Yii::$app->request->post()) && Yii::$app->request->isAjax) {
         Yii::$app->response->format = Response::FORMAT_JSON;
         return ActiveForm::validate($model);
     }
     if ($model->load(Yii::$app->request->post())) {
         if ($model->validate()) {
             $table = Comision::findOne($model->id_comision);
             $table->nombre_comision = $model->nombre_comision;
             $table->id_categoria = $model->categoria;
             $table->hora_fin = $model->hora_fin;
             $table->hora_inicio = $model->hora_inicio;
             if ($table->update()) {
                 $msg = "modificado con exito";
                 $model->nombre_comision = null;
                 $model->categoria = null;
                 $model->hora_fin = null;
                 $model->hora_inicio = null;
                 $this->redirect(["comision/buscar", 'msg' => $msg]);
             }
         }
     }
     $opciones = ArrayHelper::map(Categoria::find()->all(), 'id_categoria', 'nombre_categoria');
     return $this->render("modificar_comision", ['msg' => $msg, 'model' => $model, 'opciones' => $opciones]);
 }
コード例 #2
0
ファイル: DeportistaController.php プロジェクト: lucho314/cae
 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]);
 }
コード例 #3
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]);
 }