mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-08-18 23:33:23 +02:00
- add installGateway to app config - update route names and groups - remove `author_name` and `author_email` from `episodes` table - remove `author_name` and `author_email` from `podcasts` table - remove `owner_id` + add `created_by` and `updated_by` fields in `podcasts` and `episodes` tables - remove unnecessary comments in database fields - remove confirm password inputs from auth forms for better ux - rename `pub_date` field to `published_at` and add publication time field in episode form closes #14, #28
200 lines
5.1 KiB
PHP
200 lines
5.1 KiB
PHP
<?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\Authorization\GroupModel;
|
|
use App\Models\PodcastModel;
|
|
use App\Models\UserModel;
|
|
|
|
class Contributor extends BaseController
|
|
{
|
|
/**
|
|
* @var \App\Entities\Podcast
|
|
*/
|
|
protected $podcast;
|
|
|
|
/**
|
|
* @var \App\Entities\User|null
|
|
*/
|
|
protected $user;
|
|
|
|
public function _remap($method, ...$params)
|
|
{
|
|
$this->podcast = (new PodcastModel())->find($params[0]);
|
|
|
|
if (count($params) > 1) {
|
|
if (
|
|
!($this->user = (new UserModel())->getPodcastContributor(
|
|
$params[1],
|
|
$params[0]
|
|
))
|
|
) {
|
|
throw \CodeIgniter\Exceptions\PageNotFoundException::forPageNotFound();
|
|
}
|
|
}
|
|
|
|
return $this->$method();
|
|
}
|
|
|
|
public function list()
|
|
{
|
|
$data = [
|
|
'podcast' => $this->podcast,
|
|
];
|
|
|
|
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);
|
|
}
|
|
|
|
public function add()
|
|
{
|
|
helper('form');
|
|
|
|
$users = (new UserModel())->findAll();
|
|
$userOptions = array_reduce(
|
|
$users,
|
|
function ($result, $user) {
|
|
$result[$user->id] = $user->username;
|
|
return $result;
|
|
},
|
|
[]
|
|
);
|
|
|
|
$roles = (new GroupModel())->getContributorRoles();
|
|
$roleOptions = array_reduce(
|
|
$roles,
|
|
function ($result, $role) {
|
|
$result[$role->id] = lang('Contributor.roles.' . $role->name);
|
|
return $result;
|
|
},
|
|
[]
|
|
);
|
|
|
|
$data = [
|
|
'podcast' => $this->podcast,
|
|
'userOptions' => $userOptions,
|
|
'roleOptions' => $roleOptions,
|
|
];
|
|
|
|
replace_breadcrumb_params([0 => $this->podcast->title]);
|
|
return view('admin/contributor/add', $data);
|
|
}
|
|
|
|
public function attemptAdd()
|
|
{
|
|
try {
|
|
(new PodcastModel())->addPodcastContributor(
|
|
$this->request->getPost('user'),
|
|
$this->podcast->id,
|
|
$this->request->getPost('role')
|
|
);
|
|
} catch (\Exception $e) {
|
|
return redirect()
|
|
->back()
|
|
->withInput()
|
|
->with('errors', [
|
|
lang('Contributor.messages.alreadyAddedError'),
|
|
]);
|
|
}
|
|
|
|
return redirect()->route('contributor-list', [$this->podcast->id]);
|
|
}
|
|
|
|
public function edit()
|
|
{
|
|
helper('form');
|
|
|
|
$roles = (new GroupModel())->getContributorRoles();
|
|
$roleOptions = array_reduce(
|
|
$roles,
|
|
function ($result, $role) {
|
|
$result[$role->id] = lang('Contributor.roles.' . $role->name);
|
|
return $result;
|
|
},
|
|
[]
|
|
);
|
|
|
|
$data = [
|
|
'podcast' => $this->podcast,
|
|
'user' => $this->user,
|
|
'contributorGroupId' => (new PodcastModel())->getContributorGroupId(
|
|
$this->user->id,
|
|
$this->podcast->id
|
|
),
|
|
'roleOptions' => $roleOptions,
|
|
];
|
|
|
|
replace_breadcrumb_params([
|
|
0 => $this->podcast->title,
|
|
1 => $this->user->username,
|
|
]);
|
|
return view('admin/contributor/edit', $data);
|
|
}
|
|
|
|
public function attemptEdit()
|
|
{
|
|
(new PodcastModel())->updatePodcastContributor(
|
|
$this->user->id,
|
|
$this->podcast->id,
|
|
$this->request->getPost('role')
|
|
);
|
|
|
|
return redirect()->route('contributor-list', [$this->podcast->id]);
|
|
}
|
|
|
|
public function remove()
|
|
{
|
|
if ($this->podcast->owner_id == $this->user->id) {
|
|
return redirect()
|
|
->back()
|
|
->with('errors', [
|
|
lang('Contributor.messages.removeOwnerContributorError'),
|
|
]);
|
|
}
|
|
|
|
$podcastModel = new PodcastModel();
|
|
if (
|
|
!$podcastModel->removePodcastContributor(
|
|
$this->user->id,
|
|
$this->podcast->id
|
|
)
|
|
) {
|
|
return redirect()
|
|
->back()
|
|
->with('errors', $podcastModel->errors());
|
|
}
|
|
|
|
return redirect()
|
|
->back()
|
|
->with(
|
|
'message',
|
|
lang('Contributor.messages.removeContributorSuccess', [
|
|
'username' => $this->user->username,
|
|
'podcastTitle' => $this->podcast->title,
|
|
])
|
|
);
|
|
}
|
|
}
|