title = $title; $banner->image = $image; $banner->url = $url; $banner->target = $target; $banner->start_at = $start_at; $banner->end_at = $end_at; $banner->include_urls = $include_urls; $banner->exclude_urls = $exclude_urls; $banner->active = $active; $banner->place_id = $place_id; return $banner; } public function setImage(UploadedFile $image): void { $this->image = $image; } public function edit( $title, $image, $url, $target, $start_at, $end_at, $include_urls, $exclude_urls, $active, $place_id ): void { $this->title = $title; $this->image = $image; $this->url = $url; $this->target = $target; $this->start_at = $start_at; $this->end_at = $end_at; $this->include_urls = $include_urls; $this->exclude_urls = $exclude_urls; $this->active = $active; $this->place_id = $place_id; } /** * @inheritdoc */ public static function tableName() { return 'banners'; } /** * @inheritdoc */ public function attributeLabels() { return [ 'id' => Yii::t('banners', 'ID'), 'title' => Yii::t('banners', 'Title'), 'url' => Yii::t('banners', 'URL'), 'image' => Yii::t('banners', 'Image'), 'target' => Yii::t('banners', 'Target'), 'active' => Yii::t('banners', 'Status'), 'start_at' => Yii::t('banners', 'Start At'), 'end_at' => Yii::t('banners', 'End At'), 'created_at' => Yii::t('banners', 'Created At'), 'updated_at' => Yii::t('banners', 'Updated At'), 'include_urls' => Yii::t('banners', 'Show only on URLs'), 'exclude_urls' => Yii::t('banners', 'Not show on URLs'), 'views' => Yii::t('banners', 'Views'), 'clicks' => Yii::t('banners', 'Visits'), 'place_id' => Yii::t('banners', 'Place'), ]; } public function activate(): void { if ($this->isActive()) { throw new \DomainException('Banner is already active.'); } $this->active = self::STATUS_ACTIVE; } public function draft(): void { if ($this->isDraft()) { throw new \DomainException('Banner 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 getPlace() { return $this->hasOne(BannerPlace::class, ['id' => 'place_id']); } ###################################### public function behaviors(): array { return [ TimestampBehavior::class, ]; } public static function find(): BannerQuery { return new BannerQuery(static::class); } }