title = $title; $place->width = $width; $place->height = $height; $place->active = $active; return $place; } public function edit($title, $width, $height, $active): void { $this->title = $title; $this->width = $width; $this->height = $height; $this->active = $active; } /** * @inheritdoc */ public static function tableName() { return 'banners_places'; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => Yii::t('banners', 'ID'), 'title' => Yii::t('banners', 'Title'), 'width' => Yii::t('banners', 'Width'), 'height' => Yii::t('banners', 'Height'), 'active' => Yii::t('banners', 'Status'), ]; } public function activate(): void { if ($this->isActive()) { throw new \DomainException('Place is already active.'); } $this->active = self::STATUS_ACTIVE; } public function draft(): void { if ($this->isDraft()) { throw new \DomainException('Place is already draft.'); } $this->active = self::STATUS_DRAFT; } public function isActive(): bool { return $this->active == self::STATUS_ACTIVE; } public function isDraft(): bool { return $this->active == self::STATUS_DRAFT; } public function getBanners() { return $this->hasMany(Banner::class, ['place_id' => 'id']); } public function getActiveBanners() { return $this->hasMany(Banner::class, ['place_id' => 'id'])->andWhere(['active' => Banner::STATUS_ACTIVE]); } public static function find(): BannerPlaceQuery { return new BannerPlaceQuery(static::class); } }