mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-11 18:56:42 +02:00
refactor(modules): extract castopod parts into a modules/ folder for a scalable HMVC structure
- create Admin, Analytics, Auth, Fediverse and Install modules in the root modules/ folder - rename ActivityPub to Fediverse
This commit is contained in:
parent
94872f2338
commit
5083cd2fda
268 changed files with 4221 additions and 2186 deletions
110
modules/Admin/Controllers/PodcastPlatformController.php
Normal file
110
modules/Admin/Controllers/PodcastPlatformController.php
Normal file
|
|
@ -0,0 +1,110 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Modules\Admin\Controllers;
|
||||
|
||||
use App\Entities\Podcast;
|
||||
use App\Models\PlatformModel;
|
||||
use App\Models\PodcastModel;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
use Config\Services;
|
||||
|
||||
class PodcastPlatformController extends BaseController
|
||||
{
|
||||
protected ?Podcast $podcast;
|
||||
|
||||
public function _remap(string $method, string ...$params): mixed
|
||||
{
|
||||
if ($params === []) {
|
||||
return $this->{$method}();
|
||||
}
|
||||
|
||||
if (
|
||||
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
|
||||
) {
|
||||
unset($params[0]);
|
||||
return $this->{$method}(...$params);
|
||||
}
|
||||
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
public function index(): string
|
||||
{
|
||||
return view('Modules\Admin\Views\podcast\platforms\dashboard');
|
||||
}
|
||||
|
||||
public function platforms(string $platformType): string
|
||||
{
|
||||
helper('form');
|
||||
|
||||
$data = [
|
||||
'podcast' => $this->podcast,
|
||||
'platformType' => $platformType,
|
||||
'platforms' => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType),
|
||||
];
|
||||
|
||||
replace_breadcrumb_params([
|
||||
0 => $this->podcast->title,
|
||||
]);
|
||||
return view('Modules\Admin\Views\podcast\platforms', $data);
|
||||
}
|
||||
|
||||
public function attemptPlatformsUpdate(string $platformType): RedirectResponse
|
||||
{
|
||||
$platformModel = new PlatformModel();
|
||||
$validation = Services::validation();
|
||||
|
||||
$podcastsPlatformsData = [];
|
||||
|
||||
foreach (
|
||||
$this->request->getPost('platforms')
|
||||
as $platformSlug => $podcastPlatform
|
||||
) {
|
||||
$podcastPlatformUrl = $podcastPlatform['url'];
|
||||
if ($podcastPlatformUrl === null) {
|
||||
continue;
|
||||
}
|
||||
if (! $validation->check($podcastPlatformUrl, 'validate_url')) {
|
||||
continue;
|
||||
}
|
||||
$podcastsPlatformsData[] = [
|
||||
'platform_slug' => $platformSlug,
|
||||
'podcast_id' => $this->podcast->id,
|
||||
'link_url' => $podcastPlatformUrl,
|
||||
'link_content' => $podcastPlatform['content'],
|
||||
'is_visible' =>
|
||||
array_key_exists('visible', $podcastPlatform) &&
|
||||
$podcastPlatform['visible'] === 'yes',
|
||||
'is_on_embeddable_player' =>
|
||||
array_key_exists(
|
||||
'on_embeddable_player',
|
||||
$podcastPlatform,
|
||||
) && $podcastPlatform['on_embeddable_player'] === 'yes',
|
||||
];
|
||||
}
|
||||
|
||||
$platformModel->savePodcastPlatforms($this->podcast->id, $platformType, $podcastsPlatformsData);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('message', lang('Platforms.messages.updateSuccess'));
|
||||
}
|
||||
|
||||
public function removePodcastPlatform(string $platformSlug): RedirectResponse
|
||||
{
|
||||
(new PlatformModel())->removePodcastPlatform($this->podcast->id, $platformSlug);
|
||||
|
||||
return redirect()
|
||||
->back()
|
||||
->with('message', lang('Platforms.messages.removeLinkSuccess'));
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue