/** * Creates a new LocalizacionAccVariable model. * If creation is successful, the browser will be redirected to the 'view' page. * @param integer $variable, $localizacion * @return mixed */ public function actionCreate($variable, $localizacion) { $request = Yii::$app->request; $model = new LocalizacionAccVariable(); $model1 = new AccionCentralizadaVariableProgramacion(); $model->id_variable = $variable; //Escenario $model->scenario = $localizacion == '0' ? 'Nacional' : 'Estadal'; $model->id_pais = Pais::findOne(['nombre' => 'Venezuela'])->id; //lista desplegable $paises = Pais::find()->all(); $estados = Estados::find()->all(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Localización Y Programación Mensual", 'content' => $this->renderPartial('create', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { $model1->id_localizacion = $model->id; if ($model1->load($request->post()) && $model1->save()) { return ['forceReload' => 'true', 'title' => "Localización y Programación", 'content' => '<span class="text-success">Create VariableLocalizacion success</span>', 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Create More', ['create', 'variable' => $variable, 'localizacion' => $localizacion], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Localización y Programación", 'content' => $this->renderAjax('create', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } else { return ['title' => "Localización", 'content' => $this->renderAjax('create', ['model' => $model, 'pais' => $paises, 'estados' => $estados, 'model1' => $model1]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { if ($model->load(Yii::$app->request->post()) && $model->save()) { //return $this->redirect(['create', 'id' => $model->id]); return $this->redirect(['accion-centralizada-variable-programacion/create', 'id_localizacion' => $model->id]); } else { return $this->render('create', ['model' => $model, 'pais' => $paises, 'estados' => $estados]); } } }
/** * Updates an existing ProyectoLocalizacion model. * For ajax request will return json object * and for non-ajax request if update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $request = Yii::$app->request; $model = $this->findModel($id); //Escenario $model->scenario = $this->findAmbito($model->id_proyecto); switch ($model->scenario) { case 'Nacional': $model->id_pais = Pais::findOne(['nombre' => 'Venezuela'])->id; break; default: $model->id_pais = Pais::findOne(['nombre' => 'Venezuela'])->id; break; } //Listas desplegables $paises = Pais::find()->all(); $estados = Estados::find()->all(); $parroquias = Parroquia::find()->all(); $municipios = Municipio::find()->all(); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Update ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } else { if ($model->load($request->post()) && $model->save()) { return ['forceReload' => 'true', 'title' => "ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('view', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::a('Edit', ['update', 'id' => $id], ['class' => 'btn btn-primary', 'role' => 'modal-remote'])]; } else { return ['title' => "Update ProyectoLocalizacion #" . $id, 'content' => $this->renderPartial('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"]) . Html::button('Save', ['class' => 'btn btn-primary', 'type' => "submit"])]; } } } else { /* * Process for non-ajax request */ if ($model->load($request->post()) && $model->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'paises' => $paises, 'estados' => $estados, 'municipios' => $municipios, 'parroquias' => $parroquias]); } } }