<?php
namespace App\Controller;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use App\Controller\AbstractController;
use App\Entity\Categorie;
use App\Entity\Demande;
use App\Entity\Page;
use Sabre\Xml\Reader as XmlReader;
class PartialController extends AbstractController
{
public function categoriesMenu()
{
/** @var PageRepository $repository */
$repository = $this->getPageRepository();
$pages = $repository->getCategorieTree();
return $this->render('Partial/categories_menu.html.twig', array(
'pages' => $pages
));
}
public function preDemande()
{
$preForm = $this->getDemandeForm(new Demande(), true);
return $this->render('Partial/pre_demande.html.twig', array(
'demande_form' => $preForm->createView()
));
}
public function bandeau()
{
$em = $this->getEm();
$page = $em->getRepository(Page::class)->find(205);
return $this->render('Partial/bandeau.html.twig', ['page' => $page]);
}
public function lastDemandes()
{
$demandes = $this->getDemandeRepository()->getLastDemandes($this->getParameter('last_demandes_count'));
return $this->render('Partial/last_demandes.html.twig', array(
'demandes' => $demandes,
));
}
public function indexCategories()
{
$pages = $this->getPageRepository()->getCategorieTree();
return $this->render('Partial/categories_index.html.twig', array(
'pages' => $pages,
'groups' => array_flip($this->getParameter('category_groups'))
));
}
public function lastActus()
{
$curl = curl_init("https://blog.exacompare.fr/feed/");
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.2; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0');
$xml = curl_exec($curl);
curl_close($curl);
$reader = new XmlReader();
$reader->xml($xml);
$result = $reader->parse();
foreach ($result['value'][0]['value'] ?? [] as $value):
if ($value['name'] === '{}item'):
$rss[] = $value;
endif;
endforeach;
$feedCount = 0;
$rssData = [];
foreach ($rss as $entry) {
foreach ($entry['value'] ?? [] as $element):
if (ltrim($element['name'], '{}') === 'description'):
$element['value'] = html_entity_decode(strip_tags($element['value']), ENT_QUOTES);
endif;
$news[ltrim($element['name'], '{}')] = $element['value'];
endforeach;
if ($feedCount == $this->getParameter('last_actus_count')) {
break;
}
$rssData[] = [
'title' => $news['title'],
'description' => substr($news['description'], 0, strpos($news['description'], ' Lire la suite')),
'date_modified' => $news['pubDate'],
'authors' => $news['authors'] ?? null,
'link' => $news['link']
];
$feedCount++;
}
return $this->render('Partial/last_actus.html.twig', array(
'rss' => $rssData ?? [],
));
}
public function footerMenu(Request $request)
{
// $texteQuiSommesNous = $this->getPageRepository()->findOneByType(Page::TYPE_INDEX)->getContent();
return $this->render('Partial/footer_menu.html.twig', array(
'social_links' => array(
'facebook' => $this->getOption('facebook_url'),
'twitter' => $this->getOption('twitter_url'),
// 'googleplus' => $this->getOption('googleplus_url')
'rss' => $this->getOption('rss_url')
),
// 'texte_qui_sommes_nous' => $texteQuiSommesNous
));
}
public function preDemandeHeader(Request $request)
{
$session = $this->getSession();
$demande = $session->get('demande');
$public = $demande === null;
$categorie = false;
if (!$demande && $request->get('cid')) {
$demande = new Demande();
/** @var Demande $categorie */
if ($categorie = $this->getCategorieRepository()->find($request->get('cid'))) {
$demande->setCategorie($categorie);
}
} elseif ($demande && $request->get('cid')) {
if ($demande->getCategorie()) {
if ($demande->getCategorie()->getParent()) {
$idCategorie = $demande->getCategorie()->getParent()->getId();
} else {
$idCategorie = $demande->getCategorie()->getId();
}
if ($request->get('cid') == $idCategorie) {
$categorie = $demande->getCategorie();
} else {
$categorie = $this->getCategorieRepository()->find($request->get('cid'));
$demande->setCategorie($categorie);
}
}
} elseif (!$demande) {
$demande = new Demande();
}
// Default categorie
if (!$categorie) {
$categorie = $this->getCategorieRepository()->find(72);
}
if ($categorie->getParent()) {
$categorie = $this->getCategorieRepository()->find($categorie->getParent()->getId())->getNom();
// $categorie = $categorie->getParent()->getNom();
}
$catGroup = strtok($categorie, " ");
$unwanted_array = array( 'Š' => 'S', 'š' => 's', 'Ž' => 'Z', 'ž' => 'z', 'À' => 'A', 'Á' => 'A', 'Â' => 'A', 'Ã' => 'A', 'Ä' => 'A', 'Å' => 'A', 'Æ' => 'A', 'Ç' => 'C', 'È' => 'E', 'É' => 'E',
'Ê' => 'E', 'Ë' => 'E', 'Ì' => 'I', 'Í' => 'I', 'Î' => 'I', 'Ï' => 'I', 'Ñ' => 'N', 'Ò' => 'O', 'Ó' => 'O', 'Ô' => 'O', 'Õ' => 'O', 'Ö' => 'O', 'Ø' => 'O', 'Ù' => 'U',
'Ú' => 'U', 'Û' => 'U', 'Ü' => 'U', 'Ý' => 'Y', 'Þ' => 'B', 'ß' => 'Ss', 'à' => 'a', 'á' => 'a', 'â' => 'a', 'ã' => 'a', 'ä' => 'a', 'å' => 'a', 'æ' => 'a', 'ç' => 'c',
'è' => 'e', 'é' => 'e', 'ê' => 'e', 'ë' => 'e', 'ì' => 'i', 'í' => 'i', 'î' => 'i', 'ï' => 'i', 'ð' => 'o', 'ñ' => 'n', 'ò' => 'o', 'ó' => 'o', 'ô' => 'o', 'õ' => 'o',
'ö' => 'o', 'ø' => 'o', 'ù' => 'u', 'ú' => 'u', 'û' => 'u', 'ý' => 'y', 'þ' => 'b', 'ÿ' => 'y' );
$catGroup = strtr($catGroup, $unwanted_array);
$demande->setBienType(null);
$preForm = $this->getDemandeForm($demande, true, header: true);
return $this->render('Partial/pre_demande_header.html.twig', array(
'demande_form' => $preForm->createView(),
'categorie' => $categorie,
'catGroup' => $catGroup
));
}
public function sideCategories(Request $request)
{
$pid = $request->get('pid');
if (!$pid) {
$parentId = $this->getCategorieRepository()->getPageIdByCatId($this->getParameter('group_diagnostics'));
$parent = true;
} else {
/** @var Categorie $categorie */
$page = $this->getPageRepository()->find($pid);
if ($page->getParent()) {
$parentId = $page->getParent()->getId();
$parent = false;
} else {
$parentId = $page->getId();
$parent = true;
}
}
if ($parentId == 122) {
$diag = true;
} else {
$diag = false;
}
// echo 'PARENT : ' . $parentId;
$pages = $this->getPageRepository()->getCategoriesForSidebar($parentId);
return $this->render('Partial/side_categories.html.twig', array(
'pages' => $pages,
'diag' => $diag,
'parent' => $parent,
'pid' => $request->get('pid')
));
}
public function localSidebar(Request $request)
{
$pid = $request->get('pid');
if ($pid) {
/** @var Page $page */
$page = $this->getPageRepository()->find($pid);
$parentId = $this->getCategorieRepository()->getPageIdByCatId($this->getParameter('group_diagnostics'));
if ($page->getId() != $parentId && (!$page->getParent() || $page->getParent()->getId() != $parentId)) {
return new Response('', Response::HTTP_NO_CONTENT);
}
}
$pages = $this->getPageRepository()->getLocalPagesByCP(array(
'33000', '59000', '69000', '13000', '34000', '44000', '06000', '75000', '67000', '31000'
));
return $this->render('Partial/local_sidebar.html.twig', array(
'pages' => $pages
));
}
}