Blame view

backend/modules/user/models/search/User.php 2.25 KB
d1f8bd40   Alexey Boroda   first commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
  <?php
  
  namespace backend\modules\user\models\search;
  
  use Yii;
  use yii\base\Model;
  use yii\data\ActiveDataProvider;
  use yii\db\ActiveQuery;
  //
  use thread\app\model\interfaces\search\BaseBackendSearchModel;
  //
  use backend\modules\user\models\User as ParentModel;
  
  /**
   * Class User
   *
   * @package admin\modules\user\models\search
   * @author FilamentV <vortex.filament@gmail.com>
   * @copyright (c), Thread
   */
  class User extends ParentModel implements BaseBackendSearchModel
  {
      /**
       * @return array
       */
      public function rules()
      {
          return [
              [['username', 'email'], 'string', 'max' => 255],
              [['group_id'], 'integer'],
              [['published'], 'in', 'range' => array_keys(self::statusKeyRange())],
          ];
      }
  
      /**
       * @return array
       */
      public function scenarios()
      {
          return Model::scenarios();
      }
  
      /**
       * @param ActiveQuery $query
       * @param array $params
       * @return ActiveDataProvider
       */
      public function baseSearch($query, $params)
      {
          $dataProvider = new ActiveDataProvider([
              'query' => $query,
              'pagination' => [
                  'pageSize' => Yii::$app->modules['user']->itemOnPage
              ]
          ]);
  
          if (!($this->load($params) && $this->validate())) {
              return $dataProvider;
          }
  
          $query->andFilterWhere([
              'id' => $this->id,
              'group_id' => $this->group_id
          ]);
  
          $query->andFilterWhere(['like', 'username', $this->username])
              ->andFilterWhere(['like', 'email', $this->email])
              ->andFilterWhere(['=', 'published', $this->published]);
  
          return $dataProvider;
      }
  
      /**
       * @param array $params
       * @return ActiveDataProvider
       */
      public function search($params)
      {
          $query = ParentModel::find()->with([
              'group',
              'group.lang',
          ])->undeleted();
          return $this->baseSearch($query, $params);
      }
  
      /**
       * @param array $params
       * @return ActiveDataProvider
       */
      public function trash($params)
      {
          $query = ParentModel::find()->with([
              'group',
              'group.lang',
          ])->deleted();
          return $this->baseSearch($query, $params);
      }
  }