<?php
namespace App\Controller;
use App\Entity\Avis;
use App\Entity\Histo;
use App\Entity\Terme;
use App\Entity\AvisAr;
use App\Entity\LogCon;
use App\Form\AvisType;
use App\Entity\Domaine;
use App\Entity\Visitor;
use App\Entity\Historic;
use App\Entity\HistoricAr;
use App\Entity\Recommandation;
use App\Entity\RecommandationAr;
use App\Form\RecommandationType;
use App\Form\RecommandationArType;
use PhpOffice\PhpSpreadsheet\IOFactory;
use Doctrine\ORM\EntityManagerInterface;
use phpoffice\phpexcel\Classes\PHPExcel;
use phpDocumentor\Reflection\Types\Integer;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bridge\Doctrine\Form\Type\EntityType;
use Symfony\Component\Form\Extension\Core\Type\TextType;
use Symfony\Component\Form\Extension\Core\Type\ChoiceType;
use Symfony\Component\Form\Extension\Core\Type\SubmitType;
use Symfony\Component\Form\Extension\Core\Type\TextareaType;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Knp\Component\Pager\PaginatorInterface;
class RecController extends AbstractController
{
/**
* @Route("/rec", name="rec")
*/
public function index_rec(Request $request, PaginatorInterface $paginator): Response
{
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$query = $repo->createQueryBuilder('r')->getQuery();
$Avisnom = $repo->total_av();
$commission = $repo->total_com();
$total = $repo->total();
$recommandations = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
// Numéro de la page
50 // Limite d'affichage
);
$recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
return $this->render('rec/index.html.twig', [
'recommandations' => $recommandations,
'nombre' => $total,
'av' => $Avisnom,
'com' => $commission
]);
}
/**
* @Route("/rec/trad", name="rec_trad")
*/
public function index_trad(Request $request, PaginatorInterface $paginator): Response
{
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$query = $repo->createQueryBuilder('r')->getQuery();
$Avisnom = $repo->total_av();
$commission = $repo->total_com();
$total = $repo->total();
$recommandations = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
// Numéro de la page
50 // Limite d'affichage
);
$recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
return $this->render('rec/index_trad.html.twig', [
'recommandations' => $recommandations,
'nombre' => $total,
'av' => $Avisnom,
'com' => $commission
]);
}
/**
* @Route("/rec/ar", name="rec_ar")
*/
public function index_ar(Request $request, PaginatorInterface $paginator): Response
{
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$query = $repo->createQueryBuilder('r')->getQuery();
$Avisnom = $repo->total_av();
$commission = $repo->total_com();
$total = $repo->total();
$recommandations = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
// Numéro de la page
50 // Limite d'affichage
);
$recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
return $this->render('rec/index_ar.html.twig', [
'recommandations' => $recommandations,
'nombre' => $total,
'av' => $Avisnom,
'com' => $commission
]);
}
/**
* @Route("/rec/new", name="rec_create")
*/
public function form(Request $request, EntityManagerInterface $manager)
{
$histo = new Historic();
$recommandation = new Recommandation();
$form = $this->createForm(RecommandationType::class, $recommandation);
$form->add('AvisURL', EntityType::class, [
'class' => Avis::class,
'choice_label' => 'Intitule',
'label' => 'Avis'
]);
$form->add('Ar', RecommandationArType::class);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$user = $this->getUser();
$recommandationExist = $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
if (!$recommandationExist) {
$manager->persist($recommandation);
$manager->flush();
$message = "Cette Recommandation est saisie avec succés";
$histo->setRec($recommandation);
$histo->setUser($user);
$histo->setType("Création");
$histo->setDate(new \DateTime());
$manager->persist($histo);
$manager->flush();
return $this->redirect('rec/create.html.twig');
} else {
$message = "Cette Recommandation est déjà saisie";
return $this->redirect('rec/create.html.twig');
}
}
$av = true;
$lien = '/rec/new/';
return $this->render('rec/create.html.twig', [
'formRecommandation' => $form->createView(),
'message' => $message,
'av' => $av,
'id' => $av->getid()
// 'recommandation' => $recommandation
]);
}
/**
* @Route("/rec/{id}/edit", name="rec_edit")
*/
public function formed(int $id, Request $request, EntityManagerInterface $manager)
{
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandation = $repo->findOneBy(['id' => $id]);
$form = $this->createForm(RecommandationType::class, $recommandation);
$form->add('AvisURL', EntityType::class, [
'class' => Avis::class,
'choice_label' => 'Intitule',
]);
$form->add('Ar', RecommandationArType::class);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$manager->persist($recommandation);
$manager->flush();
$message = "Cette Recommandation est modifiée avec succés";
$histo = new Histo();
$histo->setUser($this->getUser());
$histo->setType("Modification de recommandation");
$histo->setDate(new \DateTime());
$histo->setCommentaire("Modifier la recommandation \"" . $recommandation->getRecommandation() . "\"/\"" . $recommandation->getAr()->getRecommandation() . "\" de l'avis \"" . $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " . $recommandation->getNPage() . "(fr) " . $recommandation->getAr()->getNPage() . "(ar)");
$manager->persist($histo);
$manager->flush();
}
$av = true;
return $this->render('rec/modify.html.twig', [
'formRecommandation' => $form->createView(),
'message' => $message,
'av' => $av,
'recommandation' => $recommandation
]);
}
/**
* @Route("/rec/new/ar", name="rec_create_ar")
*/
public function form_ar(RecommandationAr $recommandation = null, Request $request, EntityManagerInterface $manager)
{
$histo = new HistoricAr();
$recommandation = new RecommandationAr();
$form = $this->createForm(RecommandationArType::class, $recommandation);
$form->add('AvisURL', EntityType::class, [
'class' => AvisAr::class,
'choice_label' => 'Intitule',
'label' => 'Avis'
]);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$repo = $this->getDoctrine()->getRepository(RecommandationAr::class);
$user = $this->getUser();
$recommandationExist = $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
if (!$recommandationExist) {
$manager->persist($recommandation);
$manager->flush();
$message = "لقد تمت إضافة هذه التوصية بنجاح";
$histo->setRec($recommandation);
$histo->setUser($user);
$histo->setType("Création");
$histo->setDate(new \DateTime());
$manager->persist($histo);
$manager->flush();
} else {
$message = "هذه التوصية موجودة بالفعل";
}
}
$av = true;
return $this->render('rec/create_ar.html.twig', [
'formRecommandationAr' => $form->createView(),
'message' => $message,
'av' => $av,
'recommandation' => $recommandation
]);
}
/**
* @Route("/rec/{id}/edit/ar", name="rec_edit_ar")
*/
public function formed_ar(int $id, Request $request, EntityManagerInterface $manager)
{
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandation = $repo->findOneBy(['Ar' => $id]);
$form = $this->createForm(RecommandationType::class, $recommandation);
$form->add('AvisURL', EntityType::class, [
'class' => Avis::class,
'choice_label' => 'Intitule',
]);
$form->add('Ar', RecommandationArType::class);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$manager->persist($recommandation);
$manager->flush();
$message = "تم تعديل التوصية بنجاح";
$histo = new Histo();
$histo->setUser($this->getUser());
$histo->setType("Modification de recommandation");
$histo->setDate(new \DateTime());
$histo->setCommentaire("Modifier la recommandation \"" . $recommandation->getRecommandation() . "\"/\"" . $recommandation->getAr()->getRecommandation() . "\" de l'avis \"" . $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " . $recommandation->getNPage() . "(fr) " . $recommandation->getAr()->getNPage() . "(ar)");
$manager->persist($histo);
$manager->flush();
}
$av = true;
return $this->render('rec/modify_ar.html.twig', [
'formRecommandation' => $form->createView(),
'message' => $message,
'av' => $av,
'recommandation' => $recommandation
]);
}
/**
*@Route("/recom/{domaine}", name="rec_dom")
*/
public function index_env(string $domaine): Response
{
$re = $this->getDoctrine()->getRepository(Domaine::class);
$dom = $re->findOneBy(['Intitule' => 'Rapport Annuels']);
$rep = $this->getDoctrine()->getRepository(Avis::class);
$avis = $rep->findBy(['domaineId' => $dom]);
return $this->render('rec/index_prepa1.html.twig', [
'Domaine' => $domaine,
'rapports' => $avis
]);
}
/**
*@Route("/rec/{Domaine}", name="rec_domaine")
*/
public function index_eco(string $Domaine, Request $request, PaginatorInterface $paginator): Response
{
$re = $this->getDoctrine()->getRepository(Domaine::class);
$dom = $re->findOneBy(['Intitule' => $Domaine]);
$rep = $this->getDoctrine()->getRepository(Avis::class);
$avis = $rep->findBy(['domaineId' => $dom]);
$repos = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandations = $repos->findBy(['AvisURL' => $avis]);
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandations = $repos->findBy(['AvisURL' => $avis]);
$query = $repo->createQueryBuilder('r')->getQuery();
$total = $repos->total_dom($dom->getId());
$total_com = $rep->total_com($dom->getId());
$total_avis = $rep->total_dom($dom->getId());
$recommandations = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
// Numéro de la page
50 // Limite d'affichage
);
$recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
return $this->render('rec/index_eco.html.twig', [
'recommandations' => $recommandations,
'Domaine' => $Domaine,
'nombre' => $total,
'nombre_com' => $total_com,
'nombre_av' => $total_avis
]);
}
/**
*@Route("/rec/Environement et developpement durable/ar", name="rec_dom_env")
*/
public function index_env_ar(): Response
{
$domaine = "البيئة والتنمية المستدامة";
return $this->render('rec/index_prepa.html.twig', [
'Domaine' => $domaine,
]);
}
/**
*@Route("/recom/RAPPORTS ANNUELS/ar", name="rec_dom_rap")
*/
public function index_rap_ar(): Response
{
$domaine = "التقارير السنوية";
$re = $this->getDoctrine()->getRepository(Domaine::class);
$dom = $re->findOneBy(['Intitule' => 'Rapport Annuels']);
$rep = $this->getDoctrine()->getRepository(Avis::class);
$avis = $rep->findBy(['domaineId' => $dom]);
return $this->render('rec/index_prepa_ar.html.twig', [
'Domaine' => $domaine,
'rapports' => $avis
]);
}
/**
*@Route("/rec/{domainefr}/ar", name="rec_domaine_ar")
*/
public function index_eco_ar(string $domainefr, Request $request, PaginatorInterface $paginator): Response
{
$repoo = $this->getDoctrine()->getRepository(Domaine::class);
$Domaine = $repoo->findOneBy(['Intitule' => $domainefr]);
$repo = $this->getDoctrine()->getRepository(RecommandationAr::class);
$query = $repo->createQueryBuilder('r')->getQuery();
$recommandations = $repo->findBy(['domainefr' => $domainefr]);
$total = $repo->total_dom($domainefr);
$total_com = $repo->total_dom_com($domainefr);
$total_avis = $repo->total_dom_av($domainefr);
$recommandations = $paginator->paginate(
$query,
$request->query->getInt('page', 1),
// Numéro de la page
50 // Limite d'affichage
);
$recommandations->setTemplate('@KnpPaginator/Pagination/twitter_bootstrap_v4_pagination.html.twig'); //Application du style css
return $this->render('rec/index_eco_ar.html.twig', [
'recommandations' => $recommandations,
'Domaine' => $Domaine->getIntituleAr(),
'DomaineF' => $domainefr,
'nombre' => $total,
'nombre_com' => $total_com,
'nombre_av' => $total_avis
]);
}
/**
* @Route("/ar", name="home_ar")
*/
public function home_ar(EntityManagerInterface $manager)
{
$reposs = $this->getDoctrine()->getRepository(RecommandationAr::class);
$totalar = $reposs->total();
return $this->render('rec/home_ar.html.twig', [
'nombrear' => $totalar
]);
}
/**
* @Route("/", name="home")
*/
public function home(EntityManagerInterface $manager)
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
$ip = $_SERVER['HTTP_CLIENT_IP'];
}
//whether ip is from the proxy
elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
$ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
}
//whether ip is from the remote address
else {
$ip = $_SERVER['REMOTE_ADDR'];
} // L'adresse IP du visiteur
$date = date('Y-m-d'); // La date d'aujourd'hui, sous la forme AAAA-MM-JJ
$visitor = new Visitor();
$visitor->setIp($ip);
$visitor->setDate(new \DateTime());
$manager->persist($visitor);
$manager->flush();
$repos = $this->getDoctrine()->getRepository(Recommandation::class);
$total = $repos->total();
$rep = $this->getDoctrine()->getRepository(Avis::class);
$av = $rep->av();
for ($i = 2; $i < 10; $i++) {
$totaldom[$i] = $repos->total_dom($i);
$total_com[$i] = $rep->total_com($i);
$total_avis[$i] = $rep->total_dom($i);
}
$histo = new LogCon();
$user = $this->getUser();
$histo->setUser($user);
$histo->setType("Accueil");
$histo->setDate(new \DateTime());
$manager->persist($histo);
$manager->flush();
if (!$this->getUser()) {
return $this->render('rec/home.html.twig', [
// 'der' => $lastRow,
'nombre' => $total,
'totaldom' => $totaldom,
'total_com' => $total_com,
'total_avis' => $total_avis,
'av' => $av
]);
} else {
if ($this->getUser()->getDomaine() == "Traducteur") {
$repo = $this->getDoctrine()->getRepository(Terme::class);
$nombre = count($repo->findAll());
$repos = $this->getDoctrine()->getRepository(Avis::class);
$av = count($repos->findAll());
$av_ext = count($repos->avis_ext('CESE'));
$n_ext = count($repo->findBy(['avis' => $repos->avis_ext('CESE')]));
$org = $repo->total_org();
$av_int = count($repos->findBy(['source' => 'CESE']));
$n_int = count($repo->findBy(['avis' => $repos->findBy(['source' => 'CESE'])]));
return $this->render('accueil/home_trad.html.twig', [
'nombre' => $nombre,
'n_av' => $av,
'n_av_ext' => $av_ext,
'n_ext' => $n_ext,
'org' => $org,
'n_av_int' => $av_int,
'n_int' => $n_int
]);
} else {
return $this->render('rec/home.html.twig', [
// 'der' => $lastRow,
'nombre' => $total,
'totaldom' => $totaldom,
'total_com' => $total_com,
'total_avis' => $total_avis,
'av' => $av
]);
}
}
}
/**
* @Route("/rec/{id}", name="rec_show")
*/
public function show($id)
{
return $this->render('rec/show.html.twig', [
'recommandation' => $recommandation
]);
}
/**
* @Route("new", name="befor_create")
*/
public function before()
{
$reposi = $this->getDoctrine()->getRepository(Avis::class);
$Avis = $reposi->findAll();
$repos = $this->getDoctrine()->getRepository(Recommandation::class);
$total = $repos->total();
return $this->render('rec/befor_create.html.twig', [
'Avis' => $Avis,
'nombre' => $total
]);
}
/**
* @Route("new/ar", name="befor_create_ar")
*/
public function before_ar()
{
$reposi = $this->getDoctrine()->getRepository(AvisAr::class);
$Avis = $reposi->findAll();
$repos = $this->getDoctrine()->getRepository(RecommandationAr::class);
$total = $repos->total();
return $this->render('rec/befor_create_ar.html.twig', [
'Avis' => $Avis,
'nombre' => $total
]);
}
/**
* @Route("/rec/new/{id}", name="rec_create_many")
*/
public function forma(int $id, Recommandation $recommandation = null, Request $request, EntityManagerInterface $manager)
{
$recommandation = new Recommandation();
$av = false;
$repoo = $this->getDoctrine()->getRepository(Avis::class);
$avExistt = $repoo->findOneBy(['id' => $id]);
$avar = $avExistt->getAr();
$recommandation->setAvisURL($avExistt);
$form = $this->createForm(RecommandationType::class, $recommandation);
$form->add('Ar', RecommandationArType::class);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandationExist = $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
$recommandation->getAr()->setAvisUrl($avar);
$recommandation->getAr()->setDomainefr($avExistt->getDomaineId()->getIntitule());
if (!$recommandationExist) {
$manager->persist($recommandation);
$manager->flush();
$message = "La Recommandation est saisie avec succés";
$histo = new Histo();
$histo->setUser($this->getUser());
$histo->setType("Ajout Recommandation");
$histo->setDate(new \DateTime());
$histo->setCommentaire("Ajout la recommandation \"" . $recommandation->getRecommandation() . "\"/\"" . $recommandation->getAr()->getRecommandation() . "\" de l'avis \"" . $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " . $recommandation->getNPage() . "(fr) " . $recommandation->getAr()->getNPage() . "(ar)");
$manager->persist($histo);
$manager->flush();
} else {
$message = "Cette Recommandation est déjà saisie";
}
}
return $this->render('rec/create.html.twig', [
'formRecommandation' => $form->createView(),
'editMode' => $recommandation->getId() !== null,
'av' => $av,
'ar' => $avExistt->getId(),
'titre' => $avExistt->getIntitule(),
'message' => $message,
'recommandation' => $recommandation
// 'url' => $url
]);
}
/**
* @Route("/rec/new/{id}/ar", name="rec_create_many_ar")
*/
public function forma_ar(int $id, Recommandation $recommandation = null, Request $request, EntityManagerInterface $manager)
{
$recommandation = new Recommandation();
$av = false;
$repoo = $this->getDoctrine()->getRepository(Avis::class);
$avExistt = $repoo->findOneBy(['id' => $id]);
$avar = $avExistt->getAr();
$recommandation->setAvisURL($avExistt);
$form = $this->createForm(RecommandationType::class, $recommandation);
$form->add('Ar', RecommandationArType::class);
$form->handleRequest($request);
$message = null;
if ($form->isSubmitted() && $form->isValid()) {
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandationExist = $repo->findOneBy(['recommandation' => $recommandation->getRecommandation()]);
$user = $this->getUser();
$recommandation->getAr()->setAvisUrl($avar);
$recommandation->getAr()->setDomainefr($avExistt->getDomaineId()->getIntitule());
if (!$recommandationExist) {
$manager->persist($recommandation);
$manager->flush();
$message = "La Recommandation est saisie avec succés";
$histo = new Histo();
$histo->setUser($this->getUser());
$histo->setType("Ajout Recommandation");
$histo->setDate(new \DateTime());
$histo->setCommentaire("Ajout la recommandation \"" . $recommandation->getAr()->getRecommandation() . "\" de l'avis \"" . $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " . $recommandation->getAr()->getNPage());
$manager->persist($histo);
$manager->flush();
} else {
$message = "Cette Recommandation est déjà saisie";
}
}
return $this->render('rec/create_ar.html.twig', [
'formRecommandation' => $form->createView(),
'editMode' => $recommandation->getId() !== null,
'av' => $av,
'ar' => $avExistt->getId(),
'titre' => $avExistt->getAr()->getIntitule(),
'message' => $message,
'recommandation' => $recommandation
]);
}
/**
* @Route("/rec/{id}/delete", name="rec_delete")
*/
public function delete(Request $request, EntityManagerInterface $manager, int $id)
{
$histo = new Histo();
$repo = $this->getDoctrine()->getRepository(Recommandation::class);
$recommandation = $repo->findOneBy(['id' => $id]);
$repos = $this->getDoctrine()->getRepository(RecommandationAr::class);
$recommandationAr = $repos->findOneBy(['id' => $recommandation->getAr()->getId()]);
$message = null;
$manager->remove($recommandation);
$manager->flush();
$manager->remove($recommandationAr);
$manager->flush();
$histo->setUser($this->getUser());
$histo->setType("Suppression Recommandation");
$histo->setDate(new \DateTime());
$histo->setCommentaire("Supprimer la recommandation \"" . $recommandation->getRecommandation() . "\" de l'avis \"" . $recommandation->getAvisURL()->getIntitule() . "\", qui situe dans la page: " . $recommandation->getNPage());
$manager->persist($histo);
$manager->flush();
return $this->redirectToRoute('rec_domaine', array('Domaine' => $recommandationAr->getDomainefr()));
}
}