87 lines
2.4 KiB
PHP
87 lines
2.4 KiB
PHP
<?php
|
|
namespace Templates\Base\OnePage\Handlers;
|
|
|
|
use App\Handlers\Contracts\TemplateHandler;
|
|
use App\Helpers\PageRenderer;
|
|
use App\Helpers\Settings;
|
|
use App\Models\Content;
|
|
use App\Models\Module;
|
|
use App\Models\User;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
abstract class OnePage implements TemplateHandler
|
|
{
|
|
/**
|
|
* Name of settings key for list of pages used on homepage
|
|
*/
|
|
const HOMEPAGE_PAGES_SETTINGS_KEY = 'template.onepage.homepagePages';
|
|
|
|
/**
|
|
* Register admin menu (or multiple ones)
|
|
*
|
|
* This cannot be in ServiceProvider because Session is started at middleware. And ServiceProvider is called before
|
|
* starting any middleware..
|
|
*
|
|
* @param User $user model of logged user
|
|
*/
|
|
public static function registerAdminMenu(User $user)
|
|
{
|
|
$menu = \Menu::instance('mainMenu');
|
|
$menu->route('template.setHomepage', trans('template::admin/mainMenu.setHomepage'), [], 1, ['icon' => 'fa fa-fw fa-home']);
|
|
}
|
|
|
|
/**
|
|
* Prepare Content object to be rendered using Blade template
|
|
*
|
|
* @param Content $content
|
|
*/
|
|
public static function beforeRender(Content & $content)
|
|
{
|
|
if ($content->is_homepage) {
|
|
$pageIds = (array)json_decode(Settings::get(self::HOMEPAGE_PAGES_SETTINGS_KEY, '[]'));
|
|
|
|
if (empty($pageIds)) {
|
|
return [];
|
|
}
|
|
|
|
// get all available pages
|
|
$pages = Content::whereIn('id', $pageIds);
|
|
|
|
if (Auth::user()) {
|
|
$pages = $pages->where('status', '!=', Content::STATUS_DRAFT);
|
|
} else {
|
|
$pages = $pages->where('status', Content::STATUS_PUBLIC);
|
|
}
|
|
|
|
$pages = $pages->get();
|
|
|
|
// create real content from pages
|
|
$pagesRaw = $pagesInTemplates = [];
|
|
foreach ($pages as $page) {
|
|
$pagesRaw[$page->url] = $page;
|
|
$pagesInTemplates[$page->url] = PageRenderer::render($page)
|
|
->render();
|
|
}
|
|
|
|
// dd($pagesRaw);
|
|
|
|
// return pages into template
|
|
return ['pagesHtml' => $pagesInTemplates, 'pagesRaw' => $pagesRaw];
|
|
}
|
|
|
|
return [];
|
|
}
|
|
|
|
/**
|
|
* Install module
|
|
*
|
|
* @return mixed
|
|
*/
|
|
public static function install()
|
|
{
|
|
}
|
|
|
|
public static function uninstall(Module $template)
|
|
{
|
|
}
|
|
} |