/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Office::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, 'region_id' => $this->regionName ? $this->regionName : $this->region_id]); $query->andFilterWhere(['like', 'name', $this->name]); return $dataProvider; }
/** * 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.'); } }
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\modules\unicred\questionlist\models\Region; use app\modules\unicred\questionlist\models\Users; use app\modules\unicred\questionlist\models\Office; /* @var $this yii\web\View */ /* @var $model app\modules\unicred\questionlist\models\Users */ /* @var $form yii\widgets\ActiveForm */ $userRoles = Users::findAll(['profile_id' => Yii::$app->user->identity->username, 'profile_office_role' => 'commercial_director']); $userRegions = ArrayHelper::map($userRoles, 'region_id', 'region_id'); $offices = Office::find()->where(['region_id' => array_values($userRegions)])->orderBy('region_id')->all(); $offices = ArrayHelper::map($offices, 'id', 'name'); //$regions = ArrayHelper::map(Region::findAll(array_values($userRegions)), 'id', 'name'); ?> <div class="users-offices-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'profile_id')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, "office_id")->dropDownList($offices, [$model->office_id => ['selected' => 'selected'], 'prompt' => 'Выберите ..']); ?>
<?php use yii\helpers\Url; use yii\helpers\ArrayHelper; use app\modules\unicred\questionlist\models\Office; use app\modules\unicred\questionlist\models\AnswerList; use yii\helpers\Html; return [['class' => 'kartik\\grid\\SerialColumn', 'width' => '30px'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'questionList.title'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date_from'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date_to'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'statusName', 'filter' => AnswerList::getStatusList()], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'officeName', 'filter' => ArrayHelper::map(Office::find()->all(), 'id', 'name')], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'date'], ['class' => '\\kartik\\grid\\DataColumn', 'attribute' => 'author'], ['class' => '\\kartik\\grid\\ActionColumn', 'template' => '{confirm}', 'buttons' => ['confirm' => function ($url, $model) { return Html::a('<span class="glyphicon glyphicon-list"></span>', Url::toRoute(['confirm', 'id' => $model->id])); }]]];
<?php use yii\helpers\Html; use yii\widgets\ActiveForm; use yii\helpers\ArrayHelper; use app\modules\unicred\questionlist\models\Region; use app\modules\unicred\questionlist\models\Users; use app\modules\unicred\questionlist\models\Office; /* @var $this yii\web\View */ /* @var $model app\modules\unicred\questionlist\models\Users */ /* @var $form yii\widgets\ActiveForm */ /* @var $usersRoles array */ $offices = ArrayHelper::map(Office::find()->all(), 'id', 'name'); $regions = ArrayHelper::map(Region::find()->all(), 'id', 'name'); ?> <div class="users-offices-form"> <?php $form = ActiveForm::begin(); ?> <?php echo $form->field($model, 'profile_id')->textInput(['maxlength' => true]); ?> <?php echo $form->field($model, "office_id")->dropDownList($offices, [$model->office_id => ['selected' => 'selected'], 'prompt' => 'Выберите ..']); ?> <?php
/** * 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]); } } }