Newer
Older
<?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 CodeIgniter\HTTP\RedirectResponse;

Yassine Doghri
committed
use App\Entities\Podcast;
use CodeIgniter\Exceptions\PageNotFoundException;
use App\Models\PodcastModel;
use App\Models\PersonModel;
class PodcastPersonController extends BaseController

Yassine Doghri
committed
* @var Podcast
protected Podcast $podcast;
public function _remap(string $method, string ...$params): mixed

Yassine Doghri
committed
if (count($params) === 0) {
throw PageNotFoundException::forPageNotFound();
if (
($this->podcast = (new PodcastModel())->getPodcastById(
(int) $params[0],
)) !== null
) {

Yassine Doghri
committed
unset($params[0]);
return $this->$method(...$params);
}
throw PageNotFoundException::forPageNotFound();
public function index(): string
{
helper('form');
$data = [
'podcast' => $this->podcast,
'podcastPersons' => (new PersonModel())->getPodcastPersons(
$this->podcast->id,
),
'personOptions' => (new PersonModel())->getPersonOptions(),
'taxonomyOptions' => (new PersonModel())->getTaxonomyOptions(),
];
replace_breadcrumb_params([
0 => $this->podcast->title,
]);

Yassine Doghri
committed
return view('admin/podcast/persons', $data);
public function attemptAdd(): RedirectResponse
{
$rules = [

Yassine Doghri
committed
'persons' => 'required',
];
if (!$this->validate($rules)) {
return redirect()
->back()
->withInput()
->with('errors', $this->validator->getErrors());
}
(new PersonModel())->addPodcastPersons(
$this->podcast->id,

Yassine Doghri
committed
$this->request->getPost('persons'),
$this->request->getPost('roles') ?? [],
);
return redirect()->back();
}

Yassine Doghri
committed
public function remove(int $personId): RedirectResponse

Yassine Doghri
committed
(new PersonModel())->removePersonFromPodcast(
$this->podcast->id,

Yassine Doghri
committed
$personId,
);
return redirect()->back();
}
}