Esempio n. 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Autos::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'precio' => $this->precio, 'fecha_registro' => $this->fecha_registro, 'id_estado' => $this->id_estado]);
     $query->andFilterWhere(['like', 'marca', $this->marca]);
     /*
     ->andFilterWhere(['like', 'modelo', $this->modelo])
     ->andFilterWhere(['like', 'ano', $this->ano])
     ->andFilterWhere(['like', 'color', $this->color])
     ->andFilterWhere(['like', 'no_motor', $this->no_motor])
     ->andFilterWhere(['like', 'matricula_auto', $this->matricula_auto])
     ->andFilterWhere(['like', 'no_chassis', $this->no_chassis])
     ->andFilterWhere(['like', 'observaciones', $this->observaciones])
     ->andFilterWhere(['like', 'kilometraje', $this->kilometraje])
     ->andFilterWhere(['like', 'no_chapa', $this->no_chapa]);
     */
     $sort = SORT_DESC;
     if (!empty($params['AutosSearch']['sort'])) {
         $sort = $params['AutosSearch']['sort'];
     }
     $query->orderBy = ['fecha_registro' => $sort];
     $precioRange = '1-999999';
     if (!empty($params['AutosSearch']['precioRange'])) {
         $precioRange = explode('-', $params['AutosSearch']['precioRange']);
         $precioRange[0] = intval(trim($precioRange[0]));
         $precioRange[1] = intval(trim($precioRange[1]));
         $query->andWhere("precio >= " . $precioRange[0]);
         $query->andWhere("precio <= " . $precioRange[1]);
     }
     //Fn::PrintVar($query, 'query');
     //exit;
     return $dataProvider;
 }