*/ protected $casts = [ 'id' => 'integer', 'active' => 'boolean', 'force_pass_reset' => 'boolean', 'podcast_id' => '?integer', 'podcast_role' => '?string', ]; public function getIsOwner(): bool { $firstUser = (new UserModel())->first(); if (! $firstUser instanceof self) { return false; } return $this->username === $firstUser->username; } /** * Returns the podcasts the user is contributing to * * @return Podcast[] */ public function getPodcasts(): array { if ($this->id === null) { throw new RuntimeException('Users must be created before getting podcasts.'); } if ($this->podcasts === null) { $this->podcasts = (new PodcastModel())->getUserPodcasts($this->id); } return $this->podcasts; } /** * Returns the ids of the user's actors that have unread notifications * * @return int[] */ public function getActorIdsWithUnreadNotifications(): array { if ($this->getPodcasts() === []) { return []; } $unreadNotifications = (new NotificationModel())->whereIn( 'target_actor_id', array_column($this->getPodcasts(), 'actor_id') ) ->where('read_at', null) ->findAll(); return array_column($unreadNotifications, 'target_actor_id'); } }