mirror of
https://github.com/ad-aures/castopod.git
synced 2026-04-12 03:06:43 +02:00
refactor(modules): extract castopod parts into a modules/ folder for a scalable HMVC structure
- create Admin, Analytics, Auth, Fediverse and Install modules in the root modules/ folder - rename ActivityPub to Fediverse
This commit is contained in:
parent
94872f2338
commit
5083cd2fda
268 changed files with 4221 additions and 2186 deletions
118
modules/Admin/Controllers/PageController.php
Normal file
118
modules/Admin/Controllers/PageController.php
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
/**
|
||||
* @copyright 2020 Podlibre
|
||||
* @license https://www.gnu.org/licenses/agpl-3.0.en.html AGPL3
|
||||
* @link https://castopod.org/
|
||||
*/
|
||||
|
||||
namespace Modules\Admin\Controllers;
|
||||
|
||||
use App\Entities\Page;
|
||||
use App\Models\PageModel;
|
||||
use CodeIgniter\Exceptions\PageNotFoundException;
|
||||
use CodeIgniter\HTTP\RedirectResponse;
|
||||
|
||||
class PageController extends BaseController
|
||||
{
|
||||
protected ?Page $page;
|
||||
|
||||
public function _remap(string $method, string ...$params): mixed
|
||||
{
|
||||
if ($params === []) {
|
||||
return $this->{$method}();
|
||||
}
|
||||
|
||||
if ($this->page = (new PageModel())->find($params[0])) {
|
||||
return $this->{$method}();
|
||||
}
|
||||
|
||||
throw PageNotFoundException::forPageNotFound();
|
||||
}
|
||||
|
||||
public function list(): string
|
||||
{
|
||||
$data = [
|
||||
'pages' => (new PageModel())->findAll(),
|
||||
];
|
||||
|
||||
return view('Modules\Admin\Views\page\list', $data);
|
||||
}
|
||||
|
||||
public function view(): string
|
||||
{
|
||||
return view('Modules\Admin\Views\page\view', [
|
||||
'page' => $this->page,
|
||||
]);
|
||||
}
|
||||
|
||||
public function create(): string
|
||||
{
|
||||
helper('form');
|
||||
|
||||
return view('Modules\Admin\Views\page\create');
|
||||
}
|
||||
|
||||
public function attemptCreate(): RedirectResponse
|
||||
{
|
||||
$page = new Page([
|
||||
'title' => $this->request->getPost('title'),
|
||||
'slug' => $this->request->getPost('slug'),
|
||||
'content_markdown' => $this->request->getPost('content'),
|
||||
]);
|
||||
|
||||
$pageModel = new PageModel();
|
||||
|
||||
if (! $pageModel->insert($page)) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput()
|
||||
->with('errors', $pageModel->errors());
|
||||
}
|
||||
|
||||
return redirect()
|
||||
->route('page-list')
|
||||
->with('message', lang('Page.messages.createSuccess', [
|
||||
'pageTitle' => $page->title,
|
||||
]));
|
||||
}
|
||||
|
||||
public function edit(): string
|
||||
{
|
||||
helper('form');
|
||||
|
||||
replace_breadcrumb_params([
|
||||
0 => $this->page->title,
|
||||
]);
|
||||
return view('Modules\Admin\Views\page\edit', [
|
||||
'page' => $this->page,
|
||||
]);
|
||||
}
|
||||
|
||||
public function attemptEdit(): RedirectResponse
|
||||
{
|
||||
$this->page->title = $this->request->getPost('title');
|
||||
$this->page->slug = $this->request->getPost('slug');
|
||||
$this->page->content_markdown = $this->request->getPost('content');
|
||||
|
||||
$pageModel = new PageModel();
|
||||
|
||||
if (! $pageModel->update($this->page->id, $this->page)) {
|
||||
return redirect()
|
||||
->back()
|
||||
->withInput()
|
||||
->with('errors', $pageModel->errors());
|
||||
}
|
||||
|
||||
return redirect()->route('page-list');
|
||||
}
|
||||
|
||||
public function delete(): RedirectResponse
|
||||
{
|
||||
(new PageModel())->delete($this->page->id);
|
||||
|
||||
return redirect()->route('page-list');
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue