Code Coverage |
||||||||||
Classes and Traits |
Functions and Methods |
Lines |
||||||||
| Total | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 57 |
| UserSearch | |
0.00% |
0 / 1 |
|
0.00% |
0 / 4 |
30.00 | |
0.00% |
0 / 57 |
| attributes | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 6 |
|||
| rules | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 7 |
|||
| scenarios | |
0.00% |
0 / 1 |
2.00 | |
0.00% |
0 / 3 |
|||
| search | |
0.00% |
0 / 1 |
6.00 | |
0.00% |
0 / 41 |
|||
| <?php | |
| namespace backend\models; | |
| use Yii; | |
| use yii\base\Model; | |
| use yii\data\ActiveDataProvider; | |
| use common\models\User; | |
| /** | |
| * UserSearch represents the model behind the search form about `common\models\User`. | |
| */ | |
| class UserSearch extends User | |
| { | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function attributes() | |
| { | |
| // add related fields to searchable attributes | |
| return array_merge(parent::attributes(), [ | |
| 'participant.phone', | |
| 'participant.organization.name', | |
| ]); | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function rules() | |
| { | |
| return [ | |
| [['id', 'status'], 'integer'], | |
| [['username', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'email_confirm_token', 'firstname', 'lastname'], 'safe'], | |
| [['participant.phone', 'participant.organization.name'], 'safe'], | |
| ]; | |
| } | |
| /** | |
| * @inheritdoc | |
| */ | |
| public function scenarios() | |
| { | |
| // bypass scenarios() implementation in the parent class | |
| return Model::scenarios(); | |
| } | |
| /** | |
| * Creates data provider instance with search query applied | |
| * | |
| * @param array $params | |
| * | |
| * @return ActiveDataProvider | |
| */ | |
| public function search($params) | |
| { | |
| $query = User::find() | |
| ->joinWith('participant', false) | |
| ->joinWith('participant.organization', false); | |
| $dataProvider = new ActiveDataProvider([ | |
| 'query' => $query, | |
| ]); | |
| $dataProvider->sort->attributes['participant.phone'] = [ | |
| 'asc' => ['{{%participant}}.phone' => SORT_ASC], | |
| 'desc' => ['{{%participant}}.phone' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->attributes['participant.organization.name'] = [ | |
| 'asc' => ['{{%organization}}.name' => SORT_ASC], | |
| 'desc' => ['{{%organization}}.name' => SORT_DESC], | |
| ]; | |
| $dataProvider->sort->defaultOrder = [ | |
| 'lastname' => SORT_ASC, | |
| 'firstname' => SORT_ASC, | |
| ]; | |
| $this->load($params); | |
| if (!$this->validate()) { | |
| // uncomment the following line if you do not want to any records when validation fails | |
| // $query->where('0=1'); | |
| return $dataProvider; | |
| } | |
| $query->andFilterWhere([ | |
| 'id' => $this->id, | |
| 'status' => $this->status, | |
| 'created_at' => $this->created_at, | |
| 'updated_at' => $this->updated_at, | |
| ]); | |
| $query->andFilterWhere(['like', 'username', $this->username]) | |
| ->andFilterWhere(['like', 'auth_key', $this->auth_key]) | |
| ->andFilterWhere(['like', 'password_hash', $this->password_hash]) | |
| ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token]) | |
| ->andFilterWhere(['like', 'email', $this->email]) | |
| ->andFilterWhere(['like', 'email_confirm_token', $this->email_confirm_token]) | |
| ->andFilterWhere(['like', 'firstname', $this->firstname]) | |
| ->andFilterWhere(['like', 'lastname', $this->lastname]); | |
| $query->andFilterWhere(['like', '{{%participant}}.phone', $this->getAttribute('participant.phone')]) | |
| ->andFilterWhere(['like', '{{%organization}}.name', $this->getAttribute('participant.organization.name')]); | |
| return $dataProvider; | |
| } | |
| } |