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