UsersSearch.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. <?php
  2. namespace app\models;
  3. use dektrium\user\models\UserSearch as BaseUserSearch;
  4. use Yii;
  5. use yii\base\Model;
  6. use yii\data\ActiveDataProvider;
  7. /**
  8. * UsersSearch represents the model behind the search form about `app\models\Users`.
  9. */
  10. class UsersSearch extends BaseUserSearch
  11. {
  12. public $role;
  13. public $role_user;
  14. public $member_phone;
  15. public $org_type;
  16. public $at_org;
  17. public $fio;
  18. public $status;
  19. public $flags;
  20. public $fax;
  21. /**
  22. * @inheritdoc
  23. */
  24. public function rules()
  25. {
  26. $rules = parent::rules();
  27. $rules[] = [['role', 'org_type', 'status', 'flags'], 'integer'];
  28. $rules[] = [['fio', 'at_org', 'member_phone', 'fax'], 'string', 'max' => 255];
  29. $rules[] = [['role_user'], 'safe'];
  30. return $rules;
  31. }
  32. /**
  33. * @inheritdoc
  34. */
  35. public function scenarios()
  36. {
  37. // bypass scenarios() implementation in the parent class
  38. return Model::scenarios();
  39. }
  40. /**
  41. * Creates data provider instance with search query applied
  42. *
  43. * @param array $params
  44. *
  45. * @return ActiveDataProvider
  46. */
  47. public function search($params)
  48. {
  49. $query = User::find();
  50. $dataProvider = new ActiveDataProvider([
  51. 'query' => $query,
  52. ]);
  53. $dataProvider->sort->attributes['at_org'] = [
  54. 'asc' => ['profile.at_org' => SORT_ASC],
  55. 'desc' => ['profile.at_org' => SORT_DESC],
  56. ];
  57. $this->load($params);
  58. if (!$this->validate()) {
  59. // uncomment the following line if you do not want to return any records when validation fails
  60. // $query->where('0=1');
  61. return $dataProvider;
  62. }
  63. $query->joinWith(['profile']);
  64. $query->andFilterWhere([
  65. 'id' => $this->id,
  66. 'role' => $this->role,
  67. 'org_type' => $this->org_type,
  68. ]);
  69. $query->andFilterWhere(['like', 'user.username', $this->username])
  70. ->andFilterWhere(['like', 'user.email', $this->email])
  71. ->andFilterWhere(['like', 'user.fio', $this->fio])
  72. ->andFilterWhere(['like', 'user.at_org', $this->at_org])
  73. ->andFilterWhere(['like', 'user.member_phone', $this->member_phone])
  74. ->andFilterWhere(['like', 'user.fax', $this->fax])
  75. ->andFilterWhere(['like', 'user.registration_ip', $this->registration_ip])
  76. ->andFilterWhere(['like', 'user.created_at', $this->created_at])
  77. ->andFilterWhere(['user.role' => $this->role_user]);
  78. return $dataProvider;
  79. }
  80. public function attributeLabels(){
  81. $labels = parent::attributeLabels();
  82. $labels['at_org'] = Yii::t('app', 'At Org');
  83. $labels['role_user'] = Yii::t('app', 'Role');
  84. return $labels;
  85. }
  86. }