2021-02-10 16:20:01 +00:00
|
|
|
<?php
|
|
|
|
|
2021-06-08 09:52:11 +00:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2021-02-10 16:20:01 +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\Podcast;
|
2021-02-10 16:20:01 +00:00
|
|
|
use App\Models\PersonModel;
|
2021-05-19 16:35:13 +00:00
|
|
|
use App\Models\PodcastModel;
|
|
|
|
use CodeIgniter\Exceptions\PageNotFoundException;
|
|
|
|
use CodeIgniter\HTTP\RedirectResponse;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-12 14:00:25 +00:00
|
|
|
class PodcastPersonController extends BaseController
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-18 17:16:36 +00:00
|
|
|
protected Podcast $podcast;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function _remap(string $method, string ...$params): mixed
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-05-06 14:00:48 +00:00
|
|
|
if (count($params) === 0) {
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
if (
|
2021-06-09 12:40:22 +00:00
|
|
|
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) !== null
|
2021-05-14 17:59:35 +00:00
|
|
|
) {
|
2021-05-06 14:00:48 +00:00
|
|
|
unset($params[0]);
|
2021-05-19 16:35:13 +00:00
|
|
|
return $this->{$method}(...$params);
|
2021-05-06 14:00:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
throw PageNotFoundException::forPageNotFound();
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function index(): string
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
|
|
|
helper('form');
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2021-06-09 12:40:22 +00:00
|
|
|
'podcastPersons' => (new PersonModel())->getPodcastPersons($this->podcast->id),
|
2021-02-10 16:20:01 +00:00
|
|
|
'personOptions' => (new PersonModel())->getPersonOptions(),
|
|
|
|
'taxonomyOptions' => (new PersonModel())->getTaxonomyOptions(),
|
|
|
|
];
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
]);
|
2021-05-17 17:11:23 +00:00
|
|
|
return view('admin/podcast/persons', $data);
|
2021-02-10 16:20:01 +00:00
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
public function attemptAdd(): RedirectResponse
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
|
|
|
$rules = [
|
2021-05-17 17:11:23 +00:00
|
|
|
'persons' => 'required',
|
2021-02-10 16:20:01 +00:00
|
|
|
];
|
|
|
|
|
2021-05-19 16:35:13 +00:00
|
|
|
if (! $this->validate($rules)) {
|
2021-02-10 16:20:01 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
|
|
|
->with('errors', $this->validator->getErrors());
|
|
|
|
}
|
|
|
|
|
2021-05-14 17:59:35 +00:00
|
|
|
(new PersonModel())->addPodcastPersons(
|
2021-02-10 16:20:01 +00:00
|
|
|
$this->podcast->id,
|
2021-05-17 17:11:23 +00:00
|
|
|
$this->request->getPost('persons'),
|
|
|
|
$this->request->getPost('roles') ?? [],
|
2021-02-10 16:20:01 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-06-08 16:57:04 +00:00
|
|
|
public function remove(string $personId): RedirectResponse
|
2021-02-10 16:20:01 +00:00
|
|
|
{
|
2021-06-08 16:57:04 +00:00
|
|
|
(new PersonModel())->removePersonFromPodcast($this->podcast->id, (int) $personId);
|
2021-02-10 16:20:01 +00:00
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
}
|