2020-07-10 12:20:25 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
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-12 14:00:25 +00:00
|
|
|
use App\Entities\Episode;
|
2021-08-13 16:07:45 +00:00
|
|
|
use App\Entities\EpisodeComment;
|
2021-05-25 18:00:09 +00:00
|
|
|
use App\Entities\Image;
|
2021-05-17 17:11:23 +00:00
|
|
|
use App\Entities\Location;
|
2021-05-12 14:00:25 +00:00
|
|
|
use App\Entities\Podcast;
|
2021-08-13 11:07:29 +00:00
|
|
|
use App\Entities\Post;
|
2021-08-13 16:07:45 +00:00
|
|
|
use App\Models\EpisodeCommentModel;
|
2020-07-10 12:20:25 +00:00
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use App\Models\PodcastModel;
|
2021-08-13 11:07:29 +00:00
|
|
|
use App\Models\PostModel;
|
2020-12-07 20:13:46 +00:00
|
|
|
use App\Models\SoundbiteModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2020-10-22 17:41:59 +00:00
|
|
|
use CodeIgniter\I18n\Time;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
class EpisodeController extends BaseController
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
protected Podcast $podcast;
|
2021-05-19 16:35:13 +00:00
|
|
|
|
2021-05-31 13:32:33 +00:00
|
|
|
protected Episode $episode;
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
2021-04-02 17:20:02 +00:00
|
|
|
if (
|
2021-06-09 12:40:22 +00:00
|
|
|
($podcast = (new PodcastModel())->getPodcastById((int) $params[0])) === null
|
2021-04-02 17:20:02 +00:00
|
|
|
) {
|
2021-05-14 17:59:35 +00:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
|
2021-06-09 12:40:22 +00:00
|
|
|
$this->podcast = $podcast;
|
|
|
|
|
2020-07-10 12:20:25 +00:00
|
|
|
if (count($params) > 1) {
|
|
|
|
if (
|
2021-06-10 08:14:06 +00:00
|
|
|
! ($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())
|
|
|
|
) {
|
2021-05-14 17:59:35 +00:00
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2020-12-07 20:13:46 +00:00
|
|
|
|
2021-06-10 08:14:06 +00:00
|
|
|
$this->episode = $episode;
|
|
|
|
|
2020-12-07 20:13:46 +00:00
|
|
|
unset($params[1]);
|
|
|
|
unset($params[0]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return $this->{$method}(...$params);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function list(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function view(): string
|
2020-07-27 09:35:34 +00:00
|
|
|
{
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function create(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptCreate(): RedirectResponse
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
|
|
|
$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
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2020-07-16 10:08:23 +00:00
|
|
|
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-25 18:00:09 +00:00
|
|
|
$image = null;
|
|
|
|
$imageFile = $this->request->getFile('image');
|
|
|
|
if ($imageFile !== null && $imageFile->isValid()) {
|
|
|
|
$image = new Image($imageFile);
|
|
|
|
}
|
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
$newEpisode = new Episode([
|
2020-07-16 10:08:23 +00:00
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'title' => $this->request->getPost('title'),
|
|
|
|
'slug' => $this->request->getPost('slug'),
|
2021-07-02 06:42:03 +00:00
|
|
|
'guid' => null,
|
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'),
|
2021-05-25 18:00:09 +00:00
|
|
|
'image' => $image,
|
2021-06-09 17:00:18 +00:00
|
|
|
'location' => $this->request->getPost('location_name') === '' ? null : new 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'),
|
2021-05-19 16:35:13 +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-05-12 14:00:25 +00:00
|
|
|
'created_by' => user_id(),
|
|
|
|
'updated_by' => user_id(),
|
2021-04-02 17:20:02 +00:00
|
|
|
'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 (
|
2021-06-15 06:41:28 +00:00
|
|
|
$transcriptChoice === 'upload-file'
|
|
|
|
&& ($transcriptFile = $this->request->getFile('transcript_file'))
|
|
|
|
&& $transcriptFile->isValid()
|
2021-05-03 17:39:58 +00:00
|
|
|
) {
|
|
|
|
$newEpisode->transcript_file = $transcriptFile;
|
|
|
|
} elseif ($transcriptChoice === 'remote-url') {
|
2021-06-15 06:41:28 +00:00
|
|
|
$newEpisode->transcript_file_remote_url = $this->request->getPost(
|
|
|
|
'transcript_file_remote_url'
|
|
|
|
) === '' ? null : $this->request->getPost('transcript_file_remote_url');
|
2021-05-03 17:39:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$chaptersChoice = $this->request->getPost('chapters-choice');
|
|
|
|
if (
|
2021-06-15 06:41:28 +00:00
|
|
|
$chaptersChoice === 'upload-file'
|
|
|
|
&& ($chaptersFile = $this->request->getFile('chapters_file'))
|
|
|
|
&& $chaptersFile->isValid()
|
2021-05-03 17:39:58 +00:00
|
|
|
) {
|
|
|
|
$newEpisode->chapters_file = $chaptersFile;
|
|
|
|
} elseif ($chaptersChoice === 'remote-url') {
|
2021-06-15 06:41:28 +00:00
|
|
|
$newEpisode->chapters_file_remote_url = $this->request->getPost(
|
|
|
|
'chapters_file_remote_url'
|
|
|
|
) === '' ? null : $this->request->getPost('chapters_file_remote_url');
|
2021-05-03 17:39:58 +00:00
|
|
|
}
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$episodeModel = new EpisodeModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-05-19 16:35:13 +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
|
2021-06-11 08:03:54 +00:00
|
|
|
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
|
|
|
|
'description_footer'
|
|
|
|
) === '' ? null : $this->request->getPost('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')) {
|
2021-06-11 08:03:54 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2020-10-02 15:38:16 +00:00
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
2020-10-02 15:38:16 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $newEpisodeId]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function edit(): string
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
|
|
|
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
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptEdit(): RedirectResponse
|
2020-07-16 10:08:23 +00:00
|
|
|
{
|
|
|
|
$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
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2020-07-16 10:08:23 +00:00
|
|
|
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');
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->episode->description_markdown = $this->request->getPost('description');
|
2021-06-09 17:00:18 +00:00
|
|
|
$this->episode->location = $this->request->getPost('location_name') === '' ? null : new 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');
|
2021-05-19 16:35:13 +00:00
|
|
|
$this->episode->is_blocked = $this->request->getPost('block') === 'yes';
|
2021-06-08 09:52:11 +00:00
|
|
|
$this->episode->custom_rss_string = $this->request->getPost('custom_rss');
|
2020-12-09 17:52:30 +00:00
|
|
|
|
2021-05-31 13:32:33 +00:00
|
|
|
$this->episode->updated_by = (int) user_id();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-05-03 17:39:58 +00:00
|
|
|
$audioFile = $this->request->getFile('audio_file');
|
2021-05-12 14:00:25 +00:00
|
|
|
if ($audioFile !== null && $audioFile->isValid()) {
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->episode->audio_file = $audioFile;
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
2021-05-12 14:00:25 +00:00
|
|
|
|
2021-05-25 18:00:09 +00:00
|
|
|
$imageFile = $this->request->getFile('image');
|
|
|
|
if ($imageFile !== null && $imageFile->isValid()) {
|
|
|
|
$this->episode->image = new Image($imageFile);
|
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');
|
2021-05-31 13:32:33 +00:00
|
|
|
if ($transcriptFile !== null && $transcriptFile->isValid()) {
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->episode->transcript_file = $transcriptFile;
|
|
|
|
$this->episode->transcript_file_remote_url = null;
|
|
|
|
}
|
|
|
|
} elseif ($transcriptChoice === 'remote-url') {
|
|
|
|
if (
|
2021-06-09 12:40:22 +00:00
|
|
|
($transcriptFileRemoteUrl = $this->request->getPost('transcript_file_remote_url')) &&
|
2021-06-15 06:41:28 +00:00
|
|
|
(($transcriptFile = $this->episode->transcript_file) !== null)
|
2021-05-03 17:39:58 +00:00
|
|
|
) {
|
2021-06-08 09:52:11 +00:00
|
|
|
unlink((string) $transcriptFile);
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->episode->transcript_file_path = null;
|
2021-05-03 17:39:58 +00:00
|
|
|
}
|
2021-06-15 06:41:28 +00:00
|
|
|
$this->episode->transcript_file_remote_url = $transcriptFileRemoteUrl === '' ? null : $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');
|
2021-05-31 13:32:33 +00:00
|
|
|
if ($chaptersFile !== null && $chaptersFile->isValid()) {
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->episode->chapters_file = $chaptersFile;
|
|
|
|
$this->episode->chapters_file_remote_url = null;
|
|
|
|
}
|
|
|
|
} elseif ($chaptersChoice === 'remote-url') {
|
|
|
|
if (
|
2021-06-09 12:40:22 +00:00
|
|
|
($chaptersFileRemoteUrl = $this->request->getPost('chapters_file_remote_url')) &&
|
2021-06-15 06:41:28 +00:00
|
|
|
(($chaptersFile = $this->episode->chapters_file) !== null)
|
2021-05-03 17:39:58 +00:00
|
|
|
) {
|
2021-06-08 09:52:11 +00:00
|
|
|
unlink((string) $chaptersFile);
|
2021-05-14 17:59:35 +00:00
|
|
|
$this->episode->chapters_file_path = null;
|
2021-05-03 17:39:58 +00:00
|
|
|
}
|
2021-06-15 06:41:28 +00:00
|
|
|
$this->episode->chapters_file_remote_url = $chaptersFileRemoteUrl === '' ? null : $chaptersFileRemoteUrl;
|
2020-11-24 20:18:08 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$episodeModel = new EpisodeModel();
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2021-06-11 08:03:54 +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', $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
|
2021-06-11 08:03:54 +00:00
|
|
|
$this->podcast->episode_description_footer_markdown = $this->request->getPost(
|
|
|
|
'description_footer'
|
|
|
|
) === '' ? null : $this->request->getPost('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();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $podcastModel->update($this->podcast->id, $this->podcast)) {
|
2021-06-11 08:03:54 +00:00
|
|
|
$db->transRollback();
|
|
|
|
|
2020-10-02 15:38:16 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $podcastModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db->transComplete();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function transcriptDelete(): RedirectResponse
|
2020-11-24 20:18:08 +00:00
|
|
|
{
|
2021-06-08 09:52:11 +00:00
|
|
|
unlink((string) $this->episode->transcript_file);
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->episode->transcript_file_path = null;
|
2020-11-24 20:18:08 +00:00
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2020-11-24 20:18:08 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function chaptersDelete(): RedirectResponse
|
2020-11-24 20:18:08 +00:00
|
|
|
{
|
2021-06-08 09:52:11 +00:00
|
|
|
unlink((string) $this->episode->chapters_file);
|
2021-05-03 17:39:58 +00:00
|
|
|
$this->episode->chapters_file_path = null;
|
2020-11-24 20:18:08 +00:00
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2020-11-24 20:18:08 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-06-22 17:59:33 +00:00
|
|
|
public function publish(): string | RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2021-05-14 17:59:35 +00:00
|
|
|
|
2021-06-22 17:59:33 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Episode.publish_error')
|
|
|
|
);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptPublish(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' =>
|
|
|
|
'valid_date[Y-m-d H:i]|permit_empty',
|
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db = db_connect();
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transStart();
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$newPost = new Post([
|
2021-04-02 17:20:02 +00:00
|
|
|
'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') {
|
2021-06-08 09:52:11 +00:00
|
|
|
$scheduledPublicationDate = $this->request->getPost('scheduled_publication_date');
|
2021-04-02 17:20:02 +00:00
|
|
|
if ($scheduledPublicationDate) {
|
2021-05-31 13:32:33 +00:00
|
|
|
$this->episode->published_at = Time::createFromFormat(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone('UTC');
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', 'Schedule date must be set!');
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-31 13:32:33 +00:00
|
|
|
$this->episode->published_at = Time::now();
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$newPost->published_at = $this->episode->published_at;
|
2021-05-31 13:32:33 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->addPost($newPost)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2021-08-13 11:07:29 +00:00
|
|
|
->with('errors', $postModel->errors());
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:59:33 +00:00
|
|
|
public function publishEdit(): string | RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
if ($this->episode->publication_status === 'scheduled') {
|
|
|
|
helper(['form']);
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'episode' => $this->episode,
|
2021-08-13 11:07:29 +00:00
|
|
|
'post' => (new PostModel())
|
2021-04-02 17:20:02 +00:00
|
|
|
->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);
|
|
|
|
}
|
2021-06-22 17:59:33 +00:00
|
|
|
|
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Episode.publish_edit_error')
|
|
|
|
);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptPublishEdit(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2021-08-13 11:07:29 +00:00
|
|
|
'post_id' => 'required',
|
2021-04-02 17:20:02 +00:00
|
|
|
'publication_method' => 'required',
|
|
|
|
'scheduled_publication_date' =>
|
|
|
|
'valid_date[Y-m-d H:i]|permit_empty',
|
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db = db_connect();
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transStart();
|
|
|
|
|
|
|
|
$publishMethod = $this->request->getPost('publication_method');
|
|
|
|
if ($publishMethod === 'schedule') {
|
2021-06-08 09:52:11 +00:00
|
|
|
$scheduledPublicationDate = $this->request->getPost('scheduled_publication_date');
|
2021-04-02 17:20:02 +00:00
|
|
|
if ($scheduledPublicationDate) {
|
2021-05-31 13:32:33 +00:00
|
|
|
$this->episode->published_at = Time::createFromFormat(
|
2021-04-02 17:20:02 +00:00
|
|
|
'Y-m-d H:i',
|
|
|
|
$scheduledPublicationDate,
|
|
|
|
$this->request->getPost('client_timezone'),
|
|
|
|
)->setTimezone('UTC');
|
|
|
|
} else {
|
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('error', 'Schedule date must be set!');
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-31 13:32:33 +00:00
|
|
|
$this->episode->published_at = Time::now();
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$post = (new PostModel())->getPostById($this->request->getPost('post_id'));
|
2021-05-31 13:32:33 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
if ($post !== null) {
|
|
|
|
$post->message = $this->request->getPost('message');
|
|
|
|
$post->published_at = $this->episode->published_at;
|
2021-05-31 13:32:33 +00:00
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$postModel = new PostModel();
|
|
|
|
if (! $postModel->editPost($post)) {
|
2021-05-31 13:32:33 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2021-08-13 11:07:29 +00:00
|
|
|
->with('errors', $postModel->errors());
|
2021-05-31 13:32:33 +00:00
|
|
|
}
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-06-22 17:59:33 +00:00
|
|
|
public function publishCancel(): RedirectResponse
|
|
|
|
{
|
|
|
|
if ($this->episode->publication_status === 'scheduled') {
|
|
|
|
$db = db_connect();
|
|
|
|
$db->transStart();
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$postModel = new PostModel();
|
|
|
|
$post = $postModel
|
2021-06-22 17:59:33 +00:00
|
|
|
->where([
|
|
|
|
'actor_id' => $this->podcast->actor_id,
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
])
|
|
|
|
->first();
|
2021-08-13 11:07:29 +00:00
|
|
|
$postModel->removePost($post);
|
2021-06-22 17:59:33 +00:00
|
|
|
|
|
|
|
$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]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Episode.publish_cancel_error')
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function unpublish(): string | RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2021-05-14 17:59:35 +00:00
|
|
|
|
2021-06-22 17:59:33 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id])->with(
|
|
|
|
'error',
|
|
|
|
lang('Episode.unpublish_error')
|
|
|
|
);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptUnpublish(): RedirectResponse
|
2021-04-02 17:20:02 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'understand' => 'required',
|
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-06-11 08:03:54 +00:00
|
|
|
$db = db_connect();
|
2021-04-02 17:20:02 +00:00
|
|
|
|
|
|
|
$db->transStart();
|
|
|
|
|
2021-08-13 11:07:29 +00:00
|
|
|
$allPostsLinkedToEpisode = (new PostModel())
|
2021-04-02 17:20:02 +00:00
|
|
|
->where([
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
])
|
|
|
|
->findAll();
|
2021-08-13 11:07:29 +00:00
|
|
|
foreach ($allPostsLinkedToEpisode as $post) {
|
|
|
|
(new PostModel())->removePost($post);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// set episode published_at to null to unpublish
|
|
|
|
$this->episode->published_at = null;
|
|
|
|
|
|
|
|
$episodeModel = new EpisodeModel();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $episodeModel->update($this->episode->id, $this->episode)) {
|
2021-04-02 17:20:02 +00:00
|
|
|
$db->transRollback();
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $episodeModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$db->transComplete();
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('episode-view', [$this->podcast->id, $this->episode->id]);
|
2021-04-02 17:20:02 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function delete(): RedirectResponse
|
2020-07-10 12:20:25 +00:00
|
|
|
{
|
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
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function soundbitesEdit(): string
|
2020-12-07 20:13:46 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function soundbitesAttemptEdit(): RedirectResponse
|
2020-12-07 20:13:46 +00:00
|
|
|
{
|
2021-05-17 17:11:23 +00:00
|
|
|
$soundbites = $this->request->getPost('soundbites');
|
2020-12-07 20:13:46 +00:00
|
|
|
$rules = [
|
2021-05-17 17:11:23 +00:00
|
|
|
'soundbites.0.start_time' =>
|
|
|
|
'permit_empty|required_with[soundbites.0.duration]|decimal|greater_than_equal_to[0]',
|
|
|
|
'soundbites.0.duration' =>
|
|
|
|
'permit_empty|required_with[soundbites.0.start_time]|decimal|greater_than_equal_to[0]',
|
2020-12-07 20:13:46 +00:00
|
|
|
];
|
2021-05-17 17:11:23 +00:00
|
|
|
foreach (array_keys($soundbites) as $soundbite_id) {
|
2020-12-07 20:13:46 +00:00
|
|
|
$rules += [
|
2021-05-17 17:11:23 +00:00
|
|
|
"soundbites.{$soundbite_id}.start_time" => 'required|decimal|greater_than_equal_to[0]',
|
|
|
|
"soundbites.{$soundbite_id}.duration" => 'required|decimal|greater_than_equal_to[0]',
|
2020-12-07 20:13:46 +00:00
|
|
|
];
|
|
|
|
}
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2020-12-07 20:13:46 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-05-17 17:11:23 +00:00
|
|
|
foreach ($soundbites as $soundbite_id => $soundbite) {
|
|
|
|
if ((int) $soundbite['start_time'] < (int) $soundbite['duration']) {
|
2020-12-07 20:13:46 +00:00
|
|
|
$data = [
|
|
|
|
'podcast_id' => $this->podcast->id,
|
|
|
|
'episode_id' => $this->episode->id,
|
2021-06-08 16:57:04 +00:00
|
|
|
'start_time' => (float) $soundbite['start_time'],
|
|
|
|
'duration' => (float) $soundbite['duration'],
|
2020-12-07 20:13:46 +00:00
|
|
|
'label' => $soundbite['label'],
|
2021-05-12 14:00:25 +00:00
|
|
|
'updated_by' => user_id(),
|
2020-12-07 20:13:46 +00:00
|
|
|
];
|
2021-05-19 16:35:13 +00:00
|
|
|
if ($soundbite_id === 0) {
|
|
|
|
$data += [
|
|
|
|
'created_by' => user_id(),
|
|
|
|
];
|
2020-12-07 20:13:46 +00:00
|
|
|
} else {
|
2021-05-19 16:35:13 +00:00
|
|
|
$data += [
|
|
|
|
'id' => $soundbite_id,
|
|
|
|
];
|
2020-12-07 20:13:46 +00:00
|
|
|
}
|
2021-05-17 17:11:23 +00:00
|
|
|
|
2020-12-07 20:13:46 +00:00
|
|
|
$soundbiteModel = new SoundbiteModel();
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $soundbiteModel->save($data)) {
|
2020-12-07 20:13:46 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $soundbiteModel->errors());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-19 16:35:13 +00:00
|
|
|
return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]);
|
2020-12-07 20:13:46 +00:00
|
|
|
}
|
|
|
|
|
2021-06-08 16:57:04 +00:00
|
|
|
public function soundbiteDelete(string $soundbiteId): RedirectResponse
|
2020-12-07 20:13:46 +00:00
|
|
|
{
|
2021-06-08 16:57:04 +00:00
|
|
|
(new SoundbiteModel())->deleteSoundbite($this->podcast->id, $this->episode->id, (int) $soundbiteId);
|
2021-05-19 16:35:13 +00:00
|
|
|
|
|
|
|
return redirect()->route('soundbites-edit', [$this->podcast->id, $this->episode->id]);
|
2020-12-07 20:13:46 +00:00
|
|
|
}
|
2021-02-27 21:21:26 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function embeddablePlayer(): string
|
2021-02-27 21:21:26 +00:00
|
|
|
{
|
|
|
|
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);
|
|
|
|
}
|
2021-08-13 11:07:29 +00:00
|
|
|
|
|
|
|
public function attemptCommentCreate(): RedirectResponse
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'message' => 'required|max_length[500]',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (! $this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $this->request->getPost('message');
|
|
|
|
|
2021-08-13 16:07:45 +00:00
|
|
|
$newComment = new EpisodeComment([
|
2021-08-13 11:07:29 +00:00
|
|
|
'actor_id' => interact_as_actor_id(),
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
'message' => $message,
|
|
|
|
'created_at' => new Time('now'),
|
|
|
|
'created_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
2021-08-13 16:07:45 +00:00
|
|
|
$commentModel = new EpisodeCommentModel();
|
2021-08-13 11:07:29 +00:00
|
|
|
if (
|
|
|
|
! $commentModel->addComment($newComment, true)
|
|
|
|
) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $commentModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Comment has been successfully created
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2021-08-16 15:45:36 +00:00
|
|
|
|
|
|
|
public function attemptCommentReply(string $commentId): RedirectResponse
|
|
|
|
{
|
|
|
|
// var_dump($commentId);
|
|
|
|
// die();
|
|
|
|
|
|
|
|
$rules = [
|
|
|
|
'message' => 'required|max_length[500]',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (! $this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
$message = $this->request->getPost('message');
|
|
|
|
|
|
|
|
$newReply = new EpisodeComment([
|
|
|
|
'actor_id' => interact_as_actor_id(),
|
|
|
|
'episode_id' => $this->episode->id,
|
|
|
|
'message' => $message,
|
|
|
|
'in_reply_to_id' => $commentId,
|
|
|
|
'created_at' => new Time('now'),
|
|
|
|
'created_by' => user_id(),
|
|
|
|
]);
|
|
|
|
|
|
|
|
$commentModel = new EpisodeCommentModel();
|
|
|
|
if (
|
|
|
|
! $commentModel->addComment($newReply, true)
|
|
|
|
) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $commentModel->errors());
|
|
|
|
}
|
|
|
|
|
|
|
|
// Reply has been successfully created
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
2020-07-10 12:20:25 +00:00
|
|
|
}
|