Files
dockerfluxodecaixapro/modules/modelo/classes/Controllers/PublicController.php
T
2026-09-01 10:46:29 -03:00

72 lines
2.1 KiB
PHP
Executable File

<?php
namespace Modules\Modelo\Controllers;
use App\Controllers\BaseController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Modules\Modelo\Models\Modelo;
class PublicController extends BaseController
{
/**
* Show public Modelos for Company 1
*/
public function index(Request $request): Response
{
// Define a constant to bypass the company scope if needed
if (!defined('PUBLIC_MODELO_ACCESS')) {
define('PUBLIC_MODELO_ACCESS', true);
}
$query = Modelo::where('modelos_active', true);
// Check visibility logic
$canViewPrivate = false;
if (isset($_SESSION['user_id'])) {
$canViewPrivate = true;
}
if (!$canViewPrivate) {
$query->where('modelos_visibility', 'public');
}
$modelos = $query->orderBy('modelos_order', 'asc')->get();
return $this->renderView('@modelo/public/index.twig', [
'page_title' => 'Nossos Modelos',
'modelos' => $modelos
]);
}
/**
* Show a single Modelo by slug
*/
public function show(Request $request, string $slug): Response
{
if (!defined('PUBLIC_MODELO_ACCESS')) {
define('PUBLIC_MODELO_ACCESS', true);
}
$modelo = Modelo::where('modelos_slug', $slug)
->where('modelos_active', true)
->first();
if (!$modelo) {
return new Response('Modelo não encontrado', 404);
}
// Replace placeholders
$content = $modelo->modelos_content;
$content = str_replace('[site_name]', $_SESSION['bus_name'] ?? 'SysCMS', $content);
$content = str_replace('[current_date]', date('d/m/Y'), $content);
$content = str_replace('[contact_email]', $_SESSION['bus_email'] ?? 'contato@syscms.com', $content);
return $this->renderView('@modelo/public/show.twig', [
'page_title' => $modelo->modelos_title,
'modelo' => $modelo,
'content' => $content
]);
}
}