forked from projects/fipamo
ro
ceeb4a2573
routing needed more nuance than what was possible in the web routing controller, so a new RouteContoller was created to identify requests and then sending them to the correct controller to get the appropriatie page this was necessary because routing the previous was erroring out because when the system was looking for pages to display with dynamic page creation it would get confused with prexisting routes and choose to display whatever the Start Controller was capturing, ignoring routes defined in the web controller. but that's been cleaned up without having to re-write everything and continues to use existing controllers
125 lines
3.4 KiB
PHP
125 lines
3.4 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\Dash;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\AuthService;
|
|
use App\Services\ThemeService;
|
|
use App\Services\SortingService;
|
|
use App\Http\Controllers\Controller;
|
|
|
|
class IndexController extends Controller
|
|
{
|
|
protected PageRepositoryInterface $pages;
|
|
protected AuthService $auth;
|
|
protected ThemeService $themes;
|
|
protected SortingService $sort;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
AuthService $authService,
|
|
ThemeService $themeService,
|
|
SortingService $sortingService
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->auth = $authService;
|
|
$this->themes = $themeService;
|
|
$this->sort = $sortingService;
|
|
}
|
|
|
|
public function init($second, $third, $fourth)
|
|
{
|
|
switch ($second) {
|
|
case 'settings':
|
|
return $this->settings();
|
|
break;
|
|
case 'navigation':
|
|
return $this->navigavtion();
|
|
break;
|
|
case 'pages':
|
|
($third == null) ? $third = 'all' : $third = $third;
|
|
($fourth == null) ? $fourth = 1 : $fourth = $fourth;
|
|
return $this->book($third, $fourth);
|
|
break;
|
|
case 'page':
|
|
return $this->page($third, $fourth);
|
|
break;
|
|
case 'logout':
|
|
session()->flush();
|
|
return redirect()->intended('dashboard');
|
|
break;
|
|
default:
|
|
return $this->start();
|
|
|
|
break;
|
|
}
|
|
}
|
|
|
|
public function login()
|
|
{
|
|
if ($this->auth::status()) {
|
|
return redirect('dashboard/start');
|
|
} else {
|
|
return view('back.login', [
|
|
"status" => $this->auth::status(),
|
|
"title" => "Hi!"
|
|
]);
|
|
}
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
$result = [];
|
|
if ($this->auth::status()) {
|
|
$result = $this->pages->getGroup(1, 4);
|
|
}
|
|
return view('back.start', [
|
|
"status" => $this->auth::status(),
|
|
"result" => $result,
|
|
"title" => "Start"
|
|
]);
|
|
}
|
|
|
|
public function book($pageFilter = 'all', $pageNum = 1)
|
|
{
|
|
$result = [];
|
|
if ($this->auth::status()) {
|
|
$result = $this->pages->getGroup($pageNum, 4, $pageFilter);
|
|
}
|
|
return view('back.book', [
|
|
"status" => $this->auth::status(),
|
|
"result" => $result,
|
|
"currentPage" => $pageNum,
|
|
"title" => "Pages"
|
|
]);
|
|
}
|
|
|
|
public function page($mode, $uuid)
|
|
{
|
|
$title;
|
|
$page = [];
|
|
$views = [];
|
|
$mode == 'edit' ? $page = $this->pages->getById($uuid) : $page = [];
|
|
$mode == 'edit' ? $title = $page['title'] : $title = 'Add New';
|
|
$mode == 'edit' ? $views = $this->themes->getCustomViews($page['layout']) : $views[] = 'page';
|
|
|
|
return view('back.page', [
|
|
"status" => $this->auth::status(),
|
|
"mode" => $mode,
|
|
"page" => $page,
|
|
"views" => $views,
|
|
"title" => $title,
|
|
]);
|
|
}
|
|
|
|
public function navigation()
|
|
{
|
|
return view('back.navigation', $this->sort->navigation());
|
|
}
|
|
|
|
public function settings()
|
|
{
|
|
return view('back.settings', $this->sort->settings());
|
|
}
|
|
}
|