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;
|
|
|
|
|
|
|
|
use App\Models\PersonModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
|
|
|
|
use CodeIgniter\Entity;
|
|
|
|
|
|
|
|
class Credit extends Entity
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Person
|
|
|
|
*/
|
|
|
|
protected $person;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
2021-04-02 17:20:02 +00:00
|
|
|
* @var \App\Entities\Episode|null
|
2021-02-10 16:20:01 +00:00
|
|
|
*/
|
|
|
|
protected $episode;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $group_label;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $role_label;
|
|
|
|
|
|
|
|
public function getPodcast()
|
|
|
|
{
|
|
|
|
return (new PodcastModel())->getPodcastById(
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->attributes['podcast_id'],
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEpisode()
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (empty($this->episode_id)) {
|
|
|
|
throw new \RuntimeException(
|
|
|
|
'Credit must have episode_id before getting episode.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->episode)) {
|
|
|
|
$this->episode = (new EpisodeModel())->getPublishedEpisodeById(
|
|
|
|
$this->episode_id,
|
|
|
|
$this->podcast_id,
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
return $this->episode;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getPerson()
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (empty($this->person_id)) {
|
|
|
|
throw new \RuntimeException(
|
|
|
|
'Credit must have person_id before getting person.',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (empty($this->person)) {
|
|
|
|
$this->person = (new PersonModel())->getPersonById(
|
|
|
|
$this->person_id,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->person;
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getGroupLabel()
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (empty($this->person_group)) {
|
2021-02-10 16:20:01 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
2021-04-02 17:20:02 +00:00
|
|
|
return lang("PersonsTaxonomy.persons.{$this->person_group}.label");
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getRoleLabel()
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (empty($this->person_group) || empty($this->person_role)) {
|
2021-02-10 16:20:01 +00:00
|
|
|
return null;
|
|
|
|
} else {
|
|
|
|
return lang(
|
2021-04-02 17:20:02 +00:00
|
|
|
"PersonsTaxonomy.persons.{$this->person_group}.roles.{$this->person_role}.label",
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|