src/Controller/Utilisateur/ContactController.php line 34

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Utilisateur;
  3. use App\Entity\Clients\Client;
  4. use App\Entity\Fournisseurs\Fournisseur;
  5. use App\Entity\Kanban\FicheContact;
  6. use App\Entity\Transporteurs\Transporteur;
  7. use App\Entity\Utilisateur\Contact;
  8. use App\Form\Utilisateur\ContactType;
  9. use App\Form\Utilisateur\SupprimerContactType;
  10. use App\Library\Datatable\Util\Datatable;
  11. use App\Security\Voter\EntityVoter;
  12. use App\Service\Clients\ClientService;
  13. use App\Service\Fournisseurs\FournisseurService;
  14. use Doctrine\ORM\EntityManagerInterface;
  15. use JMS\Serializer\SerializerBuilder;
  16. use Knp\Component\Pager\PaginatorInterface;
  17. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  18. use Symfony\Component\HttpFoundation\Request;
  19. use Symfony\Component\HttpFoundation\JsonResponse;
  20. use Symfony\Component\HttpFoundation\Response;
  21. use Symfony\Component\Routing\Annotation\Route;
  22. use Symfony\Component\Validator\Validator\ValidatorInterface;
  23. use Symfony\Contracts\Translation\TranslatorInterface;
  24. class ContactController extends AbstractController
  25. {
  26.     /**
  27.      * @Route("/contact/nouveau/{id}/{type}", name="dtc_contact_ajouter")
  28.      */
  29.     public function ajouterAction(Request            $request$id$type ""EntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator,
  30.                                   FournisseurService $fournisseurServiceClientService $clientService
  31.     ) {
  32.         $titre_modal $translator->trans("Nouveau contact");
  33.         $contact     = new Contact();
  34.         $user        $this->getUser();
  35.         $contact->setUtilisateur($user);
  36.         $form   $this->createForm(ContactType::class, $contact);
  37.         $errors "";
  38.         $form->handleRequest($request);
  39.         $get        $request->query->all();
  40.         $typeForm   "";
  41.         $liste      "";
  42.         $id_contact "";
  43.         $libelle    "";
  44.         if ($form->isSubmitted()) {
  45.             if ($form->isValid()) {
  46.                 if ($type == 'commande') {
  47.                     $repo_objet $em->getRepository(Client::class);
  48.                     $objet      $repo_objet->find($id);
  49.                     $contact->setClient($objet);
  50.                     $url      "";
  51.                     $typeForm "contact";
  52.                     if (array_key_exists('liste'$get) && $get["liste"] != "") {
  53.                         $liste $get["liste"];
  54.                     }
  55.                 } elseif ($type == 'client') {
  56.                     $repo_objet $em->getRepository(Client::class);
  57.                     $objet      $repo_objet->find($id);
  58.                     $contact->setClient($objet);
  59.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  60.                 } elseif ($type == 'transporteur') {
  61.                     $repo_objet $em->getRepository(Transporteur::class);
  62.                     $objet      $repo_objet->find($id);
  63.                     $contact->setTransporteur($objet);
  64.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  65.                 } elseif ($type == 'fournisseur') {
  66.                     $repo_objet $em->getRepository(Fournisseur::class);
  67.                     $objet      $repo_objet->find($id);
  68.                     $contact->setFournisseur($objet);
  69.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  70.                 }
  71.                 /*
  72.                 if(count($objet->getContacts())>0) {
  73.                    foreach($objet->getContacts() as $c)
  74.                     {
  75.                         if($c->getId() != $contact->getId() and $contact->getDefaut() == true) {
  76.                             $c->setDefaut(false);
  77.                             $em->persist($c);
  78.                         }
  79.                         if($c->getId() != $contact->getId() and $contact->getFacturationExpeditionDefaut() == true) {
  80.                             $c->setFacturationExpeditionDefaut(false);
  81.                             $em->persist($c);
  82.                         }
  83.                     }
  84.                 }
  85.                 */
  86.                 $em->persist($contact);
  87.                 $em->flush();
  88.                 $em->refresh($contact);
  89.                 $libelle trim($contact->getPrenom()." ".$contact->getNom());
  90.                 if ($type == 'fournisseur') {
  91.                     $message_historique            = [];
  92.                     $message_historique["titre"]   = "Création d'un contact";
  93.                     $message_historique["message"] = $libelle." (id : ".$contact->getId().")";
  94.                     $fournisseurService->creerHistorique($objet'defaut'$message_historique);
  95.                 } elseif ($type == 'client') {
  96.                     $message_historique            = [];
  97.                     $message_historique["titre"]   = "Création d'un contact";
  98.                     $message_historique["message"] = $libelle." (id : ".$contact->getId().")";
  99.                     $clientService->creerHistorique($objet'defaut'$message_historique);
  100.                 }
  101.                 if (is_object($objet)) {
  102.                     $this->majContactParDefaut($contact$objet$em);
  103.                 }
  104.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  105.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]);
  106.                 } else {
  107.                     if ($type != 'commande') {
  108.                         $this->addFlash('notice'$translator->trans('Contact ajouté avec succès !'));
  109.                     }
  110.                     return new JsonResponse(
  111.                         ['rendu' => '''valide' => '1''url' => $url'type' => $typeForm'liste' => $liste'libelle' => $libelle'id_contact' => $contact->getId()]
  112.                     );
  113.                 }
  114.             } else {
  115.                 $errors $validator->validate($contact);
  116.                 $rendu  $this->renderView('Utilisateur/Contact/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  117.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  118.             }
  119.         }
  120.         $rendu $this->renderView('Utilisateur/Contact/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  121.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  122.         //return $this->render('Utilisateur/Contact/ajouter.html.twig', array('form' => $form->createView(),'errors'=>$errors,'id'=>$id,'type'=>$type));
  123.     }
  124.     /**
  125.      * @Route("/contact/modifier/{objet}/{id}/{type}", name="dtc_contact_modifier")
  126.      */
  127.     public function modifierAction(Request            $requestContact $objet$id$typeEntityManagerInterface $emTranslatorInterface $translator,
  128.                                    ValidatorInterface $validatorFournisseurService $fournisseurServiceClientService $clientService
  129.     ) {
  130.         $contact     $objet;
  131.         $titre_modal $translator->trans("Modifier contact");
  132.         $get         $request->query->all();
  133.         $user        $this->getUser();
  134.         $contact->setUtilisateur($user);
  135.         $form   $this->createForm(ContactType::class, $contact);
  136.         $errors "";
  137.         $form->handleRequest($request);
  138.         if ($form->isSubmitted()) {
  139.             $droit $this->isGranted(EntityVoter::UPDATEContact::class);
  140.             if ( ! $droit) {
  141.                 $rendu $this->renderView('Utilisateur/Contact/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  142.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  143.             }
  144.             if ($form->isValid()) {
  145.                 if ($type == 'client') {
  146.                     $repo_objet $em->getRepository(Client::class);
  147.                     $objet      $repo_objet->find($id);
  148.                     $contact->setClient($objet);
  149.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  150.                 } elseif ($type == 'transporteur') {
  151.                     $repo_objet $em->getRepository(Transporteur::class);
  152.                     $objet      $repo_objet->find($id);
  153.                     $contact->setTransporteur($objet);
  154.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  155.                 } elseif ($type == 'fournisseur') {
  156.                     $repo_objet $em->getRepository(Fournisseur::class);
  157.                     $objet      $repo_objet->find($id);
  158.                     $contact->setFournisseur($objet);
  159.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  160.                 }
  161.                 /*
  162.                 if(count($objet->getContacts())>0) {
  163.                    foreach($objet->getContacts() as $c)
  164.                     {
  165.                         if($c->getId() != $contact->getId() and $contact->getDefaut() == true) {
  166.                             $c->setDefaut(false);
  167.                             $em->persist($c);
  168.                         }
  169.                     }
  170.                 }
  171.                 */
  172.                 $em->persist($contact);
  173.                 $em->flush();
  174.                 $libelle trim($contact->getPrenom()." ".$contact->getNom()." (".$contact->getEmail().")");
  175.                 if ($type == 'fournisseur') {
  176.                     $message_historique = [];
  177.                     $message_historique["titre"]   = "Modification d'un contact";
  178.                     $message_historique["message"] = $libelle." (id : ".$contact->getId().")";
  179.                     $fournisseurService->creerHistorique($objet'defaut'$message_historique);
  180.                 } elseif ($type == 'client') {
  181.                     $message_historique            = [];
  182.                     $message_historique["titre"]   = "Modification d'un contact";
  183.                     $message_historique["message"] = $libelle." (id : ".$contact->getId().")";
  184.                     $clientService->creerHistorique($objet'defaut'$message_historique);
  185.                 }
  186.                 if (is_object($objet)) {
  187.                     $this->majContactParDefaut($contact$objet$em);
  188.                 }
  189.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  190.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]);
  191.                 } else {
  192.                     $this->addFlash('notice'$translator->trans('Contact modifié avec succès !'));
  193.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  194.                 }
  195.             } else {
  196.                 $errors $validator->validate($contact);
  197.                 $rendu  $this->renderView(
  198.                     'Utilisateur/Contact/ajouter.html.twig',
  199.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'contact' => $contact]
  200.                 );
  201.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  202.             }
  203.         }
  204.         $rendu $this->renderView('Utilisateur/Contact/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'contact' => $contact]);
  205.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  206.     }
  207.     /**
  208.      * @Route("", name="")
  209.      */
  210.     public function listerAction(Request $request$id$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  211.     {
  212.         if ($type == 'client') {
  213.             $repo_objet $em->getRepository(Client::class);
  214.             $objet      $repo_objet->find($id);
  215.         } elseif ($type == 'transporteur') {
  216.             $repo_objet $em->getRepository(Transporteur::class);
  217.             $objet      $repo_objet->find($id);
  218.         } elseif ($type == 'fournisseur') {
  219.             $repo_objet $em->getRepository(Fournisseur::class);
  220.             $objet      $repo_objet->find($id);
  221.         }
  222.         $tableau_class_cellule   = [];
  223.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [0], "visible" => true"orderable" => true"searchable" => true];
  224.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [1], "visible" => true"orderable" => true"searchable" => true];
  225.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [2], "visible" => true"orderable" => true"searchable" => true];
  226.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [3], "visible" => true"orderable" => true"searchable" => true];
  227.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [4], "visible" => true"orderable" => true"searchable" => true];
  228.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [5], "visible" => true"orderable" => true"searchable" => true];
  229.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [6], "visible" => true"orderable" => true];
  230.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [7], "visible" => true"orderable" => true];
  231.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [8], "visible" => true"orderable" => false];
  232.         $this->datatable($datatable$translator$objet$type);
  233.         return $this->render('Utilisateur/Contact/lister.html.twig', ['tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type]);
  234.     }
  235.     /**
  236.      * set datatable configs
  237.      *
  238.      * @return \App\Library\Datatable\Util\Datatable
  239.      */
  240.     private function datatable(Datatable $datatableTranslatorInterface $translator$objet$type "")
  241.     {
  242.         $type_jointure 'x.'.$type;
  243.         $datatable->setDatatableId('dta-contacts')
  244.                   ->setEntity(Contact::class, "x")
  245.                   ->setFields(
  246.                       [
  247.                           //$translator->trans("ID") =>  'x.id',
  248.                           $translator->trans("Civilité")       => 'c.libelle',
  249.                           $translator->trans("Prénom")         => 'x.prenom',
  250.                           $translator->trans("Nom")            => 'x.nom',
  251.                           $translator->trans("Fonction")       => 'x.fonction',
  252.                           $translator->trans("Service")        => 's.libelle',
  253.                           $translator->trans("Email")          => 'x.email',
  254.                           $translator->trans("Téléphone")      => 'x.telephone',
  255.                           $translator->trans("Expédition Fac") => 'x.facturationExpeditionDefaut',
  256.                           $translator->trans("Défaut")         => 'x.defaut',
  257.                           $translator->trans("Actions")        => 'x.id',
  258.                           "_identifier_"                       => 'x.id',
  259.                       ]
  260.                   )
  261.                   ->addJoin('x.civilite''c'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  262.                   ->addJoin('x.serviceObj''s'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  263.                   ->setWhere(
  264.                       $type_jointure.' = :objet',
  265.                       ['objet' => $objet]
  266.                   )
  267.                   ->setRenderers(
  268.                       [
  269.                           /*0 => array(
  270.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  271.                               'params' => array(
  272.                                       'objet'    => 'DTCUtilisateurBundle:Contact',
  273.                                       'champ'    => 'setPrenom',
  274.                                   ),
  275.                           ),
  276.                           1 => array(
  277.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  278.                               'params' => array(
  279.                                       'objet'    => 'DTCUtilisateurBundle:Contact',
  280.                                       'champ'    => 'setNom',
  281.                                   ),
  282.                           ),
  283.                           2 => array(
  284.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  285.                               'params' => array(
  286.                                       'objet'    => 'DTCUtilisateurBundle:Contact',
  287.                                       'champ'    => 'setEmail',
  288.                                   ),
  289.                           ),
  290.                           3 => array(
  291.                               'view' => 'FO/DataTable/edit_texte.html.twig',
  292.                               'params' => array(
  293.                                       'objet'    => 'DTCUtilisateurBundle:Contact',
  294.                                       'champ'    => 'setTelephone',
  295.                                   ),
  296.                           ), */
  297.                           => [
  298.                               'view' => 'FO/DataTable/booleen.html.twig',
  299.                           ],
  300.                           => [
  301.                               'view' => 'FO/DataTable/booleen.html.twig',
  302.                           ],
  303.                           => [
  304.                               'view'   => 'FO/DataTable/actions_modal.html.twig',
  305.                               'params' => [
  306.                                   'edit_route'      => 'dtc_contact_modifier',
  307.                                   'supprimer_route' => 'dtc_contact_supprimer',
  308.                                   'id'              => $objet->getId(),
  309.                                   'type'            => $type,
  310.                                   'entite'          => 'contact',
  311.                                   'table'           => 'dta-contacts',
  312.                                   'objet'           => Contact::class,
  313.                               ],
  314.                           ],
  315.                       ]
  316.                   )
  317.                   ->setOrder("x.id""desc")
  318.                   ->setSearch(true)
  319.                   ->setSearchFields([012345]);
  320.         return $datatable;
  321.     }
  322.     /**
  323.      * Grid action
  324.      * @return Response
  325.      */
  326.     /**
  327.      * @Route("/contact/grid/{id}/{type}", name="dtc_contact_liste_grid")
  328.      */
  329.     public function gridAction(Request $request$id ""$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  330.     {
  331.         if ($type == 'client') {
  332.             $repo_objet $em->getRepository(Client::class);
  333.             $objet      $repo_objet->find($id);
  334.         } elseif ($type == 'transporteur') {
  335.             $repo_objet $em->getRepository(Transporteur::class);
  336.             $objet      $repo_objet->find($id);
  337.         } elseif ($type == 'fournisseur') {
  338.             $repo_objet $em->getRepository(Fournisseur::class);
  339.             $objet      $repo_objet->find($id);
  340.         }
  341.         return $this->datatable($datatable$translator$objet$type)->execute();
  342.     }
  343.     /**
  344.      * @Route("/contact/client/{id}", name="dtc_liste_contact_client")
  345.      */
  346.     public function listerContactClientAction(Request $requestClient $clientEntityManagerInterface $em)
  347.     {
  348.         $options         '';
  349.         $optionsVehicule '';
  350.         $pro             "0";
  351.         $cpt             0;
  352.         $repo_client $em->getRepository(Client::class);
  353.         foreach ($client->getContacts() as $contact) {
  354.             $libelleAdresse "";
  355.             $libelleAdresse .= $contact->getPrenom().' '.$contact->getNom();
  356.             $options .= '<option value="'.$contact->getId().'">'.$libelleAdresse.'</option>';
  357.             $cpt++;
  358.         }
  359.         return new JsonResponse(['options' => $options]);
  360.     }
  361.     /**
  362.      * @Route("/contact/supprimer/{objet}/{id}/{type}", name="dtc_contact_supprimer")
  363.      */
  364.     public function supprimerAction(Request $requestContact $objet$id$typeEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  365.     {
  366.         $contact     $objet;
  367.         $titre_modal $translator->trans("Demande de confirmation");
  368.         $get         $request->query->all();
  369.         $user        $this->getUser();
  370.         $form   $this->createForm(SupprimerContactType::class, $contact);
  371.         $errors "";
  372.         $form->handleRequest($request);
  373.         if ($form->isSubmitted()) {
  374.             if ($form->isValid()) {
  375.                 /*$em = $em;
  376.                 $em->remove($contact);
  377.                 $em->flush();
  378.                 $this->addFlash(
  379.                     'notice',
  380.                    $translator->trans('Adresse supprimée avec succès !')
  381.                 );*/
  382.                 if ($type == 'client') {
  383.                     $repo_objet $em->getRepository(Client::class);
  384.                     $objet      $repo_objet->find($id);
  385.                     $contact->setClient(null);
  386.                     $em->persist($contact);
  387.                     $em->flush();
  388.                     $url $this->generateUrl('dtc_client_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  389.                 } elseif ($type == 'transporteur') {
  390.                     $repo_objet $em->getRepository(Transporteur::class);
  391.                     $objet      $repo_objet->find($id);
  392.                     $contact->setTransporteur(null);
  393.                     $em->persist($contact);
  394.                     $em->flush();
  395.                     $url $this->generateUrl('dtc_transporteur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  396.                 } elseif ($type == 'fournisseur') {
  397.                     $repo_objet $em->getRepository(Fournisseur::class);
  398.                     $objet      $repo_objet->find($id);
  399.                     $contact->setFournisseur(null);
  400.                     $em->persist($contact);
  401.                     $em->flush();
  402.                     $url $this->generateUrl('dtc_fournisseur_modifier', ['id' => $objet->getId(), 'tab' => 'contacts']);
  403.                 }
  404.                 if (array_key_exists('table'$get) && $get["table"] != "") {
  405.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => 'recharger_datatable''id_datatable' => $get["table"]]);
  406.                 } else {
  407.                     $this->addFlash('notice'$translator->trans('Contact supprimé avec succès !'));
  408.                     return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  409.                 }
  410.             } else {
  411.                 $errors $validator->validate($contact);
  412.                 $rendu  $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]);
  413.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  414.             }
  415.         }
  416.         $rendu $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'objet' => $objet]);
  417.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  418.     }
  419.     public function majContactParDefaut($contact$objetEntityManagerInterface $em)
  420.     {
  421.         if (method_exists($objet'getContacts') && ($contact->getDefaut() == || $contact->getFacturationExpeditionDefaut() == 1)) {
  422.             foreach ($objet->getContacts() as $cont) {
  423.                 if ($contact->getDefaut() == && $contact->getId() != $cont->getId()) {
  424.                     $cont->setDefaut(false);
  425.                 }
  426.                 if ($contact->getFacturationExpeditionDefaut() == && $contact->getId() != $cont->getId()) {
  427.                     $cont->setFacturationExpeditionDefaut(false);
  428.                 }
  429.                 $em->persist($cont);
  430.             }
  431.             $em->flush();
  432.         }
  433.     }
  434.     /**
  435.      * @Route("/contact/recherche", name="dtc_contact_recherche")
  436.      */
  437.     public function rechercheAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorPaginatorInterface $paginator)
  438.     {
  439.         $q      $request->query->get('q');
  440.         $page   $request->query->getInt('page'1);
  441.         $client $request->query->get('client');
  442.         $fiche  $request->query->get('fiche');
  443.         $repo   $em->getRepository(Contact::class);
  444.         //echo "TEST ==>".$fiche;
  445.         if ($client == "") {
  446.             $results = [];
  447.         } else {
  448.             $results $repo->getRechercheContact(trim($q), $client);
  449.         }
  450.         $pagination $paginator->paginate(
  451.             $results/* query NOT result */
  452.             $request->query->getInt('page'1)/*page number*/,
  453.             10/*limit per page*/
  454.         );
  455.         /*
  456.         $pagination_results  = $pagination->getItems();
  457.         $option_placeholde = array("libelle" =>$translator->trans("Sélectionnez"),"id"=>"0");
  458.         if( $request->query->getInt('page', 1) == 1)  array_unshift($pagination_results, $option_placeholde);
  459.         $pagination->setItems($pagination_results);
  460.         */
  461.         $pagination_results $pagination->getItems();
  462.         if ($fiche != "") {
  463.             $repo_fiche_contact $em->getRepository(FicheContact::class);
  464.             foreach ($pagination_results as $key => $value) {
  465.                 $fiche_contact_obj $repo_fiche_contact->findOneBy(["fiche" => $fiche"contact" => $value["id"]]);
  466.                 if (is_object($fiche_contact_obj)) {
  467.                     unset($pagination_results[$key]);
  468.                 }
  469.             }
  470.         }
  471.         if ($q == "" && $page 2) {
  472.             //$option_placeholde = array("libelle"=>"Choisir","id"=>"","departement_id"=>"");
  473.             $option_placeholde = ["libelle" => $translator->trans("Sélectionnez"), "id" => "0"];
  474.             array_unshift($pagination_results$option_placeholde);
  475.         } elseif ($page 2) {
  476.             /*
  477.             $contact_saisie_existe = $repo->findOneBy(array('prenom'=>$q));
  478.             if(!is_object($contact_saisie_existe)) {
  479.                 $option_placeholde = array("libelle"=>"Nouveau contact : ".$q,"id"=>'['.$q.']');
  480.                 array_unshift($pagination_results, $option_placeholde);
  481.                 $option_placeholde = array("libelle" =>$translator->trans("Sélectionnez"),"id"=>"0");
  482.                 array_unshift($pagination_results, $option_placeholde);
  483.             }
  484.             */
  485.             $option_placeholde = ["libelle" => $translator->trans("Sélectionnez"), "id" => "0"];
  486.             array_unshift($pagination_results$option_placeholde);
  487.         }
  488.         $pagination->setItems($pagination_results);
  489.         $serializer SerializerBuilder::create()->build();
  490.         return JsonResponse::fromJsonString($serializer->serialize($pagination'json'));
  491.     }
  492.     /**
  493.      * @Route("/contact/charger-tableau/{id}/{type}", name="dtc_contact_client_charger_tableau")
  494.      * @Route("/contact/charger-tableau/{id}/{type}", name="dtc_contact_charger_tableau")
  495.      */
  496.     public function chargerTableauAction(Request $request$id "0"$type ""EntityManagerInterface $em)
  497.     {
  498.         $objet null;
  499.         if ($type == "client") {
  500.             $repo_objet $em->getRepository(Client::class);
  501.             $objet      $repo_objet->find($id);
  502.         } elseif ($type == "fournisseur") {
  503.             $repo_objet $em->getRepository(Fournisseur::class);
  504.             $objet      $repo_objet->find($id);
  505.         }
  506.         $rendu $this->renderView('Utilisateur/Contact/charger_tableau.html.twig', ["id" => $id"type" => $type"objet" => $objet]);
  507.         return new JsonResponse(['rendu' => $rendu]);
  508.     }
  509. }