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-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]);
|
2020-10-29 15:45:19 +00:00
|
|
|
return view('admin/podcast/analytics/listening_time', $data);
|
2020-10-19 10:33:23 +00:00
|
|
|
}
|
|
|
|
|
2020-11-02 18:15:19 +00:00
|
|
|
public function viewAnalyticsTimePeriods()
|
|
|
|
{
|
|
|
|
$data = ['podcast' => $this->podcast];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/podcast/analytics/time_periods', $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'),
|
2020-10-29 15:45:19 +00:00
|
|
|
'description_markdown' => $this->request->getPost('description'),
|
2020-07-16 10:08:23 +00:00
|
|
|
'image' => $this->request->getFile('image'),
|
2020-10-29 15:45:19 +00:00
|
|
|
'language_code' => $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-29 15:45:19 +00:00
|
|
|
'is_blocked' => $this->request->getPost('is_blocked') === 'yes',
|
|
|
|
'is_completed' => $this->request->getPost('complete') === 'yes',
|
|
|
|
'is_locked' => $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
|
|
|
}
|
|
|
|
|
|
|
|
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');
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->podcast->description_markdown = $this->request->getPost(
|
|
|
|
'description'
|
|
|
|
);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
$image = $this->request->getFile('image');
|
|
|
|
if ($image->isValid()) {
|
|
|
|
$this->podcast->image = $image;
|
|
|
|
}
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->podcast->language_code = $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-29 15:45:19 +00:00
|
|
|
$this->podcast->is_blocked =
|
|
|
|
$this->request->getPost('is_blocked') === 'yes';
|
|
|
|
$this->podcast->is_completed =
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->request->getPost('complete') === 'yes';
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->podcast->is_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
|
|
|
}
|
|
|
|
}
|