2021-05-19 16:35:13 +00:00
|
|
|
|
<?php
|
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
|
* @copyright 2020 Ad Aures
|
2021-05-19 16:35:13 +00:00
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
|
* @link https://castopod.org/
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
namespace App\Controllers;
|
|
|
|
|
|
|
|
|
|
use App\Entities\Page;
|
|
|
|
|
use App\Models\CreditModel;
|
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
|
|
|
|
|
|
class CreditsController extends BaseController
|
|
|
|
|
{
|
|
|
|
|
public function index(): string
|
|
|
|
|
{
|
|
|
|
|
$locale = service('request')
|
|
|
|
|
->getLocale();
|
|
|
|
|
|
2022-01-23 19:00:08 +00:00
|
|
|
|
$cacheName = implode(
|
|
|
|
|
'_',
|
2022-10-15 11:22:08 +00:00
|
|
|
|
array_filter(['page', 'credits', $locale, auth()->loggedIn() ? 'authenticated' : null]),
|
2022-01-23 19:00:08 +00:00
|
|
|
|
);
|
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
|
if (! ($found = cache($cacheName))) {
|
|
|
|
|
$page = new Page([
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'title' => lang('Person.credits', [], $locale),
|
|
|
|
|
'slug' => 'credits',
|
2021-05-19 16:35:13 +00:00
|
|
|
|
'content_markdown' => '',
|
|
|
|
|
]);
|
|
|
|
|
|
2022-01-23 19:00:08 +00:00
|
|
|
|
$allPodcasts = (new PodcastModel())->findAll();
|
2021-05-19 16:35:13 +00:00
|
|
|
|
$allCredits = (new CreditModel())->findAll();
|
|
|
|
|
|
|
|
|
|
// Unlike the carpenter, we make a tree from a table:
|
|
|
|
|
$personGroup = null;
|
|
|
|
|
$personId = null;
|
|
|
|
|
$personRole = null;
|
|
|
|
|
$credits = [];
|
|
|
|
|
foreach ($allCredits as $credit) {
|
|
|
|
|
if ($personGroup !== $credit->person_group) {
|
|
|
|
|
$personGroup = $credit->person_group;
|
|
|
|
|
$personId = $credit->person_id;
|
|
|
|
|
$personRole = $credit->person_role;
|
|
|
|
|
$credits[$personGroup] = [
|
|
|
|
|
'group_label' => $credit->group_label,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'persons' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
$personId => [
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'full_name' => $credit->person->full_name,
|
|
|
|
|
'thumbnail_url' => get_avatar_url($credit->person, 'thumbnail'),
|
|
|
|
|
'information_url' => $credit->person->information_url,
|
|
|
|
|
'roles' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
$personRole => [
|
|
|
|
|
'role_label' => $credit->role_label,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'is_in' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
[
|
|
|
|
|
'link' => $credit->episode_id
|
|
|
|
|
? $credit->episode->link
|
|
|
|
|
: $credit->podcast->link,
|
|
|
|
|
'title' => $credit->episode_id
|
|
|
|
|
? (count($allPodcasts) > 1
|
2022-03-15 15:23:13 +00:00
|
|
|
|
? esc($credit->podcast->title) . ' › '
|
2021-05-19 16:35:13 +00:00
|
|
|
|
: '') .
|
2022-03-15 15:23:13 +00:00
|
|
|
|
esc($credit->episode->title) .
|
2021-05-19 16:35:13 +00:00
|
|
|
|
episode_numbering(
|
|
|
|
|
$credit->episode
|
|
|
|
|
->number,
|
|
|
|
|
$credit->episode
|
|
|
|
|
->season_number,
|
|
|
|
|
'text-xs ml-2',
|
|
|
|
|
true,
|
|
|
|
|
)
|
2022-03-15 15:23:13 +00:00
|
|
|
|
: esc($credit->podcast->title),
|
2021-05-19 16:35:13 +00:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
} elseif ($personId !== $credit->person_id) {
|
|
|
|
|
$personId = $credit->person_id;
|
|
|
|
|
$personRole = $credit->person_role;
|
|
|
|
|
$credits[$personGroup]['persons'][$personId] = [
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'full_name' => $credit->person->full_name,
|
|
|
|
|
'thumbnail_url' => get_avatar_url($credit->person, 'thumbnail'),
|
2021-05-19 16:35:13 +00:00
|
|
|
|
'information_url' => $credit->person->information_url,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'roles' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
$personRole => [
|
|
|
|
|
'role_label' => $credit->role_label,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'is_in' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
[
|
|
|
|
|
'link' => $credit->episode_id
|
|
|
|
|
? $credit->episode->link
|
|
|
|
|
: $credit->podcast->link,
|
|
|
|
|
'title' => $credit->episode_id
|
|
|
|
|
? (count($allPodcasts) > 1
|
2022-03-15 15:23:13 +00:00
|
|
|
|
? esc($credit->podcast->title) . ' › '
|
2021-05-19 16:35:13 +00:00
|
|
|
|
: '') .
|
2022-03-15 15:23:13 +00:00
|
|
|
|
esc($credit->episode->title) .
|
2021-05-19 16:35:13 +00:00
|
|
|
|
episode_numbering(
|
|
|
|
|
$credit->episode->number,
|
|
|
|
|
$credit->episode
|
|
|
|
|
->season_number,
|
|
|
|
|
'text-xs ml-2',
|
|
|
|
|
true,
|
|
|
|
|
)
|
2022-03-15 15:23:13 +00:00
|
|
|
|
: esc($credit->podcast->title),
|
2021-05-19 16:35:13 +00:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
} elseif ($personRole !== $credit->person_role) {
|
|
|
|
|
$personRole = $credit->person_role;
|
|
|
|
|
$credits[$personGroup]['persons'][$personId]['roles'][
|
|
|
|
|
$personRole
|
|
|
|
|
] = [
|
|
|
|
|
'role_label' => $credit->role_label,
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'is_in' => [
|
2021-05-19 16:35:13 +00:00
|
|
|
|
[
|
|
|
|
|
'link' => $credit->episode_id
|
|
|
|
|
? $credit->episode->link
|
|
|
|
|
: $credit->podcast->link,
|
|
|
|
|
'title' => $credit->episode_id
|
|
|
|
|
? (count($allPodcasts) > 1
|
2022-03-15 15:23:13 +00:00
|
|
|
|
? esc($credit->podcast->title) . ' › '
|
2021-05-19 16:35:13 +00:00
|
|
|
|
: '') .
|
2022-03-15 15:23:13 +00:00
|
|
|
|
esc($credit->episode->title) .
|
2021-05-19 16:35:13 +00:00
|
|
|
|
episode_numbering(
|
|
|
|
|
$credit->episode->number,
|
|
|
|
|
$credit->episode->season_number,
|
|
|
|
|
'text-xs ml-2',
|
|
|
|
|
true,
|
|
|
|
|
)
|
2022-03-15 15:23:13 +00:00
|
|
|
|
: esc($credit->podcast->title),
|
2021-05-19 16:35:13 +00:00
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
} else {
|
|
|
|
|
$credits[$personGroup]['persons'][$personId]['roles'][
|
|
|
|
|
$personRole
|
|
|
|
|
]['is_in'][] = [
|
|
|
|
|
'link' => $credit->episode_id
|
|
|
|
|
? $credit->episode->link
|
|
|
|
|
: $credit->podcast->link,
|
|
|
|
|
'title' => $credit->episode_id
|
|
|
|
|
? (count($allPodcasts) > 1
|
2022-03-15 15:23:13 +00:00
|
|
|
|
? esc($credit->podcast->title) . ' › '
|
2021-05-19 16:35:13 +00:00
|
|
|
|
: '') .
|
2022-03-15 15:23:13 +00:00
|
|
|
|
esc($credit->episode->title) .
|
2021-05-19 16:35:13 +00:00
|
|
|
|
episode_numbering(
|
|
|
|
|
$credit->episode->number,
|
|
|
|
|
$credit->episode->season_number,
|
|
|
|
|
'text-xs ml-2',
|
|
|
|
|
true,
|
|
|
|
|
)
|
2022-03-15 15:23:13 +00:00
|
|
|
|
: esc($credit->podcast->title),
|
2021-05-19 16:35:13 +00:00
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$data = [
|
2021-11-12 16:31:35 +00:00
|
|
|
|
'metatags' => get_page_metatags($page),
|
2023-06-12 14:47:38 +00:00
|
|
|
|
'page' => $page,
|
|
|
|
|
'credits' => $credits,
|
2021-05-19 16:35:13 +00:00
|
|
|
|
];
|
|
|
|
|
|
2021-11-12 16:31:35 +00:00
|
|
|
|
$found = view('pages/credits', $data);
|
2021-05-19 16:35:13 +00:00
|
|
|
|
|
|
|
|
|
cache()
|
|
|
|
|
->save($cacheName, $found, DECADE);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $found;
|
|
|
|
|
}
|
|
|
|
|
}
|