2020-07-16 10:08:23 +00:00
|
|
|
<?php
|
2020-08-04 11:25:22 +00:00
|
|
|
|
2020-07-16 10:08:23 +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;
|
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Authorization\GroupModel;
|
2020-07-16 10:08:23 +00:00
|
|
|
use App\Models\PodcastModel;
|
2020-07-31 16:05:10 +00:00
|
|
|
use App\Models\UserModel;
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
class Contributor extends BaseController
|
|
|
|
{
|
2020-08-05 17:26:04 +00:00
|
|
|
/**
|
|
|
|
* @var \App\Entities\Podcast
|
|
|
|
*/
|
|
|
|
protected $podcast;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @var \App\Entities\User|null
|
|
|
|
*/
|
|
|
|
protected $user;
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
public function _remap($method, ...$params)
|
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
$this->podcast = (new PodcastModel())->find($params[0]);
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
if (count($params) > 1) {
|
|
|
|
if (
|
2020-07-31 16:05:10 +00:00
|
|
|
!($this->user = (new UserModel())->getPodcastContributor(
|
|
|
|
$params[1],
|
|
|
|
$params[0]
|
|
|
|
))
|
2020-07-16 10:08:23 +00:00
|
|
|
) {
|
|
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->$method();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function list()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
];
|
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/contributor/list', $data);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function view()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'contributor' => (new UserModel())->getPodcastContributor(
|
|
|
|
$this->user->id,
|
|
|
|
$this->podcast->id
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->user->username,
|
|
|
|
]);
|
|
|
|
return view('admin/contributor/view', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function add()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
2020-07-31 16:05:10 +00:00
|
|
|
'users' => (new UserModel())->findAll(),
|
|
|
|
'roles' => (new GroupModel())->getContributorRoles(),
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
|
|
return view('admin/contributor/add', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptAdd()
|
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
try {
|
|
|
|
(new PodcastModel())->addPodcastContributor(
|
|
|
|
$this->request->getPost('user'),
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->request->getPost('role')
|
|
|
|
);
|
|
|
|
} catch (\Exception $e) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->withInput()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', [
|
|
|
|
lang('Contributor.messages.alreadyAddedError'),
|
|
|
|
]);
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
|
|
|
return redirect()->route('contributor_list', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function edit()
|
|
|
|
{
|
|
|
|
$data = [
|
|
|
|
'podcast' => $this->podcast,
|
|
|
|
'user' => $this->user,
|
2020-08-04 11:25:22 +00:00
|
|
|
'contributorGroupId' => (new PodcastModel())->getContributorGroupId(
|
2020-07-31 16:05:10 +00:00
|
|
|
$this->user->id,
|
|
|
|
$this->podcast->id
|
|
|
|
),
|
|
|
|
'roles' => (new GroupModel())->getContributorRoles(),
|
2020-07-16 10:08:23 +00:00
|
|
|
];
|
|
|
|
|
2020-08-05 16:10:39 +00:00
|
|
|
replace_breadcrumb_params([
|
|
|
|
0 => $this->podcast->title,
|
|
|
|
1 => $this->user->username,
|
|
|
|
]);
|
|
|
|
return view('admin/contributor/edit', $data);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function attemptEdit()
|
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
(new PodcastModel())->updatePodcastContributor(
|
|
|
|
$this->user->id,
|
|
|
|
$this->podcast->id,
|
|
|
|
$this->request->getPost('role')
|
2020-07-16 10:08:23 +00:00
|
|
|
);
|
|
|
|
|
|
|
|
return redirect()->route('contributor_list', [$this->podcast->id]);
|
|
|
|
}
|
|
|
|
|
|
|
|
public function remove()
|
|
|
|
{
|
2020-07-31 16:05:10 +00:00
|
|
|
if ($this->podcast->owner_id == $this->user->id) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with('errors', [
|
2020-08-04 11:25:22 +00:00
|
|
|
lang('Contributor.messages.removeOwnerContributorError'),
|
2020-07-31 16:05:10 +00:00
|
|
|
]);
|
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-08-04 11:25:22 +00:00
|
|
|
$podcastModel = new PodcastModel();
|
2020-07-31 16:05:10 +00:00
|
|
|
if (
|
2020-08-04 11:25:22 +00:00
|
|
|
!$podcastModel->removePodcastContributor(
|
2020-07-31 16:05:10 +00:00
|
|
|
$this->user->id,
|
|
|
|
$this->podcast->id
|
2020-07-16 10:08:23 +00:00
|
|
|
)
|
2020-07-31 16:05:10 +00:00
|
|
|
) {
|
|
|
|
return redirect()
|
|
|
|
->back()
|
2020-08-04 11:25:22 +00:00
|
|
|
->with('errors', $podcastModel->errors());
|
2020-07-31 16:05:10 +00:00
|
|
|
}
|
2020-07-16 10:08:23 +00:00
|
|
|
|
2020-07-31 16:05:10 +00:00
|
|
|
return redirect()
|
|
|
|
->back()
|
|
|
|
->with(
|
|
|
|
'message',
|
2020-08-04 11:25:22 +00:00
|
|
|
lang('Contributor.messages.removeContributorSuccess', [
|
2020-07-31 16:05:10 +00:00
|
|
|
'username' => $this->user->username,
|
|
|
|
'podcastTitle' => $this->podcast->title,
|
|
|
|
])
|
|
|
|
);
|
2020-07-16 10:08:23 +00:00
|
|
|
}
|
|
|
|
}
|