Commit a45352682236b330256ed1cf6b09387f3384c98d
1 parent
8e9eb2a7
Importers CRUD
Showing
2 changed files
with
76 additions
and
0 deletions
Show diff stats
common/config/main.php
| 1 | +<?php | |
| 2 | + | |
| 3 | +namespace common\models; | |
| 4 | + | |
| 5 | +use Yii; | |
| 6 | +use yii\base\Model; | |
| 7 | +use yii\data\ActiveDataProvider; | |
| 8 | +use backend\models\User; | |
| 9 | + | |
| 10 | +/** | |
| 11 | + * UserSearch represents the model behind the search form about `backend\models\User`. | |
| 12 | + */ | |
| 13 | +class UserSearch extends User | |
| 14 | +{ | |
| 15 | + /** | |
| 16 | + * @inheritdoc | |
| 17 | + */ | |
| 18 | + public function rules() | |
| 19 | + { | |
| 20 | + return [ | |
| 21 | + [['id', 'is_super', 'office_id', 'acl_accounts_access', 'active'], 'integer'], | |
| 22 | + [['login', 'password', 'email', 'name', 'photo', 'contacts'], 'safe'], | |
| 23 | + ]; | |
| 24 | + } | |
| 25 | + | |
| 26 | + /** | |
| 27 | + * @inheritdoc | |
| 28 | + */ | |
| 29 | + public function scenarios() | |
| 30 | + { | |
| 31 | + // bypass scenarios() implementation in the parent class | |
| 32 | + return Model::scenarios(); | |
| 33 | + } | |
| 34 | + | |
| 35 | + /** | |
| 36 | + * Creates data provider instance with search query applied | |
| 37 | + * | |
| 38 | + * @param array $params | |
| 39 | + * | |
| 40 | + * @return ActiveDataProvider | |
| 41 | + */ | |
| 42 | + public function search($params) | |
| 43 | + { | |
| 44 | + $query = User::find(); | |
| 45 | + | |
| 46 | + $dataProvider = new ActiveDataProvider([ | |
| 47 | + 'query' => $query, | |
| 48 | + ]); | |
| 49 | + | |
| 50 | + $this->load($params); | |
| 51 | + | |
| 52 | + if (!$this->validate()) { | |
| 53 | + // uncomment the following line if you do not want to return any records when validation fails | |
| 54 | + // $query->where('0=1'); | |
| 55 | + return $dataProvider; | |
| 56 | + } | |
| 57 | + | |
| 58 | + $query->andFilterWhere([ | |
| 59 | + 'id' => $this->id, | |
| 60 | + 'is_super' => $this->is_super, | |
| 61 | + 'office_id' => $this->office_id, | |
| 62 | + 'acl_accounts_access' => $this->acl_accounts_access, | |
| 63 | + 'active' => $this->active, | |
| 64 | + ]); | |
| 65 | + | |
| 66 | + $query->andFilterWhere(['like', 'login', $this->login]) | |
| 67 | + ->andFilterWhere(['like', 'password', $this->password]) | |
| 68 | + ->andFilterWhere(['like', 'email', $this->email]) | |
| 69 | + ->andFilterWhere(['like', 'name', $this->name]) | |
| 70 | + ->andFilterWhere(['like', 'photo', $this->photo]) | |
| 71 | + ->andFilterWhere(['like', 'contacts', $this->contacts]); | |
| 72 | + | |
| 73 | + return $dataProvider; | |
| 74 | + } | |
| 75 | +} | ... | ... |