Exemplo n.º 1
0
 public function actionCrear($msg = null)
 {
     $this->layout = 'mainadmin';
     $msg = null;
     $model = new ValidarEvento();
     session_start();
     if (isset($_SESSION['dni'])) {
         unset($_SESSION['dni']);
     }
     if (isset($_SESSION['deporte'])) {
         unset($_SESSION['deporte']);
     }
     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()) {
             $tabla = new Evento();
             $tabla->nombre = $model->nombre;
             $tabla->condicion = $model->condicion;
             $tabla->fecha = $model->fecha;
             $tabla->id_profesor_titular = $model->id_profesor_titular;
             $tabla->id_profesor_suplente = $model->id_profesor_suplente;
             $tabla->id_deporte = $model->id_deporte;
             if ($tabla->insert()) {
                 $model->nombre = null;
                 $model->condicion = null;
                 $model->fecha = null;
                 $model->id_profesor_titular = null;
                 $model->id_profesor_suplente = null;
                 if ($model->convocados == 1) {
                     $_SESSION['deporte'] = $model->id_deporte;
                     $_SESSION['id_evento'] = Yii::$app->db->getLastInsertID('evento');
                     $model->id_deporte = null;
                     $this->redirect(["evento/clista"]);
                 }
                 $model->id_deporte = null;
             } else {
                 $msg = "No se pudo registrar Clase";
             }
         }
     }
     $deporte = ArrayHelper::map(Deporte::find()->all(), 'id_deporte', 'nombre_deporte');
     $profesor = ArrayHelper::map(Profesor::find()->all(), 'dni', 'nombre');
     $categoria = ArrayHelper::map(Categoria::find()->all(), 'id_categoria', 'nombre_categoria');
     $convocados = ArrayHelper::map(Convocados::find()->all(), 'id_lista', 'nombre');
     return $this->render("crear", ['model' => $model, 'msg' => $msg, "profesor" => $profesor, "categoria" => $categoria, "deporte" => $deporte, "convocados" => $convocados]);
 }