×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: PHP
Posted by: Federico Benedetti
Added: May 8, 2020 9:59 AM
Views: 4327
Tags: no tags
  1.     public function search($params)
  2.     {
  3.         $query  = Categorie::find()
  4.             ->leftJoin("categorie as master","master.id = categorie.id_master")
  5.             ->where("categorie.id_master > 0")
  6.         ;
  7.         $dataProvider = new ActiveDataProvider([
  8.             'query' => $query,
  9.             'pagination' => [
  10.                 'pageSize' => 30
  11.             ],
  12.             'sort' => [
  13.                 'attributes' => [
  14.                     'id_master' => [
  15.                         'asc' => [
  16.                             'master.ordine'     => SORT_ASC,
  17.                             'master.nome'       => SORT_ASC,
  18.                             'categorie.ordine'  => SORT_ASC,
  19.                             'categorie.nome'    => SORT_ASC,
  20.                         ],
  21.                         'desc'=> [
  22.                             'master.ordine'     => SORT_DESC,
  23.                             'master.nome'       => SORT_DESC,
  24.                             'categorie.ordine'  => SORT_ASC,
  25.                             'categorie.nome'    => SORT_ASC,
  26.                         ],
  27.                     ]
  28.                 ],
  29.                 'defaultOrder' => ['id_master'=>SORT_ASC]
  30.             ]
  31.         ]);
  32.  
  33.         $this->load($params);
  34.  
  35.         if (!$this->validate()) {
  36.             // uncomment the following line if you do not want to return any records when validation fails
  37.             // $query->where('0=1');
  38.             return $dataProvider;
  39.         }
  40.  
  41.         $query->andFilterWhere([
  42.             'categorie.id' => $this->id,
  43.             'categorie.id_master' => $this->id_master,
  44.             'categorie.ordine' => $this->ordine,
  45.             'categorie.evidenza' => $this->evidenza,
  46.         ]);
  47.  
  48.         $query->andFilterWhere(['like', 'categorie.nome', $this->nome])
  49.             ->andFilterWhere(['like', 'categorie.slug', $this->slug])
  50.             ->andFilterWhere(['like', 'categorie.stato', $this->stato]);
  51.  
  52.         return $dataProvider;
  53.     }
  54.