Ejemplo n.º 1
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = CompanyPhone::find();
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $this->load($params);
     if (!$this->validate()) {
         // uncomment the following line if you do not want to return any records when validation fails
         // $query->where('0=1');
         return $dataProvider;
     }
     $query->andFilterWhere(['id' => $this->id, 'company_id' => $this->company_id]);
     $query->andFilterWhere(['like', 'phone', $this->phone]);
     return $dataProvider;
 }
Ejemplo n.º 2
0
 public function actionCompanies()
 {
     $query = new \yii\db\Query();
     $query->select(['company.id', 'company.title', 'building.address'])->from('company')->join('INNER JOIN', 'building', 'company.building_id = building.id');
     $this->filterBuilding($query);
     $this->filterRubrics($query);
     $this->filterCompanies($query);
     $this->filterGeometry($query);
     $this->titleSearch($query);
     $query->orderBy('id');
     $query->limit(1000);
     $companies = $query->createCommand()->queryAll();
     // заполненией найденных компаний, рубриками и телефонами
     foreach ($companies as $key => $company) {
         $companies[$key]['phones'] = ArrayHelper::getColumn(CompanyPhone::find()->asArray()->where(["company_id" => $company["id"]])->all(), 'phone');
         $companies[$key]['rubrics'] = Rubric::find()->select(['rubric.id', 'rubric.title'])->asArray()->innerJoin('company_rubric', 'company_rubric.rubric_id = rubric.id')->where(['company_rubric.company_id' => $company["id"]])->all();
     }
     return $companies;
 }