ro
928d5468db
theme controller class was using hard coded uuids to find and display
page data, so that's been tweaked so that is no longer needed and finds
what it needs based on what time of view is being requested
also connected it the the preview 👁️ button in the page edit screen so
page layouts based on the current theme can be seen before they are
published
98 lines
3 KiB
PHP
98 lines
3 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
|
use App\Services\Assets\AssetService;
|
|
use App\Interfaces\MemberRepositoryInterface;
|
|
use App\Services\Data\SortingService;
|
|
use App\Services\Data\ThemeService;
|
|
|
|
class ThemeController extends Controller
|
|
{
|
|
protected PageRepositoryInterface $pages;
|
|
protected MemberRepositoryInterface $member;
|
|
protected AssetService $assets;
|
|
protected SortingService $sort;
|
|
protected ThemeService $themes;
|
|
|
|
public function __construct(
|
|
PageRepositoryInterface $pageRepository,
|
|
MemberRepositoryInterface $memberRepo,
|
|
AssetService $assetService,
|
|
SortingService $sortService,
|
|
ThemeService $themeService,
|
|
) {
|
|
$this->pages = $pageRepository;
|
|
$this->member = $memberRepo;
|
|
$this->assets = $assetService;
|
|
$this->sort = $sortService;
|
|
$this->themes = $themeService;
|
|
}
|
|
|
|
public function start()
|
|
{
|
|
if ($this->member::status()) {
|
|
return view('theme.start', [
|
|
"status" => $this->member::status(),
|
|
"title" => "Fipamo Theme Kit",
|
|
"pages" => $this->themes->getCustomViews('page')
|
|
]);
|
|
} else {
|
|
return redirect('dashboard');
|
|
}
|
|
}
|
|
|
|
public function getView($view = 'index', $id = null)
|
|
{
|
|
//move assets to theme testing dir
|
|
$this->assets->moveToTheme();
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
|
$template;
|
|
$pageData = [];
|
|
switch ($view) {
|
|
case "index":
|
|
case "page":
|
|
$page;
|
|
if ($view == 'index') {
|
|
$template = $currentTheme . '.index';
|
|
$page = $this->pages->getBySlug('first');
|
|
} else {
|
|
$template = $currentTheme . '.page';
|
|
//if coming from theme page, grabs id of latest page
|
|
if ($id == null) {
|
|
$id = $this->getPageID();
|
|
}
|
|
$page = $this->pages->getById($id);
|
|
}
|
|
$pageData = $this->sort->page($page);
|
|
break;
|
|
case "tags":
|
|
$template = $currentTheme . '.tags';
|
|
$pageData = $this->sort->tags();
|
|
break;
|
|
case "archives":
|
|
case "archive":
|
|
$template = $currentTheme . '.archive';
|
|
$pageData = $this->sort->archive();
|
|
break;
|
|
default:
|
|
$template = $currentTheme . '.index';
|
|
$page = $this->pages->getBySlug('first');
|
|
$pageData = $this->sort->page($page);
|
|
}
|
|
if ($this->member::status()) {
|
|
return view($template, $pageData);
|
|
} else {
|
|
return redirect('dashboard/start');
|
|
}
|
|
}
|
|
|
|
private function getPageID()
|
|
{
|
|
$book = $this->pages->getAll();
|
|
$page = $book->where('layout', 'page')->first();
|
|
return $page['uuid'];
|
|
}
|
|
}
|