Advertisement
pmtpenza22

Untitled

Feb 18th, 2019
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.28 KB | None | 0 0
  1. <?php
  2.  
  3. namespace backend\models;
  4.  
  5. use yii\base\Model;
  6. use yii\data\ActiveDataProvider;
  7. use backend\models\Product;
  8.  
  9. /**
  10. * ProductSearch represents the model behind the search form of `backend\models\Product`.
  11. */
  12. class ProductSearch extends Product
  13. {
  14. /**
  15. * {@inheritdoc}
  16. */
  17. public function rules()
  18. {
  19. return [
  20. [['id', 'status', 'hit', 'new', 'sale', 'category_id', 'meta_title'], 'integer'],
  21. [['name', 'description', 'image', 'meta_keyword', 'meta_description'], 'safe'],
  22. [['price_roz', 'price_opt'], 'number'],
  23. ];
  24. }
  25.  
  26. /**
  27. * {@inheritdoc}
  28. */
  29. public function scenarios()
  30. {
  31. // bypass scenarios() implementation in the parent class
  32. return Model::scenarios();
  33. }
  34.  
  35. /**
  36. * Creates data provider instance with search query applied
  37. *
  38. * @param array $params
  39. *
  40. * @return ActiveDataProvider
  41. */
  42. public function search($params)
  43. {
  44. $query = Product::find();
  45.  
  46. // add conditions that should always apply here
  47.  
  48. $dataProvider = new ActiveDataProvider([
  49. 'query' => $query,
  50. ]);
  51.  
  52. $this->load($params);
  53.  
  54. if (!$this->validate()) {
  55. // uncomment the following line if you do not want to return any records when validation fails
  56. // $query->where('0=1');
  57. return $dataProvider;
  58. }
  59.  
  60. // grid filtering conditions
  61. $query->andFilterWhere([
  62. 'id' => $this->id,
  63. 'status' => $this->status,
  64. 'price_roz' => $this->price_roz,
  65. 'price_opt' => $this->price_opt,
  66. 'hit' => $this->hit,
  67. 'new' => $this->new,
  68. 'sale' => $this->sale,
  69. 'category_id' => $this->category_id,
  70. 'meta_title' => $this->meta_title,
  71. ]);
  72.  
  73. $query->andFilterWhere(['like', 'name', $this->name])
  74. ->andFilterWhere(['like', 'description', $this->description])
  75. ->andFilterWhere(['like', 'image', $this->image])
  76. ->andFilterWhere(['like', 'meta_keyword', $this->meta_keyword])
  77. ->andFilterWhere(['like', 'meta_description', $this->meta_description]);
  78.  
  79. return $dataProvider;
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement