2024-03-14 16:58:11 -06:00
|
|
|
<?php
|
|
|
|
|
2024-05-09 11:24:12 -06:00
|
|
|
namespace App\Http\Controllers;
|
2024-03-14 16:58:11 -06:00
|
|
|
|
|
|
|
use App\Interfaces\PageRepositoryInterface;
|
2024-05-12 22:14:53 -06:00
|
|
|
use App\Services\Assets\AssetService;
|
2024-05-13 12:06:05 -06:00
|
|
|
use App\Interfaces\MemberRepositoryInterface;
|
2024-05-12 22:14:53 -06:00
|
|
|
use App\Services\Data\SortingService;
|
|
|
|
use App\Services\Data\ThemeService;
|
2024-03-14 16:58:11 -06:00
|
|
|
|
|
|
|
class ThemeController extends Controller
|
|
|
|
{
|
|
|
|
protected PageRepositoryInterface $pages;
|
2024-05-13 12:06:05 -06:00
|
|
|
protected MemberRepositoryInterface $member;
|
2024-03-16 12:36:51 -06:00
|
|
|
protected AssetService $assets;
|
2024-03-14 16:58:11 -06:00
|
|
|
protected SortingService $sort;
|
2024-04-25 15:03:06 -06:00
|
|
|
protected ThemeService $themes;
|
2024-03-14 16:58:11 -06:00
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
PageRepositoryInterface $pageRepository,
|
2024-05-13 12:06:05 -06:00
|
|
|
MemberRepositoryInterface $memberRepo,
|
2024-03-16 12:36:51 -06:00
|
|
|
AssetService $assetService,
|
2024-03-14 16:58:11 -06:00
|
|
|
SortingService $sortService,
|
2024-04-25 15:03:06 -06:00
|
|
|
ThemeService $themeService,
|
2024-03-14 16:58:11 -06:00
|
|
|
) {
|
2024-03-16 12:36:51 -06:00
|
|
|
$this->pages = $pageRepository;
|
2024-05-13 12:06:05 -06:00
|
|
|
$this->member = $memberRepo;
|
2024-03-16 12:36:51 -06:00
|
|
|
$this->assets = $assetService;
|
|
|
|
$this->sort = $sortService;
|
2024-04-25 15:03:06 -06:00
|
|
|
$this->themes = $themeService;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function start()
|
|
|
|
{
|
2024-05-13 12:06:05 -06:00
|
|
|
if ($this->member::status()) {
|
2024-04-25 15:03:06 -06:00
|
|
|
return view('theme.start', [
|
2024-05-13 12:06:05 -06:00
|
|
|
"status" => $this->member::status(),
|
2024-04-25 15:03:06 -06:00
|
|
|
"title" => "Fipamo Theme Kit",
|
|
|
|
"pages" => $this->themes->getCustomViews('page')
|
|
|
|
]);
|
|
|
|
} else {
|
2024-05-06 15:09:24 -06:00
|
|
|
return redirect('dashboard');
|
2024-04-25 15:03:06 -06:00
|
|
|
}
|
2024-03-14 16:58:11 -06:00
|
|
|
}
|
|
|
|
|
2024-06-26 17:10:24 -06:00
|
|
|
public function getView($view = 'index', $id = null)
|
2024-03-14 16:58:11 -06:00
|
|
|
{
|
2024-03-16 12:36:51 -06:00
|
|
|
//move assets to theme testing dir
|
|
|
|
$this->assets->moveToTheme();
|
|
|
|
$currentTheme = $this->assets->getCurrentTheme();
|
2024-03-15 14:28:26 -06:00
|
|
|
$template;
|
|
|
|
$pageData = [];
|
2024-03-14 20:03:46 -06:00
|
|
|
switch ($view) {
|
2024-03-15 14:28:26 -06:00
|
|
|
case "index":
|
2024-03-14 20:03:46 -06:00
|
|
|
case "page":
|
2024-06-26 17:10:24 -06:00
|
|
|
$page;
|
|
|
|
if ($view == 'index') {
|
|
|
|
$template = $currentTheme . '.index';
|
2024-09-04 14:32:36 -06:00
|
|
|
$page = $this->pages->getById(0);
|
2024-06-26 17:10:24 -06:00
|
|
|
} else {
|
2024-03-16 12:36:51 -06:00
|
|
|
$template = $currentTheme . '.page';
|
2024-06-26 17:10:24 -06:00
|
|
|
//if coming from theme page, grabs id of latest page
|
|
|
|
if ($id == null) {
|
2024-09-04 14:32:36 -06:00
|
|
|
$uuid = $this->getPageUUID();
|
2024-11-01 15:23:22 -06:00
|
|
|
} else {
|
|
|
|
//get page by uuid
|
|
|
|
$page = $this->pages->getByUuid($id);
|
2024-06-26 17:10:24 -06:00
|
|
|
}
|
|
|
|
}
|
2024-06-25 15:33:42 -06:00
|
|
|
$pageData = $this->sort->page($page);
|
2024-03-15 14:28:26 -06:00
|
|
|
break;
|
|
|
|
case "tags":
|
2024-03-16 12:36:51 -06:00
|
|
|
$template = $currentTheme . '.tags';
|
2024-03-28 16:42:37 -06:00
|
|
|
$pageData = $this->sort->tags();
|
2024-03-15 14:28:26 -06:00
|
|
|
break;
|
|
|
|
case "archives":
|
|
|
|
case "archive":
|
2024-03-16 12:36:51 -06:00
|
|
|
$template = $currentTheme . '.archive';
|
2024-03-28 16:42:37 -06:00
|
|
|
$pageData = $this->sort->archive();
|
2024-03-14 20:03:46 -06:00
|
|
|
break;
|
2024-04-25 15:03:06 -06:00
|
|
|
default:
|
2024-06-25 15:33:42 -06:00
|
|
|
$template = $currentTheme . '.index';
|
2024-06-26 17:10:24 -06:00
|
|
|
$page = $this->pages->getBySlug('first');
|
2024-04-25 15:03:06 -06:00
|
|
|
$pageData = $this->sort->page($page);
|
2024-03-14 20:03:46 -06:00
|
|
|
}
|
2024-05-13 12:06:05 -06:00
|
|
|
if ($this->member::status()) {
|
2024-03-15 14:28:26 -06:00
|
|
|
return view($template, $pageData);
|
2024-03-14 16:58:11 -06:00
|
|
|
} else {
|
|
|
|
return redirect('dashboard/start');
|
|
|
|
}
|
|
|
|
}
|
2024-06-26 17:10:24 -06:00
|
|
|
|
2024-09-04 14:32:36 -06:00
|
|
|
private function getPageUUID()
|
2024-06-26 17:10:24 -06:00
|
|
|
{
|
|
|
|
$book = $this->pages->getAll();
|
|
|
|
$page = $book->where('layout', 'page')->first();
|
|
|
|
return $page['uuid'];
|
|
|
|
}
|
2024-03-14 16:58:11 -06:00
|
|
|
}
|