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
|
|
|
/**
|
2022-02-19 16:06:11 +00:00
|
|
|
* @copyright 2020 Ad Aures
|
2021-02-10 16:20:01 +00:00
|
|
|
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
|
|
|
* @link https://castopod.org/
|
|
|
|
*/
|
|
|
|
|
2021-08-23 11:05:16 +00:00
|
|
|
namespace Modules\Admin\Controllers;
|
2021-02-10 16:20:01 +00:00
|
|
|
|
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-08-11 15:47:23 +00:00
|
|
|
if ($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
|
|
|
if (
|
2023-04-14 11:11:53 +00:00
|
|
|
($this->podcast = (new PodcastModel())->getPodcastById((int) $params[0])) instanceof Podcast
|
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([
|
2022-10-15 11:22:08 +00:00
|
|
|
0 => $this->podcast->at_handle,
|
2021-02-10 16:20:01 +00:00
|
|
|
]);
|
2021-09-02 16:34:25 +00:00
|
|
|
return view('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();
|
|
|
|
}
|
|
|
|
}
|