PageRenderTime 58ms CodeModel.GetById 25ms RepoModel.GetById 0ms app.codeStats 0ms

/common/models/search/User.php

https://gitlab.com/makkooz/nikestreetbeat
PHP | 102 lines | 66 code | 12 blank | 24 comment | 1 complexity | 7fe7d037196f56456b9d48df31ed0d19 MD5 | raw file
  1. <?php
  2. /**
  3. * @link http://www.writesdown.com/
  4. * @copyright Copyright (c) 2015 WritesDown
  5. * @license http://www.writesdown.com/license/
  6. */
  7. namespace common\models\search;
  8. use common\models\User as UserModel;
  9. use Yii;
  10. use yii\base\Model;
  11. use yii\data\ActiveDataProvider;
  12. /**
  13. * User represents the model behind the search form about `common\models\User`.
  14. *
  15. * @author Agiel K. Saputra <13nightevil@gmail.com>
  16. * @since 0.1.0
  17. */
  18. class User extends UserModel
  19. {
  20. /**
  21. * @inheritdoc
  22. */
  23. public function rules()
  24. {
  25. return [
  26. [['id', 'status'], 'integer'],
  27. [
  28. [
  29. 'username',
  30. 'email',
  31. 'full_name',
  32. 'display_name',
  33. 'password_hash',
  34. 'password_reset_token',
  35. 'auth_key',
  36. 'created_at',
  37. 'updated_at',
  38. 'login_at',
  39. ],
  40. 'safe',
  41. ],
  42. ];
  43. }
  44. /**
  45. * @inheritdoc
  46. */
  47. public function scenarios()
  48. {
  49. // bypass scenarios() implementation in the parent class
  50. return Model::scenarios();
  51. }
  52. /**
  53. * Creates data provider instance with search query applied
  54. *
  55. * @param array $params
  56. * @return ActiveDataProvider
  57. */
  58. public function search($params)
  59. {
  60. $query = UserModel::find();
  61. $query->andWhere(['<>', 'id', Yii::$app->user->id]);
  62. $dataProvider = new ActiveDataProvider([
  63. 'query' => $query,
  64. 'sort' => [
  65. 'defaultOrder' => [
  66. 'id' => SORT_DESC,
  67. ],
  68. ],
  69. ]);
  70. $this->load($params);
  71. if (!$this->validate()) {
  72. return $dataProvider;
  73. }
  74. $query->andFilterWhere([
  75. 'id' => $this->id,
  76. 'status' => $this->status,
  77. ]);
  78. $query->andFilterWhere(['like', 'username', $this->username])
  79. ->andFilterWhere(['like', 'email', $this->email])
  80. ->andFilterWhere(['like', 'full_name', $this->full_name])
  81. ->andFilterWhere(['like', 'display_name', $this->display_name])
  82. ->andFilterWhere(['like', 'password_hash', $this->password_hash])
  83. ->andFilterWhere(['like', 'password_reset_token', $this->password_reset_token])
  84. ->andFilterWhere(['like', 'auth_key', $this->auth_key])
  85. ->andFilterWhere(['like', 'created_at', $this->created_at])
  86. ->andFilterWhere(['like', 'updated_at', $this->updated_at])
  87. ->andFilterWhere(['like', 'login_at', $this->login_at]);
  88. return $dataProvider;
  89. }
  90. }