/** * @param array $options * @return $this */ public function api_user_orders($options = []) { $query = Order::find()->where(['user_id' => \Yii::$app->user->id]); $this->_adp = new ActiveDataProvider(['query' => $query, 'pagination' => isset($options['pagination']) ? $options['pagination'] : []]); foreach ($this->_adp->models as $order) { $this->_orders[$order->id] = $order; } return $this->_adp->models; }
/** * @param $params * @return ActiveDataProvider */ public function search($params) { $query = Order::find(); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['id' => SORT_ASC], 'attributes' => ['id', 'name', 'address', 'phone', 'country_id', 'status', 'created_at', 'updated_at']]]); $this->load($params); if (!$this->validate()) { $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['status' => $this->status, 'country_id' => $this->country_id]); $query->andFilterWhere(['like', 'name', $this->name]); $query->andFilterWhere(['like', 'address', $this->address]); $query->andFilterWhere(['like', 'phone', $this->phone]); return $dataProvider; }