/** * 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->findModelAnswerList($id); if ($model->status != 'clear') { if ($request->isAjax) { Yii::$app->response->format = Response::FORMAT_JSON; return ['title' => "Обновить невозможно", 'content' => $this->renderAjax('view', ['modelAnswerList' => $model]), 'footer' => Html::button('Close', ['class' => 'btn btn-default pull-left', 'data-dismiss' => "modal"])]; } else { return $this->render('view', ['modelAnswerList' => $model]); } } $modelsQuestionList = QuestionList::find()->all(); $questionLists = ArrayHelper::map($modelsQuestionList, 'id', 'title'); $statusList = $model->statusList; $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' => "Изменение опроса №" . $id, 'content' => $this->renderAjax('update', ['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->save()) { return ['forceReload' => '#crud-datatable-pjax', 'title' => "Опросный лист №" . $id, 'content' => $this->renderAjax('view', ['modelAnswerList' => $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' => "Изменение опроса №" . $id, 'content' => $this->renderAjax('update', ['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->save()) { return $this->redirect(['view', 'id' => $model->id]); } else { return $this->render('update', ['model' => $model, 'questionLists' => $questionLists, 'DoList' => $DoList, 'statusList' => $statusList]); } } }