with($optionsSearch['with']) ->joinWith($optionsSearch['join_with'], true) ->where(['subscription.id_producer' => Producer::getId()]) ->groupBy('subscription.id') ; $dataProvider = new \yii\data\ActiveDataProvider([ 'query' => $query, 'sort' => ['attributes' => ['username']], 'pagination' => [ 'pageSize' => 20, ], ]); $dataProvider->sort->attributes['username'] = [ 'asc' => ['user.lastname' => SORT_ASC, 'user.name' => SORT_ASC], 'desc' => ['user.lastname' => SORT_DESC, 'user.name' => SORT_DESC], ]; $dataProvider->sort->attributes['id_point_sale'] = [ 'asc' => ['point_sale.name' => SORT_ASC], 'desc' => ['point_sale.name' => SORT_DESC], ]; $dataProvider->sort->attributes['auto_payment'] = [ 'asc' => ['subscription.auto_payment' => SORT_ASC], 'desc' => ['subscription.auto_payment' => SORT_DESC], ]; $this->load($params); if (!$this->validate()) { return $dataProvider; } if(isset($this->id_user) && is_numeric($this->id_user)) { $query->andWhere([ 'subscription.id_user' => $this->id_user ]) ; } if(isset($this->id_point_sale) && is_numeric($this->id_point_sale)) { $query->andWhere([ 'subscription.id_point_sale' => $this->id_point_sale ]) ; } if(isset($this->auto_payment) && is_numeric($this->auto_payment)) { $query->andWhere([ 'subscription.auto_payment' => $this->auto_payment ]) ; } if(isset($this->week_frequency) && is_numeric($this->week_frequency)) { $query->andWhere([ 'subscription.week_frequency' => $this->week_frequency ]) ; } if(isset($this->day) && strlen($this->day)) { $query->andWhere([ 'subscription.'.$this->day => 1 ]) ; } if(strlen($this->date_begin)) { $date = \DateTime::createFromFormat('d/m/Y', $this->date_begin); $query->andWhere([ 'subscription.date_begin' => date('Y-m-d',$date->format('U')) ]) ; } $query->andFilterWhere([ 'or', ['like', 'user.lastname', $this->username], ['like', 'user.name', $this->username], ['like', 'subscription.username', $this->username] ]); $query->andFilterWhere(['like', 'product.name', $this->product_name]) ; return $dataProvider; } }