Advertisement
pmtpenza22

Untitled

Mar 1st, 2019
471
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.42 KB | None | 0 0
  1. <?php
  2.  
  3. namespace backend\models;
  4.  
  5. use yii\base\Model;
  6. use yii\data\ActiveDataProvider;
  7. use backend\models\AllUser;
  8.  
  9.  
  10. /**
  11. * AllUserSearch represents the model behind the search form of `\backend\models\AllUser`.
  12. */
  13. class AllUserSearch extends AllUser
  14. {
  15. /**
  16. * {@inheritdoc}
  17. */
  18. public function rules()
  19. {
  20. return [
  21. [['id', 'status', 'created_at', 'updated_at', 'parent_id'], 'integer'],
  22. [['username', 'auth_key', 'password_hash', 'password_reset_token', 'email', 'phone', 'name', 'phone_dispech', 'inn', 'ogrn', 'bank', 'bik', 'schet', 'korschet', 'adress_fakt', 'adress_yr', 'boss', 'kv'], '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 = AllUser::find();
  45.  
  46. // add conditions that should always apply here
  47.  
  48. $dataProvider = new ActiveDataProvider([
  49. 'query' => $query,
  50. 'query' => $query,
  51. 'pagination' => [
  52. 'forcePageParam' => false,
  53. 'pageSizeParam' => false,
  54. 'pageSize' => 10
  55. ]
  56. ]);
  57.  
  58. $this->load($params);
  59.  
  60. if (!$this->validate()) {
  61. // uncomment the following line if you do not want to return any records when validation fails
  62. // $query->where('0=1');
  63. return $dataProvider;
  64. }
  65.  
  66. // grid filtering conditions
  67. $query->andFilterWhere([
  68. 'id' => $this->id,
  69. 'status' => $this->status,
  70. 'created_at' => $this->created_at,
  71. 'updated_at' => $this->updated_at,
  72. 'parent_id' => $this->parent_id,
  73. ]);
  74.  
  75. $query->andFilterWhere(['like', 'username', $this->username])
  76. ->andFilterWhere(['like', 'auth_key', $this->auth_key])
  77. ->andFilterWhere(['like', 'password_hash', $this->password_hash])
  78. ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
  79. ->andFilterWhere(['like', 'email', $this->email])
  80. ->andFilterWhere(['like', 'phone', $this->phone])
  81. ->andFilterWhere(['like', 'name', $this->name])
  82. ->andFilterWhere(['like', 'phone_dispech', $this->phone_dispech])
  83. ->andFilterWhere(['like', 'inn', $this->inn])
  84. ->andFilterWhere(['like', 'ogrn', $this->ogrn])
  85. ->andFilterWhere(['like', 'bank', $this->bank])
  86. ->andFilterWhere(['like', 'bik', $this->bik])
  87. ->andFilterWhere(['like', 'schet', $this->schet])
  88. ->andFilterWhere(['like', 'korschet', $this->korschet])
  89. ->andFilterWhere(['like', 'adress_fakt', $this->adress_fakt])
  90. ->andFilterWhere(['like', 'adress_yr', $this->adress_yr])
  91. ->andFilterWhere(['like', 'boss', $this->boss])
  92. ->andFilterWhere(['like', 'kv', $this->kv]);
  93.  
  94. return $dataProvider;
  95. }
  96. $query = AllUser::find()
  97. ->select('user.*')
  98. ->leftJoin('auth_assignment', '`auth_assignment`.`user_id` = `user`.`id`')
  99. ->andWhere(['auth_assignment.item_name'=>'admin']);
  100. return $query;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement