Commit 043f49c7 authored by Yassine Doghri's avatar Yassine Doghri
Browse files

feat: add platforms form in podcast settings

- set and remove platform links for a podcast
- remove unnecessary fields from platforms and platform_links tables
- add platforms svg icons to show in form
- update platform and auth seeders
- update svgo config for images
parent 9a5d5a15
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
plugins:
  - removeXMLNS: true
  - removeDimensions: true
  - addAttributesToSVGElement:
      attributes:
        - width: "1em"
        - height: "1em"
  - sortAttrs: true
  - prefixIds: true
+24 −0
Original line number Diff line number Diff line
@@ -196,6 +196,30 @@ $routes->group(
                        ]);
                    });
                });

                $routes->group('settings', function ($routes) {
                    $routes->get('/', 'PodcastSettings/$1', [
                        'as' => 'podcast-settings',
                    ]);
                    $routes->get('platforms', 'PodcastSettings::platforms/$1', [
                        'as' => 'platforms',
                        'filter' => 'permission:podcast-manage_platforms',
                    ]);
                    $routes->post(
                        'platforms',
                        'PodcastSettings::attemptPlatformsUpdate/$1',
                        ['filter' => 'permission:podcast-manage_platforms']
                    );

                    $routes->get(
                        'platforms/(:num)/remove-link',
                        'PodcastSettings::removePlatformLink/$1/$2',
                        [
                            'as' => 'platforms-remove',
                            'filter' => 'permission:podcast-manage_platforms',
                        ]
                    );
                });
            });
        });

+98 −0
Original line number Diff line number Diff line
<?php

/**
 * @copyright  2020 Podlibre
 * @license    https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
 * @link       https://castopod.org/
 */

namespace App\Controllers\Admin;

use App\Models\PlatformModel;
use App\Models\PodcastModel;
use Config\Services;

class PodcastSettings extends BaseController
{
    /**
     * @var \App\Entities\Podcast|null
     */
    protected $podcast;

    public function _remap($method, ...$params)
    {
        if (!($this->podcast = (new PodcastModel())->find($params[0]))) {
            throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
        }
        unset($params[0]);

        return $this->$method(...$params);
    }

    public function index()
    {
        return view('admin/podcast/settings/dashboard');
    }

    public function platforms()
    {
        helper('form');

        $data = [
            'podcast' => $this->podcast,
            'platforms' => (new PlatformModel())->getPlatformsWithLinks(),
        ];

        replace_breadcrumb_params([0 => $this->podcast->title]);
        return view('admin/podcast/settings/platforms', $data);
    }

    public function attemptPlatformsUpdate()
    {
        $platformModel = new PlatformModel();
        $validation = Services::validation();

        $platformLinksData = [];
        foreach (
            $this->request->getPost('platforms')
            as $platformName => $platformLink
        ) {
            $platformLinkUrl = $platformLink['url'];
            if (
                !empty($platformLinkUrl) &&
                $validation->check($platformLinkUrl, 'valid_url')
            ) {
                $platformId = $platformModel->getPlatformId($platformName);
                array_push($platformLinksData, [
                    'platform_id' => $platformId,
                    'podcast_id' => $this->podcast->id,
                    'link_url' => $platformLinkUrl,
                    'visible' => array_key_exists('visible', $platformLink)
                        ? $platformLink['visible'] == 'yes'
                        : false,
                ]);
            }
        }

        $platformModel->savePlatformLinks(
            $this->podcast->id,
            $platformLinksData
        );

        return redirect()
            ->back()
            ->with('message', lang('Platforms.messages.updateSuccess'));
    }

    public function removePlatformLink($platformId)
    {
        (new PlatformModel())->removePlatformLink(
            $this->podcast->id,
            $platformId
        );

        return redirect()
            ->back()
            ->with('message', lang('Platforms.messages.removeLinkSuccess'));
    }
}
+5 −31
Original line number Diff line number Diff line
@@ -29,47 +29,21 @@ class AddPlatforms extends Migration
                'constraint' => 191,
                'unique' => true,
            ],
            'home_url' => [
            'label' => [
                'type' => 'VARCHAR',
                'constraint' => 191,
            ],
            'submit_url' => [
                'type' => 'VARCHAR',
                'constraint' => 191,
                'null' => true,
            ],
            'iosapp_url' => [
            'home_url' => [
                'type' => 'VARCHAR',
                'constraint' => 191,
                'null' => true,
            ],
            'androidapp_url' => [
            'submit_url' => [
                'type' => 'VARCHAR',
                'constraint' => 191,
                'null' => true,
                'default' => null,
            ],
            'comment' => [
                'type' => 'TEXT',
                'null' => true,
            ],
            'display_by_default' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
            ],
            'ios_deeplink' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
            ],
            'android_deeplink' => [
                'type' => 'TINYINT',
                'constraint' => 1,
                'default' => 0,
                'comment' =>
                    'Android deeplinking for this platform: 0=No, 1=Manual, 2=Automatic.',
            ],
            'logo_file_name' => [
            'icon_filename' => [
                'type' => 'VARCHAR',
                'constraint' => 1024,
            ],
+1 −12
Original line number Diff line number Diff line
@@ -18,12 +18,6 @@ class AddPlatformLinks extends Migration
    public function up()
    {
        $this->forge->addField([
            'id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
                'unsigned' => true,
                'auto_increment' => true,
            ],
            'podcast_id' => [
                'type' => 'BIGINT',
                'constraint' => 20,
@@ -38,11 +32,6 @@ class AddPlatformLinks extends Migration
                'type' => 'VARCHAR',
                'constraint' => 191,
            ],
            'comment' => [
                'type' => 'TEXT',
                'comment' => 'Comment.',
                'null' => true,
            ],
            'visible' => [
                'type' => 'TINYINT',
                'constraint' => 1,
@@ -55,7 +44,7 @@ class AddPlatformLinks extends Migration
                'type' => 'TIMESTAMP',
            ],
        ]);
        $this->forge->addKey('id', true);
        $this->forge->addPrimaryKey(['podcast_id', 'platform_id']);
        $this->forge->addForeignKey('podcast_id', 'podcasts', 'id');
        $this->forge->addForeignKey('platform_id', 'platforms', 'id');
        $this->forge->createTable('platform_links');
Loading