|
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192 |
- <?php
-
-
-
- namespace common\models ;
-
- use common\models\Product ;
-
- class ProductSearch extends Product
- {
- public function rules()
- {
- return [
- [['active', 'order', 'quantity_max', 'id_producer'], 'integer'],
- [['monday', 'tuesday', 'wednesday', 'thursday', 'friday', 'saturday', 'sunday', 'unavailable'], 'boolean'],
- [['price', 'weight'], 'number'],
- [[ 'photo'], 'file'],
- [['name', 'description', 'photo'], 'string', 'max' => 255],
- [['recipe'], 'string', 'max' => 1000],
- ];
- }
-
- public function search($params)
- {
- $optionsSearch = self::defaultOptionsSearch() ;
-
- $query = Product::find()
- ->with($optionsSearch['with'])
- ->innerJoinWith($optionsSearch['join_with'], true)
- ->where(['product.id_producer' => Producer::getId()])
- ->orderBy('product.order ASC')
- ;
-
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => ['attributes' => ['order', 'photo', 'name', 'description','active']],
- 'pagination' => [
- 'pageSize' => 20,
- ],
- ]);
-
- $this->load($params);
- if (!$this->validate()) {
- return $dataProvider;
- }
-
- $query->andFilterWhere(['like', 'product.name', $this->name]) ;
- $query->andFilterWhere(['like', 'product.description', $this->description]) ;
-
- if(isset($this->active) && is_numeric($this->active)) {
- $query->andWhere([
- 'product.active' => $this->active
- ]) ;
- }
-
- return $dataProvider;
- }
- }
|