fipamo/app/Http/Controllers/Theming/ThemeController.php
ro efb2e4f0bd
created asset service class to handle file moving
theme controller was getting top heavy, so an asset service class was
plugged in to handle moving assets around for theme testing and
eventually to production when HTML rendering is set up
2024-03-16 12:36:51 -06:00

105 lines
4.1 KiB
PHP

<?php
namespace App\Http\Controllers\Theming;
use App\Http\Controllers\Controller;
use App\Interfaces\PageRepositoryInterface;
use App\Services\AuthService;
use App\Services\SortingService;
use App\Services\AssetService;
class ThemeController extends Controller
{
protected PageRepositoryInterface $pages;
protected AuthService $auth;
protected AssetService $assets;
protected SortingService $sort;
public function __construct(
PageRepositoryInterface $pageRepository,
AuthService $authService,
AssetService $assetService,
SortingService $sortService,
) {
$this->pages = $pageRepository;
$this->auth = $authService;
$this->assets = $assetService;
$this->sort = $sortService;
}
public function getView($view = 'index')
{
//move assets to theme testing dir
$this->assets->moveToTheme();
$currentTheme = $this->assets->getCurrentTheme();
$template;
$pageData = [];
switch ($view) {
case "index":
case "page":
$view == 'index' ?
$template = $currentTheme . '.index' :
$template = $currentTheme . '.page';
$page = $this->pages->getById('09E5A362-BA31-4AE2-9DEE-C93DFBE005C3');
$data = $this->sort->page($page);
$pageData = [
"debug" => "true",
"theme" => $currentTheme,
"status" => $this->auth::status(),
"title" => "THEME PAGE",
"meta" => $data['meta'],
"menu" => $data['menu'],
"info" => $data['info'],
"media" => $data['media'],
"files" => $data['files'],
"content" => $data['content'],
"recent" => $data['recent'],
"feature" => $data['featured'],
"tags" => $data['tags'],
"dynamicRender" => $data['dynamicRender'],
];
break;
case "tags":
$template = $currentTheme . '.tags';
$data = $this->sort->tags();
$pageData = [
'debug' => true, // for theme kit
'theme' => $currentTheme, // for theme kit
'title' => 'Pages Tagged as Tag',
'dynamicRender' => $data['info']['dynamicRender'],
'tags' => $data['info']['tags'][3]['pages'],
'info' => $data['info'],
'menu' => $data['info']['menu'],
'media' => [
['file' => $data['info']['image'],
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
],
];
break;
case "archives":
case "archive":
$template = $currentTheme . '.archive';
$data = $this->sort->archive();
$pageData = [
'debug' => true, // for theme kit
'theme' => $currentTheme, // for theme kit
'title' => 'Archives',
'dynamicRender' => $data['info']['dynamicRender'],
'archive' => $data['archive'],
'info' => $data['info'],
'menu' => $data['info']['menu'],
'media' => [
['file' => $data['info']['image'],
'type' => trim(pathinfo($data['info']['image'], PATHINFO_EXTENSION))]
],
];
break;
}
if ($this->auth::status()) {
return view($template, $pageData);
} else {
return redirect('dashboard/start');
}
}
}