'Активна', self::STATUS_INACTIVE => 'Не активна', ]; } /** * {@inheritdoc} */ public static function tableName() { return 'company'; } public function behaviors() { return [ [ 'class' => TimestampBehavior::class, 'createdAtAttribute' => 'created_at', 'updatedAtAttribute' => 'updated_at', 'value' => new Expression('NOW()'), ], ]; } /** * {@inheritdoc} */ public function rules() { return [ [['inn', 'name', 'user_id'], 'required'], [['created_at', 'updated_at'], 'safe'], [['status', 'user_id'], 'integer'], [['name', 'address', 'inn'], 'string', 'max' => 255], ]; } /** * {@inheritdoc} */ public function attributeLabels() { return [ 'id' => 'ID', 'inn' => 'ИНН', 'name' => 'Название', 'address' => 'Адрес', 'created_at' => 'Дата создания', 'updated_at' => 'Дата редактирования', 'status' => 'Статус', 'user_id' => 'Пользователь', ]; } /** * Gets query for [[Addresses]]. * * @return \yii\db\ActiveQuery */ public function getAddresses() { return $this->hasMany(Addresses::class, ['company_id' => 'id']); } /** * Gets query for [[Checks]]. * * @return \yii\db\ActiveQuery */ public function getChecks() { return $this->hasMany(Check::class, ['company_id' => 'id']); } /** * Gets query for [[Products]]. * * @return \yii\db\ActiveQuery */ public function getProducts() { return $this->hasMany(Product::class, ['company_id' => 'id']); } public static function getMyCompany() { $companies = self::find()->where(['user_id' => Yii::$app->user->id])->all(); } }