<?php
namespace ProjectBiz\PortalBundle\Controller;
use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaComparison;
use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaComposite;
use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaConstant;
use ProjectBiz\DatabaseBundle\Database\Criteria\CriteriaMappedColumn;
use Symfony\Component\HttpFoundation\Request;
class PagesController extends BaseController
{
public function index(Request $request, $slug)
{
$pageRepo = $this->getGenericRepository('Pages');
$criteria = new CriteriaComposite(
'AND',
[
new CriteriaComparison('=', new CriteriaMappedColumn('Pages_Slug'), new CriteriaConstant($slug)),
new CriteriaComparison('=', new CriteriaMappedColumn('Pages_Active'), new CriteriaConstant(1))
]
);
$page = $pageRepo->findOneBy($criteria);
if ($page) {
if (!$this->getSecurityContextWrapper()->checkRights($page['Pages_PermissionRead'])) {
throw $this->createAccessDeniedException();
}
$params = [
'content' => $page['Pages_Content'],
'title' => $page['Pages_Title'],
'breadcrumbs' => [
[
'label' => $this->container->getParameter('citibiz.portal'),
'href' => $this->generateUrl('portal')
],
[
'label' => $page['Pages_Title'],
'href' => $this->generateUrl('pages', ['slug' => $page['Pages_Slug']])
]
]
];
if (!empty($page['Pages_Template'])) {
return $this->render($page['Pages_Template'], $params);
}
return $this->render('@ProjectBizPortal/Pages/index.html.twig', $params);
}
throw $this->createNotFoundException();
}
}