/**
  * findModel
  * @param int $id
  * @return null|Company
  * @throws NotFoundHttpException
  */
 private function findModel($id)
 {
     $model = Company::findOne($id);
     if (empty($model)) {
         throw new NotFoundHttpException('Company not found!');
     }
     return $model;
 }
 /**
  * @param array $params
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Company::find()->from(['c' => self::tableName()])->joinWith(['user', 'ownership']);
     $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['attributes' => ['id', 'name', 'userName' => ['asc' => ['u.first_name' => SORT_ASC, 'u.last_name' => SORT_ASC], 'desc' => ['u.first_name' => SORT_DESC, 'u.last_name' => SORT_DESC]], 'ownershipName' => ['asc' => ['ot.name' => SORT_ASC], 'desc' => ['ot.name' => SORT_DESC]], 'edrpou']]]);
     $this->load($params);
     if (!$this->validate()) {
         return $dataProvider;
     }
     $query->andFilterWhere(['c.id' => $this->id, 'c.edrpou' => $this->edrpou]);
     $query->andFilterWhere(['like', 'c.name', $this->name])->andFilterWhere(['like', 'u.first_name', $this->userName])->orFilterWhere(['like', 'u.last_name', $this->userName])->andFilterWhere(['like', 'ot.name', $this->ownershipName]);
     return $dataProvider;
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompany()
 {
     return $this->hasOne(Company::className(), ['id' => 'company_id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompanies()
 {
     return $this->hasMany(Company::className(), ['ownership_id' => 'id']);
 }
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompanies()
 {
     return $this->hasMany(Company::className(), ['id' => 'company_id'])->viaTable('company_to_sphere', ['sphere_id' => 'id']);
 }