/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = QuestionList::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id]); $query->andFilterWhere(['like', 'title', $this->title]); return $dataProvider; }
/** * 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]); } } }