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-07-31 16:05:10 +00:00
|
|
|
use Config\Services;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
|
|
|
class Podcast extends BaseController
|
|
|
|
{
|
|
|
|
protected ?\App\Entities\Podcast $podcast;
|
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
|
|
|
if (count($params) > 0) {
|
2020-07-31 16:05:10 +00:00
|
|
|
if (!($this->podcast = (new PodcastModel())->find($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 myPodcasts()
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
$data = [
|
2020-08-04 11:25:22 +00:00
|
|
|
'podcasts' => (new PodcastModel())->getUserPodcasts(user()->id),
|
2020-07-31 16:05:10 +00:00
|
|
|
];
|
2020-07-27 09:35:34 +00:00
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
return view('admin/podcast/list', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function list()
|
|
|
|
{
|
|
|
|
if (!has_permission('podcasts-list')) {
|
|
|
|
return redirect()->route('my_podcasts');
|
2020-07-27 09:35:34 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$data = ['podcasts' => (new PodcastModel())->findAll()];
|
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-07-27 09:35:34 +00:00
|
|
|
return view('admin/podcast/view', $data);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
helper(['form', 'misc']);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
$languageModel = new LanguageModel();
|
|
|
|
$categoryModel = new CategoryModel();
|
|
|
|
$data = [
|
|
|
|
'languages' => $languageModel->findAll(),
|
|
|
|
'categories' => $categoryModel->findAll(),
|
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')
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
echo view('admin/podcast/create', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptCreate()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'image' => 'uploaded[image]|is_image[image]|ext_in[image,jpg,png]',
|
|
|
|
];
|
|
|
|
|
|
|
|
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'),
|
|
|
|
'episode_description_footer' => $this->request->getPost(
|
|
|
|
'episode_description_footer'
|
|
|
|
),
|
|
|
|
'image' => $this->request->getFile('image'),
|
|
|
|
'language' => $this->request->getPost('language'),
|
|
|
|
'category' => $this->request->getPost('category'),
|
|
|
|
'explicit' => (bool) $this->request->getPost('explicit'),
|
|
|
|
'author_name' => $this->request->getPost('author_name'),
|
|
|
|
'author_email' => $this->request->getPost('author_email'),
|
|
|
|
'owner' => user(),
|
|
|
|
'owner_name' => $this->request->getPost('owner_name'),
|
|
|
|
'owner_email' => $this->request->getPost('owner_email'),
|
|
|
|
'type' => $this->request->getPost('type'),
|
|
|
|
'copyright' => $this->request->getPost('copyright'),
|
|
|
|
'block' => (bool) $this->request->getPost('block'),
|
|
|
|
'complete' => (bool) $this->request->getPost('complete'),
|
|
|
|
'custom_html_head' => $this->request->getPost('custom_html_head'),
|
|
|
|
]);
|
|
|
|
|
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-07-10 12:20:25 +00:00
|
|
|
$db->transComplete();
|
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
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('podcast_list');
|
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-07-16 10:08:23 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2020-08-04 11:25:22 +00:00
|
|
|
'languages' => (new LanguageModel())->findAll(),
|
|
|
|
'categories' => (new CategoryModel())->findAll(),
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
echo view('admin/podcast/edit', $data);
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
public function attemptEdit()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'image' =>
|
|
|
|
'uploaded[image]|is_image[image]|ext_in[image,jpg,png]|permit_empty',
|
|
|
|
];
|
|
|
|
|
|
|
|
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');
|
|
|
|
$this->podcast->episode_description_footer = $this->request->getPost(
|
|
|
|
'episode_description_footer'
|
|
|
|
);
|
|
|
|
|
|
|
|
$image = $this->request->getFile('image');
|
|
|
|
if ($image->isValid()) {
|
|
|
|
$this->podcast->image = $image;
|
|
|
|
}
|
|
|
|
$this->podcast->language = $this->request->getPost('language');
|
|
|
|
$this->podcast->category = $this->request->getPost('category');
|
|
|
|
$this->podcast->explicit = (bool) $this->request->getPost('explicit');
|
|
|
|
$this->podcast->author_name = $this->request->getPost('author_name');
|
|
|
|
$this->podcast->author_email = $this->request->getPost('author_email');
|
|
|
|
$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');
|
|
|
|
$this->podcast->block = (bool) $this->request->getPost('block');
|
|
|
|
$this->podcast->complete = (bool) $this->request->getPost('complete');
|
|
|
|
$this->podcast->custom_html_head = $this->request->getPost(
|
|
|
|
'custom_html_head'
|
|
|
|
);
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
if (!$podcastModel->save($this->podcast)) {
|
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
|
|
|
|
|
|
|
return redirect()->route('podcast_list');
|
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
|
|
|
|
|
|
|
return redirect()->route('podcast_list');
|
|
|
|
}
|
|
|
|
}
|