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/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
use App\Entities\Episode as EpisodeEntity;
|
2021-04-02 17:20:02 +00:00
|
|
|
use App\Entities\Note;
|
2020-07-10 12:20:25 +00:00
|
|
|
use App\Models\EpisodeModel;
|
2021-04-02 17:20:02 +00:00
|
|
|
use App\Models\NoteModel;
|
2020-07-10 12:20:25 +00:00
|
|
|
use App\Models\PodcastModel;
|
2020-12-07 20:13:46 +00:00
|
|
|
use App\Models\SoundbiteModel;
|
2020-10-22 17:41:59 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
|
|
|
class Episode extends BaseController
|
|
|
|
{
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Podcast
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Episode|null
|
2020-08-05 17:26:04 +00:00
|
|
|
*/
|
|
|
|
protected $episode;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-12-07 20:13:46 +00:00
|
|
|
/**
|
2021-05-06 14:00:48 +00:00
|
|
|
* @var Soundbite|null
|
2020-12-07 20:13:46 +00:00
|
|
|
*/
|
|
|
|
protected $soundbites;
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (
|
|
|
|
!($this->podcast = (new PodcastModel())->getPodcastById($params[0]))
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
|
|
|
if (count($params) > 1) {
|
|
|
|
if (
|
2020-08-04 11:25:22 +00:00
|
|
|
!($this->episode = (new EpisodeModel())
|
2020-07-10 12:20:25 +00:00
|
|
|
->where([
|
2020-07-16 10:08:23 +00:00
|
|
|
'id' => $params[1],
|
|
|
|
'podcast_id' => $params[0],
|
2020-07-10 12:20:25 +00:00
|
|
|
])
|
|
|
|
->first())
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
2020-12-07 20:13:46 +00:00
|
|
|
|
|
|
|
unset($params[1]);
|
|
|
|
unset($params[0]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2020-12-07 20:13:46 +00:00
|
|
|
return $this->$method(...$params);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function list()
|
|
|
|
{
|
2020-10-02 15:38:16 +00:00
|
|
|
$episodes = (new EpisodeModel())
|
|
|
|
->where('podcast_id', $this->podcast->id)
|
|
|
|
->orderBy('created_at', 'desc');
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2020-10-02 15:38:16 +00:00
|
|
|
'episodes' => $episodes->paginate(10),
|
|
|
|
'pager' => $episodes->pager,
|
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-10 12:20:25 +00:00
|
|
|
return view('admin/episode/list', $data);
|
|
|
|
}
|
|
|
|
|
2020-07-27 09:35:34 +00:00
|
|
|
public function view()
|
|
|
|
{
|
2020-10-02 15:38:16 +00:00
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
2020-07-27 09:35:34 +00:00
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
2020-07-27 09:35:34 +00:00
|
|
|
return view('admin/episode/view', $data);
|
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function create()
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
2020-07-16 10:08:23 +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,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/create', $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 attemptCreate()
|
|
|
|
{
|
|
|
|
$rules = [
|
2021-05-03 17:39:58 +00:00
|
|
|
'audio_file' => 'uploaded[audio_file]|ext_in[audio_file,mp3,m4a]',
|
2020-07-16 10:08:23 +00:00
|
|
|
'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]',
|
2021-05-03 17:39:58 +00:00
|
|
|
'transcript_file' =>
|
|
|
|
'ext_in[transcript,txt,html,srt,json]|permit_empty',
|
|
|
|
'chapters_file' => 'ext_in[chapters,json]|permit_empty',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-05-06 14:00:48 +00:00
|
|
|
$newEpisode = new EpisodeEntity([
|
2020-07-16 10:08:23 +00:00
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'title' => $this->request->getPost('title'),
|
|
|
|
'slug' => $this->request->getPost('slug'),
|
2020-10-12 15:57:01 +00:00
|
|
|
'guid' => '',
|
2021-05-03 17:39:58 +00:00
|
|
|
'audio_file' => $this->request->getFile('audio_file'),
|
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-12-23 14:11:38 +00:00
|
|
|
'location' => $this->request->getPost('location_name'),
|
2020-11-24 20:18:08 +00:00
|
|
|
'transcript' => $this->request->getFile('transcript'),
|
|
|
|
'chapters' => $this->request->getFile('chapters'),
|
2020-10-02 15:38:16 +00:00
|
|
|
'parental_advisory' =>
|
|
|
|
$this->request->getPost('parental_advisory') !== 'undefined'
|
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null,
|
2020-10-29 17:25:15 +00:00
|
|
|
'number' => $this->request->getPost('episode_number')
|
|
|
|
? $this->request->getPost('episode_number')
|
|
|
|
: null,
|
|
|
|
'season_number' => $this->request->getPost('season_number')
|
|
|
|
? $this->request->getPost('season_number')
|
|
|
|
: null,
|
2020-07-16 10:08:23 +00:00
|
|
|
'type' => $this->request->getPost('type'),
|
2020-10-29 15:45:19 +00:00
|
|
|
'is_blocked' => $this->request->getPost('block') == 'yes',
|
2021-03-19 16:12:36 +00:00
|
|
|
'custom_rss_string' => $this->request->getPost('custom_rss'),
|
2021-04-02 17:20:02 +00:00
|
|
|
'created_by' => user()->id,
|
|
|
|
'updated_by' => user()->id,
|
|
|
|
'published_at' => null,
|
2020-07-16 10:08:23 +00:00
|
|
|
]);
|
|
|
|
|
2021-05-03 17:39:58 +00:00
|
|
|
$transcriptChoice = $this->request->getPost('transcript-choice');
|
|
|
|
if (
|
|
|
|
$transcriptChoice === 'upload-file' &&
|
|
|
|
($transcriptFile = $this->request->getFile('transcript_file'))
|
|
|
|
) {
|
|
|
|
$newEpisode->transcript_file = $transcriptFile;
|
|
|
|
} elseif ($transcriptChoice === 'remote-url') {
|
|
|
|
$newEpisode->transcript_file_remote_url = $this->request->getPost(
|
|
|
|
'transcript_file_remote_url',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$chaptersChoice = $this->request->getPost('chapters-choice');
|
|
|
|
if (
|
|
|
|
$chaptersChoice === 'upload-file' &&
|
|
|
|
($chaptersFile = $this->request->getFile('chapters_file'))
|
|
|
|
) {
|
|
|
|
$newEpisode->chapters_file = $chaptersFile;
|
|
|
|
} elseif ($chaptersChoice === 'remote-url') {
|
|
|
|
$newEpisode->chapters_file_remote_url = $this->request->getPost(
|
|
|
|
'chapters_file_remote_url',
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$episodeModel = new EpisodeModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
if (!($newEpisodeId = $episodeModel->insert($newEpisode, true))) {
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $episodeModel->errors());
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
// update podcast's episode_description_footer_markdown if changed
|
2020-10-02 15:38:16 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
|
|
|
|
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
|
2021-04-02 17:20:02 +00:00
|
|
|
'description_footer',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
if (!$podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$newEpisodeId,
|
|
|
|
]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$data = [
|
2020-10-02 15:38:16 +00:00
|
|
|
'podcast' => $this->podcast,
|
2020-07-16 10:08:23 +00:00
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/edit', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptEdit()
|
|
|
|
{
|
|
|
|
$rules = [
|
2021-05-03 17:39:58 +00:00
|
|
|
'audio_file' =>
|
|
|
|
'uploaded[audio_file]|ext_in[audio_file,mp3,m4a]|permit_empty',
|
2020-07-16 10:08:23 +00:00
|
|
|
'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]',
|
2021-05-03 17:39:58 +00:00
|
|
|
'transcript_file' =>
|
|
|
|
'ext_in[transcript_file,txt,html,srt,json]|permit_empty',
|
|
|
|
'chapters_file' => 'ext_in[chapters_file,json]|permit_empty',
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->episode->title = $this->request->getPost('title');
|
|
|
|
$this->episode->slug = $this->request->getPost('slug');
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->episode->description_markdown = $this->request->getPost(
|
2021-04-02 17:20:02 +00:00
|
|
|
'description',
|
2020-10-29 15:45:19 +00:00
|
|
|
);
|
2020-12-23 14:11:38 +00:00
|
|
|
$this->episode->location = $this->request->getPost('location_name');
|
2020-10-02 15:38:16 +00:00
|
|
|
$this->episode->parental_advisory =
|
|
|
|
$this->request->getPost('parental_advisory') !== 'undefined'
|
|
|
|
? $this->request->getPost('parental_advisory')
|
|
|
|
: null;
|
2020-10-29 17:25:15 +00:00
|
|
|
$this->episode->number = $this->request->getPost('episode_number')
|
|
|
|
? $this->request->getPost('episode_number')
|
|
|
|
: null;
|
2020-07-16 10:08:23 +00:00
|
|
|
$this->episode->season_number = $this->request->getPost('season_number')
|
|
|
|
? $this->request->getPost('season_number')
|
|
|
|
: null;
|
|
|
|
$this->episode->type = $this->request->getPost('type');
|
2020-10-29 15:45:19 +00:00
|
|
|
$this->episode->is_blocked = $this->request->getPost('block') == 'yes';
|
2021-03-19 16:12:36 +00:00
|
|
|
$this->episode->custom_rss_string = $this->request->getPost(
|
2021-04-02 17:20:02 +00:00
|
|
|
'custom_rss',
|
2021-03-19 16:12:36 +00:00
|
|
|
);
|
2020-12-09 17:52:30 +00:00
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
$this->episode->updated_by = user()->id;
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-05-03 17:39:58 +00:00
|
|
|
$audioFile = $this->request->getFile('audio_file');
|
|
|
|
if ($audioFile) {
|
|
|
|
$this->episode->audio_file = $audioFile;
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
$image = $this->request->getFile('image');
|
|
|
|
if ($image) {
|
|
|
|
$this->episode->image = $image;
|
|
|
|
}
|
2021-05-03 17:39:58 +00:00
|
|
|
|
|
|
|
$transcriptChoice = $this->request->getPost('transcript-choice');
|
|
|
|
if ($transcriptChoice === 'upload-file') {
|
|
|
|
$transcriptFile = $this->request->getFile('transcript_file');
|
|
|
|
if ($transcriptFile->isValid()) {
|
|
|
|
$this->episode->transcript_file = $transcriptFile;
|
|
|
|
$this->episode->transcript_file_remote_url = null;
|
|
|
|
}
|
|
|
|
} elseif ($transcriptChoice === 'remote-url') {
|
|
|
|
if (
|
|
|
|
$transcriptFileRemoteUrl = $this->request->getPost(
|
|
|
|
'transcript_file_remote_url',
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
if (
|
|
|
|
($transcriptFile = $this->episode->transcript_file) &&
|
|
|
|
!empty($transcriptFile)
|
|
|
|
) {
|
|
|
|
unlink($transcriptFile);
|
|
|
|
$this->episode->transcript_file_path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->episode->transcript_file_remote_url = $transcriptFileRemoteUrl;
|
2020-11-24 20:18:08 +00:00
|
|
|
}
|
2021-05-03 17:39:58 +00:00
|
|
|
|
|
|
|
$chaptersChoice = $this->request->getPost('chapters-choice');
|
|
|
|
if ($chaptersChoice === 'upload-file') {
|
|
|
|
$chaptersFile = $this->request->getFile('chapters_file');
|
|
|
|
if ($chaptersFile->isValid()) {
|
|
|
|
$this->episode->chapters_file = $chaptersFile;
|
|
|
|
$this->episode->chapters_file_remote_url = null;
|
|
|
|
}
|
|
|
|
} elseif ($chaptersChoice === 'remote-url') {
|
|
|
|
if (
|
|
|
|
$chaptersFileRemoteUrl = $this->request->getPost(
|
|
|
|
'chapters_file_remote_url',
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
if (
|
|
|
|
($chaptersFile = $this->episode->chapters_file) &&
|
|
|
|
!empty($chaptersFile)
|
|
|
|
) {
|
|
|
|
unlink($chaptersFile);
|
|
|
|
$this->episode->chapters_file_path = null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
$this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl;
|
2020-11-24 20:18:08 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$episodeModel = new EpisodeModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
2020-07-16 10:08:23 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $episodeModel->errors());
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
// update podcast's episode_description_footer_markdown if changed
|
|
|
|
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
|
2021-04-02 17:20:02 +00:00
|
|
|
'description_footer',
|
2020-10-02 15:38:16 +00:00
|
|
|
);
|
|
|
|
|
2020-10-29 15:45:19 +00:00
|
|
|
if ($this->podcast->hasChanged('episode_description_footer_markdown')) {
|
2020-10-02 15:38:16 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
|
|
|
if (!$podcastModel->update($this->podcast->id, $this->podcast)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2020-11-24 20:18:08 +00:00
|
|
|
public function transcriptDelete()
|
|
|
|
{
|
2021-05-03 17:39:58 +00:00
|
|
|
unlink($this->episode->transcript_file);
|
|
|
|
$this->episode->transcript_file_path = null;
|
2020-11-24 20:18:08 +00:00
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function chaptersDelete()
|
|
|
|
{
|
2021-05-03 17:39:58 +00:00
|
|
|
unlink($this->episode->chapters_file);
|
|
|
|
$this->episode->chapters_file_path = null;
|
2020-11-24 20:18:08 +00:00
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-04-02 17:20:02 +00:00
|
|
|
public function publish()
|
|
|
|
{
|
|
|
|
if ($this->episode->publication_status === 'not_published') {
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/publish', $data);
|
|
|
|
} else {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptPublish()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' =>
|
|
|
|
'valid_date[Y-m-d H:i]|permit_empty',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
$newNote = new Note([
|
|
|
|
'actor_id' => $this->podcast->actor_id,
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
'message' => $this->request->getPost('message'),
|
|
|
|
'created_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$publishMethod = $this->request->getPost('publication_method');
|
|
|
|
if ($publishMethod === 'schedule') {
|
|
|
|
$scheduledPublicationDate = $this->request->getPost(
|
|
|
|
'scheduled_publication_date',
|
|
|
|
);
|
|
|
|
if ($scheduledPublicationDate) {
|
|
|
|
$scheduledDateUTC = Time::createFromFormat(
|
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone('UTC');
|
|
|
|
$this->episode->published_at = $scheduledDateUTC;
|
|
|
|
$newNote->published_at = $scheduledDateUTC;
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', 'Schedule date must be set!');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$dateNow = Time::now();
|
|
|
|
$this->episode->published_at = $dateNow;
|
|
|
|
$newNote->published_at = $dateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
$noteModel = new NoteModel();
|
|
|
|
if (!$noteModel->addNote($newNote)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $noteModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function publishEdit()
|
|
|
|
{
|
|
|
|
if ($this->episode->publication_status === 'scheduled') {
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
'note' => (new NoteModel())
|
|
|
|
->where([
|
|
|
|
'actor_id' => $this->podcast->actor_id,
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
])
|
|
|
|
->first(),
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/publish_edit', $data);
|
|
|
|
} else {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptPublishEdit()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'note_id' => 'required',
|
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' =>
|
|
|
|
'valid_date[Y-m-d H:i]|permit_empty',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
$note = (new NoteModel())->getNoteById(
|
|
|
|
$this->request->getPost('note_id'),
|
|
|
|
);
|
|
|
|
$note->message = $this->request->getPost('message');
|
|
|
|
|
|
|
|
$publishMethod = $this->request->getPost('publication_method');
|
|
|
|
if ($publishMethod === 'schedule') {
|
|
|
|
$scheduledPublicationDate = $this->request->getPost(
|
|
|
|
'scheduled_publication_date',
|
|
|
|
);
|
|
|
|
if ($scheduledPublicationDate) {
|
|
|
|
$scheduledDateUTC = Time::createFromFormat(
|
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone('UTC');
|
|
|
|
$this->episode->published_at = $scheduledDateUTC;
|
|
|
|
$note->published_at = $scheduledDateUTC;
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', 'Schedule date must be set!');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$dateNow = Time::now();
|
|
|
|
$this->episode->published_at = $dateNow;
|
|
|
|
$note->published_at = $dateNow;
|
|
|
|
}
|
|
|
|
|
|
|
|
$noteModel = new NoteModel();
|
|
|
|
if (!$noteModel->editNote($note)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $noteModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unpublish()
|
|
|
|
{
|
|
|
|
if ($this->episode->publication_status === 'published') {
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/unpublish', $data);
|
|
|
|
} else {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptUnpublish()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'understand' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db = \Config\Database::connect();
|
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
$allNotesLinkedToEpisode = (new NoteModel())
|
|
|
|
->where([
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
])
|
|
|
|
->findAll();
|
|
|
|
foreach ($allNotesLinkedToEpisode as $note) {
|
|
|
|
(new NoteModel())->removeNote($note);
|
|
|
|
}
|
|
|
|
|
|
|
|
// set episode published_at to null to unpublish
|
|
|
|
$this->episode->published_at = null;
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
if (!$episodeModel->update($this->episode->id, $this->episode)) {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
public function delete()
|
|
|
|
{
|
2020-08-04 11:25:22 +00:00
|
|
|
(new EpisodeModel())->delete($this->episode->id);
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2020-08-14 18:27:57 +00:00
|
|
|
return redirect()->route('episode-list', [$this->podcast->id]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-12-07 20:13:46 +00:00
|
|
|
|
|
|
|
public function soundbitesEdit()
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/soundbites', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function soundbitesAttemptEdit()
|
|
|
|
{
|
|
|
|
$soundbites_array = $this->request->getPost('soundbites_array');
|
|
|
|
$rules = [
|
|
|
|
'soundbites_array.0.start_time' =>
|
|
|
|
'permit_empty|required_with[soundbites_array.0.duration]|decimal|greater_than_equal_to[0]',
|
|
|
|
'soundbites_array.0.duration' =>
|
|
|
|
'permit_empty|required_with[soundbites_array.0.start_time]|decimal|greater_than_equal_to[0]',
|
|
|
|
];
|
|
|
|
foreach ($soundbites_array as $soundbite_id => $soundbite) {
|
|
|
|
$rules += [
|
|
|
|
"soundbites_array.{$soundbite_id}.start_time" => 'required|decimal|greater_than_equal_to[0]',
|
|
|
|
"soundbites_array.{$soundbite_id}.duration" => 'required|decimal|greater_than_equal_to[0]',
|
|
|
|
];
|
|
|
|
}
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach ($soundbites_array as $soundbite_id => $soundbite) {
|
|
|
|
if (
|
|
|
|
!empty($soundbite['start_time']) &&
|
|
|
|
!empty($soundbite['duration'])
|
|
|
|
) {
|
|
|
|
$data = [
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
'start_time' => $soundbite['start_time'],
|
|
|
|
'duration' => $soundbite['duration'],
|
|
|
|
'label' => $soundbite['label'],
|
|
|
|
'updated_by' => user()->id,
|
|
|
|
];
|
|
|
|
if ($soundbite_id == 0) {
|
|
|
|
$data += ['created_by' => user()->id];
|
|
|
|
} else {
|
|
|
|
$data += ['id' => $soundbite_id];
|
|
|
|
}
|
|
|
|
$soundbiteModel = new SoundbiteModel();
|
|
|
|
if (!$soundbiteModel->save($data)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $soundbiteModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return redirect()->route('soundbites-edit', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function soundbiteDelete($soundbiteId)
|
|
|
|
{
|
|
|
|
(new SoundbiteModel())->deleteSoundbite(
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
2021-04-02 17:20:02 +00:00
|
|
|
$soundbiteId,
|
2020-12-07 20:13:46 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->route('soundbites-edit', [
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
]);
|
|
|
|
}
|
2021-02-27 21:21:26 +00:00
|
|
|
|
|
|
|
public function embeddablePlayer()
|
|
|
|
{
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
|
|
|
'themes' => EpisodeModel::$themes,
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/embeddable_player', $data);
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|