First Commit
This commit is contained in:
Executable
+108
@@ -0,0 +1,108 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use Kernel\View;
|
||||
use Symfony\Component\HttpFoundation\Response;
|
||||
|
||||
abstract class BaseController
|
||||
{
|
||||
protected View $view;
|
||||
|
||||
public function __construct(View $view)
|
||||
{
|
||||
$this->view = $view;
|
||||
}
|
||||
|
||||
/**
|
||||
* Render a view with data.
|
||||
*
|
||||
* @param string $viewName
|
||||
* @param array $data
|
||||
* @return Response
|
||||
*/
|
||||
protected function renderView(string $viewName, array $data = []): Response
|
||||
{
|
||||
// Get config pages visibility
|
||||
$configPagesVisibility = [];
|
||||
if (class_exists('Modules\Configindex\Models\ConfigPage')) {
|
||||
$busId = $_SESSION['user_idbus'] ?? $_SESSION['current_company_id'] ?? 1;
|
||||
$baseDir = dirname(dirname(__DIR__));
|
||||
$activeTheme = \Kernel\View::getActiveTheme() ?? 'default';
|
||||
$indexViewsDir = $baseDir . '/modules/index/views';
|
||||
$themeViewsDir = $baseDir . '/themes/' . $activeTheme . '/modules/index/views';
|
||||
|
||||
$pages = \Modules\Configindex\Models\ConfigPage::where('config_index_bus_id', $busId)->get();
|
||||
foreach ($pages as $page) {
|
||||
$key = $page->config_index_key;
|
||||
|
||||
// Verifica se o arquivo físico existe
|
||||
$fileExists = false;
|
||||
if ($key === 'index') {
|
||||
$fileExists = true;
|
||||
} else {
|
||||
$possiblePaths = [
|
||||
$indexViewsDir . '/' . $key . '.twig',
|
||||
$indexViewsDir . '/' . $key . '.php',
|
||||
$themeViewsDir . '/' . $key . '.twig',
|
||||
$themeViewsDir . '/' . $key . '.php',
|
||||
$baseDir . '/themes/' . $activeTheme . '/' . $key . '.twig',
|
||||
$baseDir . '/themes/' . $activeTheme . '/' . $key . '.php',
|
||||
$baseDir . '/modules/' . $key . '/views/index.twig', // Adicionado para checar módulos
|
||||
];
|
||||
foreach ($possiblePaths as $path) {
|
||||
if (is_file($path)) {
|
||||
$fileExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$configPagesVisibility[$key] = [
|
||||
'public' => (bool)$page->config_index_show_public_nav && $fileExists,
|
||||
'dashboard' => (bool)$page->config_index_show_dashboard_nav && $fileExists,
|
||||
'title' => $page->config_index_title ?: ucfirst($key)
|
||||
];
|
||||
}
|
||||
// Garante que as páginas padrão tenham uma configuração inicial, mas respeita o banco de dados
|
||||
foreach (['about', 'contact', 'services'] as $key) {
|
||||
if (!isset($configPagesVisibility[$key])) {
|
||||
// Verifica se o arquivo físico existe para os padrões também
|
||||
$fileExists = false;
|
||||
$possiblePaths = [
|
||||
$indexViewsDir . '/' . $key . '.twig',
|
||||
$indexViewsDir . '/' . $key . '.php',
|
||||
$themeViewsDir . '/' . $key . '.twig',
|
||||
$themeViewsDir . '/' . $key . '.php',
|
||||
$baseDir . '/themes/' . $activeTheme . '/' . $key . '.twig',
|
||||
$baseDir . '/themes/' . $activeTheme . '/' . $key . '.php',
|
||||
];
|
||||
foreach ($possiblePaths as $path) {
|
||||
if (is_file($path)) {
|
||||
$fileExists = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Se não estiver no banco, o padrão é oculto (false) para evitar exibição indesejada
|
||||
$configPagesVisibility[$key] = ['public' => false, 'dashboard' => false, 'title' => ucfirst($key)];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Get SEO settings
|
||||
$seoSettings = [];
|
||||
if (class_exists('App\Models\Module')) {
|
||||
$seoModule = \App\Models\Module::where('modules_name', 'seo')->first();
|
||||
if ($seoModule && $seoModule->modules_settings) {
|
||||
$seoSettings = $seoModule->modules_settings;
|
||||
}
|
||||
}
|
||||
|
||||
$commonData = [
|
||||
'config_pages_visibility' => $configPagesVisibility,
|
||||
'seo' => $seoSettings
|
||||
];
|
||||
|
||||
return new Response($this->view->render($viewName, array_merge($commonData, $data)));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user