Skip to content
Snippets Groups Projects
PodcastPlatformController.php 3.36 KiB
Newer Older
  • Learn to ignore specific revisions
  •  * @copyright  2020 Ad Aures
    
     * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
     * @link       https://castopod.org/
     */
    
    
    use App\Models\PlatformModel;
    use App\Models\PodcastModel;
    
    use CodeIgniter\Exceptions\PageNotFoundException;
    use CodeIgniter\HTTP\RedirectResponse;
    
    use Config\Services;
    
    
    class PodcastPlatformController extends BaseController
    
        public function _remap(string $method, string ...$params): mixed
    
            if ($params === []) {
    
                ($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) instanceof Podcast
    
        public function index(): string
    
            return view('podcast/platforms\dashboard');
    
        public function platforms(string $platformType): string
    
                'podcast'      => $this->podcast,
    
                'platforms'    => (new PlatformModel())->getPlatformsWithLinks($this->podcast->id, $platformType),
    
            return view('podcast/platforms', $data);
    
        public function attemptPlatformsUpdate(string $platformType): RedirectResponse
        {
    
            $platformModel = new PlatformModel();
            $validation = Services::validation();
    
    
            foreach (
                $this->request->getPost('platforms')
    
                as $platformSlug => $podcastPlatform
    
                $podcastPlatformUrl = trim((string) $podcastPlatform['url']);
    
                if ($podcastPlatformUrl === null) {
    
                if (! $validation->check(htmlentities($podcastPlatformUrl), 'valid_url_strict')) {
    
                $podcastPlatformAccountId = trim((string) $podcastPlatform['account_id']);
    
                $podcastsPlatformsData[] = [
                    'platform_slug' => $platformSlug,
    
                    'podcast_id'    => $this->podcast->id,
                    'link_url'      => $podcastPlatformUrl,
                    'account_id'    => $podcastPlatformAccountId === '' ? null : $podcastPlatformAccountId,
                    'is_visible'    => array_key_exists('visible', $podcastPlatform) &&
    
                        $podcastPlatform['visible'] === 'yes',
    
                    'is_on_embed' => array_key_exists(
                        'on_embed',
                        $podcastPlatform
                    ) && $podcastPlatform['on_embed'] === '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'));
        }
    }