<?php
namespace App\Controller;
use App\Entity\User;
use App\Repository\UserRepository;
use App\Entity\Upartistik;
use App\Repository\UpartistikRepository;
use App\Entity\MobilierCategories;
use App\Repository\MobilierCategoriesRepository;
use App\Entity\Mobilier;
use App\Repository\MobilierRepository;
use App\Entity\Stats;
use App\Repository\AdminStatsRepository;
use App\Entity\Couv;
use App\Repository\CouvRepository;
use App\Entity\Apropos;
use App\Repository\AproposRepository;
use App\Entity\Accmobilier;
use App\Repository\AccmobilierRepository;
use App\Entity\AccEspPro;
use App\Repository\AccEspProRepository;
use App\Entity\AccContact;
use App\Repository\AccContactRepository;
use App\Entity\Contact;
use App\Repository\ContactRepository;
use App\Entity\ProImages;
use App\Repository\ProImagesRepository;
use App\Entity\ProTexte;
use App\Repository\ProTexteRepository;
use App\Form\UserType;
use App\Form\UserEditType;
use App\Form\UpartistikType;
use App\Form\CouvType;
use App\Form\ContactType;
use App\Form\AproposType;
use App\Form\AccmobilierType;
use App\Form\AccespaceproType;
use App\Form\AccContactType;
use App\Form\EspaceProImageType;
use App\Form\EspaceProTexteType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Component\Security\Core\User\UserInterface;
use Symfony\Component\Security\Core\Encoder\UserPasswordEncoderInterface;
use Doctrine\ORM\EntityManagerInterface;
use Symfony\Component\HttpFoundation\File\UploadedFile;
use Symfony\Component\String\Slugger\SluggerInterface;
use Doctrine\Common\Collections\ArrayCollection;
use Symfony\Component\HttpFoundation\JsonResponse;
use App\Factory\JsonResponseFactory;
use Symfony\Component\HttpFoundation\Session\SessionInterface;
/**
* @Route("/admin")
*/
class AdminController extends AbstractController
{
/**
* @var UserRepository
*/
private $repository;
private $passwordEncoder;
public function __construct(ProTexteRepository $protexterepo, ProImagesRepository $proimagerepo, AccContactRepository $acccontactrepo, AccEspProRepository $accespaceprorepo, AccmobilierRepository $accmobilierrepo, AproposRepository $apropos, CouvRepository $couvrepo, MobilierRepository $mobRepo,AdminStatsRepository $stats, MobilierCategoriesRepository $mobCat, UserRepository $repository, EntityManagerInterface $em, UserPasswordEncoderInterface $passwordEncoder, UpartistikRepository $upartRepo)
{
$this->stats = $stats;
$this->repository = $repository;
$this->em = $em;
$this->passwordEncoder = $passwordEncoder;
$this->upartRepo = $upartRepo;
$this->mobCat = $mobCat;
$this->mobRepo = $mobRepo;
$this->couvrepo = $couvrepo;
$this->aproposrepo = $apropos;
$this->accmobilierrepo = $accmobilierrepo;
$this->accespaceprorepo = $accespaceprorepo;
$this->acccontactrepo = $acccontactrepo;
$this->proimagerepo = $proimagerepo;
$this->protexterepo = $protexterepo;
}
/**
* @Route("/", name="admin_index")
*/
public function index(UserRepository $userRepository): Response
{
// case users
$allAdmins = $userRepository->findAllAdmins();
$allMembres = $userRepository->findAllMembres();
// case Catalogue
$mobRepo = $this->mobRepo->findParOrdreActif();
// case stats // content="text/plain; charset=utf-8"
$image = $this->dessineGraphV();
// recup les visite sur la page construction
//$recupVisite = $this->stats->recupJour(new \DateTime());
// dump($recupVisite);
return $this->render('admin/index.html.twig', [
'controller_name' => 'admin_index',
'upartRepo' => $this->upartRepo->find(1),
'allAdmins' => $allAdmins,
'allMembres' => $allMembres,
'mobRepo' => $mobRepo,
//'graph' => $this->dessineGraph(),
'EncodedImage' => $image,
]);
}
// dessineGraph()
public function dessineGraph()
{
require_once ('graph/jpgraph.php');
require_once ('graph/jpgraph_line.php');
$now = new \DateTime();
// dump($now);
$visite = $this->stats->RecupVisiteSem();
// dump($visite);
$datay1 = array(20,15,23,15,25,15,0);
$datay2 = array(12,9,42,8,6);
$datay3 = array(5,17,32,24,28);
// Setup the graph
$graph = new \Graph(500,340);
$graph->SetScale("textlin");
$theme_class=new \UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Filled Y-grid');
$graph->SetBox(false);
$graph->SetMargin(40,20,36,63,32);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(array('A','B','C','D','E'));
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new \LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Visites');
// Create the second line
$p2 = new \LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Administration');
// Create the third line
$p3 = new \LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('UP artistik');
$graph->legend->SetFrameWeight(1);
// Output line
//$gdImgHandler = $graph->Stroke();
// Display the graph
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
//Start buffering
ob_start();
//Print the data stream to the buffer
$graph->img->Stream();
//Get the conents of the buffer
$image_data = ob_get_contents();
//Stop the buffer/clear it.
ob_end_clean();
//Set the variable equal to the base 64 encoded value of the stream.
//This gets passed to the browser and displayed.
$image = base64_encode($image_data);
return $image;
}
public function dessineGraphV()
{
require_once ('graph/jpgraph.php');
require_once ('graph/jpgraph_line.php');
// recup
$date0 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d"), date("Y")));
$date1 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")+1, date("Y")));
$dateM1 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-1, date("Y")));
$dateM2 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-2, date("Y")));
$dateM3 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-3, date("Y")));
$dateM4 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-4, date("Y")));
$dateM5 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-5, date("Y")));
$dateM6 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-6, date("Y")));
$dateM7 = date("Y-m-d H:i:s", mktime(0, 0, 0, date("m") , date("d")-7, date("Y")));
// recup table visiteur
$visite0 = $this->stats->recupJour($date0, $date1);
$visite1 = $this->stats->recupJour($dateM1, $date0);
$visite2 = $this->stats->recupJour($dateM2, $dateM1);
$visite3 = $this->stats->recupJour($dateM3, $dateM2);
$visite4 = $this->stats->recupJour($dateM4, $dateM3);
$visite5 = $this->stats->recupJour($dateM5, $dateM4);
$visite6 = $this->stats->recupJour($dateM6, $dateM5);
$visite7 = $this->stats->recupJour($dateM7, $dateM6);
// dump($date0);
// dump($date1);
// dump(count($visite0));
$datay1 = array(count($visite7), count($visite6), count($visite5), count($visite4), count($visite3), count($visite2), count($visite1), count($visite0));
$datay2 = array(0,0,0,0,0,0,0);
$datay3 = array(0,0,0,0,0,0,0);
// Setup the graph
$graph = new \Graph(500,230);
$graph->SetScale("textlin");
$theme_class=new \UniversalTheme;
$graph->SetTheme($theme_class);
$graph->img->SetAntiAliasing(false);
$graph->title->Set('Visites');
$graph->SetBox(false);
$graph->SetMargin(40,20,36,63,32);
$graph->img->SetAntiAliasing();
$graph->yaxis->HideZeroLabel();
$graph->yaxis->HideLine(false);
$graph->yaxis->HideTicks(false,false);
$graph->xgrid->Show();
$graph->xgrid->SetLineStyle("solid");
$graph->xaxis->SetTickLabels(
array(
date("D d", mktime(0, 0, 0, date("m") , date("d")-7, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-6, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-5, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-4, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-3, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-2, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d")-1, date("Y"))),
date("D d", mktime(0, 0, 0, date("m") , date("d"), date("Y")))
)
);
$graph->xgrid->SetColor('#E3E3E3');
// Create the first line
$p1 = new \LinePlot($datay1);
$graph->Add($p1);
$p1->SetColor("#6495ED");
$p1->SetLegend('Visites');
// Create the second line
$p2 = new \LinePlot($datay2);
$graph->Add($p2);
$p2->SetColor("#B22222");
$p2->SetLegend('Administration');
// Create the third line
$p3 = new \LinePlot($datay3);
$graph->Add($p3);
$p3->SetColor("#FF1493");
$p3->SetLegend('UP artistik');
$graph->legend->SetFrameWeight(1);
// Output line
//$gdImgHandler = $graph->Stroke();
// Display the graph
$gdImgHandler = $graph->Stroke(_IMG_HANDLER);
//Start buffering
ob_start();
//Print the data stream to the buffer
$graph->img->Stream();
//Get the conents of the buffer
$image_data = ob_get_contents();
//Stop the buffer/clear it.
ob_end_clean();
//Set the variable equal to the base 64 encoded value of the stream.
//This gets passed to the browser and displayed.
$image = base64_encode($image_data);
return $image;
}
/* Gestion de l'espace disque *********************************************** */
/**
* @Route("/espaceDisc/", name="admin_espaceDisc_index", methods={"GET"})
*/
public function espaceDisc(): Response
{
// espace disque serveur
$df = disk_free_space("/");
// dump($df);
$ds = disk_total_space("/");
// dump($ds);
$espUse = number_format(($ds / ($ds - $df)), $decimals = 1 );
// dump($espUse);
return $this->render('admin/espaceDisc.html.twig', [
'controller_name' => 'admin_espaceDisc_index',
'upartRepo' => $this->upartRepo->find(1),
'df' => $df,
'ds' => $ds,
'espUse' => $espUse,
]);
}
/* Gestion de la table USER *********************************************** */
/**
* @Route("/user/", name="admin_user_index", methods={"GET"})
*/
public function indexUser(UserRepository $userRepository): Response
{
$allUser = $userRepository->findAll();
return $this->render('admin/user/index.html.twig', [
'controller_name' => 'admin_user_index',
'upartRepo' => $this->upartRepo->find(1),
'users' => $allUser,
]);
}
/**
* @Route("/user/new", name="admin_user_new", methods={"GET", "POST"})
*/
public function newUser(Request $request, EntityManagerInterface $entityManager): Response
{
$user = new User();
$form = $this->createForm(UserType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
// crypte le mot de passe
$user->setPassword($this->passwordEncoder->encodePassword(
$user,
$form['password']->getData()
));
$entityManager->persist($user);
$entityManager->flush();
return $this->redirectToRoute('admin_user_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('admin/user/new.html.twig', [
'controller_name' => 'admin_user_new',
'upartRepo' => $this->upartRepo->find(1),
'previous' => $request->headers->get("referer"),
'user' => $user,
'form' => $form,
]);
}
/**
* @Route("/user/{id}", name="admin_user_show", methods={"GET"})
*/
public function show(User $user): Response
{
return $this->render('admin/user/show.html.twig', [
'controller_name' => 'admin_user_show',
'upartRepo' => $this->upartRepo->find(1),
'user' => $user,
]);
}
/**
* @Route("/user/{id}/edit", name="admin_user_edit", methods={"GET", "POST"})
*/
public function edit(Request $request, User $user, EntityManagerInterface $entityManager): Response
{
$form = $this->createForm(UserEditType::class, $user);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$entityManager->flush();
return $this->redirectToRoute('admin_user_index', [], Response::HTTP_SEE_OTHER);
}
return $this->renderForm('admin/user/edit.html.twig', [
'controller_name' => 'admin_user_edit',
'upartRepo' => $this->upartRepo->find(1),
'previous' => $request->headers->get("referer"),
'user' => $user,
'form' => $form,
]);
}
/**
* @Route("/user/{id}", name="admin_user_delete", methods={"POST"})
*/
public function delete(Request $request, User $user, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$user->getId(), $request->request->get('_token'))) {
$entityManager->remove($user);
$entityManager->flush();
}
return $this->redirectToRoute('admin_user_index', [], Response::HTTP_SEE_OTHER);
}
/* Gestion de la table UPARTISTIK *********************************************** */
/**
* @Route("/upartistik/", name="admin_upartistik_index", methods={"GET", "POST"})
*/
public function indexUpartistik(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
$form = $this->createForm(UpartistikType::class, $allUpart);
// dump($form);
$form->handleRequest($request);
if ($form->isSubmitted() && $form->isValid()) {
$this->em->persist($allUpart);
$this->em->flush();
//return $this->redirectToRoute('stats_index', [], Response::HTTP_SEE_OTHER);
}
return $this->render('admin/upartistik/index.html.twig', [
'controller_name' => 'admin_upartistik_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'form' => $form->createView(),
]);
}
/* Gestion des graph *********************************************** */
/* Gestion de la page Accueil *********************************************** */
/**
* @Route("/accueil/", name="admin_accueil_index", methods={"GET", "POST"})
*/
public function admin_accueil_index(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
return $this->render('admin/accueil/index.html.twig', [
'controller_name' => 'admin_accueil_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
]);
}
/* Gestion de la case Couverture *********************** */
/**
* @Route("/accueil/couv/", name="admin_accueil_couv_index", methods={"GET", "POST"})
*/
public function admin_accueil_couv_index(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
$allVisuels = $this->couvrepo->findAll();
/*
// init new objet image
$img = new Couv();
$img->setType("ext");
$img->setUrlfile("originalFilename");
$img->setOrdre(1);
$img->setActif(1);
$img->setDatecrea(new \DateTime());
$img->setDuree(22);
$this->em->persist($img);
$this->em->flush();
*/
return $this->render('admin/accueil/couv.html.twig', [
'controller_name' => 'admin_accueil_couv_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'allVisuels' => $allVisuels,
]);
}
/**
* @Route("/accueil/couv/new", name="admin_accueil_couv_new", methods={"GET", "POST"})
*/
public function admin_accueil_couv_new(Request $request, EntityManagerInterface $entityManager): Response
{
$couv = new Couv();
$form = $this->createForm(CouvType::class, $couv);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/couvnew.html.twig', [
'controller_name' => 'admin_accueil_couv_new',
'upartRepo' => $this->upartRepo->find(1),
'couv' => $couv,
'form' => $form,
]);
}
/**
* @Route("/accueil/couv/new/traitement", name="admin_accueil_couv_new_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_couv_new_traitement(Request $request, EntityManagerInterface $entityManager, SluggerInterface $slugger, UserInterface $user): Response
{
// dump($request);
// dump($request->files->all());
// recupere
$image = $request->files->get('couv')["urlfile"];
// dump($image);
$alt = $request->request->get('couv')["alt"];
// dump($alt);
$nbrVisuel = $this->couvrepo->findAll();
// dump(count($image));
$json = array();
// boucle pour chaque image
//for ($i=0; $i<count($image); $i++){
// init new objet image
$img = new Couv();
// construction du nom du document
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$image->guessExtension();
$docExt = strtolower($image->guessExtension());
// configure l'objet image
$img->setType($docExt);
$img->setUrlfile($newFilename);
$img->setOrdre( count($nbrVisuel) + 1);
$img->setActif(1);
$img->setDatecrea(new \DateTime());
$img->setAlt($alt);
// video
if ( $docExt == 'mp4' || $docExt == 'm4v'){
$img->setDuree(22);
}
// image
else{
$img->setDuree(3);
}
// enregistre dans la Bdd
$this->em->persist($img);
$this->em->flush();
// Move the file to the directory where brochures are stored
$destination = $this->copieFile("couv", $newFilename, $user, $image);
//}
$json['ok'] = 'ok';
return new JsonResponse($json);
/*
return 0;
*/
}
/**
* @Route("/accueil/couv/suppr/{id}", name="admin_accueil_couv_delete", methods={"POST"})
*/
public function admin_accueil_couv_delete(Request $request, Couv $couv, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$couv->getId(), $request->request->get('_token'))) {
// 1. recup ordre
$ordreSuppr = $couv->getOrdre();
// 2. vire fichier du disque dur
$destination = $this->getParameter('documents_directory');
unlink($destination."couv/".$couv->getUrlfile());
if ( $couv->getUrlposter() != '' ){
unlink($destination."couv/".$couv->getUrlposter());
}
// 3. vire de la base
$entityManager->remove($couv);
$entityManager->flush();
}
return $this->redirectToRoute('admin_accueil_couv_index', [], Response::HTTP_SEE_OTHER);
}
// fonction de copie du fichier
public function copieFile($repertoire, $newFilename, $user, $lien)
{
try
{
$destination = $this->getParameter('documents_directory').'/'.$repertoire.'/';
$lien->move(
$destination,
$newFilename
);
return $destination;
}
catch (FileException $e)
{
$this->addFlash('success', 'Echec document : '.$newFilename.' !');
return $this->redirectToRoute('priv_docs_liste');
}
}
/* Gestion de la case Ă propos *********************** */
/**
* @Route("/accueil/apropos/", name="admin_accueil_apropos_index", methods={"GET", "POST"})
*/
public function admin_accueil_apropos_index(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
$allVisuels = $this->couvrepo->findAll();
return $this->render('admin/accueil/apropos.html.twig', [
'controller_name' => 'admin_accueil_apropos_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'allVisuels' => $allVisuels,
'apropos' => $this->aproposrepo->find(1),
]);
}
/**
* @Route("/accueil/apropos/new", name="admin_accueil_apropos_new", methods={"GET", "POST"})
*/
public function admin_accueil_apropos_new(Request $request, EntityManagerInterface $entityManager): Response
{
$apropos = new Apropos();
$form = $this->createForm(AproposType::class, $apropos);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/aproposnew.html.twig', [
'controller_name' => 'admin_accueil_apropos_new',
'upartRepo' => $this->upartRepo->find(1),
'apropos' => $apropos,
'form' => $form,
]);
}
/**
* @Route("/accueil/apropos/traitement", name="admin_accueil_apropos_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_apropos_traitement(Request $request): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$apropos = new Apropos();
$apropos->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($apropos);
$this->em->flush();
// reponse
return $this->redirectToRoute('admin_accueil_apropos_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/accueil/apropos/modif/{id}", name="admin_accueil_apropos_modif", methods={"GET", "POST"})
*/
public function admin_accueil_apropos_modif(Request $request, $id): Response
{
$apropos = $this->aproposrepo->find($id);
// dump($apropos);
//$apropos = new Apropos();
$form = $this->createForm(AproposType::class, $apropos);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/aproposnew.html.twig', [
'controller_name' => 'admin_accueil_apropos_modif',
'upartRepo' => $this->upartRepo->find(1),
'apropos' => $apropos,
'form' => $form,
]);
}
/**
* @Route("/accueil/apropos/modif/{id}/traitement", name="admin_accueil_apropos_modif_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_apropos_modif_traitement(Request $request, $id): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$apropos = $this->aproposrepo->find($id);
$apropos->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($apropos);
$this->em->flush();
/*
*/
// reponse
return $this->redirectToRoute('admin_accueil_apropos_index', [], Response::HTTP_SEE_OTHER);
}
/* Gestion de la case mobilier *********************** */
/**
* @Route("/accueil/mobilier/", name="admin_accueil_mobilier_index", methods={"GET", "POST"})
*/
public function admin_accueil_mobilier_index(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
$allVisuels = $this->couvrepo->findAll();
return $this->render('admin/accueil/mobilier.html.twig', [
'controller_name' => 'admin_accueil_mobilier_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'allVisuels' => $allVisuels,
'accmobiliers' => $this->accmobilierrepo->findByOrdre(),
]);
}
/**
* @Route("/accueil/mobilier/new", name="admin_accueil_mobilier_new", methods={"GET", "POST"})
*/
public function admin_accueil_mobilier_new(Request $request, EntityManagerInterface $entityManager): Response
{
$accmobilier = new AccMobilier();
$form = $this->createForm(AccmobilierType::class, $accmobilier);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/mobiliernew.html.twig', [
'controller_name' => 'admin_accueil_mobilier_new',
'upartRepo' => $this->upartRepo->find(1),
'accmobilier' => $this->accmobilierrepo->findAll(),
'form' => $form,
]);
}
/**
* @Route("/accueil/mobilier/new/traitement", name="admin_accueil_mobilier_new_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_mobilier_new_traitement(Request $request, EntityManagerInterface $entityManager, SluggerInterface $slugger, UserInterface $user): Response
{
// dump($request);
// dump($request->files->all());
// recupere
$image = $request->files->get('accmobilier')["url"];
// dump($image);
$alt = $image;
// dump($alt);
$nbrVisuel = $this->accmobilierrepo->findAll();
$ordre = count($nbrVisuel) + 1;
// dump($ordre);
// dump(count($image));
$json = array();
// boucle pour chaque image
//for ($i=0; $i<count($image); $i++){
// init new objet image
$img = new Accmobilier();
// construction du nom du document
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$image->guessExtension();
$docExt = strtolower($image->guessExtension());
// configure l'objet image
// $img->setType($docExt);
$img->setUrl($newFilename);
$img->setOrdre($ordre);
$img->setAlt($originalFilename);
// enregistre dans la Bdd
$this->em->persist($img);
$this->em->flush();
// Move the file to the directory where brochures are stored
$destination = $this->copieFile("accmobilier", $newFilename, $user, $image);
// creation d'une vignette
$this->makeVignette(640, 640, "accmobilier", $destination, $newFilename, $user);
//}
$json['ok'] = 'ok';
return new JsonResponse($json);
}
/**
* @Route("/accueil/mobilier/suppr/{id}", name="admin_accueil_mobilier_delete", methods={"POST"})
*/
public function admin_accueil_mobilier_delete(Request $request, Accmobilier $accmobilier, EntityManagerInterface $entityManager): Response
{
if ($this->isCsrfTokenValid('delete'.$accmobilier->getId(), $request->request->get('_token'))) {
// 1. recup ordre
$ordreSuppr = $accmobilier->getOrdre();
// 2. vire fichier du disque dur
$destination = $this->getParameter('documents_directory');
unlink($destination."accmobilier/".$accmobilier->getUrl());
unlink($destination."accmobilier/640/v_".$accmobilier->getUrl());
// 3. vire de la base
$entityManager->remove($accmobilier);
$entityManager->flush();
}
return $this->redirectToRoute('admin_accueil_mobilier_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/accueil/mobilier/chgOrdreImage", name="admin_accueil_mobilier_chgOrdre", methods={"POST"})
*/
public function admin_accueil_mobilier_chgOrdre(Request $request): Response
{
$json = array();
if ($request->isXmlHttpRequest()) {
$id = $request->request->get('id');
$newOrdre = $request->request->get('newOrdre');
// recup le mobilier
$img = $this->accmobilierrepo->find($id);
// dump($img);
// renseigne
$img->setOrdre($newOrdre);
// update
$this->em->persist($img);
$this->em->flush();
$json['ok'] = $newOrdre;
} else {
$json['error'] = $this->illegalRequest;
}
return new JsonResponse($json);
}
public function makeVignette($widthMax, $heightMax, $repertoire, $destination, $newFilename, $user)
{
$wx = $widthMax;
$hx = $heightMax;
// chemin du repertoire des vignettes
$destinationV = $this->getParameter('documents_directory').'/'.$repertoire.'/640/';
// creation du repertoire vignette
if (!is_dir($destinationV))
{
mkdir($destinationV);
}
// recup taille jpg
list($width, $height) = getimagesize($destination.$newFilename);
// test si paysage ou portrait et recup la taille de la vignette
if ($width > $height)
{
// paysage
$ratio = $wx / $width;
$wx = floor($width * $ratio);
$hx = floor($height * $ratio);
}
else
{
// portrait
$ratio = $hx / $height;
$wx = floor($width * $ratio);
$hx = floor($height * $ratio);
}
// stockage de l'image
$src = imagecreatefromjpeg($destination.$newFilename);
// creation de l'image de reception
$tmp = imagecreatetruecolor($wx, $hx);
// chemin d'Ă©criture
$filenameV = $destinationV.'v_'.$newFilename;
// copy and resize
imagecopyresampled($tmp, $src, 0, 0, 0, 0, $wx, $hx, $width, $height);
// enregistre l'image
imagejpeg($tmp, $filenameV);
//
return true;
}
/* Gestion de la case espace pro *********************** */
/**
* @Route("/accueil/espacepro/", name="admin_accueil_espacepro_index", methods={"GET", "POST"})
*/
public function admin_accueil_espacepro_index(Request $request): Response
{
$allUpart = $this->upartRepo->find(1);
$allVisuels = $this->couvrepo->findAll();
return $this->render('admin/accueil/espacepro.html.twig', [
'controller_name' => 'admin_accueil_espacepro_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'allVisuels' => $allVisuels,
'accespacepros' => $this->accespaceprorepo->findByOrdre(),
]);
}
/**
* @Route("/accueil/espacepro/new", name="admin_accueil_espacepro_new", methods={"GET", "POST"})
*/
public function admin_accueil_espacepro_new(Request $request): Response
{
$accespacepro = new AccEspPro();
$form = $this->createForm(AccespaceproType::class, $accespacepro);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/espacepronew.html.twig', [
'controller_name' => 'admin_accueil_espacepro_new',
'upartRepo' => $this->upartRepo->find(1),
'accespacepros' => $this->accespaceprorepo->findByOrdre(),
'form' => $form,
]);
}
/**
* @Route("/accueil/espacepro/new/traitement", name="admin_accueil_espacepro_new_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_espacepro_new_traitement(Request $request, SluggerInterface $slugger, UserInterface $user): Response
{
// dump($request);
// dump($request->files->all());
// recupere
$image = $request->files->get('accespacepro')["url"];
// dump($image);
$alt = $image;
// dump($alt);
$nbrVisuel = $this->accespaceprorepo->findAll();
$ordre = count($nbrVisuel) + 1;
// dump($ordre);
// dump(count($image));
$json = array();
// boucle pour chaque image
//for ($i=0; $i<count($image); $i++){
// init new objet image
$img = new AccEspPro();
// construction du nom du document
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$image->guessExtension();
$docExt = strtolower($image->guessExtension());
// configure l'objet image
// $img->setType($docExt);
$img->setUrl($newFilename);
$img->setOrdre($ordre);
$img->setAlt($originalFilename);
// enregistre dans la Bdd
$this->em->persist($img);
$this->em->flush();
// Move the file to the directory where brochures are stored
$destination = $this->copieFile("accespacepro", $newFilename, $user, $image);
// creation d'une vignette
$this->makeVignette(640, 640, "accespacepro", $destination, $newFilename, $user);
//}
$json['ok'] = 'ok';
return new JsonResponse($json);
}
/**
* @Route("/accueil/espacepro/suppr/{id}", name="admin_accueil_espacepro_delete", methods={"POST"})
*/
public function admin_accueil_espacepro_delete(Request $request, AccEspPro $accespacepro): Response
{
if ($this->isCsrfTokenValid('delete'.$accespacepro->getId(), $request->request->get('_token'))) {
// 1. recup ordre
$ordreSuppr = $accespacepro->getOrdre();
// 2. vire fichier du disque dur
$destination = $this->getParameter('documents_directory');
unlink($destination."accespacepro/".$accespacepro->getUrl());
unlink($destination."accespacepro/640/v_".$accespacepro->getUrl());
// 3. vire de la base
$this->em->remove($accespacepro);
$this->em->flush();
}
return $this->redirectToRoute('admin_accueil_espacepro_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/accueil/espacepro/chgOrdreImage", name="admin_accueil_espacepro_chgOrdre", methods={"POST"})
*/
public function admin_accueil_espacepro_chgOrdre(Request $request): Response
{
$json = array();
if ($request->isXmlHttpRequest()) {
$id = $request->request->get('id');
$newOrdre = $request->request->get('newOrdre');
// recup le mobilier
$img = $this->accespaceprorepo->find($id);
// dump($img);
// renseigne
$img->setOrdre($newOrdre);
// update
$this->em->persist($img);
$this->em->flush();
$json['ok'] = $newOrdre;
} else {
$json['error'] = $this->illegalRequest;
}
return new JsonResponse($json);
}
/* Gestion de la case contact *********************** */
/**
* @Route("/accueil/contact/", name="admin_accueil_contact_index", methods={"GET", "POST"})
*/
public function admin_accueil_contact_index(Request $request, SessionInterface $session): Response
{
$allUpart = $this->upartRepo->find(1);
// form
$form = $this->createForm(ContactType::class);
$form->handleRequest($request);
// captcha
$name = date('Y_m_d_h_i_s');
return $this->render('admin/accueil/contact.html.twig', [
'controller_name' => 'admin_accueil_contact_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'form' => $form->createView(),
'img' => $this->admin_accueil_contact_captcha($name, $session),
'name' => $name,
'acccontact' => $this->acccontactrepo->findAll(),
]);
}
/**
* @Route("/accueil/contact/captcha/{name}", name="admin_accueil_contact_captcha")
*/
public function admin_accueil_contact_captcha($name, SessionInterface $session): Response
{
// Création d'une image vide et ajout d'un texte
$session->set('captcha', mt_rand(10000, 99999));
$im = imagecreate(110, 40);
$font = realpath('fonts/ASMAN.TTF');
$bg = imagecolorallocate($im, 205, 215, 212);
$textcolor = imagecolorallocate($im, 75, 60, 80);
$code = $session->get('captcha');
imagettftext($im, 23, 5, 15, 35, $textcolor, $font, $code);
// DĂ©finit le contenu de l'en-tĂªte - dans ce cas, image/jpeg
header('Content-Type: image/jpeg');
$save = "captcha/".$name.".jpg";
// Affichage de l'image
imagejpeg($im, $save);
// Libération de la mémoire
imagedestroy($im);
$headers = array(
'Content-Type' => 'image/jpeg',
'Content-Disposition' => 'inline; filename="'.$im.'"'
);
return new Response($save, 200, $headers);
}
/**
* @Route("/accueil/contact/new", name="admin_accueil_contact_new", methods={"GET", "POST"})
*/
public function admin_accueil_contact_new(Request $request, EntityManagerInterface $entityManager): Response
{
$accContact = new AccContact();
$form = $this->createForm(AccContactType::class, $accContact);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/contactnew.html.twig', [
'controller_name' => 'admin_accueil_contact_new',
'upartRepo' => $this->upartRepo->find(1),
'accContact' => $accContact,
'form' => $form,
]);
}
/**
* @Route("/accueil/contact/traitement", name="admin_accueil_contact_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_contact_traitement(Request $request): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$accContact = new AccContact();
$accContact->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($accContact);
$this->em->flush();
// reponse
return $this->redirectToRoute('admin_accueil_contact_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/accueil/contact/modif/{id}", name="admin_accueil_contact_modif", methods={"GET", "POST"})
*/
public function admin_accueil_contact_modif(Request $request, $id): Response
{
$acccontact = $this->acccontactrepo->find($id);
// dump($acccontact);
//$acccontact = new AccContact();
$form = $this->createForm(AccContactType::class, $acccontact);
$form->handleRequest($request);
return $this->renderForm('admin/accueil/contactnew.html.twig', [
'controller_name' => 'admin_accueil_contact_modif',
'upartRepo' => $this->upartRepo->find(1),
'acccontact' => $acccontact,
'form' => $form,
]);
}
/**
* @Route("/accueil/contact/modif/{id}/traitement", name="admin_accueil_contact_modif_traitement", methods={"GET", "POST"})
*/
public function admin_accueil_contact_modif_traitement(Request $request, $id): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$accContact = $this->acccontactrepo->find($id);
$accContact->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($accContact);
$this->em->flush();
/*
*/
// reponse
return $this->redirectToRoute('admin_accueil_contact_index', [], Response::HTTP_SEE_OTHER);
}
/* Gestion de la case espace pro *********************** */
/**
* @Route("/espacepro/", name="admin_espacepro_index", methods={"GET", "POST"})
*/
public function admin_espacepro_index(Request $request, SessionInterface $session): Response
{
$allUpart = $this->upartRepo->find(1);
return $this->render('admin/pro/index.html.twig', [
'controller_name' => 'admin_espacepro_index',
'upartRepo' => $this->upartRepo->find(1),
'allUpart' => $allUpart,
'accespacepros' => $this->accespaceprorepo->findByOrdre(),
'proimages' => $this->proimagerepo->findByOrdre(),
'protexte' => $this->protexterepo->find(1),
]);
}
/**
* @Route("/espacepro/visuel/new", name="admin_espacepro_image_new", methods={"GET", "POST"})
*/
public function admin_espacepro_image_new(Request $request, EntityManagerInterface $entityManager): Response
{
$proImage = new ProImages();
$form = $this->createForm(EspaceProImageType::class, $proImage);
$form->handleRequest($request);
return $this->renderForm('admin/pro/epImagenew.html.twig', [
'controller_name' => 'admin_espacepro_image_new',
'upartRepo' => $this->upartRepo->find(1),
'proimages' => $this->proimagerepo->findByOrdre(),
'form' => $form,
]);
}
/**
* @Route("/espacepro/visuel/new/traitement", name="admin_espacepro_image_new_traitement", methods={"GET", "POST"})
*/
public function admin_espacepro_image_new_traitement(Request $request, EntityManagerInterface $entityManager, SluggerInterface $slugger, UserInterface $user): Response
{
// dump($request);
// dump($request->files->all());
// recupere
$image = $request->files->get('espace_pro_image')["url"];
// dump($image);
$alt = $image;
// dump($alt);
$nbrVisuel = $this->proimagerepo->findAll();
$ordre = count($nbrVisuel) + 1;
// dump($ordre);
// dump(count($image));
$json = array();
// boucle pour chaque image
//for ($i=0; $i<count($image); $i++){
// init new objet image
$img = new ProImages();
// construction du nom du document
$originalFilename = pathinfo($image->getClientOriginalName(), PATHINFO_FILENAME);
$safeFilename = $slugger->slug($originalFilename);
$newFilename = $safeFilename.'-'.uniqid().'.'.$image->guessExtension();
$docExt = strtolower($image->guessExtension());
// configure l'objet image
// $img->setType($docExt);
$img->setUrl($newFilename);
$img->setOrdre($ordre);
$img->setAlt($originalFilename);
// enregistre dans la Bdd
$this->em->persist($img);
$this->em->flush();
// Move the file to the directory where brochures are stored
$destination = $this->copieFile("espacePro", $newFilename, $user, $image);
// creation d'une vignette
$this->makeVignette(640, 640, "espacePro", $destination, $newFilename, $user);
//}
$json['ok'] = 'ok';
return new JsonResponse($json);
}
/**
* @Route("/espacepro/visuel/suppr/{id}", name="admin_espacepro_image_delete", methods={"POST"})
*/
public function admin_espacepro_image_delete(Request $request, ProImages $proImage): Response
{
if ($this->isCsrfTokenValid('delete'.$proImage->getId(), $request->request->get('_token'))) {
// 1. recup ordre
$ordreSuppr = $proImage->getOrdre();
// 2. vire fichier du disque dur
$destination = $this->getParameter('documents_directory');
unlink($destination."espacePro/".$proImage->getUrl());
unlink($destination."espacePro/640/v_".$proImage->getUrl());
// 3. vire de la base
$this->em->remove($proImage);
$this->em->flush();
}
return $this->redirectToRoute('admin_espacepro_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/espacepro/visuel/chgOrdreImage", name="admin_espacepro_image_chgOrdre", methods={"POST"})
*/
public function admin_espacepro_image_chgOrdre(Request $request): Response
{
$json = array();
if ($request->isXmlHttpRequest()) {
$id = $request->request->get('id');
$newOrdre = $request->request->get('newOrdre');
// recup le visuel
$img = $this->proimagerepo->find($id);
// dump($img);
// renseigne
$img->setOrdre($newOrdre);
// update
$this->em->persist($img);
$this->em->flush();
$json['ok'] = $newOrdre;
} else {
$json['error'] = $this->illegalRequest;
}
return new JsonResponse($json);
}
/**
* @Route("/espacepro/texte/new", name="admin_espacepro_texte_new", methods={"GET", "POST"})
*/
public function admin_espacepro_texte_new(Request $request, EntityManagerInterface $entityManager): Response
{
$espaceProTexte = new ProTexte();
$form = $this->createForm(EspaceProTexteType::class, $espaceProTexte);
$form->handleRequest($request);
return $this->renderForm('admin/pro/textenew.html.twig', [
'controller_name' => 'admin_espacepro_texte_new',
'upartRepo' => $this->upartRepo->find(1),
'espaceProTexte' => $espaceProTexte,
'form' => $form,
]);
}
/**
* @Route("/espacepro/texte/traitement", name="admin_espacepro_texte_traitement", methods={"GET", "POST"})
*/
public function admin_espacepro_texte_traitement(Request $request): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$proTexte = new ProTexte();
$proTexte->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($proTexte);
$this->em->flush();
// reponse
return $this->redirectToRoute('admin_espacepro_index', [], Response::HTTP_SEE_OTHER);
}
/**
* @Route("/espacepro/texte/modif/{id}", name="admin_espacepro_texte_modif", methods={"GET", "POST"})
*/
public function admin_espacepro_texte_modif(Request $request, $id): Response
{
$espaceProTexte = $this->protexterepo->find($id);
// dump($espaceProTexte);
//$apropos = new Apropos();
$form = $this->createForm(EspaceProTexteType::class, $espaceProTexte);
$form->handleRequest($request);
return $this->renderForm('admin/pro/textenew.html.twig', [
'controller_name' => 'admin_espacepro_texte_modif',
'upartRepo' => $this->upartRepo->find(1),
'espaceProTexte' => $espaceProTexte,
'form' => $form,
]);
}
/**
* @Route("/espacepro/texte/modif/{id}/traitement", name="admin_espacepro_texte_modif_traitement", methods={"GET", "POST"})
*/
public function admin_espacepro_texte_modif_traitement(Request $request, $id): Response
{
// recup données
$texte = $_POST["texte"];
//$texte = utf8_decode(htmlspecialchars($_POST["texte"]));
// dump($texte);
// formatage
// traitement
$apropos = $this->protexterepo->find($id);
$apropos->setTexte($texte);
// enregistre dans la Bdd
$this->em->persist($apropos);
$this->em->flush();
// reponse
return $this->redirectToRoute('admin_espacepro_index', [], Response::HTTP_SEE_OTHER);
}
}