/** * Updates an existing AnswerList 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); $modelsQuestionList = QuestionList::find()->all(); $questionLists = ArrayHelper::map($modelsQuestionList, 'id', 'title'); $statusList = $model->statusList; $viewName = 'update'; // коммерческий директор может только менять статус опросного листа if (!User::hasRole(['unicredQuestionListSystemAdmin'])) { $viewName = 'update_status'; unset($statusList['answered']); } $modelsOffice = Office::find()->all(); $DoList = ArrayHelper::map($modelsOffice, 'id', 'name'); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Update AnswerList #" . $id, 'content' => $this->renderAjax($viewName, ['model' => $model, 'questionLists' => $questionLists, 'DoList' => $DoList, 'statusList' => $statusList]), '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->list_name = $model->questionList->title; if ($model->save()) { return $this->redirect(['index']); } /*if ($model->save()) return [ 'forceReload'=>'#crud-datatable-pjax', 'title'=> "AnswerList #".$id, 'content'=>$this->renderAjax('view', [ 'model' => $model, 'questionLists' => $questionLists, 'DoList' => $DoList, 'answersDataProvider' => new ArrayDataProvider([ 'allModels' => $model->answers, ]), ]), '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 AnswerList #" . $id, 'content' => $this->renderAjax($viewName, ['model' => $model, 'questionLists' => $questionLists, 'DoList' => $DoList, 'statusList' => $statusList]), '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->list_name = $model->questionList->title; if ($model->save()) { return $this->redirect(['view', 'id' => $model->id]); } } else { return $this->render($viewName, ['model' => $model, 'questionLists' => $questionLists, 'DoList' => $DoList, 'statusList' => $statusList]); } } }
/** * Finds the Office model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Office the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Office::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getOffice() { return $this->hasOne(Office::className(), ['id' => 'do_id']); }
/** * Updates an existing UsersOffices 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); $modelsOffice = Office::find()->all(); $usersRoles = UsersOffices::getRoles(); $offices = ArrayHelper::map($modelsOffice, 'id', 'name'); if ($request->isAjax) { /* * Process for ajax request */ Yii::$app->response->format = Response::FORMAT_JSON; if ($request->isGet) { return ['title' => "Update UsersOffices #" . $id, 'content' => $this->renderAjax('update', ['model' => $model, 'offices' => $offices, 'usersRoles' => $usersRoles]), '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()) { $this->changeRoleAction($model); return ['forceReload' => '#crud-datatable-pjax', 'title' => "UsersOffices #" . $id, 'content' => $this->renderAjax('view', ['model' => $model]), '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 UsersOffices #" . $id, 'content' => $this->renderAjax('update', ['model' => $model]), '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()) { $this->changeRoleAction($model); return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'offices' => $offices, 'usersRoles' => $usersRoles]); } } }