|
- <?php
-
-
-
- namespace common\models ;
-
- use common\helpers\GlobalParam;
- use common\models\PointSale ;
-
- class PointSaleSearch extends PointSale
- {
- var $delivery ;
- var $access_type ;
-
- public function rules()
- {
- return [
- [['restricted_access'], 'boolean'],
- [['name', 'code'], 'string', 'max' => 255],
- [['address', 'locality', 'infos_monday', 'infos_tuesday',
- 'infos_wednesday', 'infos_thursday', 'infos_friday',
- 'infos_saturday', 'infos_sunday'], 'string'],
- [['point_production', 'credit', 'delivery_monday', 'delivery_tuesday',
- 'delivery_wednesday', 'delivery_thursday', 'delivery_friday',
- 'delivery_saturday', 'delivery_sunday'], 'boolean'],
- ['id_producer', 'integer'],
- [['users', 'users_comment', 'code','name', 'delivery', 'access_type'], 'safe']
- ];
- }
-
- public function search($params)
- {
- $optionsSearch = self::defaultOptionsSearch() ;
-
- $query = PointSale::find()
- ->with($optionsSearch['with'])
- ->innerJoinWith($optionsSearch['join_with'], true)
- ->where(['point_sale.id_producer' => GlobalParam::getCurrentProducerId()])
- ;
-
- $dataProvider = new ActiveDataProvider([
- 'query' => $query,
- 'sort' => ['attributes' => ['name', 'locality','point_production','credit']],
- 'pagination' => [
- 'pageSize' => 20,
- ],
- ]);
-
- $this->load($params);
- if (!$this->validate()) {
- return $dataProvider;
- }
-
- if(isset($this->point_production) && is_numeric($this->point_production)) {
- $query->andWhere([
- 'point_sale.point_production' => $this->point_production
- ]) ;
- }
-
- if(isset($this->delivery) && strlen($this->delivery)) {
- $query->andWhere([
- 'point_sale.delivery_'.$this->delivery => 1
- ]) ;
- }
-
- if(isset($this->access_type) && strlen($this->access_type)) {
- if($this->access_type == 'open') {
- $query->andWhere(['or',
- ['=','point_sale.code',''],
- ['IS','point_sale.code',null],
- ]) ;
- $query->andWhere(['point_sale.restricted_access' => 0]) ;
- }
- elseif($this->access_type == 'code') {
- $query->andWhere(['!=','point_sale.code','']) ;
- }
- elseif($this->access_type == 'restricted_access') {
- $query->andWhere(['point_sale.restricted_access' => 1]) ;
- }
- }
-
- $query->andFilterWhere(['like', 'point_sale.name', $this->name]) ;
- $query->andFilterWhere(['like', 'point_sale.locality', $this->locality]) ;
-
- return $dataProvider;
- }
-
- }
|