2021-04-22 17:20:28 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-04-22 17:20:28 +00:00
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-04-22 17:20:28 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
|
|
|
use App\Models\PodcastModel;
|
2021-08-27 10:58:22 +00:00
|
|
|
use Modules\Fediverse\Entities\Actor as FediverseActor;
|
2024-05-29 10:24:13 +00:00
|
|
|
use Override;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2021-04-22 17:20:28 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property Podcast|null $podcast
|
|
|
|
* @property boolean $is_podcast
|
|
|
|
*/
|
2021-08-27 10:58:22 +00:00
|
|
|
class Actor extends FediverseActor
|
2021-04-22 17:20:28 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Podcast $podcast = null;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
protected bool $is_podcast = false;
|
2021-04-22 17:20:28 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getIsPodcast(): bool
|
2021-04-22 17:20:28 +00:00
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
return $this->getPodcast() instanceof Podcast;
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getPodcast(): ?Podcast
|
2021-04-22 17:20:28 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->id === null) {
|
2021-06-08 09:52:11 +00:00
|
|
|
throw new RuntimeException('Podcast id must be set before getting associated podcast.');
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
|
|
|
|
2021-08-11 15:47:23 +00:00
|
|
|
if (! $this->podcast instanceof Podcast) {
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->podcast = (new PodcastModel())->getPodcastByActorId($this->id);
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->podcast;
|
|
|
|
}
|
2021-11-23 11:54:34 +00:00
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-11-23 11:54:34 +00:00
|
|
|
public function getAvatarImageUrl(): string
|
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
if ($this->podcast instanceof Podcast) {
|
2021-11-23 11:54:34 +00:00
|
|
|
return $this->podcast->cover->thumbnail_url;
|
|
|
|
}
|
|
|
|
|
2022-09-07 10:04:02 +00:00
|
|
|
return parent::getAvatarImageUrl();
|
2021-11-23 11:54:34 +00:00
|
|
|
}
|
|
|
|
|
2024-05-29 10:24:13 +00:00
|
|
|
#[Override]
|
2021-11-23 11:54:34 +00:00
|
|
|
public function getAvatarImageMimetype(): string
|
|
|
|
{
|
2023-04-14 11:11:53 +00:00
|
|
|
if ($this->podcast instanceof Podcast) {
|
2021-11-23 11:54:34 +00:00
|
|
|
return $this->podcast->cover->thumbnail_mimetype;
|
|
|
|
}
|
|
|
|
|
2022-09-07 10:04:02 +00:00
|
|
|
return parent::getAvatarImageMimetype();
|
2021-11-23 11:54:34 +00:00
|
|
|
}
|
2021-04-22 17:20:28 +00:00
|
|
|
}
|