/** * @return array */ private function getAllRecords() { $customer_records = CustomerRecord::find()->all(); if (!$customer_records) { return []; } $customers = []; /** @var CustomerRecord $customer_record */ foreach ($customer_records as $customer_record) { $phone_records = PhoneRecord::find()->where(['customer_id' => $customer_record->id])->one(); if ($phone_records) { $customers[] = $this->makeCustomer($customer_record, $phone_records); } } return $customers; }
/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = CustomerRecord::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $query->joinWith('addresses'); $dataProvider->sort->attributes['country'] = ['asc' => ['address.country' => SORT_ASC], 'desc' => ['address.country' => SORT_DESC]]; $query->joinWith('emails'); $dataProvider->sort->attributes['email'] = ['asc' => ['email.address' => SORT_ASC], 'desc' => ['email.address' => SORT_DESC]]; /* $query->joinWith('phones'); $dataProvider->sort->attributes['phone'] = [ 'asc' => ['phone.number' => SORT_ASC], 'desc' => ['phone.number' => SORT_DESC], ]; */ if (!($this->load($params) && $this->validate())) { return $dataProvider; } $query->andFilterWhere(['customer.id' => $this->id, 'birth_date' => $this->birth_date, 'created_at' => $this->created_at, 'created_by' => $this->created_by, 'updated_at' => $this->updated_at, 'updated_by' => $this->updated_by]); $query->andFilterWhere(['like', 'name', $this->name])->andFilterWhere(['like', 'notes', $this->notes]); // $query->andWhere(['like', 'address.country', $this->country]); return $dataProvider; }