Newer
Older
<?php
/**
* @copyright 2020 Podlibre
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
* @link https://castopod.org/
*/
namespace App\Entities;

Yassine Doghri
committed
use RuntimeException;
use App\Models\PersonModel;
use App\Models\PodcastModel;
use App\Models\EpisodeModel;

Yassine Doghri
committed
use CodeIgniter\Entity\Entity;
class Credit extends Entity
{
/**

Yassine Doghri
committed
* @var Person
*/
protected $person;
/**

Yassine Doghri
committed
* @var Podcast
*/
protected $podcast;
/**

Yassine Doghri
committed
* @var Episode|null
*/
protected $episode;
/**
* @var string
*/
protected $group_label;
/**
* @var string
*/
protected $role_label;

Yassine Doghri
committed
/**
* @var array<string, string>
*/
protected $casts = [
'person_group' => 'string',
'person_role' => 'string',
'person_id' => 'integer',
'full_name' => 'integer',
'podcast_id' => 'integer',
'episode_id' => '?integer',
];
public function getPodcast(): Podcast
{
return (new PodcastModel())->getPodcastById(
$this->attributes['podcast_id'],

Yassine Doghri
committed
public function getEpisode(): ?Episode
if (empty($this->episode_id)) {

Yassine Doghri
committed
throw new RuntimeException(
'Credit must have episode_id before getting episode.',
);
}
if (empty($this->episode)) {
$this->episode = (new EpisodeModel())->getPublishedEpisodeById(
$this->podcast_id,

Yassine Doghri
committed
$this->episode_id,
return $this->episode;

Yassine Doghri
committed
public function getPerson(): Person
if (empty($this->person_id)) {

Yassine Doghri
committed
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;

Yassine Doghri
committed
public function getGroupLabel(): ?string
if (empty($this->person_group)) {
return null;
}

Yassine Doghri
committed
return lang("PersonsTaxonomy.persons.{$this->person_group}.label");

Yassine Doghri
committed
public function getRoleLabel(): ?string

Yassine Doghri
committed
if (empty($this->person_group)) {
return null;
}
if (empty($this->person_role)) {
return null;
}

Yassine Doghri
committed
return lang(
"PersonsTaxonomy.persons.{$this->person_group}.roles.{$this->person_role}.label",
);