2021-02-10 16:20:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Entities;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use RuntimeException;
|
2021-02-10 16:20:01 +00:00
|
|
|
use App\Models\PersonModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use App\Models\EpisodeModel;
|
2021-05-06 14:00:48 +00:00
|
|
|
use CodeIgniter\Entity\Entity;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
/**
|
|
|
|
* @property int $podcast_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Podcast|null $podcast
|
2021-05-12 14:00:25 +00:00
|
|
|
* @property int|null $episode_id
|
|
|
|
* @property Episode|null $episode
|
|
|
|
* @property string $full_name
|
|
|
|
* @property string $person_group
|
|
|
|
* @property string $group_label
|
|
|
|
* @property string $person_role
|
|
|
|
* @property string $role_label
|
|
|
|
* @property int $person_id
|
2021-05-14 17:59:35 +00:00
|
|
|
* @property Person|null $person
|
2021-05-12 14:00:25 +00:00
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
class Credit extends Entity
|
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
protected ?Person $person = null;
|
|
|
|
protected ?Podcast $podcast = null;
|
|
|
|
protected ?Episode $episode = null;
|
2021-05-14 17:59:35 +00:00
|
|
|
protected string $group_label;
|
|
|
|
protected string $role_label;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
/**
|
|
|
|
* @var array<string, string>
|
|
|
|
*/
|
|
|
|
protected $casts = [
|
|
|
|
'podcast_id' => 'integer',
|
|
|
|
'episode_id' => '?integer',
|
2021-05-12 14:00:25 +00:00
|
|
|
'person_id' => 'integer',
|
|
|
|
'full_name' => 'string',
|
|
|
|
'person_group' => 'string',
|
|
|
|
'person_role' => 'string',
|
2021-05-06 14:00:48 +00:00
|
|
|
];
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function getPerson(): ?Person
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->person_id === null) {
|
|
|
|
throw new RuntimeException(
|
|
|
|
'Credit must have person_id before getting person.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->person === null) {
|
|
|
|
$this->person = (new PersonModel())->getPersonById(
|
|
|
|
$this->person_id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->person;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function getPodcast(): ?Podcast
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->podcast_id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-05-12 14:00:25 +00:00
|
|
|
'Credit must have podcast_id before getting podcast.',
|
2021-04-02 17:20:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->podcast === null) {
|
|
|
|
$this->podcast = (new PodcastModel())->getPodcastById(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->podcast_id,
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->podcast;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getEpisode(): ?Episode
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->episode_id === null) {
|
2021-05-06 14:00:48 +00:00
|
|
|
throw new RuntimeException(
|
2021-05-12 14:00:25 +00:00
|
|
|
'Credit must have episode_id before getting episode.',
|
2021-04-02 17:20:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->episode === null) {
|
|
|
|
$this->episode = (new EpisodeModel())->getPublishedEpisodeById(
|
|
|
|
$this->podcast_id,
|
|
|
|
$this->episode_id,
|
2021-04-02 17:20:02 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
return $this->episode;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getGroupLabel(): string
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->person_group === null) {
|
|
|
|
return '';
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
return lang("PersonsTaxonomy.persons.{$this->person_group}.label");
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
public function getRoleLabel(): string
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->person_group === '') {
|
|
|
|
return '';
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($this->person_role === '') {
|
|
|
|
return '';
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
return lang(
|
|
|
|
"PersonsTaxonomy.persons.{$this->person_group}.roles.{$this->person_role}.label",
|
|
|
|
);
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
}
|