/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = User::find(); $query->joinWith('profile'); $dataProvider = new ActiveDataProvider(['query' => $query]); $dataProvider->sort->attributes['name'] = ['asc' => [UserProfile::tableName() . '.[[first_name]]' => SORT_ASC, UserProfile::tableName() . '.[[last_name]]' => SORT_ASC, UserProfile::tableName() . '.[[patronymic]]' => SORT_ASC], 'desc' => [UserProfile::tableName() . '.[[first_name]]' => SORT_DESC, UserProfile::tableName() . '.[[last_name]]' => SORT_DESC, UserProfile::tableName() . '.[[patronymic]]' => SORT_DESC], 'default' => SORT_ASC]; $dataProvider->sort->defaultOrder = ['username' => SORT_ASC]; if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['id' => $this->id, User::tableName() . '.[[role]]' => $this->role, User::tableName() . '.[[status]]' => $this->status, User::tableName() . '.[[last_visit_at]]' => $this->last_visit_at]); $query->andFilterWhere(['like', User::tableName() . '.[[username]]', $this->username])->andFilterWhere(['like', User::tableName() . '.[[email]]', $this->email]); $query->andFilterWhere(['or', ['like', UserProfile::tableName() . '.[[first_name]]', $this->name], ['like', UserProfile::tableName() . '.[[last_name]]', $this->name], ['like', UserProfile::tableName() . '.[[patronymic]]', $this->name]]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getProfile() { return $this->hasOne(UserProfile::className(), ['user_id' => 'id']); }
echo Yii::t('maddoger/user', 'Bio'); ?> </div> </div> <div class="panel-body"> <?php echo $form->field($profileModel, 'last_name')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($profileModel, 'first_name')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($profileModel, 'patronymic')->textInput(['maxlength' => 255]); ?> <?php echo $form->field($profileModel, 'gender')->dropDownList(UserProfile::getGenders(), ['prompt' => '']); ?> <?php echo $form->field($profileModel, 'avatar', ['template' => '{label} <br />' . ($profileModel->avatar ? Html::img($profileModel->avatar, ['width' => 150]) : '') . '{input} {hint} {error}'])->fileInput(); ?> <?php echo $form->field($profileModel, 'delete_avatar')->checkbox(); ?> </div> </div> <div class="panel panel-default"> <div class="panel-heading"> <div class="panel-title"><?php echo Yii::t('maddoger/user', 'Settings'); ?> </div>