anggagewor

Untitled

Feb 1st, 2022
1,101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.58 KB | None | 0 0
  1.  
  2.     /**
  3.      * Creates data provider instance with search query applied
  4.      *
  5.      * @param array $params
  6.      *
  7.      */
  8.     public function search($params)
  9.     {
  10.         $query = Clients::find();
  11.         // add conditions that should always apply here
  12.  
  13.         $dataProvider = new ActiveDataProvider([
  14.             'query' => $query
  15.         ]);
  16.  
  17.         $dataProvider->setPagination(false);
  18.         $this->load($params);
  19.  
  20.         if (!$this->validate()) {
  21.             // uncomment the following line if you do not want to return any records when validation fails
  22.             // $query->where('0=1');
  23.             return $dataProvider;
  24.         }
  25.  
  26.         // grid filtering conditions
  27.         $query->andFilterWhere([
  28.             'id' => $this->id,
  29.             'created_date' => $this->created_date,
  30.             'updated_date' => $this->updated_date,
  31.         ]);
  32.  
  33.         $query->andFilterWhere(['like', 'name', $this->name]);
  34.         $models = [];
  35.         foreach ($dataProvider->models as $model)
  36.         {
  37.             if( $model->getTransactions()->count() > 0){
  38.                 $models[]=$model;
  39.             }
  40.  
  41.         }
  42.         $dataProvider->setModels($models);
  43.         $dataProvider->setTotalCount(count($models));
  44.         $dataProvider->setPagination([
  45.             'totalCount' => count($models),
  46.             'pageSizeLimit' => 20
  47.         ]);
  48.         return new ArrayDataProvider([
  49.             'allModels' => $dataProvider->models,
  50.             'sort' => [],
  51.             'pagination' => [
  52.                 'pageSize' => 20,
  53.             ],
  54.         ]);
  55.     }
Advertisement
Add Comment
Please, Sign In to add comment