src/Controller/ApplicationController.php line 76
<?php
namespace App\Controller;
use App\Services\DbMenu;
use App\Services\DbPage;
use App\Services\DbProduct;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
class ApplicationController extends AbstractController
{
#[Route(
path: ['fr' => '/{_locale}/applications', 'en' => '/{_locale}/applications'],
name: 'applications_menu',
requirements: [
'_locale' => 'en|fr',
],
priority: 4
)]
public function applications_menu(Request $request, DbMenu $dbMenu): Response
{
if ($request->getLocale() == 'fr') {
$link = '/en/applications';
$breadcrumb = array(['name' => 'Applications', 'link_rewrite' => 'applications']);
$lienDb = "applications";
} else {
$link = '/fr/applications';
$breadcrumb = array(['name' => 'Applications', 'link_rewrite' => 'applications']);
$lienDb = "applications";
}
$parent = $dbMenu->getContent($lienDb, $request->getLocale());
$menus = $dbMenu->getMenus($parent[0]['id_cms_category'], $request->getLocale());
$menusCms = $dbMenu->getMenusCms($parent[0]['id_cms_category'], $request->getLocale());
return $this->render('apropos/aproposmenu.html.twig', ['link' => $link, 'breadcrumb' => $breadcrumb, 'menus' => $menus, 'menusCms' => $menusCms]);
}
#[Route(
path: ['fr' => '/{_locale}/applications/{link}', 'en' => '/{_locale}/applications/{link}'],
name: 'applications_sousmenu',
requirements: [
'_locale' => 'en|fr',
],
priority: 3
)]
public function applications_sousmenu(Request $request, DbMenu $dbMenu, $link = null): Response
{
if ($request->getLocale() == 'fr') {
$altlink = '/en/applications';
$breadcrumb = array(['name' => 'Applications', 'link_rewrite' => 'applications']);
} else {
$altlink = '/fr/applications';
$breadcrumb = array(['name' => 'Applications', 'link_rewrite' => 'applications']);
}
$parent = $dbMenu->getContent($link, $request->getLocale());
$content = array(['meta_title' => $parent[0]['name'], 'link_rewrite' => $link]);
$menus = $dbMenu->getMenus($parent[0]['id_cms_category'], $request->getLocale());
$menusCms = $dbMenu->getMenusCms($parent[0]['id_cms_category'], $request->getLocale());
return $this->render('apropos/aproposmenu.html.twig', ['link' => $link, 'breadcrumb' => $breadcrumb, 'menus' => $menus, 'menusCms' => $menusCms, 'contents' => $content]);
}
#[Route(
path: ['fr' => '/{_locale}/applications/{categorie}/{link}', 'en' => '/{_locale}/applications/{categorie}/{link}'],
name: 'application',
requirements: [
'_locale' => 'en|fr',
],
priority: 2
)]
public function application(Request $request, DbPage $dbPage, DbProduct $dbProduct, $categorie = null, $link = null): Response
{
$breadcrumb = [];
foreach (explode('/', $request->getPathInfo()) as $path) {
if (($cat = $dbProduct->getCategories($request->getLocale(), $path)) != []) {
$breadcrumb[] = [
'name' => $cat[0]["name"],
'link_rewrite' => $cat[0]["link_rewrite"]
];
}
}
$contents = $dbPage->getContent($link, $request->getLocale());
$link = $dbPage->getLink($contents[0]['id_cms'], $request, $categorie);
$appProduct = [];
$references = "";
if (preg_match_all('/\{products\}(.*?)\{\/products\}/', $contents[0]['content'], $matches)) {
$resultats = $matches[1];
foreach ($resultats as $resultat) {
$references .= $references == "" ? $resultat : ','.$resultat;
}
foreach (explode(",", $references) as $reference) {
if ($product = $dbProduct->getProductReferenceApplication($request->getLocale(), $reference)) {
array_push($appProduct, $product[0]);
}
}
}
$i = 0;
$remplacement = "";
$menus = $dbProduct->getProductApplicationMenu($request->getLocale());
return $this->render('application/application.html.twig', ['contents' => $contents, 'link' => $link, 'products' => $appProduct, 'menus' => $menus, 'breadcrumb' => $breadcrumb]);
}
}
?>