2021-02-10 16:20:01 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @copyright 2020 Podlibre
|
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace App\Controllers\Admin;
|
|
|
|
|
|
|
|
use App\Models\EpisodePersonModel;
|
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use App\Models\EpisodeModel;
|
|
|
|
use App\Models\PersonModel;
|
|
|
|
|
|
|
|
class EpisodePerson extends BaseController
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\Episode
|
|
|
|
*/
|
|
|
|
protected $episode;
|
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
|
|
|
if (count($params) > 1) {
|
|
|
|
if (
|
|
|
|
!($this->podcast = (new PodcastModel())->getPodcastById(
|
2021-04-20 13:43:38 +00:00
|
|
|
$params[0],
|
2021-02-10 16:20:01 +00:00
|
|
|
))
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!($this->episode = (new EpisodeModel())
|
|
|
|
->where([
|
|
|
|
'id' => $params[1],
|
|
|
|
'podcast_id' => $params[0],
|
|
|
|
])
|
|
|
|
->first())
|
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
unset($params[1]);
|
|
|
|
unset($params[0]);
|
|
|
|
|
|
|
|
return $this->$method(...$params);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function index()
|
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'episode' => $this->episode,
|
|
|
|
'podcast' => $this->podcast,
|
2021-04-20 13:43:38 +00:00
|
|
|
'episodePersons' => (new EpisodePersonModel())->getEpisodePersons(
|
2021-02-10 16:20:01 +00:00
|
|
|
$this->podcast->id,
|
2021-04-20 13:43:38 +00:00
|
|
|
$this->episode->id,
|
2021-02-10 16:20:01 +00:00
|
|
|
),
|
|
|
|
'personOptions' => (new PersonModel())->getPersonOptions(),
|
|
|
|
'taxonomyOptions' => (new PersonModel())->getTaxonomyOptions(),
|
|
|
|
];
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->episode->title,
|
|
|
|
]);
|
|
|
|
return view('admin/episode/person', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptAdd()
|
|
|
|
{
|
|
|
|
$rules = [
|
|
|
|
'person' => 'required',
|
|
|
|
];
|
|
|
|
|
|
|
|
if (!$this->validate($rules)) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
|
|
|
(new EpisodePersonModel())->addEpisodePersons(
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
|
|
|
$this->request->getPost('person'),
|
2021-04-20 13:43:38 +00:00
|
|
|
$this->request->getPost('person_group_role'),
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove($episodePersonId)
|
|
|
|
{
|
|
|
|
(new EpisodePersonModel())->removeEpisodePersons(
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->episode->id,
|
2021-04-20 13:43:38 +00:00
|
|
|
$episodePersonId,
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|