private function providePhones($count = 150)
 {
     print_r("Provide phones. Count: " . $count . "...");
     $this->faker->unique(true);
     $companies = Company::find()->asArray()->all();
     $company_ids = ArrayHelper::getColumn($companies, 'id');
     $company_ids_length = count($company_ids) - 1;
     for ($i = 0; $i < $count; $i++) {
         $company_phone = new CompanyPhone();
         $company_phone->phone = $this->faker->unique()->phoneNumber;
         $company_phone->company_id = $company_ids[mt_rand(1, $company_ids_length)];
         $company_phone->save();
     }
     print_r("DONE" . PHP_EOL);
 }
 public function deleteCompany($company)
 {
     \App\Models\CompanyEmail::where('company_id', $company->id)->delete();
     \App\Models\CompanyPhone::where('company_id', $company->id)->delete();
     \App\Models\CompanyAddress::where('company_id', $company->id)->delete();
     $company->delete();
 }
 /**
  * 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;
 }
 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;
 }
Example #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompanyPhones()
 {
     return $this->hasMany(CompanyPhone::className(), ['company_id' => 'id']);
 }
 /**
  * Finds the CompanyPhone model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return CompanyPhone the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = CompanyPhone::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }