148 lines
4.3 KiB
PHP
148 lines
4.3 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace App\Http\Controllers;
|
||
|
|
||
|
use App\Interfaces\PageRepositoryInterface;
|
||
|
use App\Interfaces\MemberRepositoryInterface;
|
||
|
use App\Services\Data\ThemeService;
|
||
|
use Illuminate\Http\Request;
|
||
|
|
||
|
class PageController extends Controller
|
||
|
{
|
||
|
protected PageRepositoryInterface $page;
|
||
|
protected MemberRepositoryInterface $member;
|
||
|
protected ThemeService $themes;
|
||
|
|
||
|
public function __construct(
|
||
|
PageRepositoryInterface $pageRepo,
|
||
|
MemberRepositoryInterface $memberRepo,
|
||
|
ThemeService $themeService,
|
||
|
) {
|
||
|
$this->page = $pageRepo;
|
||
|
$this->member = $memberRepo;
|
||
|
$this->themes = $themeService;
|
||
|
}
|
||
|
|
||
|
//---
|
||
|
// GET Actions
|
||
|
//---
|
||
|
|
||
|
public function start(string $one = 'all', string $two = '1')
|
||
|
{
|
||
|
//checks mode to see what needs to get loaded
|
||
|
switch ($one) {
|
||
|
case "edit":
|
||
|
case "add":
|
||
|
return $this->page($one, $two);
|
||
|
break;
|
||
|
|
||
|
default:
|
||
|
return $this->book($one, $two);
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
private function page($mode, $uuid)
|
||
|
{
|
||
|
$title;
|
||
|
$page = [];
|
||
|
$views = [];
|
||
|
$mode == 'edit' ? $page = $this->page->getByUuid($uuid) : $page = [];
|
||
|
$mode == 'edit' ? $title = 'Edit Page' : $title = 'Add New';
|
||
|
$mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page';
|
||
|
|
||
|
//just a patch for now to get this out of the template
|
||
|
if ($mode == 'edit') {
|
||
|
$id = $page['id'];
|
||
|
$uuid = $page['uuid'];
|
||
|
$slug = $page['slug'];
|
||
|
$feature = $page['feature'];
|
||
|
$layout = $page['layout'];
|
||
|
$tags = $page['tags'];
|
||
|
$content = $page['content'];
|
||
|
$date = $page['created'];
|
||
|
$updated = $page['updated'];
|
||
|
$media = $page['media'];
|
||
|
$files = $page['docs'];
|
||
|
$editTitle = $page['title'];
|
||
|
} else {
|
||
|
$id = "";
|
||
|
$uuid = "";
|
||
|
$slug = "";
|
||
|
$feature = "";
|
||
|
$layout = "";
|
||
|
$tags = "";
|
||
|
$content = "";
|
||
|
$date = "";
|
||
|
$updated = "";
|
||
|
$media = "";
|
||
|
$files = "";
|
||
|
$editTitle = "";
|
||
|
};
|
||
|
|
||
|
return view('back.page', [
|
||
|
"status" => $this->member::status(),
|
||
|
"mode" => $mode,
|
||
|
"page" => $page,
|
||
|
"views" => $views,
|
||
|
"id" => $id,
|
||
|
"uuid" => $uuid,
|
||
|
"slug" => $slug,
|
||
|
"feature" => $feature,
|
||
|
"layout" => $layout,
|
||
|
"tags" => $tags,
|
||
|
"content" => $content,
|
||
|
"date" => $date,
|
||
|
"updated" => $updated,
|
||
|
"media" => $media,
|
||
|
"files" => $files,
|
||
|
"title" => urldecode($title),
|
||
|
"editTitle" => urldecode($editTitle),
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
private function book($pageFilter, $pageNum)
|
||
|
{
|
||
|
$result = [];
|
||
|
if ($this->member::status()) {
|
||
|
$result = $this->page->getGroup($pageNum, 4, $pageFilter);
|
||
|
}
|
||
|
return view('back.book', [
|
||
|
"status" => $this->member::status(),
|
||
|
"result" => $result,
|
||
|
"currentPage" => $pageNum,
|
||
|
"title" => "Pages"
|
||
|
]);
|
||
|
}
|
||
|
|
||
|
//---
|
||
|
// POST Actions
|
||
|
//---
|
||
|
public function create(Request $request)
|
||
|
{
|
||
|
$body = json_decode($request->getContent());
|
||
|
$result = $this->page->create($body);
|
||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||
|
}
|
||
|
|
||
|
//---
|
||
|
// PUT Actions
|
||
|
//---
|
||
|
public function write(Request $request)
|
||
|
{
|
||
|
$body = json_decode($request->getContent());
|
||
|
$result = $this->page->update($body);
|
||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||
|
}
|
||
|
|
||
|
//---
|
||
|
// DELETE Actions
|
||
|
//---
|
||
|
public function delete(Request $request)
|
||
|
{
|
||
|
$body = json_decode($request->getContent());
|
||
|
$result = $this->page->delete($body);
|
||
|
return response()->json($result)->header('Content-Type', 'application/json');
|
||
|
}
|
||
|
}
|