2020-05-31 19:15:52 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-06-10 15:00:12 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Libraries\SimpleRSSElement;
|
2020-09-04 09:09:26 +00:00
|
|
|
use App\Models\CategoryModel;
|
2020-06-26 14:34:52 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2021-05-14 17:59:35 +00:00
|
|
|
use App\Models\PersonModel;
|
2020-09-04 09:09:26 +00:00
|
|
|
use App\Models\PlatformModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Models\UserModel;
|
2021-05-12 14:00:25 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2020-08-04 11:25:22 +00:00
|
|
|
use League\CommonMark\CommonMarkConverter;
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2020-05-31 19:15:52 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int $id
|
|
|
|
* @property int $actor_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Actor|null $actor
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $name
|
|
|
|
* @property string $link
|
|
|
|
* @property string $feed_url
|
|
|
|
* @property string $title
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property string|null $description Holds text only description, striped of any markdown or html special characters
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string $description_markdown
|
|
|
|
* @property string $description_html
|
|
|
|
* @property Image $image
|
|
|
|
* @property string $image_path
|
|
|
|
* @property string $image_mimetype
|
|
|
|
* @property string $language_code
|
|
|
|
* @property int $category_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Category|null $category
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property int[] $other_categories_ids
|
|
|
|
* @property Category[] $other_categories
|
|
|
|
* @property string|null $parental_advisory
|
|
|
|
* @property string|null $publisher
|
|
|
|
* @property string $owner_name
|
|
|
|
* @property string $owner_email
|
|
|
|
* @property string $type
|
|
|
|
* @property string|null $copyright
|
|
|
|
* @property string|null $episode_description_footer_markdown
|
|
|
|
* @property string|null $episode_description_footer_html
|
|
|
|
* @property bool $is_blocked
|
|
|
|
* @property bool $is_completed
|
|
|
|
* @property bool $is_locked
|
|
|
|
* @property string|null $imported_feed_url
|
|
|
|
* @property string|null $new_feed_url
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property Location|null $location
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $location_name
|
|
|
|
* @property string|null $location_geo
|
2021-05-17 17:11:23 +00:00
|
|
|
* @property string|null $location_osm
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property string|null $payment_pointer
|
|
|
|
* @property array|null $custom_rss
|
|
|
|
* @property string $custom_rss_string
|
|
|
|
* @property string|null $partner_id
|
|
|
|
* @property string|null $partner_link_url
|
|
|
|
* @property string|null $partner_image_url
|
|
|
|
* @property int $created_by
|
|
|
|
* @property int $updated_by
|
|
|
|
* @property Time $created_at;
|
|
|
|
* @property Time $updated_at;
|
|
|
|
* @property Time|null $deleted_at;
|
|
|
|
*
|
|
|
|
* @property Episode[] $episodes
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Person[] $persons
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property User[] $contributors
|
|
|
|
* @property Platform[] $podcasting_platforms
|
|
|
|
* @property Platform[] $social_platforms
|
|
|
|
* @property Platform[] $funding_platforms
|
|
|
|
*
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
class Podcast extends Entity
|
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
protected string $link;
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Actor $actor = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
protected Image $image;
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?string $description = null;
|
|
|
|
protected ?Category $category = null;
|
2020-09-04 09:09:26 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Category[]|null
|
2020-10-02 15:38:16 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $other_categories = null;
|
2020-10-02 15:38:16 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var string[]|null
|
2020-10-02 15:38:16 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $other_categories_ids = null;
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Episode[]|null
|
2021-05-12 14:00:25 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $episodes = null;
|
2021-05-12 14:00:25 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Person[]|null
|
2021-05-12 14:00:25 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $persons = null;
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var User[]|null
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $contributors = null;
|
2020-08-05 17:26:04 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $podcasting_platforms = null;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $social_platforms = null;
|
2020-11-18 17:17:56 +00:00
|
|
|
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @var Platform[]|null
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-18 17:16:36 +00:00
|
|
|
protected ?array $funding_platforms = null;
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Location $location = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
protected string $custom_rss_string;
|
2021-03-19 16:12:36 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
2020-05-31 19:15:52 +00:00
|
|
|
protected $casts = [
|
2020-06-12 19:31:10 +00:00
|
|
|
'id' => 'integer',
|
2021-04-02 17:20:02 +00:00
|
|
|
'actor_id' => 'integer',
|
2020-05-31 19:15:52 +00:00
|
|
|
'name' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'title' => 'string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'description_markdown' => 'string',
|
|
|
|
'description_html' => 'string',
|
2021-05-03 17:39:58 +00:00
|
|
|
'image_path' => 'string',
|
2021-04-02 17:20:02 +00:00
|
|
|
'image_mimetype' => 'string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'language_code' => 'string',
|
2020-08-21 08:41:09 +00:00
|
|
|
'category_id' => 'integer',
|
2020-10-02 15:38:16 +00:00
|
|
|
'parental_advisory' => '?string',
|
|
|
|
'publisher' => '?string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'owner_name' => 'string',
|
|
|
|
'owner_email' => 'string',
|
2020-06-26 14:34:52 +00:00
|
|
|
'type' => 'string',
|
2020-05-31 19:15:52 +00:00
|
|
|
'copyright' => '?string',
|
2020-10-29 15:45:19 +00:00
|
|
|
'episode_description_footer_markdown' => '?string',
|
|
|
|
'episode_description_footer_html' => '?string',
|
|
|
|
'is_blocked' => 'boolean',
|
|
|
|
'is_completed' => 'boolean',
|
|
|
|
'is_locked' => 'boolean',
|
2020-08-21 08:41:09 +00:00
|
|
|
'imported_feed_url' => '?string',
|
2020-10-06 15:39:27 +00:00
|
|
|
'new_feed_url' => '?string',
|
2020-12-23 14:11:38 +00:00
|
|
|
'location_name' => '?string',
|
|
|
|
'location_geo' => '?string',
|
2021-05-17 17:11:23 +00:00
|
|
|
'location_osm' => '?string',
|
2020-11-26 18:53:52 +00:00
|
|
|
'payment_pointer' => '?string',
|
2021-03-19 16:12:36 +00:00
|
|
|
'custom_rss' => '?json-array',
|
2021-03-30 16:21:00 +00:00
|
|
|
'partner_id' => '?string',
|
|
|
|
'partner_link_url' => '?string',
|
|
|
|
'partner_image_url' => '?string',
|
2020-10-20 13:46:00 +00:00
|
|
|
'created_by' => 'integer',
|
|
|
|
'updated_by' => 'integer',
|
2020-05-31 19:15:52 +00:00
|
|
|
];
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getActor(): Actor
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($this->actor_id === 0) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must have an actor_id before getting actor.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->actor === null) {
|
2021-04-22 17:20:28 +00:00
|
|
|
$this->actor = model('ActorModel')->getActorById($this->actor_id);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->actor;
|
|
|
|
}
|
|
|
|
|
2020-08-21 08:41:09 +00:00
|
|
|
/**
|
|
|
|
* Saves a cover image to the corresponding podcast folder in `public/media/podcast_name/`
|
|
|
|
*/
|
2021-05-14 17:59:35 +00:00
|
|
|
public function setImage(Image $image): static
|
2020-06-30 18:17:41 +02:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
// Save image
|
|
|
|
$image->saveImage('podcasts/' . $this->attributes['name'], 'cover');
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->attributes['image_mimetype'] = $image->mimetype;
|
|
|
|
$this->attributes['image_path'] = $image->path;
|
2020-06-30 18:17:41 +02:00
|
|
|
|
2020-09-08 11:45:17 +00:00
|
|
|
return $this;
|
2020-06-30 18:17:41 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getImage(): Image
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
return new Image(null, $this->image_path, $this->image_mimetype);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getLink(): string
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
return url_to('podcast-activity', $this->attributes['name']);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getFeedUrl(): string
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
return url_to('podcast_feed', $this->attributes['name']);
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's episodes
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Episode[]
|
2020-07-10 12:20:25 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getEpisodes(): array
|
2020-06-26 14:34:52 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting episodes.',
|
2020-07-10 12:20:25 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->episodes === null) {
|
2020-07-10 12:20:25 +00:00
|
|
|
$this->episodes = (new EpisodeModel())->getPodcastEpisodes(
|
2020-09-04 09:09:26 +00:00
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->type,
|
2020-07-10 12:20:25 +00:00
|
|
|
);
|
|
|
|
}
|
2020-06-26 14:34:52 +00:00
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
return $this->episodes;
|
2020-06-26 14:34:52 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast's persons
|
|
|
|
*
|
2021-05-14 17:59:35 +00:00
|
|
|
* @return Person[]
|
2021-02-10 16:20:01 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getPersons(): array
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting persons.',
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->persons === null) {
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->persons = (new PersonModel())->getPodcastPersons($this->id);
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
return $this->persons;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
|
|
|
* Returns the podcast category entity
|
|
|
|
*/
|
2021-05-14 17:59:35 +00:00
|
|
|
public function getCategory(): ?Category
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting category.',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
if ($this->category === null) {
|
2021-04-22 17:20:28 +00:00
|
|
|
$this->category = (new CategoryModel())->getCategoryById(
|
|
|
|
$this->category_id,
|
|
|
|
);
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->category;
|
|
|
|
}
|
|
|
|
|
2020-07-28 15:57:48 +00:00
|
|
|
/**
|
|
|
|
* Returns all podcast contributors
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return User[]
|
2020-07-28 15:57:48 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getContributors(): array
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcasts must be created before getting contributors.',
|
2020-07-31 16:05:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->contributors === null) {
|
2020-07-31 16:05:10 +00:00
|
|
|
$this->contributors = (new UserModel())->getPodcastContributors(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id,
|
2020-07-31 16:05:10 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->contributors;
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
2020-07-28 15:57:48 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function setDescriptionMarkdown(string $descriptionMarkdown): static
|
2020-07-28 15:57:48 +00:00
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'html_input' => 'strip',
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
2020-07-28 15:57:48 +00:00
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->attributes['description_markdown'] = $descriptionMarkdown;
|
|
|
|
$this->attributes['description_html'] = $converter->convertToHtml(
|
2021-04-02 17:20:02 +00:00
|
|
|
$descriptionMarkdown,
|
2020-10-29 15:45:19 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function setEpisodeDescriptionFooterMarkdown(
|
2021-05-06 14:00:48 +00:00
|
|
|
?string $episodeDescriptionFooterMarkdown = null
|
2021-05-14 17:59:35 +00:00
|
|
|
): static {
|
2020-10-29 15:45:19 +00:00
|
|
|
if ($episodeDescriptionFooterMarkdown) {
|
|
|
|
$converter = new CommonMarkConverter([
|
|
|
|
'html_input' => 'strip',
|
|
|
|
'allow_unsafe_links' => false,
|
|
|
|
]);
|
|
|
|
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_markdown'
|
|
|
|
] = $episodeDescriptionFooterMarkdown;
|
|
|
|
$this->attributes[
|
|
|
|
'episode_description_footer_html'
|
|
|
|
] = $converter->convertToHtml($episodeDescriptionFooterMarkdown);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getDescription(): string
|
2020-10-29 15:45:19 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
if ($this->description === null) {
|
|
|
|
$this->description = trim(
|
|
|
|
(string) preg_replace(
|
|
|
|
'~\s+~',
|
|
|
|
' ',
|
|
|
|
strip_tags($this->attributes['description_html']),
|
|
|
|
),
|
|
|
|
);
|
2020-10-29 15:45:19 +00:00
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $this->description;
|
2020-07-28 15:57:48 +00:00
|
|
|
}
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
/**
|
2020-11-18 17:17:56 +00:00
|
|
|
* Returns the podcast's podcasting platform links
|
2020-09-04 09:09:26 +00:00
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-09-04 09:09:26 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getPodcastingPlatforms(): array
|
2020-09-04 09:09:26 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting podcasting platform links.',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->podcasting_platforms === null) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->podcasting_platforms = (new PlatformModel())->getPodcastPlatforms(
|
2020-11-18 17:17:56 +00:00
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'podcasting',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->podcasting_platforms;
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the podcast's social platform links
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getSocialPlatforms(): array
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting social platform links.',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->social_platforms === null) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->social_platforms = (new PlatformModel())->getPodcastPlatforms(
|
2020-11-18 17:17:56 +00:00
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'social',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->social_platforms;
|
2020-11-18 17:17:56 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the podcast's funding platform links
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Platform[]
|
2020-11-18 17:17:56 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getFundingPlatforms(): array
|
2020-11-18 17:17:56 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting funding platform links.',
|
2020-11-18 17:17:56 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->funding_platforms === null) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->funding_platforms = (new PlatformModel())->getPodcastPlatforms(
|
2020-11-18 17:17:56 +00:00
|
|
|
$this->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
'funding',
|
2020-09-04 09:09:26 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->funding_platforms;
|
2020-09-04 09:09:26 +00:00
|
|
|
}
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-02-27 21:21:26 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @return Category[]
|
2021-02-27 21:21:26 +00:00
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
public function getOtherCategories(): array
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Podcast must be created before getting other categories.',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->other_categories === null) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->other_categories = (new CategoryModel())->getPodcastCategories(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->id,
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->other_categories;
|
|
|
|
}
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
* @return int[]
|
2021-05-06 14:00:48 +00:00
|
|
|
*/
|
|
|
|
public function getOtherCategoriesIds(): array
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->other_categories_ids === null) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->other_categories_ids = array_column(
|
|
|
|
$this->getOtherCategories(),
|
2021-04-02 17:20:02 +00:00
|
|
|
'id',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->other_categories_ids;
|
|
|
|
}
|
2020-12-23 14:11:38 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves the location name and fetches OpenStreetMap info
|
|
|
|
*/
|
2021-05-17 17:11:23 +00:00
|
|
|
public function setLocation(?Location $location = null): static
|
2020-12-23 14:11:38 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
if ($location === null) {
|
2021-05-12 14:00:25 +00:00
|
|
|
$this->attributes['location_name'] = null;
|
|
|
|
$this->attributes['location_geo'] = null;
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->attributes['location_osm'] = null;
|
2020-12-23 14:11:38 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2020-12-23 14:11:38 +00:00
|
|
|
if (
|
2021-05-17 17:11:23 +00:00
|
|
|
!isset($this->attributes['location_name']) ||
|
|
|
|
$this->attributes['location_name'] !== $location->name
|
2020-12-23 14:11:38 +00:00
|
|
|
) {
|
2021-05-17 17:11:23 +00:00
|
|
|
$location->fetchOsmLocation();
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->attributes['location_name'] = $location->name;
|
|
|
|
$this->attributes['location_geo'] = $location->geo;
|
|
|
|
$this->attributes['location_osm'] = $location->osm;
|
2020-12-23 14:11:38 +00:00
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2020-12-23 14:11:38 +00:00
|
|
|
return $this;
|
|
|
|
}
|
2021-03-19 16:12:36 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getLocation(): ?Location
|
|
|
|
{
|
|
|
|
if ($this->location_name === null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->location === null) {
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->location = new Location(
|
|
|
|
$this->location_name,
|
|
|
|
$this->location_geo,
|
|
|
|
$this->location_osm,
|
|
|
|
);
|
2021-05-12 14:00:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->location;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
/**
|
|
|
|
* Get custom rss tag as XML String
|
|
|
|
*/
|
2021-05-06 14:00:48 +00:00
|
|
|
function getCustomRssString(): string
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($this->attributes['custom_rss'] === null) {
|
2021-03-19 16:12:36 +00:00
|
|
|
return '';
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
helper('rss');
|
|
|
|
|
|
|
|
$xmlNode = (new SimpleRSSElement(
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"/>',
|
|
|
|
))->addChild('channel');
|
|
|
|
array_to_rss(
|
|
|
|
[
|
|
|
|
'elements' => $this->custom_rss,
|
|
|
|
],
|
|
|
|
$xmlNode,
|
|
|
|
);
|
|
|
|
|
|
|
|
return str_replace(['<channel>', '</channel>'], '', $xmlNode->asXML());
|
2021-03-19 16:12:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Saves custom rss tag into json
|
|
|
|
*/
|
2021-05-14 17:59:35 +00:00
|
|
|
function setCustomRssString(string $customRssString): static
|
2021-03-19 16:12:36 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
if ($customRssString === '') {
|
2021-05-06 14:00:48 +00:00
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
helper('rss');
|
|
|
|
$customRssArray = rss_to_array(
|
|
|
|
simplexml_load_string(
|
|
|
|
'<?xml version="1.0" encoding="utf-8"?><rss xmlns:itunes="http://www.itunes.com/dtds/podcast-1.0.dtd" xmlns:podcast="https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md" xmlns:content="http://purl.org/rss/1.0/modules/content/" version="2.0"><channel>' .
|
|
|
|
$customRssString .
|
2021-04-02 17:20:02 +00:00
|
|
|
'</channel></rss>',
|
|
|
|
),
|
2021-03-19 16:12:36 +00:00
|
|
|
)['elements'][0];
|
2021-05-06 14:00:48 +00:00
|
|
|
|
2021-03-19 16:12:36 +00:00
|
|
|
if (array_key_exists('elements', $customRssArray)) {
|
|
|
|
$this->attributes['custom_rss'] = json_encode(
|
2021-04-02 17:20:02 +00:00
|
|
|
$customRssArray['elements'],
|
2021-03-19 16:12:36 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
$this->attributes['custom_rss'] = null;
|
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
return $this;
|
2021-03-19 16:12:36 +00:00
|
|
|
}
|
2020-05-31 19:15:52 +00:00
|
|
|
}
|