2020-07-10 12:20:25 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Models\CategoryModel;
|
|
|
|
use App\Models\LanguageModel;
|
|
|
|
use App\Models\PodcastModel;
|
2020-08-21 08:41:09 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2020-07-31 16:05:10 +00:00
|
|
|
use Config\Services;
|
2020-08-21 08:41:09 +00:00
|
|
|
use League\HTMLToMarkdown\HtmlConverter;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
|
|
|
class Podcast extends BaseController
|
|
|
|
{
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast|null
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
|
|
|
if (count($params) > 0) {
|
2020-09-04 09:09:26 +00:00
|
|
|
if (
|
|
|
|
!($this->podcast = (new PodcastModel())->getPodcastById(
|
|
|
|
$params[0]
|
|
|
|
))
|
|
|
|
) {
|
2020-07-10 12:20:25 +00:00
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
public function list()
|
|
|
|
{
|
|
|
|
if (!has_permission('podcasts-list')) {
|
2020-08-18 16:31:28 +00:00
|
|
|
$data = [
|
|
|
|
'podcasts' => (new PodcastModel())->getUserPodcasts(user()->id),
|
|
|
|
];
|
|
|
|
} else {
|
|
|
|
$data = ['podcasts' => (new PodcastModel())->findAll()];
|
2020-07-27 09:35:34 +00:00
|
|
|
}
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
return view('admin/podcast/list', $data);
|
|
|
|
}
|
|
|
|
|
2020-07-27 09:35:34 +00:00
|
|
|
public function view()
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2020-07-27 09:35:34 +00:00
|
|
|
$data = ['podcast' => $this->podcast];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
2020-07-27 09:35:34 +00:00
|
|
|
return view('admin/podcast/view', $data);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2020-10-14 10:38:48 +00:00
|
|
|
public function viewAnalytics()
|
2020-10-06 15:39:27 +00:00
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
2020-10-14 10:38:48 +00:00
|
|
|
return view('admin/podcast/analytics/index', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewAnalyticsWebpages()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/webpages', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewAnalyticsLocations()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/locations', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function viewAnalyticsUniqueListeners()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/unique_listeners', $data);
|
|
|
|
}
|
|
|
|
|
2020-10-19 10:33:23 +00:00
|
|
|
public function viewAnalyticsListeningTime()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/listening-time', $data);
|
|
|
|
}
|
|
|
|
|
2020-10-14 10:38:48 +00:00
|
|
|
public function viewAnalyticsPlayers()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/players', $data);
|
2020-10-06 15:39:27 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
helper(['form', 'misc']);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$data = [
|
2020-08-14 18:27:57 +00:00
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
2020-08-04 11:25:22 +00:00
|
|
|
'browserLang' => get_browser_language(
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->request->getServer('HTTP_ACCEPT_LANGUAGE')
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
return view('admin/podcast/create', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptCreate()
|
|
|
|
{
|
|
|
|
$rules = [
|
2020-09-08 11:45:17 +00:00
|
|
|
'image' =>
|
|
|
|
'uploaded[image]|is_image[image]|ext_in[image,jpg,png]|min_dims[image,1400,1400]|is_image_squared[image]',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$podcast = new \App\Entities\Podcast([
|
|
|
|
'title' => $this->request->getPost('title'),
|
|
|
|
'name' => $this->request->getPost('name'),
|
|
|
|
'description' => $this->request->getPost('description'),
|
|
|
|
'image' => $this->request->getFile('image'),
|
|
|
|
'language' => $this->request->getPost('language'),
|
2020-08-21 08:41:09 +00:00
|
|
|
'category_id' => $this->request->getPost('category'),
|
2020-10-02 15:38:16 +00:00
|
|
|
'parental_advisory' =>
|
|
|
|
$this->request->getPost('parental_advisory') !== 'undefined'
|
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null,
|
2020-07-16 10:08:23 +00:00
|
|
|
'owner_name' => $this->request->getPost('owner_name'),
|
|
|
|
'owner_email' => $this->request->getPost('owner_email'),
|
2020-10-02 15:38:16 +00:00
|
|
|
'publisher' => $this->request->getPost('publisher'),
|
2020-07-16 10:08:23 +00:00
|
|
|
'type' => $this->request->getPost('type'),
|
|
|
|
'copyright' => $this->request->getPost('copyright'),
|
2020-10-02 15:38:16 +00:00
|
|
|
'block' => $this->request->getPost('block') === 'yes',
|
|
|
|
'complete' => $this->request->getPost('complete') === 'yes',
|
2020-10-20 13:46:00 +00:00
|
|
|
'lock' => $this->request->getPost('lock') === 'yes',
|
2020-08-14 18:27:57 +00:00
|
|
|
'created_by' => user(),
|
|
|
|
'updated_by' => user(),
|
2020-07-16 10:08:23 +00:00
|
|
|
]);
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
$db = \Config\Database::connect();
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$db->transStart();
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
if (!($newPodcastId = $podcastModel->insert($podcast, true))) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transRollback();
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $podcastModel->errors());
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
$authorize = Services::authorization();
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastAdminGroup = $authorize->group('podcast_admin');
|
2020-07-31 16:05:10 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastModel->addPodcastContributor(
|
2020-07-31 16:05:10 +00:00
|
|
|
user()->id,
|
2020-08-04 11:25:22 +00:00
|
|
|
$newPodcastId,
|
|
|
|
$podcastAdminGroup->id
|
2020-07-31 16:05:10 +00:00
|
|
|
);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
// set Podcast categories
|
|
|
|
(new CategoryModel())->setPodcastCategories(
|
|
|
|
$newPodcastId,
|
|
|
|
$this->request->getPost('other_categories')
|
|
|
|
);
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$db->transComplete();
|
|
|
|
|
2020-08-18 16:31:28 +00:00
|
|
|
return redirect()->route('podcast-view', [$newPodcastId]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2020-08-21 08:41:09 +00:00
|
|
|
public function import()
|
|
|
|
{
|
|
|
|
helper(['form', 'misc']);
|
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
2020-08-21 08:41:09 +00:00
|
|
|
|
|
|
|
$data = [
|
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
|
|
|
'browserLang' => get_browser_language(
|
|
|
|
$this->request->getServer('HTTP_ACCEPT_LANGUAGE')
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
return view('admin/podcast/import', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptImport()
|
|
|
|
{
|
|
|
|
helper(['media', 'misc']);
|
|
|
|
|
|
|
|
$rules = [
|
2020-10-08 16:38:30 +00:00
|
|
|
'imported_feed_url' => 'required|validate_url',
|
2020-09-08 11:45:17 +00:00
|
|
|
'season_number' => 'is_natural_no_zero|permit_empty',
|
|
|
|
'max_episodes' => 'is_natural_no_zero|permit_empty',
|
2020-08-21 08:41:09 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
$feed = simplexml_load_file(
|
|
|
|
$this->request->getPost('imported_feed_url')
|
|
|
|
);
|
|
|
|
} catch (\ErrorException $ex) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', [
|
|
|
|
$ex->getMessage() .
|
|
|
|
': <a href="' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
'" rel="noreferrer noopener" target="_blank">' .
|
|
|
|
$this->request->getPost('imported_feed_url') .
|
|
|
|
' ⎋</a>',
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
$nsItunes = $feed->channel[0]->children(
|
|
|
|
'http://www.itunes.com/dtds/podcast-1.0.dtd'
|
|
|
|
);
|
2020-10-20 13:46:00 +00:00
|
|
|
$nsPodcast = $feed->channel[0]->children(
|
|
|
|
'https://github.com/Podcastindex-org/podcast-namespace/blob/main/docs/1.0.md'
|
|
|
|
);
|
|
|
|
|
|
|
|
if ((string) $nsPodcast->locked === 'yes') {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', [lang('PodcastImport.lock_import')]);
|
|
|
|
}
|
2020-08-21 08:41:09 +00:00
|
|
|
|
|
|
|
$podcast = new \App\Entities\Podcast([
|
|
|
|
'name' => $this->request->getPost('name'),
|
|
|
|
'imported_feed_url' => $this->request->getPost('imported_feed_url'),
|
2020-10-06 15:39:27 +00:00
|
|
|
'new_feed_url' => base_url(
|
|
|
|
route_to('podcast_feed', $this->request->getPost('name'))
|
|
|
|
),
|
2020-08-21 08:41:09 +00:00
|
|
|
'title' => $feed->channel[0]->title,
|
|
|
|
'description' => $feed->channel[0]->description,
|
|
|
|
'image' => download_file($nsItunes->image->attributes()),
|
|
|
|
'language' => $this->request->getPost('language'),
|
|
|
|
'category_id' => $this->request->getPost('category'),
|
2020-10-02 15:38:16 +00:00
|
|
|
'parental_advisory' => empty($nsItunes->explicit)
|
|
|
|
? null
|
|
|
|
: (in_array($nsItunes->explicit, ['yes', 'true'])
|
|
|
|
? 'explicit'
|
2020-10-06 15:39:27 +00:00
|
|
|
: (in_array($nsItunes->explicit, ['no', 'false'])
|
|
|
|
? 'clean'
|
|
|
|
: null)),
|
2020-08-21 08:41:09 +00:00
|
|
|
'owner_name' => $nsItunes->owner->name,
|
|
|
|
'owner_email' => $nsItunes->owner->email,
|
2020-10-02 15:38:16 +00:00
|
|
|
'publisher' => $nsItunes->author,
|
2020-08-21 08:41:09 +00:00
|
|
|
'type' => empty($nsItunes->type) ? 'episodic' : $nsItunes->type,
|
|
|
|
'copyright' => $feed->channel[0]->copyright,
|
|
|
|
'block' => empty($nsItunes->block)
|
|
|
|
? false
|
2020-10-02 15:38:16 +00:00
|
|
|
: $nsItunes->block === 'yes',
|
2020-08-21 08:41:09 +00:00
|
|
|
'complete' => empty($nsItunes->complete)
|
|
|
|
? false
|
2020-10-02 15:38:16 +00:00
|
|
|
: $nsItunes->complete === 'yes',
|
2020-08-21 08:41:09 +00:00
|
|
|
'created_by' => user(),
|
|
|
|
'updated_by' => user(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
if (!($newPodcastId = $podcastModel->insert($podcast, true))) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$db->transRollback();
|
2020-08-21 08:41:09 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$authorize = Services::authorization();
|
|
|
|
$podcastAdminGroup = $authorize->group('podcast_admin');
|
|
|
|
|
|
|
|
$podcastModel->addPodcastContributor(
|
|
|
|
user()->id,
|
|
|
|
$newPodcastId,
|
|
|
|
$podcastAdminGroup->id
|
|
|
|
);
|
|
|
|
|
|
|
|
$converter = new HtmlConverter();
|
|
|
|
|
|
|
|
$numberItems = $feed->channel[0]->item->count();
|
|
|
|
$lastItem =
|
|
|
|
!empty($this->request->getPost('max_episodes')) &&
|
|
|
|
$this->request->getPost('max_episodes') < $numberItems
|
|
|
|
? $this->request->getPost('max_episodes')
|
|
|
|
: $numberItems;
|
|
|
|
|
|
|
|
$slugs = [];
|
|
|
|
|
|
|
|
// For each Episode:
|
|
|
|
for ($itemNumber = 1; $itemNumber <= $lastItem; $itemNumber++) {
|
|
|
|
$item = $feed->channel[0]->item[$numberItems - $itemNumber];
|
|
|
|
|
|
|
|
$nsItunes = $item->children(
|
|
|
|
'http://www.itunes.com/dtds/podcast-1.0.dtd'
|
|
|
|
);
|
|
|
|
|
|
|
|
$slug = slugify(
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->request->getPost('slug_field') === 'title'
|
2020-08-21 08:41:09 +00:00
|
|
|
? $item->title
|
|
|
|
: basename($item->link)
|
|
|
|
);
|
|
|
|
if (in_array($slug, $slugs)) {
|
|
|
|
$slugNumber = 2;
|
|
|
|
while (in_array($slug . '-' . $slugNumber, $slugs)) {
|
|
|
|
$slugNumber++;
|
|
|
|
}
|
|
|
|
$slug = $slug . '-' . $slugNumber;
|
|
|
|
}
|
|
|
|
$slugs[] = $slug;
|
|
|
|
|
|
|
|
$newEpisode = new \App\Entities\Episode([
|
|
|
|
'podcast_id' => $newPodcastId,
|
|
|
|
'guid' => empty($item->guid) ? null : $item->guid,
|
|
|
|
'title' => $item->title,
|
|
|
|
'slug' => $slug,
|
|
|
|
'enclosure' => download_file($item->enclosure->attributes()),
|
|
|
|
'description' => $converter->convert(
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->request->getPost('description_field') === 'summary'
|
2020-08-21 08:41:09 +00:00
|
|
|
? $nsItunes->summary
|
2020-10-02 15:38:16 +00:00
|
|
|
: ($this->request->getPost('description_field') ===
|
2020-08-21 08:41:09 +00:00
|
|
|
'subtitle_summary'
|
2020-10-02 15:38:16 +00:00
|
|
|
? $nsItunes->subtitle . "\n" . $nsItunes->summary
|
2020-08-21 08:41:09 +00:00
|
|
|
: $item->description)
|
|
|
|
),
|
2020-10-26 16:13:43 +00:00
|
|
|
'image' =>
|
|
|
|
!$nsItunes->image || empty($nsItunes->image->attributes())
|
|
|
|
? null
|
|
|
|
: download_file($nsItunes->image->attributes()),
|
2020-10-06 15:39:27 +00:00
|
|
|
'parental_advisory' => empty($nsItunes->explicit)
|
|
|
|
? null
|
|
|
|
: (in_array($nsItunes->explicit, ['yes', 'true'])
|
2020-10-02 15:38:16 +00:00
|
|
|
? 'explicit'
|
2020-10-06 15:39:27 +00:00
|
|
|
: (in_array($nsItunes->explicit, ['no', 'false'])
|
|
|
|
? 'clean'
|
|
|
|
: null)),
|
2020-09-08 11:45:17 +00:00
|
|
|
'number' =>
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->request->getPost('force_renumber') === 'yes'
|
2020-09-08 11:45:17 +00:00
|
|
|
? $itemNumber
|
|
|
|
: $nsItunes->episode,
|
2020-08-21 08:41:09 +00:00
|
|
|
'season_number' => empty(
|
|
|
|
$this->request->getPost('season_number')
|
|
|
|
)
|
|
|
|
? $nsItunes->season
|
|
|
|
: $this->request->getPost('season_number'),
|
|
|
|
'type' => empty($nsItunes->episodeType)
|
|
|
|
? 'full'
|
|
|
|
: $nsItunes->episodeType,
|
|
|
|
'block' => empty($nsItunes->block)
|
|
|
|
? false
|
2020-10-02 15:38:16 +00:00
|
|
|
: $nsItunes->block === 'yes',
|
2020-08-21 08:41:09 +00:00
|
|
|
'created_by' => user(),
|
|
|
|
'updated_by' => user(),
|
2020-10-22 17:41:59 +00:00
|
|
|
'published_at' => strtotime($item->pubDate),
|
2020-08-21 08:41:09 +00:00
|
|
|
]);
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
if (!$episodeModel->insert($newEpisode)) {
|
|
|
|
// FIXME: What shall we do?
|
2020-08-21 08:41:09 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
return redirect()->route('podcast-view', [$newPodcastId]);
|
2020-08-21 08:41:09 +00:00
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function edit()
|
|
|
|
{
|
2020-07-16 10:08:23 +00:00
|
|
|
helper('form');
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-09-04 09:09:26 +00:00
|
|
|
$languageOptions = (new LanguageModel())->getLanguageOptions();
|
|
|
|
$categoryOptions = (new CategoryModel())->getCategoryOptions();
|
2020-08-14 18:27:57 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2020-08-14 18:27:57 +00:00
|
|
|
'languageOptions' => $languageOptions,
|
|
|
|
'categoryOptions' => $categoryOptions,
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/edit', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
public function attemptEdit()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'image' =>
|
2020-09-08 11:45:17 +00:00
|
|
|
'is_image[image]|ext_in[image,jpg,png]|min_dims[image,1400,1400]|is_image_squared[image]',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->podcast->title = $this->request->getPost('title');
|
|
|
|
$this->podcast->name = $this->request->getPost('name');
|
|
|
|
$this->podcast->description = $this->request->getPost('description');
|
|
|
|
|
|
|
|
$image = $this->request->getFile('image');
|
|
|
|
if ($image->isValid()) {
|
|
|
|
$this->podcast->image = $image;
|
|
|
|
}
|
|
|
|
$this->podcast->language = $this->request->getPost('language');
|
2020-08-21 08:41:09 +00:00
|
|
|
$this->podcast->category_id = $this->request->getPost('category');
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->podcast->parental_advisory =
|
|
|
|
$this->request->getPost('parental_advisory') !== 'undefined'
|
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null;
|
|
|
|
$this->podcast->publisher = $this->request->getPost('publisher');
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->podcast->owner_name = $this->request->getPost('owner_name');
|
|
|
|
$this->podcast->owner_email = $this->request->getPost('owner_email');
|
|
|
|
$this->podcast->type = $this->request->getPost('type');
|
|
|
|
$this->podcast->copyright = $this->request->getPost('copyright');
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->podcast->block = $this->request->getPost('block') === 'yes';
|
|
|
|
$this->podcast->complete =
|
|
|
|
$this->request->getPost('complete') === 'yes';
|
2020-10-20 13:46:00 +00:00
|
|
|
$this->podcast->lock = $this->request->getPost('lock') === 'yes';
|
2020-08-14 18:27:57 +00:00
|
|
|
$this->updated_by = user();
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
$db = \Config\Database::connect();
|
|
|
|
$db->transStart();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (!$podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
$db->transRollback();
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $podcastModel->errors());
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
// set Podcast categories
|
|
|
|
(new CategoryModel())->setPodcastCategories(
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->request->getPost('other_categories')
|
|
|
|
);
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast-view', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
2020-10-05 08:44:51 +00:00
|
|
|
public function latestEpisodes(int $limit, int $podcast_id)
|
2020-10-02 15:38:16 +00:00
|
|
|
{
|
|
|
|
$episodes = (new EpisodeModel())
|
2020-10-05 08:44:51 +00:00
|
|
|
->where('podcast_id', $podcast_id)
|
2020-10-02 15:38:16 +00:00
|
|
|
->orderBy('created_at', 'desc')
|
|
|
|
->findAll($limit);
|
|
|
|
|
|
|
|
return view('admin/podcast/latest_episodes', ['episodes' => $episodes]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function delete()
|
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
(new PodcastModel())->delete($this->podcast->id);
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-14 18:27:57 +00:00
|
|
|
return redirect()->route('podcast-list');
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
}
|