コード例 #1
0
 /**
  * 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;
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompany()
 {
     return $this->hasOne(Company::className(), ['id' => 'company_id']);
 }
コード例 #4
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompanies()
 {
     return $this->hasMany(Company::className(), ['ownership_id' => 'id']);
 }
コード例 #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getCompanies()
 {
     return $this->hasMany(Company::className(), ['id' => 'company_id'])->viaTable('company_to_sphere', ['sphere_id' => 'id']);
 }