<?php
namespace App\Controller;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use App\Repository\SectionsRepository;
use App\Repository\LignesRepository;
use App\Repository\PagesRepository;
use App\Repository\BlocsRepository;
use App\Repository\ContenusRepository;
use App\Repository\CarouselsRepository;
use App\Repository\TypesContenusRepository;
use App\Repository\AccordeonsRepository;
use App\Repository\ActualitesRepository;
use App\Repository\DictionnaireRepository;
use App\Entity\Sections;
use App\Entity\Lignes;
use App\Entity\Blocs;
use App\Entity\Contenus;
use Symfony\Component\Form\Extension\Core\Type\FileType;
use Symfony\Component\Form\Extension\Core\Type\EmailType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\NumberType;
use Symfony\Component\Form\Extension\Core\Type\CheckboxType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\HiddenType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\HttpFoundation\Request;
class AdminController extends AbstractController
{
/**
* @Route("/changer-locale/{locale}", name="changerLocale")
*/
public function changerLocale($locale, Request $request)
{
$loc = $request->getSession()->get('_locale');
$referer = $request->headers->get('referer');
if($locale == 'fr')
{
$temp = str_replace('/en/','/fr/',$referer);
}
if($locale == 'en')
{
$temp = str_replace('/fr/','/en/',$referer);
}
// On stocke la langue demandée dans la session
$request->getSession()->set('_locale', $locale);
if(!empty($temp))
{
return $this->redirect($temp);
}
else
{
return $this->redirect($this->generateUrl('app_industrialisation'));
}
}
/**
* @Route("/maj-fichiers-translation", name="majFichiersTranslation")
*/
public function majFichiersTranslation(DictionnaireRepository $dicoRepo)
{
$em = $this->getDoctrine()->getManager();
$dictionnaire = $dicoRepo->findAll();
/*$TabLang = ['en'];
foreach ($TabLang as $lang){
}*/
$contenuEn = "<?php".PHP_EOL.
"return array(".PHP_EOL;
foreach ($dictionnaire as $ligne) {
$contenuEn .= '"'.$ligne->getCle().'"=>"'.$ligne->getEn().'",'.PHP_EOL;
}
$contenuEn .= ");".PHP_EOL.
"?>";
$document_root = '../translations/';
// Création du fichier en.php
$e = fopen($document_root."messages.en.php", "a");
file_put_contents($document_root."messages.en.php", $contenuEn);
fclose($e);
$contenuFr = "<?php".PHP_EOL.
"return array(".PHP_EOL;
foreach ($dictionnaire as $ligne) {
$contenuFr .= '"'.$ligne->getCle().'"=>"'.$ligne->getFr().'",'.PHP_EOL;
}
$contenuFr .= ");".PHP_EOL.
"?>";
$document_root = '../translations/';
// Création du fichier en.php
$e = fopen($document_root."messages.fr.php", "a");
file_put_contents($document_root."messages.fr.php", $contenuFr);
fclose($e);
return $this->redirect($this->generateUrl('adminDictionnaire'));
}
/**
* @Route("/admin", name="app_admin")
*/
public function index(): Response
{
return $this->render('admin/index.html.twig', [
'controller_name' => 'AdminController',
]);
}
/**
* @Route("/admin/addSection", name="app_addSection")
*/
public function addSection(SectionsRepository $sectionsRepository, LignesRepository $lignesRepository, PagesRepository $pagesRepository,ActualitesRepository $actualitesRepository, Request $request): Response
{
if(isset($_POST['page']))
{
$page = $pagesRepository->findOneById($_POST['page']);
}
if(isset($_POST['actualite']))
{
$actu = $actualitesRepository->findOneById($_POST['actualite']);
}
$section = new Sections();
if(!empty($_FILES))
{
if(!empty($_FILES['imageSection']['tmp_name']))
{
$tmpName = $_FILES['imageSection']['tmp_name'];
$fileNameParts = explode('.', $_FILES['imageSection']['name']);
$ext = end($fileNameParts);
if(!empty($ext))
{
$name = uniqid().'.'.$ext;
$size = $_FILES['imageSection']['size'];
$error = $_FILES['imageSection']['error'];
move_uploaded_file($tmpName, '../public/uploads/sections/'.$name);
$section->setImage($name);
}
}
if(!empty($_FILES['imageRond']['tmp_name']))
{
$tmpName = $_FILES['imageRond']['tmp_name'];
$fileNameParts = explode('.', $_FILES['imageRond']['name']);
$ext = end($fileNameParts);
if(!empty($ext))
{
$name = uniqid().'.'.$ext;
$size = $_FILES['imageRond']['size'];
$error = $_FILES['imageRond']['error'];
move_uploaded_file($tmpName, '../public/uploads/sections/'.$name);
$section->setRond($name);
}
}
}
$section->setColor($_POST['couleurSection']);
$section->setOrdre($_POST['ordreSection']);
if(isset($_POST['page']))
{
$section->setPages($page);
}
if(isset($_POST['actualite']))
{
$section->setActualites($actu);
}
$sectionsRepository->add($section, true);
$ligne = new Lignes();
$ligne->setOrdre(1);
$ligne->setSections($section);
$lignesRepository->add($ligne, true);
$referer = $request->headers->get('referer').'#section'.$section->getId();
return $this->redirect($referer);
}
/**
* @Route("/admin/addBloc/{ligne}/{type}", name="app_addBloc")
*/
public function addBloc(SectionsRepository $sectionsRepository, LignesRepository $lignesRepository, BlocsRepository $blocsRepository, Request $request, $ligne, $type): Response
{
$ligneT = $lignesRepository->findOneById($ligne);
$ligne = new Lignes();
$ligne->setSections($ligneT->getSections());
$ligne->setOrdre(1);
$lignesRepository->add($ligne, true);
if($type == 12)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType($type);
$blocsRepository->add($bloc, true);
}
if($type == 66)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(6);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(6);
$blocsRepository->add($bloc, true);
}
if($type == 444)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(4);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(4);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(4);
$blocsRepository->add($bloc, true);
}
if($type == 84)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(8);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(4);
$blocsRepository->add($bloc, true);
}
if($type == 48)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(4);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(8);
$blocsRepository->add($bloc, true);
}
if($type == 3333)
{
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(3);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(3);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(3);
$blocsRepository->add($bloc, true);
$bloc = new Blocs();
$bloc->setLignes($ligne);
$bloc->SetType(3);
$blocsRepository->add($bloc, true);
}
$referer = $request->headers->get('referer').'#bloc'.$bloc->getId();
return $this->redirect($referer);
}
/**
* @Route("/admin/addContent/{bloc}/{type}", name="app_addContent")
*/
public function app_addContent(BlocsRepository $blocsRepository,ContenusRepository $contenusRepository,TypesContenusRepository $typesContenusRepository, Request $request, $bloc, $type): Response
{
function replaceSpecialChar($str) {
$ch0 = array(
" "=>"_",
"é"=>"e",
"è"=>"e",
"ê"=>"e",
"ë"=>"e",
"à"=>"a",
"ç"=>"c",
"("=>"_",
")"=>"_",
"'"=>"_",
"&"=>"_",
"ù"=>"u",
);
$str = strtr($str,$ch0);
return $str;
}
$block = $blocsRepository->findOneById($bloc);
$referer = $request->headers->get('referer');
if(isset($_POST['page']))
{
$page = $pagesRepository->findOneById($_POST['page']);
}
if(isset($_POST['actualite']))
{
$actu = $actualitesRepository->findOneById($_POST['actualite']);
}
$contenu = new Contenus();
if($type == 'accordeon')
{
$typeCon = $typesContenusRepository->findOneById(8);
$contenu->setBlocs($block);
$contenu->setTypesContenus($typeCon);
$contenusRepository->add($contenu,true);
return $this->redirectToRoute('app_accordeons_index', ['contenu'=>$contenu->getId()]);
}
if($type == 'carousel')
{
$typeCon = $typesContenusRepository->findOneById(9);
$contenu->setBlocs($block);
$contenu->setTypesContenus($typeCon);
$contenusRepository->add($contenu,true);
return $this->redirectToRoute('app_carousels_index', ['contenu'=>$contenu->getId()]);
}
if($type == 'boxpictocarousel')
{
$typeCon = $typesContenusRepository->findOneById(10);
$contenu->setBlocs($block);
$contenu->setTypesContenus($typeCon);
$contenusRepository->add($contenu,true);
return $this->redirectToRoute('app_carousels_index', ['contenu'=>$contenu->getId()]);
}
if($type == 'temoignage')
{
$typeCon = $typesContenusRepository->findOneById(11);
$contenu->setBlocs($block);
$contenu->setTypesContenus($typeCon);
$contenusRepository->add($contenu,true);
return $this->redirectToRoute('app_temoignages_index', []);
}
if($type == 'chiffrescles' || $type == 'chiffrescles2' )
{
if($type == 'chiffrescles')
{
$typeCon = $typesContenusRepository->findOneById(5);
}
if($type == 'chiffrescles2')
{
$typeCon = $typesContenusRepository->findOneById(6);
}
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'texte' )
{
if($type == 'texte')
{
$typeCon = $typesContenusRepository->findOneById(1);
}
$form = $this->createFormBuilder($contenu)
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('document',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'image')
{
$typeCon = $typesContenusRepository->findOneById(2);
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => true, 'label' => false, 'empty_data' => 'ok'))
->add('lien',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreFr',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'video')
{
$typeCon = $typesContenusRepository->findOneById(3);
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('video',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'document')
{
$typeCon = $typesContenusRepository->findOneById(14);
$modaltypeDoc = $request->request->get('modal_select_doc');
$form = $this->createFormBuilder($contenu)
->add('document', FileType::class, array('data_class' => null, 'required' => true, 'label' => false, 'empty_data' => 'ok'))
->add('image', FileType::class, array('data_class' => null, 'required' => true, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('modal',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false,
'data' => $modaltypeDoc
])
->getForm();
}
if($type == 'avantage')
{
if($type == 'avantage')
{
$typeCon = $typesContenusRepository->findOneById(7);
}
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'button')
{
if($type == 'button')
{
$typeCon = $typesContenusRepository->findOneById(12);
$modaltype = $request->request->get('modal_select');
}
$form = $this->createFormBuilder($contenu)
->add('lien',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('modal',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false,
'data' => $modaltype
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'boxpicto')
{
if($type == 'boxpicto')
{
$typeCon = $typesContenusRepository->findOneById(4);
}
if($type == 'avantage')
{
$typeCon = $typesContenusRepository->findOneById(7);
}
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('video',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
$form->handleRequest($request);
if ($form->isSubmitted()) {
if($type == 'image' || $type == 'boxpicto' || $type == 'avantage' || $type == 'boutton')
{
$file = $form->get('image')->getData();
if($file != 'ok') {
$path = '/';
$fileName = str_replace(' ','_',$file->getClientOriginalName());
$file->move(
$this->getParameter('contenus_directory').$path,
$fileName
);
$contenu->setImage($fileName);
}
}
if( $type == 'document' )
{
$file = $form->get('document')->getData();
if($file != 'ok') {
$path = '/';
$fileName = str_replace(' ','_',$file->getClientOriginalName());
$file->move(
$this->getParameter('contenus_directory').$path,
$fileName
);
$contenu->setDocument($fileName);
}
$fileImage = $form->get('image')->getData();
if($fileImage != 'ok') {
$path = '/';
$name = $fileImage->getClientOriginalName();
$fileNameImage = $name.'.'.$fileImage->guessExtension();
$fileImage->move(
$this->getParameter('contenus_directory').$path,
$fileNameImage
);
$contenu->setImage($fileNameImage);
}
else
{
$contenu->setImage($oldImg);
}
}
if(isset($_POST['background']))
{
$contenu->setBackground($_POST['background']);
}
if(isset($_POST['couleur1']))
{
$contenu->setCouleur1($_POST['couleur1']);
}
$contenu->setBlocs($block);
$contenu->setTypesContenus($typeCon);
$contenusRepository->add($contenu,true);
$urlReferer = $_POST['redirection'].'#bloc'.$contenu->getBlocs()->getId();
return $this->redirect($urlReferer);
}
return $this->render('admin/addContenu.html.twig', [
'form' => $form->createView(),
'typeCon'=>$typeCon->getLibelle(),
'contenu'=>$contenu,
'referer' =>$referer
]);
}
/**
* @Route("/admin/editContent/{id}/{type}", name="app_editContent")
*/
public function app_editContent(BlocsRepository $blocsRepository,ContenusRepository $contenusRepository,TypesContenusRepository $typesContenusRepository, Request $request, $id, $type): Response
{
$contenu = $contenusRepository->findOneById($id);
$oldImg = $contenu->getImage();
$oldDoc = $contenu->getDocument();
// $page = $contenu->getBlocs()->getLignes()->getSections()->getPages()->getRoute();
$referer = $request->headers->get('referer');
if($type == 'button')
{
if($type == 'button')
{
$modaltype = $request->request->get('modal_select');
$typeCon = $typesContenusRepository->findOneById(12);
}
$form = $this->createFormBuilder($contenu)
->add('lien',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('modal',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false,
'data' => $modaltype
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'document')
{
$typeCon = $typesContenusRepository->findOneById(14);
$modaltypeDoc = $request->request->get('modal_select_doc');
$form = $this->createFormBuilder($contenu)
->add('document', FileType::class, array('data_class' => null, 'required' => true, 'label' => false, 'empty_data' => 'ok'))
->add('image', FileType::class, array('data_class' => null, 'required' => true, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('modal',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false,
'data' => $modaltypeDoc
])
->getForm();
}
if($type == 'chiffrescles' || $type == 'chiffrescles2' )
{
if($type == 'chiffrescles')
{
$typeCon = $typesContenusRepository->findOneById(5);
}
if($type == 'chiffrescles2')
{
$typeCon = $typesContenusRepository->findOneById(6);
}
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'texte' )
{
if($type == 'texte')
{
$typeCon = $typesContenusRepository->findOneById(1);
}
$form = $this->createFormBuilder($contenu)
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('document',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'accordeon')
{
$typeCon = $typesContenusRepository->findOneById(8);
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'image')
{
$typeCon = $typesContenusRepository->findOneById(2);
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('lien',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'video')
{
$typeCon = $typesContenusRepository->findOneById(3);
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('video',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'boxpicto')
{
if($type == 'boxpicto')
{
$typeCon = $typesContenusRepository->findOneById(4);
}
if($type == 'avantage')
{
$typeCon = $typesContenusRepository->findOneById(7);
}
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('video',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'boxmodal')
{
if($type == 'boxmodal')
{
$typeCon = $typesContenusRepository->findOneById(13);
}
if($type == 'boxpict')
{
$typeCon = $typesContenusRepository->findOneById(4);
}
if($type == 'avantage')
{
$typeCon = $typesContenusRepository->findOneById(7);
}
$form = $this->createFormBuilder($contenu)
->add('titreFr',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
if($type == 'avantage')
{
if($type == 'avantage')
{
$typeCon = $typesContenusRepository->findOneById(7);
}
$form = $this->createFormBuilder($contenu)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('titreFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('titreEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteFr',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->add('texteEn',TextareaType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
}
$form->handleRequest($request);
if ($form->isSubmitted()) {
if($type == 'image' || $type == 'boxpicto' || $type == 'avantage')
{
$file = $form->get('image')->getData();
if($file != 'ok') {
$path = '/';
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move(
$this->getParameter('contenus_directory').$path,
$fileName
);
$contenu->setImage($fileName);
}
else
{
$contenu->setImage($oldImg);
}
}
if( $type == 'document' )
{
$file = $form->get('document')->getData();
if($file != 'ok') {
$path = '/';
$origine = str_replace(' ','_',$file->getClientOriginalName());
$fileName = md5(uniqid()).'-'.$origine.'.'.$file->guessExtension();
$file->move(
$this->getParameter('contenus_directory').$path,
$fileName
);
$contenu->setDocument($fileName);
}
else
{
$contenu->setDocument($oldDoc);
}
$fileImage = $form->get('image')->getData();
if($fileImage != 'ok') {
$path = '/';
$fileNameImage = md5(uniqid()).'.'.$fileImage->guessExtension();
$fileImage->move(
$this->getParameter('contenus_directory').$path,
$fileNameImage
);
$contenu->setImage($fileNameImage);
}
else
{
$contenu->setImage($oldImg);
}
}
if(isset($_POST['background']))
{
$contenu->setBackground($_POST['background']);
}
if(isset($_POST['couleur1']))
{
$contenu->setCouleur1($_POST['couleur1']);
}
$contenusRepository->add($contenu,true);
$urlReferer = $_POST['redirection'].'#bloc'.$contenu->getBlocs()->getId();
return $this->redirect($urlReferer);
}
return $this->render('admin/editContenu.html.twig', [
'form' => $form->createView(),
'typeCon'=>$typeCon->getLibelle(),
'contenu'=>$contenu,
'referer' =>$referer
]);
}
/**
* @Route("/admin/deleteContent/{id}", name="app_deleteContent")
*/
public function app_deleteContent(BlocsRepository $blocsRepository,ContenusRepository $contenusRepository,TypesContenusRepository $typesContenusRepository, Request $request, $id): Response
{
$contenu = $contenusRepository->findOneById($id);
$page = $contenu->getBlocs()->getLignes()->getSections()->getPages()->getRoute();
$loc = $request->getLocale();
if(!empty($contenu->getImage()))
{
$lien = '../public/uploads/contenus/'.$contenu->getImage();
unlink($lien);
}
$contenusRepository->remove($contenu, true);
$referer = $this->generateUrl($page, ['locale'=>$loc]).'#bloc'.$contenu->getBlocs()->getId();
return $this->redirect($referer);
}
/**
* @Route("/admin/app_deleteLigne/{id}/{pages}", name="app_deleteLigne")
*/
public function app_deleteLigne(LignesRepository $lignesRepo, BlocsRepository $blocsRepository,ContenusRepository $contenusRepository,PagesRepository $pagesRepository,AccordeonsRepository $accordeonsRepository, CarouselsRepository $carouselsRepository, Request $request, $id, $pages): Response
{
$pageR = $pagesRepository->findOneById($pages);
$page = $pageR->getRoute();
$ligne = $lignesRepo->findOneById($id);
$blocks = $blocsRepository->findBy(['Lignes'=>$ligne]);
foreach($blocks as $block)
{
$section = $block->getLignes()->getSections()->getId();
$contenu = $contenusRepository->findBy(['Blocs'=>$block]);
$idsContenu = array();
foreach($contenu as $res)
{
array_push($idsContenu,$res->getId());
if($res->getImage() != "ok")
{
$lien = '../public/uploads/contenus/'.$res->getImage();
unlink($lien);
}
}
$accordeons = $accordeonsRepository->findBy(['Contenus'=>$idsContenu]);
// SUPPRESSION DES ACCORDEONS
foreach($accordeons as $resA)
{
$accordeonsRepository->remove($resA, true);
}
$carousels = $carouselsRepository->findBy(['Contenus'=>$idsContenu]);
// SUPPRESSION DES CAROUSELS
foreach($carousels as $resC)
{
if(!empty($resC->getImage()))
{
$lien = '../public/uploads/carousels/'.$resC->getImage();
unlink($lien);
}
$carouselsRepository->remove($resC, true);
}
foreach($contenu as $res)
{
$contenusRepository->remove($res, true);
}
$blocsRepository->remove($block, true);
}
$lignesRepo->remove($ligne, true);
// return $this->redirectToRoute($page, []);
$referer = $request->headers->get('referer').'#section'.$section;
return $this->redirect($referer);
}
/**
* @Route("/admin/app_deleteBlock/{id}/{pages}", name="app_deleteBlock")
*/
public function app_deleteBlock(BlocsRepository $blocsRepository,ContenusRepository $contenusRepository,PagesRepository $pagesRepository,AccordeonsRepository $accordeonsRepository, CarouselsRepository $carouselsRepository, Request $request, $id, $pages): Response
{
$pageR = $pagesRepository->findOneById($pages);
$page = $pageR->getRoute();
$block = $blocsRepository->findOneBy(['id'=>$id]);
$section = $block->getLignes()->getSections()->getId();
$contenu = $contenusRepository->findBy(['Blocs'=>$block]);
$idsContenu = array();
foreach($contenu as $res)
{
array_push($idsContenu,$res->getId());
if(!empty($res->getImage()))
{
$lien = '../public/uploads/contenus/'.$res->getImage();
unlink($lien);
}
}
$accordeons = $accordeonsRepository->findBy(['Contenus'=>$idsContenu]);
// SUPPRESSION DES ACCORDEONS
foreach($accordeons as $resA)
{
$accordeonsRepository->remove($resA, true);
}
$carousels = $carouselsRepository->findBy(['Contenus'=>$idsContenu]);
// SUPPRESSION DES CAROUSELS
foreach($carousels as $resC)
{
if(!empty($resC->getImage()))
{
$lien = '../public/uploads/carousels/'.$resC->getImage();
unlink($lien);
}
$carouselsRepository->remove($resC, true);
}
foreach($contenu as $res)
{
$contenusRepository->remove($res, true);
}
$blocsRepository->remove($block, true);
// return $this->redirectToRoute($page, []);
$referer = $request->headers->get('referer').'#section'.$section;
return $this->redirect($referer);
}
/**
* @Route("/admin/deleteSection/{id}/{pages}", name="app_deleteSection")
*/
public function app_deleteSection(BlocsRepository $blocsRepository, LignesRepository $lignesRepository,SectionsRepository $sectionsRepository,ContenusRepository $contenusRepository,PagesRepository $pagesRepository,AccordeonsRepository $accordeonsRepository, CarouselsRepository $carouselsRepository, Request $request, $id, $pages): Response
{
$pageR = $pagesRepository->findOneById($pages);
if(!empty($pageR))
{
$page = $pageR->getRoute();
}
//SECTION, LIGNES, BLOCS, CONTENUS, ACCORDEONS, CAROUSELS
$sections = $sectionsRepository->findOneById($id);
$oldSection = $sections->getId();
$lignes = $lignesRepository->findBy(array('Sections'=>$sections));
foreach($lignes as $ligne)
{
$block = $blocsRepository->findBy(array('Lignes'=>$ligne));
foreach($block as $res)
{
$contenus = $contenusRepository->findBy(array('Blocs'=>$res));
foreach($contenus as $res2)
{
// SUPPRIMER LES ACCORDEONS
$accordeons = $accordeonsRepository->findBy(array('Contenus'=>$res2));
foreach($accordeons as $res4)
{
$accordeonsRepository->remove($res4, true);
}
// SUPPRIMER LES CAROIUSELS
$carousels = $carouselsRepository->findBy(array('Contenus'=>$res2));
foreach($carousels as $res5)
{
$carouselsRepository->remove($res5, true);
}
$contenusRepository->remove($res2, true);
}
$blocsRepository->remove($res, true);
}
$lignesRepository->remove($ligne, true);
}
$sectionsRepository->remove($sections, true);
//return $this->redirectToRoute($page, []);
$referer = $request->headers->get('referer').'#section'.$oldSection;
return $this->redirect($referer);
if(!empty($pageR))
{
//return $this->redirectToRoute($page, []);
$referer = $request->headers->get('referer').'#section'.$oldSection;
return $this->redirect($referer);
}
else
{
$titre = str_replace(' ','_',$sections->getActualites()->getTitreFr());
$titre = str_replace("'",'_',$sections->getActualites()->getTitreFr());
$url = $this->generateUrl('actualitesD', array('id' => $sections->getActualites()->getId(), 'titre' => $titre));
$referer = $url.'#section'.$oldSection;
return $this->redirect($referer);
}
}
/**
* @Route("/admin/updateSection/{id}/{pages}", name="app_updateSection")
*/
public function app_updateSection(BlocsRepository $blocsRepository, LignesRepository $lignesRepository,SectionsRepository $sectionsRepository,ContenusRepository $contenusRepository,PagesRepository $pagesRepository,AccordeonsRepository $accordeonsRepository, CarouselsRepository $carouselsRepository, Request $request, $id, $pages): Response
{
$loc = $request->getLocale();
$pageR = $pagesRepository->findOneById($pages);
if(!empty($pageR))
{
$page = $pageR->getRoute();
}
//SECTION, LIGNES, BLOCS, CONTENUS, ACCORDEONS, CAROUSELS
$sections = $sectionsRepository->findOneById($id);
$oldImg = $sections->getImage();
$oldRond = $sections->getRond();
$form = $this->createFormBuilder($sections)
->add('image', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('rond', FileType::class, array('data_class' => null, 'required' => false, 'label' => false, 'empty_data' => 'ok'))
->add('ordre',NumberType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
$file = $form->get('image')->getData();
if($file != 'ok') {
$path = '/';
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move(
$this->getParameter('sections_directory').$path,
$fileName
);
$sections->setImage($fileName);
}
else
{
$sections->setImage($oldImg);
}
$file = $form->get('rond')->getData();
if($file != 'ok') {
$path = '/';
$fileName = md5(uniqid()).'.'.$file->guessExtension();
$file->move(
$this->getParameter('sections_directory').$path,
$fileName
);
$sections->setRond($fileName);
}
else
{
$sections->setRond($oldRond);
}
$sections->setColor($_POST['background']);
$sectionsRepository->add($sections, true);
if(!empty($pageR))
{
$url = $this->generateUrl($page, array('locale'=>$loc));
$referer = $url.'#section'.$sections->getId();
//$referer = $request->headers->get('referer').'#section'.$sections->getId();
return $this->redirect($referer);
}
else
{
$titre = str_replace(' ','_',$sections->getActualites()->getTitreFr());
$titre = str_replace("'",'_',$sections->getActualites()->getTitreFr());
$url = $this->generateUrl('actualitesD', array('id' => $sections->getActualites()->getId(), 'titre' => $titre,'locale'=>$loc));
$referer = $url.'#section'.$sections->getId();
return $this->redirect($referer);
}
}
return $this->render('admin/updateSection.html.twig', [
'form' => $form->createView(),
'section'=>$sections
]);
}
/**
* @Route("/admin/updateSectionActu/{id}/{pages}", name="app_updateSectionActu")
*/
public function app_updateSectionActu(BlocsRepository $blocsRepository, LignesRepository $lignesRepository,SectionsRepository $sectionsRepository,ContenusRepository $contenusRepository,PagesRepository $pagesRepository,AccordeonsRepository $accordeonsRepository, CarouselsRepository $carouselsRepository, Request $request, $id, $pages): Response
{
$pageR = $pagesRepository->findOneById($pages);
if(!empty($pageR))
{
$page = $pageR->getRoute();
}
//SECTION, LIGNES, BLOCS, CONTENUS, ACCORDEONS, CAROUSELS
$sections = $sectionsRepository->findOneById($id);
$oldImg = $sections->getImage();
$oldRond = $sections->getRond();
$form = $this->createFormBuilder($sections)
->add('ordre',NumberType::class, [
'attr' => ['class' => 'attached-input'],
'label' => false,
'required' => false
])
->getForm();
$form->handleRequest($request);
if ($form->isSubmitted()) {
$sectionsRepository->add($sections, true);
$titre1 = str_replace(' ','_',$sections->getActualites()->getTitreFr());
$titre = str_replace("'",'_',$titre1);
$url = $this->generateUrl('actualitesD', array('id' => $sections->getActualites()->getId(), 'titre' => $titre));
$referer = $url.'#section'.$sections->getId();
return $this->redirectToRoute('actualitesD', array('id' => $sections->getActualites()->getId(), 'titre' => $titre));
}
return $this->render('admin/updateSectionActu.html.twig', [
'form' => $form->createView(),
'section'=>$sections
]);
}
}