2021-02-10 16:20:01 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
|
* @copyright 2021 Ad Aures
|
2021-02-10 16:20:01 +00:00
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
|
* @link https://castopod.org/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
use App\Entities\Person;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
use CodeIgniter\Model;
|
|
|
|
|
|
|
|
|
|
class PersonModel extends Model
|
|
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $table = 'persons';
|
2021-05-17 17:11:23 +00:00
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $primaryKey = 'id';
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
2024-04-26 09:26:22 +00:00
|
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $allowedFields = [
|
|
|
|
|
'id',
|
|
|
|
|
'full_name',
|
|
|
|
|
'unique_name',
|
|
|
|
|
'information_url',
|
2021-12-14 16:41:10 +00:00
|
|
|
|
'avatar_id',
|
2021-02-10 16:20:01 +00:00
|
|
|
|
'created_by',
|
|
|
|
|
'updated_by',
|
|
|
|
|
];
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
protected $returnType = Person::class;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $useSoftDeletes = false;
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var bool
|
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $useTimestamps = true;
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
|
|
|
|
* @var array<string, string>
|
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $validationRules = [
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'full_name' => 'required',
|
|
|
|
|
'unique_name' => 'required|regex_match[/^[a-z0-9\-]{1,32}$/]|is_unique[persons.unique_name,id,{id}]',
|
|
|
|
|
'created_by' => 'required',
|
|
|
|
|
'updated_by' => 'required',
|
2021-02-10 16:20:01 +00:00
|
|
|
|
];
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
2024-04-26 09:26:22 +00:00
|
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $afterInsert = ['clearCache'];
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* clear cache before update if by any chance, the person name changes, so will the person link
|
|
|
|
|
*
|
2024-04-26 09:26:22 +00:00
|
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $beforeUpdate = ['clearCache'];
|
2021-05-06 14:00:48 +00:00
|
|
|
|
|
|
|
|
|
/**
|
2024-04-26 09:26:22 +00:00
|
|
|
|
* @var list<string>
|
2021-05-06 14:00:48 +00:00
|
|
|
|
*/
|
2021-02-10 16:20:01 +00:00
|
|
|
|
protected $beforeDelete = ['clearCache'];
|
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
|
public function getPersonById(int $personId): ?Person
|
2021-02-10 16:20:01 +00:00
|
|
|
|
{
|
2021-04-20 13:43:38 +00:00
|
|
|
|
$cacheName = "person#{$personId}";
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
2021-02-10 16:20:01 +00:00
|
|
|
|
$found = $this->find($personId);
|
2021-04-20 13:43:38 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->save($cacheName, $found, DECADE);
|
2021-02-10 16:20:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
|
public function getPerson(string $fullName): ?Person
|
2021-02-10 16:20:01 +00:00
|
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->where('full_name', $fullName)
|
|
|
|
|
->first();
|
2021-02-10 16:20:01 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
|
/**
|
2021-05-18 17:16:36 +00:00
|
|
|
|
* @return object[]
|
2021-05-17 17:11:23 +00:00
|
|
|
|
*/
|
2021-05-19 16:35:13 +00:00
|
|
|
|
public function getPersonRoles(int $personId, int $podcastId, ?int $episodeId): array
|
|
|
|
|
{
|
2021-05-25 18:00:09 +00:00
|
|
|
|
if ($episodeId !== null) {
|
2021-05-17 17:11:23 +00:00
|
|
|
|
$cacheName = "podcast#{$podcastId}_episode#{$episodeId}_person#{$personId}_roles";
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
2022-06-13 16:30:34 +00:00
|
|
|
|
$found = $this->builder()
|
2021-05-17 17:11:23 +00:00
|
|
|
|
->select('episodes_persons.person_group as group, episodes_persons.person_role as role')
|
|
|
|
|
->join('episodes_persons', 'persons.id = episodes_persons.person_id')
|
|
|
|
|
->where('persons.id', $personId)
|
|
|
|
|
->where('episodes_persons.episode_id', $episodeId)
|
|
|
|
|
->get()
|
|
|
|
|
->getResultObject();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
$cacheName = "podcast#{$podcastId}_person#{$personId}_roles";
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
2022-06-13 16:30:34 +00:00
|
|
|
|
$found = $this->builder()
|
2021-05-17 17:11:23 +00:00
|
|
|
|
->select('podcasts_persons.person_group as group, podcasts_persons.person_role as role')
|
|
|
|
|
->join('podcasts_persons', 'persons.id = podcasts_persons.person_id')
|
|
|
|
|
->where('persons.id', $personId)
|
|
|
|
|
->where('podcasts_persons.podcast_id', $podcastId)
|
|
|
|
|
->get()
|
|
|
|
|
->getResultObject();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
|
* @return array<string, string>
|
2021-05-17 17:11:23 +00:00
|
|
|
|
*/
|
|
|
|
|
public function getPersonOptions(): array
|
|
|
|
|
{
|
|
|
|
|
$options = [];
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($options = cache('person_options'))) {
|
2021-05-17 17:11:23 +00:00
|
|
|
|
$options = array_reduce(
|
|
|
|
|
$this->select('`id`, `full_name`')
|
|
|
|
|
->orderBy('`full_name`', 'ASC')
|
|
|
|
|
->findAll(),
|
2023-08-26 13:03:01 +00:00
|
|
|
|
static function (array $result, $person): array {
|
2021-05-17 17:11:23 +00:00
|
|
|
|
$result[$person->id] = $person->full_name;
|
|
|
|
|
return $result;
|
|
|
|
|
},
|
|
|
|
|
[],
|
|
|
|
|
);
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->save('person_options', $options, DECADE);
|
2021-05-17 17:11:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2021-05-19 16:35:13 +00:00
|
|
|
|
* @return array<string, string>
|
2021-05-17 17:11:23 +00:00
|
|
|
|
*/
|
|
|
|
|
public function getTaxonomyOptions(): array
|
|
|
|
|
{
|
|
|
|
|
$options = [];
|
2021-05-19 16:35:13 +00:00
|
|
|
|
$locale = service('request')
|
|
|
|
|
->getLocale();
|
2021-05-17 17:11:23 +00:00
|
|
|
|
$cacheName = "taxonomy_options_{$locale}";
|
|
|
|
|
|
2021-05-31 13:32:33 +00:00
|
|
|
|
/** @var array<string, mixed> $personsTaxonomy */
|
2021-05-17 17:11:23 +00:00
|
|
|
|
$personsTaxonomy = lang('PersonsTaxonomy.persons');
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($options = cache($cacheName))) {
|
2021-05-17 17:11:23 +00:00
|
|
|
|
foreach ($personsTaxonomy as $group_key => $group) {
|
|
|
|
|
foreach ($group['roles'] as $role_key => $role) {
|
|
|
|
|
$options[
|
|
|
|
|
"{$group_key},{$role_key}"
|
|
|
|
|
] = "{$group['label']} › {$role['label']}";
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->save($cacheName, $options, DECADE);
|
2021-05-17 17:11:23 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $options;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
public function addPerson(string $fullName, ?string $informationUrl, string $image): int | bool
|
|
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
|
$person = new Person([
|
2023-06-21 16:17:11 +00:00
|
|
|
|
'created_by' => user_id(),
|
|
|
|
|
'updated_by' => user_id(),
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'full_name' => $fullName,
|
|
|
|
|
'unique_name' => slugify($fullName),
|
2021-02-10 16:20:01 +00:00
|
|
|
|
'information_url' => $informationUrl,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'image' => download_file($image),
|
2023-06-21 16:17:11 +00:00
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
|
2021-02-10 16:20:01 +00:00
|
|
|
|
return $this->insert($person);
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
|
/**
|
|
|
|
|
* @return Person[]
|
|
|
|
|
*/
|
|
|
|
|
public function getEpisodePersons(int $podcastId, int $episodeId): array
|
|
|
|
|
{
|
|
|
|
|
$cacheName = "podcast#{$podcastId}_episode#{$episodeId}_persons";
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
2022-06-13 16:30:34 +00:00
|
|
|
|
$this->builder()
|
2021-05-25 18:00:09 +00:00
|
|
|
|
->select(
|
|
|
|
|
'persons.*, episodes_persons.podcast_id as podcast_id, episodes_persons.episode_id as episode_id'
|
|
|
|
|
)
|
2021-05-17 17:11:23 +00:00
|
|
|
|
->distinct()
|
|
|
|
|
->join('episodes_persons', 'persons.id = episodes_persons.person_id')
|
|
|
|
|
->where('episodes_persons.episode_id', $episodeId)
|
2022-06-13 16:30:34 +00:00
|
|
|
|
->orderby('persons.full_name');
|
|
|
|
|
$found = $this->findAll();
|
2021-05-14 17:59:35 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->save($cacheName, $found, DECADE);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return Person[]
|
|
|
|
|
*/
|
|
|
|
|
public function getPodcastPersons(int $podcastId): array
|
|
|
|
|
{
|
|
|
|
|
$cacheName = "podcast#{$podcastId}_persons";
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
2022-06-13 16:30:34 +00:00
|
|
|
|
$this->builder()
|
2021-05-17 17:11:23 +00:00
|
|
|
|
->select('persons.*, podcasts_persons.podcast_id as podcast_id')
|
|
|
|
|
->distinct()
|
|
|
|
|
->join('podcasts_persons', 'persons.id=podcasts_persons.person_id')
|
|
|
|
|
->where('podcasts_persons.podcast_id', $podcastId)
|
2022-06-13 16:30:34 +00:00
|
|
|
|
->orderby('persons.full_name');
|
|
|
|
|
$found = $this->findAll();
|
2021-05-14 17:59:35 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->save($cacheName, $found, DECADE);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function addEpisodePerson(
|
|
|
|
|
int $podcastId,
|
|
|
|
|
int $episodeId,
|
|
|
|
|
int $personId,
|
2021-05-17 17:11:23 +00:00
|
|
|
|
string $groupSlug,
|
|
|
|
|
string $roleSlug
|
2022-09-28 14:00:05 +00:00
|
|
|
|
): bool {
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('episodes_persons')
|
|
|
|
|
->insert([
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'episode_id' => $episodeId,
|
|
|
|
|
'person_id' => $personId,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
'person_group' => $groupSlug,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'person_role' => $roleSlug,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-09-28 14:00:05 +00:00
|
|
|
|
public function addPodcastPerson(int $podcastId, int $personId, string $groupSlug, string $roleSlug): bool
|
|
|
|
|
{
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('podcasts_persons')
|
2023-06-21 16:17:11 +00:00
|
|
|
|
->ignore(true)
|
2021-05-19 16:35:13 +00:00
|
|
|
|
->insert([
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'person_id' => $personId,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
'person_group' => $groupSlug,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'person_role' => $roleSlug,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add persons to podcast
|
|
|
|
|
*
|
2023-11-15 14:20:41 +00:00
|
|
|
|
* @param int[] $personIds
|
|
|
|
|
* @param string[] $roles
|
2021-05-14 17:59:35 +00:00
|
|
|
|
*
|
|
|
|
|
* @return bool|int Number of rows inserted or FALSE on failure
|
|
|
|
|
*/
|
2021-05-31 13:32:33 +00:00
|
|
|
|
public function addPodcastPersons(int $podcastId, array $personIds = [], array $roles = []): int | bool
|
2021-05-19 16:35:13 +00:00
|
|
|
|
{
|
2021-05-31 13:32:33 +00:00
|
|
|
|
if ($personIds === []) {
|
2021-05-14 17:59:35 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->delete("podcast#{$podcastId}_persons");
|
|
|
|
|
(new PodcastModel())->clearCache([
|
|
|
|
|
'id' => $podcastId,
|
|
|
|
|
]);
|
2021-05-17 17:11:23 +00:00
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
|
$data = [];
|
2021-05-31 13:32:33 +00:00
|
|
|
|
foreach ($personIds as $personId) {
|
2021-05-17 17:11:23 +00:00
|
|
|
|
if ($roles === []) {
|
2023-11-15 14:20:41 +00:00
|
|
|
|
// add to default group (cast) and role (host), see https://podcastindex.org/namespace/1.0#person
|
2021-05-14 17:59:35 +00:00
|
|
|
|
$data[] = [
|
2023-11-15 14:20:41 +00:00
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'person_id' => $personId,
|
|
|
|
|
'person_group' => 'cast',
|
|
|
|
|
'person_role' => 'host',
|
2021-05-14 17:59:35 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
|
foreach ($roles as $role) {
|
|
|
|
|
$groupRole = explode(',', $role);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
$data[] = [
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'person_id' => $personId,
|
2021-05-17 17:11:23 +00:00
|
|
|
|
'person_group' => $groupRole[0],
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'person_role' => $groupRole[1],
|
2021-05-14 17:59:35 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('podcasts_persons')
|
2021-05-25 18:00:09 +00:00
|
|
|
|
->ignore(true)
|
2021-05-19 16:35:13 +00:00
|
|
|
|
->insertBatch($data);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add persons to episode
|
|
|
|
|
*
|
2021-05-20 17:53:25 +00:00
|
|
|
|
* @return string|bool Number of rows inserted or FALSE on failure
|
2021-05-14 17:59:35 +00:00
|
|
|
|
*/
|
2021-05-20 17:53:25 +00:00
|
|
|
|
public function removePersonFromPodcast(int $podcastId, int $personId): string | bool
|
2021-05-14 17:59:35 +00:00
|
|
|
|
{
|
2021-05-25 18:00:09 +00:00
|
|
|
|
cache()->deleteMatching("podcast#{$podcastId}_person#{$personId}*");
|
|
|
|
|
cache()
|
|
|
|
|
->delete("podcast#{$podcastId}_persons");
|
2021-05-31 13:32:33 +00:00
|
|
|
|
(new PodcastModel())->clearCache([
|
|
|
|
|
'id' => $podcastId,
|
|
|
|
|
]);
|
2021-05-25 18:00:09 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('podcasts_persons')
|
|
|
|
|
->delete([
|
|
|
|
|
'podcast_id' => $podcastId,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'person_id' => $personId,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Add persons to episode
|
|
|
|
|
*
|
|
|
|
|
* @param int[] $personIds
|
2023-11-15 14:20:41 +00:00
|
|
|
|
* @param string[] $roles
|
2021-05-19 16:35:13 +00:00
|
|
|
|
*
|
2021-05-14 17:59:35 +00:00
|
|
|
|
* @return bool|int Number of rows inserted or FALSE on failure
|
|
|
|
|
*/
|
2023-11-15 14:20:41 +00:00
|
|
|
|
public function addEpisodePersons(int $podcastId, int $episodeId, array $personIds, array $roles): bool | int
|
|
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
|
if ($personIds !== []) {
|
2021-05-25 18:00:09 +00:00
|
|
|
|
cache()
|
|
|
|
|
->delete("podcast#{$podcastId}_episode#{$episodeId}_persons");
|
2021-05-19 16:35:13 +00:00
|
|
|
|
(new EpisodeModel())->clearCache([
|
|
|
|
|
'id' => $episodeId,
|
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
|
|
|
|
|
$data = [];
|
|
|
|
|
foreach ($personIds as $personId) {
|
2023-11-15 14:20:41 +00:00
|
|
|
|
if ($roles === []) {
|
|
|
|
|
$data[] = [
|
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'episode_id' => $episodeId,
|
|
|
|
|
'person_id' => $personId,
|
|
|
|
|
'person_group' => 'cast',
|
|
|
|
|
'person_role' => 'host',
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($roles as $role) {
|
|
|
|
|
$groupRole = explode(',', $role);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
$data[] = [
|
2023-11-15 14:20:41 +00:00
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'episode_id' => $episodeId,
|
|
|
|
|
'person_id' => $personId,
|
|
|
|
|
'person_group' => $groupRole[0],
|
|
|
|
|
'person_role' => $groupRole[1],
|
2021-05-14 17:59:35 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('episodes_persons')
|
2021-05-25 18:00:09 +00:00
|
|
|
|
->ignore(true)
|
2021-05-19 16:35:13 +00:00
|
|
|
|
->insertBatch($data);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
2022-03-04 14:33:48 +00:00
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
2021-05-20 17:13:13 +00:00
|
|
|
|
public function removePersonFromEpisode(int $podcastId, int $episodeId, int $personId): bool | string
|
2021-05-19 16:35:13 +00:00
|
|
|
|
{
|
2021-05-25 18:00:09 +00:00
|
|
|
|
cache()->deleteMatching("podcast#{$podcastId}_episode#{$episodeId}_person#{$personId}*");
|
|
|
|
|
cache()
|
|
|
|
|
->delete("podcast#{$podcastId}_episode#{$episodeId}_persons");
|
2021-05-31 13:32:33 +00:00
|
|
|
|
(new EpisodeModel())->clearCache([
|
|
|
|
|
'id' => $episodeId,
|
|
|
|
|
]);
|
2021-05-25 18:00:09 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
return $this->db->table('episodes_persons')
|
|
|
|
|
->delete([
|
|
|
|
|
'podcast_id' => $podcastId,
|
|
|
|
|
'episode_id' => $episodeId,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'person_id' => $personId,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
]);
|
2021-05-14 17:59:35 +00:00
|
|
|
|
}
|
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
|
/**
|
2021-05-14 17:59:35 +00:00
|
|
|
|
* @param mixed[] $data
|
2021-05-19 16:35:13 +00:00
|
|
|
|
*
|
2021-05-06 14:00:48 +00:00
|
|
|
|
* @return array<string, array<string|int, mixed>>
|
|
|
|
|
*/
|
|
|
|
|
protected function clearCache(array $data): array
|
2021-02-10 16:20:01 +00:00
|
|
|
|
{
|
2021-06-09 12:40:22 +00:00
|
|
|
|
$personId = is_array($data['id']) ? $data['id'][0] : $data['id'];
|
2021-02-10 16:20:01 +00:00
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
|
|
|
|
->delete('person_options');
|
|
|
|
|
cache()
|
|
|
|
|
->delete("person#{$personId}");
|
2021-02-10 16:20:01 +00:00
|
|
|
|
|
2021-04-20 13:43:38 +00:00
|
|
|
|
// clear cache for every credits page
|
2021-05-19 16:35:13 +00:00
|
|
|
|
cache()
|
2021-05-31 13:32:33 +00:00
|
|
|
|
->deleteMatching('page_credits*');
|
2021-02-10 16:20:01 +00:00
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
}
|