*/ protected $casts = [ 'id' => 'integer', 'podcast_id' => 'integer', 'email' => 'string', 'token' => 'string', 'status' => 'string', 'status_message' => '?string', 'created_by' => 'integer', 'updated_by' => 'integer', ]; public function getStatus(): string { return ($this->expires_at instanceof Time && $this->expires_at->isBefore( Time::now() )) ? 'expired' : $this->attributes['status']; } /** * Suspend a subscription. * * @return $this */ public function suspend(string $reason): static { $this->attributes['status'] = 'suspended'; $this->attributes['status_message'] = $reason; return $this; } /** * Resumes a subscription / unSuspend. * * @return $this */ public function resume(): static { $this->attributes['status'] = 'active'; $this->attributes['status_message'] = null; return $this; } /** * Checks to see if a subscription has been suspended. */ public function isSuspended(): bool { return isset($this->attributes['status']) && $this->attributes['status'] === 'suspended'; } /** * Returns the subscription's podcast */ public function getPodcast(): ?Podcast { if ($this->podcast_id === null) { throw new RuntimeException('Subscription must have a podcast_id before getting podcast.'); } if (! $this->podcast instanceof Podcast) { $this->podcast = (new PodcastModel())->getPodcastById($this->podcast_id); } return $this->podcast; } public function getDownloadsLast3Months(): int { return (new AnalyticsPodcastBySubscriptionModel())->getNumberOfDownloadsLast3Months( $this->podcast_id, $this->id ); } }