2020-08-27 12:05:44 +02:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2020-08-27 12:05:44 +02:00
|
|
|
/**
|
2022-02-19 17:06:11 +01:00
|
|
|
* @copyright 2020 Ad Aures
|
2020-08-27 12:05:44 +02:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 13:05:16 +02:00
|
|
|
namespace Modules\Admin\Controllers;
|
2020-08-27 12:05:44 +02:00
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
use App\Entities\Podcast;
|
2020-08-27 12:05:44 +02:00
|
|
|
use App\Models\PlatformModel;
|
|
|
|
use App\Models\PodcastModel;
|
2021-05-19 18:35:13 +02:00
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2020-08-27 12:05:44 +02:00
|
|
|
use Config\Services;
|
|
|
|
|
2021-05-12 16:00:25 +02:00
|
|
|
class PodcastPlatformController extends BaseController
|
2020-08-27 12:05:44 +02:00
|
|
|
{
|
2021-05-18 19:16:36 +02:00
|
|
|
protected ?Podcast $podcast;
|
2020-08-27 12:05:44 +02:00
|
|
|
|
2021-05-14 19:59:35 +02:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2020-08-27 12:05:44 +02:00
|
|
|
{
|
2021-08-11 17:47:23 +02:00
|
|
|
if ($params === []) {
|
2021-05-19 18:35:13 +02:00
|
|
|
return $this->{$method}();
|
2021-05-06 16:00:48 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 19:59:35 +02:00
|
|
|
if (
|
2021-06-09 14:40:22 +02:00
|
|
|
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
|
2021-05-14 19:59:35 +02:00
|
|
|
) {
|
2021-05-06 16:00:48 +02:00
|
|
|
unset($params[0]);
|
2021-05-19 18:35:13 +02:00
|
|
|
return $this->{$method}(...$params);
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-06 16:00:48 +02:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 19:59:35 +02:00
|
|
|
public function index(): string
|
2020-08-27 12:05:44 +02:00
|
|
|
{
|
2021-09-02 18:34:25 +02:00
|
|
|
return view('podcast/platforms\dashboard');
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-14 19:59:35 +02:00
|
|
|
public function platforms(string $platformType): string
|
2020-08-27 12:05:44 +02:00
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2020-11-18 18:17:56 +01:00
|
|
|
'platformType' => $platformType,
|
2021-06-09 14:40:22 +02:00
|
|
|
'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType),
|
2020-08-27 12:05:44 +02:00
|
|
|
];
|
|
|
|
|
2021-05-19 18:35:13 +02:00
|
|
|
replace_breadcrumb_params([
|
2022-10-15 13:22:08 +02:00
|
|
|
0 => $this->podcast->at_handle,
|
2021-05-19 18:35:13 +02:00
|
|
|
]);
|
2021-08-27 12:58:22 +02:00
|
|
|
|
2021-09-02 18:34:25 +02:00
|
|
|
return view('podcast/platforms', $data);
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
|
|
|
|
2021-05-19 18:35:13 +02:00
|
|
|
public function attemptPlatformsUpdate(string $platformType): RedirectResponse
|
|
|
|
{
|
2020-08-27 12:05:44 +02:00
|
|
|
$platformModel = new PlatformModel();
|
|
|
|
$validation = Services::validation();
|
|
|
|
|
2020-11-18 18:17:56 +01:00
|
|
|
$podcastsPlatformsData = [];
|
|
|
|
|
2020-08-27 12:05:44 +02:00
|
|
|
foreach (
|
|
|
|
$this->request->getPost('platforms')
|
2020-11-18 18:17:56 +01:00
|
|
|
as $platformSlug => $podcastPlatform
|
2020-08-27 12:05:44 +02:00
|
|
|
) {
|
2022-11-01 16:15:39 +01:00
|
|
|
$podcastPlatformUrl = trim((string) $podcastPlatform['url']);
|
2021-05-12 16:00:25 +02:00
|
|
|
if ($podcastPlatformUrl === null) {
|
2021-05-06 16:00:48 +02:00
|
|
|
continue;
|
|
|
|
}
|
2022-03-04 15:33:48 +01:00
|
|
|
|
2021-05-19 18:35:13 +02:00
|
|
|
if (! $validation->check($podcastPlatformUrl, 'validate_url')) {
|
2021-05-06 16:00:48 +02:00
|
|
|
continue;
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
2022-03-04 15:33:48 +01:00
|
|
|
|
2022-11-01 16:15:39 +01:00
|
|
|
$podcastPlatformAccountId = trim((string) $podcastPlatform['account_id']);
|
2021-05-06 16:00:48 +02:00
|
|
|
$podcastsPlatformsData[] = [
|
|
|
|
'platform_slug' => $platformSlug,
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'link_url' => $podcastPlatformUrl,
|
2022-11-01 16:15:39 +01:00
|
|
|
'account_id' => $podcastPlatformAccountId === '' ? null : $podcastPlatformAccountId,
|
2021-05-06 16:00:48 +02:00
|
|
|
'is_visible' =>
|
|
|
|
array_key_exists('visible', $podcastPlatform) &&
|
2021-05-19 18:35:13 +02:00
|
|
|
$podcastPlatform['visible'] === 'yes',
|
2021-10-20 16:22:58 +02:00
|
|
|
'is_on_embed' =>
|
|
|
|
array_key_exists('on_embed', $podcastPlatform,) && $podcastPlatform['on_embed'] === 'yes',
|
2021-05-06 16:00:48 +02:00
|
|
|
];
|
2020-08-27 12:05:44 +02:00
|
|
|
}
|
|
|
|
|
2021-06-08 11:52:11 +02:00
|
|
|
$platformModel->savePodcastPlatforms($this->podcast->id, $platformType, $podcastsPlatformsData);
|
2020-08-27 12:05:44 +02:00
|
|
|
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('message', lang('Platforms.messages.updateSuccess'));
|
|
|
|
}
|
|
|
|
|
2021-05-19 18:35:13 +02:00
|
|
|
public function removePodcastPlatform(string $platformSlug): RedirectResponse
|
|
|
|
{
|
2021-06-08 11:52:11 +02:00
|
|
|
(new PlatformModel())->removePodcastPlatform($this->podcast->id, $platformSlug);
|
2020-08-27 12:05:44 +02:00
|
|
|
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('message', lang('Platforms.messages.removeLinkSuccess'));
|
|
|
|
}
|
|
|
|
}
|