src/Controller/Fournisseurs/CategorieController.php line 481

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Fournisseurs;
  3. use App\Entity\Fournisseurs\Categorie;
  4. use App\Entity\Fournisseurs\Fournisseur;
  5. use App\Entity\Fournisseurs\FournisseurCategorie;
  6. use App\Form\Fournisseurs\CategorieModalType;
  7. use App\Form\Fournisseurs\CategorieType;
  8. use App\Form\Fournisseurs\SupprimerCategorieType;
  9. use App\Library\Datatable\Util\Datatable;
  10. use App\Security\Voter\EntityVoter;
  11. use App\Service\Utilisateur\ColonneTableauService;
  12. use Doctrine\ORM\EntityManagerInterface;
  13. use JMS\Serializer\SerializerBuilder;
  14. use Knp\Component\Pager\PaginatorInterface;
  15. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  16. use Symfony\Component\HttpFoundation\JsonResponse;
  17. use Symfony\Component\HttpFoundation\Request;
  18. use Symfony\Component\HttpFoundation\Response;
  19. use Symfony\Component\Routing\Annotation\Route;
  20. use Symfony\Component\Validator\Validator\ValidatorInterface;
  21. use Symfony\Contracts\Translation\TranslatorInterface;
  22. class CategorieController extends AbstractController
  23. {
  24.     /**
  25.      * @Route("/categories-fournisseur/dupliquer/{id}", name="dtc_categorie_fournisseur_dupliquer")
  26.      */
  27.     public function dupliquerAction(Request $requestCategorie $categorieEntityManagerInterface $emTranslatorInterface $translator)
  28.     {
  29.         $categorie_duplique = clone $categorie;
  30.         $categorie_duplique->setLibelle("COPIE ".$categorie_duplique->getLibelle());
  31.         $em->persist($categorie_duplique);
  32.         $em->flush();
  33.         $this->addFlash(
  34.             'notice',
  35.             $translator->trans('Catégorie fournisseur dupliquée avec succès !')
  36.         );
  37.         return $this->redirectToRoute('dtc_categorie_fournisseur_liste');
  38.     }
  39.     /**
  40.      * @Route("/Categories-fournisseur/nouveau", name="dtc_categorie_fournisseur_ajouter")
  41.      */
  42.     public function ajouterAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  43.     {
  44.         $categorie = new Categorie;
  45.         $user      $this->getUser();
  46.         $categorie->setUtilisateur($user);
  47.         $form   $this->createForm(CategorieType::class, $categorie);
  48.         $errors "";
  49.         $form->handleRequest($request);
  50.         if ($form->isSubmitted()) {
  51.             if ($form->isValid()) {
  52.                 $em->persist($categorie);
  53.                 $em->flush();
  54.                 $this->addFlash(
  55.                     'notice',
  56.                     $translator->trans('Catégorie fournisseur ajoutée avec succès !')
  57.                 );
  58.                 return $this->redirectToRoute('dtc_categorie_fournisseur_liste');
  59.             } else {
  60.                 $errors $validator->validate($categorie);
  61.             }
  62.         }
  63.         return $this->render('Fournisseurs/Categorie/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  64.     }
  65.     /**
  66.      * @Route("/categories-fournisseur/supprimer/multiple", name="dtc_categorie_fournisseur_liste_supprimer")
  67.      */
  68.     public function supprimerMultipleAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  69.     {
  70.         $url $this->generateUrl('dtc_categorie_fournisseur_liste', []);
  71.         return new JsonResponse(['url' => $url'valide' => '1']);
  72.         $data $request->get('dataTables');
  73.         $ids  $data['actions'];
  74.         $repo $em->getRepository(Categorie::class);
  75.         for ($i 0$i count($ids); $i++) {
  76.             $v $repo->find($ids[$i]);
  77.             if (is_object($v)) {
  78.                 $em->remove($v);
  79.             }
  80.         }
  81.         $em->flush();
  82.         $this->addFlash(
  83.             'notice',
  84.             $translator->trans('Catégories fournisseur supprimées avec succès !')
  85.         );
  86.         $url $this->generateUrl('dtc_categorie_fournisseur_liste', []);
  87.         return new JsonResponse(['url' => $url'valide' => '1']);
  88.     }
  89.     /*
  90.     /**
  91.      * @Route("/categories-fournisseur/supprimer/{id}", name="dtc_categorie_fournisseur_supprimer")
  92.     public function supprimerAction(Request $request, Categorie $categorie, EntityManagerInterface $em, TranslatorInterface $translator, ValidatorInterface $validator) {
  93.         $titre_modal =$translator->trans("Demande de confirmation");
  94.         $request = $request;
  95.         $user = $this->getUser();
  96.         $form = $this->createForm(new SupprimerCategorieType, $categorie);
  97.         $errors = "";
  98.         $form->handleRequest($request);
  99.         $validator = $validator;
  100.         if ($form->isSubmitted()) {
  101.             if ($form->isValid()) {
  102.                 $em = $em;
  103.                 $em->remove($categorie);
  104.                 $em->flush();
  105.                 $this->addFlash(
  106.                     'notice',
  107.                    $translator->trans('Catégorie fournisseur supprimée avec succès !')
  108.                 );
  109.                 $url = $this->generateUrl('dtc_categorie_fournisseur_liste', array());
  110.                 return new JsonResponse(array('rendu'=>'','valide'=>'1','url'=>$url), 200, array('Content-Type'=>'application/json'));
  111.             }
  112.              else {
  113.                 $errors = $validator->validate($categorie);
  114.                 $rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', array('form' => $form->createView(),'errors'=>$errors,'id'=>$categorie->getId(),'type'=>''));
  115.                 return new Response(json_encode(array('rendu'=>$rendu,'valide'=>'0','url'=>'','titre'=>$titre_modal)), 200, array('Content-Type'=>'application/json'));
  116.             }
  117.         }
  118.         $rendu = $this->renderView('FO/Supprimer/supprimer.html.twig', array('form' => $form->createView(),'id'=>$categorie->getId(),'type'=>'','errors'=>$errors));
  119.         return new Response(json_encode(array('rendu'=>$rendu,'valide'=>'0','url'=>'','titre'=>$titre_modal)), 200, array('Content-Type'=>'application/json'));
  120.     }
  121.     */
  122.     /**
  123.      * @Route("/Categories-fournisseur/modifier/{id}", name="dtc_categorie_fournisseur_modifier")
  124.      */
  125.     public function modifierAction(Request            $requestCategorie $categorieEntityManagerInterface $emTranslatorInterface $translator,
  126.                                    ValidatorInterface $validatorDatatable $datatable
  127.     ) {
  128.         $user $this->getUser();
  129.         $categorie->setUtilisateur($user);
  130.         $form   $this->createForm(CategorieType::class, $categorie);
  131.         $errors "";
  132.         $form->handleRequest($request);
  133.         if ($form->isSubmitted()) {
  134.             $droit $this->isGranted(EntityVoter::UPDATECategorie::class);
  135.             if ( ! $droit) {
  136.                 return $this->redirectToRoute('dtc_fournisseur_modifier', ["id" => $categorie->getId()]);
  137.             }
  138.             if ($form->isValid()) {
  139.                 $em->persist($categorie);
  140.                 $em->flush();
  141.                 $this->addFlash(
  142.                     'notice',
  143.                     $translator->trans('Catégorie fournisseur sauvegardée avec succès !')
  144.                 );
  145.                 return $this->redirectToRoute('dtc_categorie_fournisseur_modifier', ["id" => $categorie->getId()]);
  146.             } else {
  147.                 $errors $validator->validate($categorie);
  148.             }
  149.         }
  150.         $this->datatableFournisseurs($categorie$request$datatable$translator);
  151.         return $this->render('Fournisseurs/Categorie/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'categorie' => $categorie]);
  152.     }
  153.     /**
  154.      * @Route("/Categories-fournisseur/", name="dtc_categorie_fournisseur_liste")
  155.      */
  156.     public function listerAction(Request $requestEntityManagerInterface $emColonneTableauService $serviceColonneTableauDatatable $datatableTranslatorInterface $translator)
  157.     {
  158.         $tableau_class_cellule[] = ["className" => "colonne_id""targets" => [0], "visible" => false"orderable" => false];
  159.         $tableau_class_cellule[] = [
  160.             "className" => "visible_export colonne_id",
  161.             "targets"   => [1],
  162.             "visible"   => $serviceColonneTableau->getColonneUtilisateur(Categorie::class, "id"),
  163.         ];
  164.         $tableau_class_cellule[] = [
  165.             "className" => "visible_export colonne_logo",
  166.             "targets"   => [2],
  167.             "visible"   => $serviceColonneTableau->getColonneUtilisateur(Categorie::class, "libelle"),
  168.         ];
  169.         $tableau_class_cellule[] = [
  170.             "className" => "visible_export colonne_logo",
  171.             "targets"   => [3],
  172.             "visible"   => $serviceColonneTableau->getColonneUtilisateur(Categorie::class, "categorieParent"),
  173.         ];
  174.         $tableau_class_cellule[] = ["orderable" => false"className" => "colonne_id""targets" => [4], "visible" => true];
  175.         $this->datatable($request$datatable$translator);
  176.         $categorie_enfants          = [];
  177.         $repo_categorie_fournisseur $em->getRepository(Categorie::class);
  178.         $categorie_fournisseur      $repo_categorie_fournisseur->findBy(["categorieParent" => null], ['libelle' => 'ASC']);
  179.         $param $request->query->all();
  180.         return $this->render('Fournisseurs/Categorie/lister.html.twig', [
  181.             'parametres'          => $param,
  182.             "categorie_parent"    => $categorie_fournisseur,
  183.             'tableauClassColonne' => $tableau_class_cellule,
  184.         ]);
  185.         //return $this->render('Fournisseurs/Categorie/lister.html.twig', array('tableauClassColonne'=>$tableau_class_cellule));
  186.     }
  187.     /**
  188.      * set datatable configs
  189.      *
  190.      * @return \App\Library\Datatable\Util\Datatable
  191.      */
  192.     private function datatable(Request $requestDatatable $datatableTranslatorInterface $translator)
  193.     {
  194.         $param $request->query->all();
  195.         $datatable->setEntity(Categorie::class, "x")
  196.                   ->setFields(
  197.                       [
  198.                           $translator->trans("ID")               => 'x.id',
  199.                           $translator->trans("Libellé")          => 'x.libelle',
  200.                           $translator->trans("Catégorie parent") => 'p.libelle',
  201.                           $translator->trans("Actions")          => 'x.id',
  202.                           "_identifier_"                         => 'x.id',
  203.                       ]
  204.                   )
  205.                   ->addJoin('x.categorieParent''p'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  206.                   ->setRenderers(
  207.                       [
  208.                           => [
  209.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  210.                               'params' => [
  211.                                   'edit_route' => 'dtc_categorie_fournisseur_modifier',
  212.                               ],
  213.                           ],
  214.                           => [
  215.                               'view'   => 'FO/DataTable/actions.html.twig',
  216.                               'params' => [
  217.                                   'edit_route'      => 'dtc_categorie_fournisseur_modifier',
  218.                                   'dupliquer_route' => 'dtc_categorie_fournisseur_dupliquer',
  219.                                   //'supprimer_route'    => 'dtc_categorie_fournisseur_supprimer',
  220.                                   'objet'           => Categorie::class,
  221.                               ],
  222.                           ],
  223.                       ]
  224.                   )
  225.                   ->setMultiple(
  226.                       [
  227.                           'delete' => [
  228.                               'title' => 'Non disponible',
  229.                               'route' => 'dtc_categorie_fournisseur_liste_supprimer',
  230.                           ],
  231.                       ]
  232.                   )
  233.                   ->setOrder("x.id""desc")
  234.                   ->setSearch(true)
  235.                   ->setSearchFields([12]);
  236.         $where      "";
  237.         $parameters = [];
  238.         if (array_key_exists('parametres'$param)) {
  239.             if (array_key_exists('categorie_parent'$param["parametres"]) and $param["parametres"]["categorie_parent"] > 0) {
  240.                 //echo "AZERTYUI";
  241.                 //$datatable->addJoin('x.clientCategorie', 'cc', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  242.                 //$datatable->addJoin('cc.categorie', 'catC', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  243.                 $parameters["categorie"] = $param["parametres"]["categorie_parent"];
  244.                 $where                   .= "x.categorieParent = :categorie";
  245.             }
  246.         }
  247.         if ($where != '') {
  248.             //echo $where;
  249.             $datatable->setWhere($where$parameters);
  250.         }
  251.         return $datatable;
  252.     }
  253.     /**
  254.      * @Route("/categories-fournisseur/grid", name="dtc_categorie_fournisseur_liste_grid")
  255.      */
  256.     public function gridAction(Request $requestDatatable $datatableTranslatorInterface $translator)
  257.     {
  258.         return $this->datatable($request$datatable$translator)->execute();
  259.     }
  260.     /**
  261.      * @Route("/categories-fournisseur/recherche", name="dtc_categorie_fournisseur_recherche")
  262.      */
  263.     public function rechercheAction(Request $requestEntityManagerInterface $emPaginatorInterface $paginator)
  264.     {
  265.         $q      $request->query->get('q');
  266.         $parent $request->query->get('parent');
  267.         $repo   $em->getRepository(Categorie::class);
  268.         //$results = $repo->getRechercheMarque($q);
  269.         $results $repo->getRechercheCategorie($q$parent);
  270.         $pagination $paginator->paginate(
  271.             $results/* query NOT result */
  272.             $request->query->getInt('page'1)/*page number*/,
  273.             10/*limit per page*/
  274.         );
  275.         $pagination_results $pagination->getItems();
  276.         $option_placeholde  = ["libelle" => "Choisir""id" => ""];
  277.         array_unshift($pagination_results$option_placeholde);
  278.         $pagination->setItems($pagination_results);
  279.         $serializer SerializerBuilder::create()->build();
  280.         return JsonResponse::fromJsonString($serializer->serialize($pagination'json'));
  281.     }
  282.     /**
  283.      * @Route("/Categories-fournisseur/fournisseurs/grid/{id}", name="dtc_categorie_fournisseur_fournisseurs_liste_grid")
  284.      */
  285.     public function gridFournisseursAction(Request $requestCategorie $categorieDatatable $datatableTranslatorInterface $translator)
  286.     {
  287.         //$this->datatableProduits($categorie);
  288.         return $this->datatableFournisseurs($categorie$request$datatable$translator)->execute();
  289.     }
  290.     /**
  291.      * set datatable configs
  292.      *
  293.      * @return \App\Library\Datatable\Util\Datatable
  294.      */
  295.     private function datatableFournisseurs($categorieRequest $requestDatatable $datatableTranslatorInterface $translator)
  296.     {
  297.         $param $request->query->all();
  298.         $datatable->setEntity(Fournisseur::class, "x")
  299.                   ->setFields(
  300.                       [
  301.                           $translator->trans("ID")        => 'x.id',
  302.                           $translator->trans("Réf")       => 'x.reference',
  303.                           $translator->trans("Libellé")   => 'x.libelle',
  304.                           $translator->trans("Email")     => 'x.email',
  305.                           $translator->trans("Téléphone") => 'x.telephone',
  306.                           $translator->trans("Fax") => 'x.fax',
  307.                           $translator->trans("Tva") => 'x.tva',
  308.                           $translator->trans("Actions") => 'x.id',
  309.                           "_identifier_"                => 'x.id',
  310.                       ]
  311.                   )
  312.                   ->addJoin('x.fournisseurCategorie''fc'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN)
  313.                   ->setRenderers(
  314.                       [
  315.                           => [
  316.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  317.                               'params' => [
  318.                                   'edit_route' => 'dtc_fournisseur_modifier',
  319.                               ],
  320.                           ],
  321.                           => [
  322.                               'view'   => 'FO/DataTable/avec_lien_edit_route.html.twig',
  323.                               'params' => [
  324.                                   'edit_route' => 'dtc_fournisseur_modifier',
  325.                               ],
  326.                           ],
  327.                           => [
  328.                               'view'   => 'FO/DataTable/actions.html.twig',
  329.                               'params' => [
  330.                                   'edit_route'      => 'dtc_fournisseur_modifier',
  331.                                   'dupliquer_route' => 'dtc_fournisseur_dupliquer',
  332.                                   //'supprimer_route'    => 'dtc_fournisseur_supprimer',
  333.                                   'objet'           => Fournisseur::class,
  334.                               ],
  335.                           ],
  336.                       ]
  337.                   )
  338.                   ->setMultiple(
  339.                       [
  340.                           'delete' => [
  341.                               'title' => 'Non disponible',
  342.                               'route' => 'dtc_fournisseur_liste_supprimer',
  343.                           ],
  344.                       ]
  345.                   )
  346.                   ->setOrder("x.id""desc")
  347.                   ->setSearch(true)
  348.                   ->setSearchFields([01]);
  349.         //$datatable->setSearchFields(array(0,2));
  350.         $where      "";
  351.         $parameters = [];
  352.         if (array_key_exists('parametres'$param)) {
  353.             if (array_key_exists('categorie_fournisseur'$param["parametres"]) and $param["parametres"]["categorie_fournisseur"] > 0) {
  354.                 //echo "AZERTYUI";
  355.                 //$datatable->addJoin('x.clientCategorie', 'cc', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  356.                 $datatable->addJoin('x.categorie''c'\Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  357.                 $parameters["categorie"] = $param["parametres"]["categorie_fournisseur"];
  358.                 $where                   .= "c.categorieParent = :categorie";
  359.                 if (array_key_exists('sous_categorie_fournisseur'$param["parametres"]) and $param["parametres"]["sous_categorie_fournisseur"] > 0) {
  360.                     //$datatable->addJoin('x.clientCategorie', 'cc2', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  361.                     //$datatable->addJoin('cc2.categorie', 'catC2', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  362.                     $parameters["sous_categorie"] = $param["parametres"]["sous_categorie_fournisseur"];
  363.                     $where                        .= " and x.categorie = :sous_categorie";
  364.                 }
  365.             }
  366.         }
  367.         //$datatable->addJoin('x.categorie', 'c', \Doctrine\ORM\Query\Expr\Join::LEFT_JOIN);
  368.         $parameters["categorie"] = $categorie->getId();
  369.         //print_r($parameters);
  370.         if ($where != '') {
  371.             $where .= ' and ';
  372.         }
  373.         //$where .= 'x.parent is null';
  374.         $where .= 'fc.categorie = :categorie';
  375.         if ($where != '') {
  376.             //echo $where;
  377.             $datatable->setWhere($where$parameters);
  378.         }
  379.         return $datatable;
  380.     }
  381.     /**
  382.      * @Route("", name="")
  383.      */
  384.     public function listerCategorieDossierAction(Request $request$fournisseurId ''EntityManagerInterface $em)
  385.     {
  386.         $repo_fournisseur           $em->getRepository(Fournisseur::class);
  387.         $repo_categorie             $em->getRepository(Categorie::class);
  388.         $repo_fournisseur_categorie $em->getRepository(FournisseurCategorie::class);
  389.         $fournisseur           $repo_fournisseur->find($fournisseurId);
  390.         $fournisseurCategories = [];
  391.         if (is_object($fournisseur)) {
  392.             $categoriesFournisseur $repo_fournisseur_categorie->findBy(['fournisseur' => $fournisseurId], ['libelle' => 'ASC']);
  393.             foreach ($categoriesFournisseur as $categorieFournisseur) {
  394.                 $fournisseurCategories[] = $categorieFournisseur->getCategorie()->getId();
  395.             }
  396.         }
  397.         //\Doctrine\Common\Util\Debug::dump($fournisseurId);
  398.         $categories $repo_categorie->findBy(['categorieParent' => null], ['libelle' => 'ASC']);//CategorieParent
  399.         return $this->render('Fournisseurs/Categorie/lister-dossier.html.twig', [
  400.             'nbCategoriesEnfant'    => [],
  401.             'categories'            => $categories,
  402.             'fournisseur'           => $fournisseur,
  403.             'categoriesFournisseur' => $fournisseurCategories,
  404.             'mode'                  => '',
  405.             'move'                  => true,
  406.         ]);
  407.     }
  408.     /**
  409.      * @Route("/categorie-fournisseur/ajouter/modal", name="dtc_categorie_fournisseur_ajouter_modal")
  410.      */
  411.     public function ajouterModalAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  412.     {
  413.         $repo_categorie $em->getRepository(Categorie::class);
  414.         $titre_modal    $translator->trans("Créer une nouvelle catégorie");
  415.         $errors         "";
  416.         $errorsSup      = [];
  417.         $categorie      = new Categorie;
  418.         $parentId $request->query->get('parent');
  419.         if ($parentId == '') {
  420.             $parentId null;
  421.         }//par defaut le parent est la categorie racine.
  422.         if ($parentId != '') {
  423.             $parent $repo_categorie->find($parentId);
  424.             if (is_object($parent)) {
  425.                 $titre_modal .= ' enfant de '.$parent->getLibelle();
  426.                 $categorie->setCategorieParent($parent);
  427.             }
  428.         }
  429.         $user $this->getUser();
  430.         $categorie->setUtilisateur($user);
  431.         $form $this->createForm(CategorieModalType::class, $categorie);
  432.         $form->handleRequest($request);
  433.         if ($form->isSubmitted()) {
  434.             if ($form->isValid()) {
  435.                 $em->persist($categorie);
  436.                 $em->flush();
  437.                 $url $this->generateUrl('dtc_categorie_fournisseur_liste', []);
  438.                 //$url="";
  439.                 $this->addFlash('notice'$translator->trans('Categorie ajoutée avec succès !'));
  440.                 return new JsonResponse(['rendu' => '''errorsSup' => $errorsSup'valide' => '1''url' => $url'type' => '''libelle' => ''],
  441.                                         200,
  442.                                         ['Content-Type' => 'application/json']);
  443.             } else {
  444.                 $errors $validator->validate($categorie);
  445.             }
  446.         }
  447.         $rendu $this->renderView(
  448.             'Fournisseurs/Categorie/ajouter-modal.html.twig',
  449.             ['form' => $form->createView(), 'errorsSup' => $errorsSup'errors' => $errors'errorsSup' => $errorsSup'categorie' => $categorie]
  450.         );
  451.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  452.     }
  453.     /**
  454.      * @Route("", name="")
  455.      */
  456.     public function supprimerAction(Request $requestCategorie $objetEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  457.     {
  458.         $titre_modal $translator->trans("Demande de confirmation");
  459.         $user        $this->getUser();
  460.         $message     '';
  461.         $errorsSup   = [];
  462.         //Verifier si la categorie a des produits
  463.         if (count($objet->getFournisseurCategorie()) > 0) {
  464.             $errorsSup[] = 'La catégorie n\'est pas supprimable car elle contient des fournisseurs.';
  465.         }
  466.         //Verifier si la categorie a des categories enfantes
  467.         if (count($objet->getCategoriesEnfant()) > 0) {
  468.             //if ($message != '') $message .= ' ';
  469.             $errorsSup[] = 'La catégorie n\'est pas supprimable car elle contient des catégories enfants';
  470.         }
  471.         $form   $this->createForm(SupprimerCategorieType::class, $objet);
  472.         $errors "";
  473.         $form->handleRequest($request);
  474.         //if ($form->isSubmitted() && $message != '') {
  475.         if ($form->isSubmitted() && count($errorsSup) == 0) {
  476.             if ($form->isValid()) {
  477.                 $em->remove($objet);
  478.                 $em->flush();
  479.                 $this->addFlash('notice'$translator->trans('Catégorie supprimée avec succès !'));
  480.                 $url $this->generateUrl('dtc_categorie_fournisseur_liste');
  481.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  482.             } else {
  483.                 $errors $validator->validate($objet);
  484.                 $rendu  $this->renderView(
  485.                     'Fournisseurs/Categorie/supprimer.html.twig',
  486.                     ['form' => $form->createView(), 'errors' => $errors'errorsSup' => $errorsSup'message' => $message]
  487.                 );
  488.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  489.             }
  490.         }
  491.         $rendu $this->renderView('Fournisseurs/Categorie/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors'errorsSup' => $errorsSup'message' => $message]);
  492.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  493.     }
  494.     /**
  495.      * @Route("", name="")
  496.      */
  497.     public function listerCategorieDossierFournisseurAction(Request $request$fournisseur null$mode ""EntityManagerInterface $em)
  498.     {
  499.         $repo_fournisseur           $em->getRepository(Fournisseur::class);
  500.         $fournisseur                $repo_fournisseur->find($fournisseur);
  501.         $repo_categorie             $em->getRepository(Categorie::class);
  502.         $repo_fournisseur_categorie $em->getRepository(FournisseurCategorie::class);
  503.         $nbCategoriesEnfant    = [];
  504.         $fournisseurCategories = [];
  505.         if (is_object($fournisseur)) {
  506.             //$categoriesFournisseur = $repo_fournisseur_categorie->findByArticle($fournisseurId);
  507.             foreach ($fournisseur->getFournisseurCategorie() as $categorieFournisseur) {
  508.                 $boucler                 true;
  509.                 $fournisseurCategories[] = $categorieFournisseur->getCategorie()->getId();
  510.                 if (is_object($categorieFournisseur->getCategorie()->getCategorieParent()) and $categorieFournisseur->getCategorie()->getCategorieParent()->getId() > 0) {
  511.                     $parent $categorieFournisseur->getCategorie()->getCategorieParent();
  512.                     while ($boucler) {
  513.                         if ( ! array_key_exists($parent->getId(), $nbCategoriesEnfant)) {
  514.                             $nbCategoriesEnfant[$parent->getId()] = 1;
  515.                         } else {
  516.                             $nbCategoriesEnfant[$parent->getId()]++;
  517.                         }
  518.                         if (is_object($parent->getCategorieParent()) and $parent->getCategorieParent()->getId() > 1) {
  519.                             $parent $parent->getCategorieParent();
  520.                         } else {
  521.                             $boucler false;
  522.                         }
  523.                     }
  524.                 }
  525.             }
  526.         }
  527.         $categories $repo_categorie->findBy(['categorieParent' => null], ['libelle' => 'ASC']);//CategorieParent
  528.         return $this->render('Fournisseurs/Categorie/lister-dossier.html.twig', [
  529.             'nbCategoriesEnfant'    => $nbCategoriesEnfant,
  530.             'categories'            => $categories,
  531.             'fournisseur'           => $fournisseur,
  532.             'categoriesFournisseur' => $fournisseurCategories,
  533.             'mode'                  => $mode,
  534.         ]);
  535.     }
  536.     /**
  537.      * @Route("/categorie/charger-tableau/{id}/{type}", name="dtc_categorie_fournisseur_charger_tableau")
  538.      */
  539.     public function chargerTableauAction(Request $requestFournisseur $fournisseurEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  540.     {
  541.         $rendu $this->renderView('Fournisseurs/Categorie/charger_tableau.html.twig', ["fournisseur" => $fournisseur]);
  542.         return new JsonResponse(['rendu' => $rendu]);
  543.     }
  544. }