src/Controller/Kanban/ColonneController.php line 384

Open in your IDE?
  1. <?php
  2. namespace App\Controller\Kanban;
  3. use App\Entity\GestionComerciale\Commande;
  4. use App\Entity\Kanban\Colonne;
  5. use App\Entity\Kanban\Fiche;
  6. use App\Entity\Kanban\Kanban;
  7. use App\Form\Kanban\ColonneType;
  8. use App\Form\Kanban\SupprimerColonneType;
  9. use App\Library\Datatable\Util\Datatable;
  10. use App\Security\Voter\EntityVoter;
  11. use Doctrine\ORM\EntityManagerInterface;
  12. use JMS\Serializer\SerializerBuilder;
  13. use Knp\Component\Pager\PaginatorInterface;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\JsonResponse;
  16. use Symfony\Component\HttpFoundation\Request;
  17. use Symfony\Component\HttpFoundation\Response;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Component\Validator\Validator\ValidatorInterface;
  20. use Symfony\Contracts\Translation\TranslatorInterface;
  21. class ColonneController extends AbstractController
  22. {
  23.     /**
  24.      * @Route("/tunnels-colonne/ajouter", name="dtc_kanban_colonne_ajouter")
  25.      */
  26.     public function ajouterAction(Request $requestEntityManagerInterface $emValidatorInterface $validator)
  27.     {
  28.         $colonne = new Colonne();
  29.         $user    $this->getUser();
  30.         //$colonne->setUtilisateur($user);
  31.         $errors "";
  32.         $kanban $em->getRepository(Kanban::class)->find(1);
  33.         $form   $this->createForm(ColonneType::class, $colonne, ['validation_groups' => ['Default']]);
  34.         $form->handleRequest($request);
  35.         if ($form->isSubmitted()) {
  36.             if ($form->isValid()) {
  37.                 if (is_object($kanban)) {
  38.                     $colonne->setKanban($kanban);
  39.                 }
  40.                 $em->persist($colonne);
  41.                 $em->flush();
  42.                 $this->addFlash(
  43.                     'notice',
  44.                     'Colonne ajouté avec succès !'
  45.                 );
  46.                 return $this->redirectToRoute('dtc_kanban_colonne_liste');
  47.             } else {
  48.                 $errors $validator->validate($colonne);
  49.             }
  50.         }
  51.         return $this->render('Kanban/Colonne/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors]);
  52.     }
  53.     /**
  54.      * @Route("/tunnels-colonne/modifier/{id}", name="dtc_kanban_colonne_modifier")
  55.      */
  56.     public function modifierAction(Request $requestColonne $colonneEntityManagerInterface $emValidatorInterface $validator)
  57.     {
  58.         $user $this->getUser();
  59.         //$colonne->setUtilisateur($user);
  60.         $form   $this->createForm(ColonneType::class, $colonne, ['validation_groups' => ['Default']]);
  61.         $errors "";
  62.         $kanban $em->getRepository(Kanban::class)->find(1);
  63.         $form->handleRequest($request);
  64.         if ($form->isSubmitted()) {
  65.             $droit $this->isGranted(EntityVoter::UPDATEColonne::class);
  66.             //echo "EEEE";
  67.             if ( ! $droit) {
  68.                 $em->refresh($colonne);
  69.                 return $this->redirectToRoute('dtc_kanban_colonne_modifier', ["id" => $colonne->getId()]);
  70.             }
  71.             if ($form->isValid()) {
  72.                 if (is_object($kanban)) {
  73.                     $colonne->setKanban($kanban);
  74.                 }
  75.                 $em->persist($colonne);
  76.                 $em->flush();
  77.                 $this->addFlash(
  78.                     'notice',
  79.                     'Colonne sauvegardée avec succès !'
  80.                 );
  81.                 return $this->redirectToRoute('dtc_kanban_colonne_modifier', ["id" => $colonne->getId()]);
  82.             } else {
  83.                 $errors $validator->validate($colonne);
  84.             }
  85.         }
  86.         return $this->render('Kanban/Colonne/ajouter.html.twig', ['form' => $form->createView(), 'errors' => $errors'colonne' => $colonne]);
  87.     }
  88.     /**
  89.      * @Route("/tunnels-colonne/liste", name="dtc_kanban_colonne_liste")
  90.      */
  91.     public function listerAction(Request $request$id$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  92.     {
  93.         if ($type == 'kanban') {
  94.             $repo_objet $em->getRepository(Kanban::class);
  95.             $objet      $repo_objet->find($id);
  96.         }
  97.         $tableau_class_cellule   = [];
  98.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [0], "visible" => false"orderable" => true"searchable" => true];
  99.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [1], "visible" => false"orderable" => true"searchable" => true];
  100.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id""targets" => [2], "visible" => true"orderable" => true"searchable" => true];
  101.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [3], "visible" => true"orderable" => true"searchable" => true];
  102.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [4], "visible" => true"orderable" => true"searchable" => true];
  103.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [5], "visible" => true"orderable" => true"searchable" => true];
  104.         $tableau_class_cellule[] = ["className" => "visible_export colonne_id text-center""targets" => [6], "visible" => true"orderable" => false"searchable" => true];
  105.         /*
  106.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(0),"visible"=>true,"orderable"=>true,"searchable"=> true);
  107.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(1),"visible"=>true,"orderable"=>true,"searchable"=> true);
  108.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(2),"visible"=>true,"orderable"=>true,"searchable"=> true);
  109.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(3),"visible"=>true,"orderable"=>true,"searchable"=> true);
  110.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(4),"visible"=>true,"orderable"=>true,"searchable"=> true);
  111.         $tableau_class_cellule[]=array("className"=>"visible_export colonne_id","targets"=>array(5),"visible"=>true,"orderable"=>true,"searchable"=> true);
  112.         $tableau_class_cellule[]=array("orderable"=>false,"className"=>"colonne_id","targets"=>array(6),"visible"=>true);
  113.         */
  114.         $this->datatable($request$datatable$translator$objet$type);
  115.         $param $request->query->all();
  116.         return $this->render('Kanban/Colonne/lister.html.twig', ['parametres' => $param'tableauClassColonne' => $tableau_class_cellule"id" => $id"type" => $type]);
  117.     }
  118.     /**
  119.      * set datatable configs
  120.      *
  121.      * @return \App\Library\Datatable\Util\Datatable
  122.      */
  123.     private function datatable(Request $requestDatatable $datatableTranslatorInterface $translator$objet$type "")
  124.     {
  125.         $type_jointure 'x.'.$type;
  126.         $param         $request->query->all();
  127.         $datatable->setEntity(Colonne::class, "x")
  128.                   ->setFields(
  129.                       [
  130.                           "ID"                              => 'x.id',
  131.                           $translator->trans("Libellé")     => 'x.libelle',
  132.                           $translator->trans("Position")    => 'x.position',
  133.                           $translator->trans("Durée")       => 'x.delai',
  134.                           $translator->trans("Probabilité") => 'x.probabilite',
  135.                           "Actions"                         => 'x.id',
  136.                           "_identifier_"                    => 'x.id',
  137.                       ]
  138.                   )
  139.                   ->setRenderers(
  140.                       [
  141.                           /*
  142.                           0 => array(
  143.                           'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
  144.                            'params' => array(
  145.                                       'edit_route'    => 'dtc_kanban_colonne_modifier'
  146.                                   ),
  147.                           ),
  148.                           1 => array(
  149.                           'view' => 'FO/DataTable/avec_lien_edit_route.html.twig',
  150.                            'params' => array(
  151.                                       'edit_route'    => 'dtc_kanban_colonne_modifier'
  152.                                   ),
  153.                           ),
  154.                           */
  155.                           => [
  156.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  157.                               'params' => [
  158.                                   'objet' => Colonne::class,
  159.                                   'champ' => 'setPosition',
  160.                               ],
  161.                           ],
  162.                           => [
  163.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  164.                               'params' => [
  165.                                   'objet' => Colonne::class,
  166.                                   'champ' => 'setDelai',
  167.                               ],
  168.                           ],
  169.                           => [
  170.                               'view'   => 'FO/DataTable/edit_texte.html.twig',
  171.                               'params' => [
  172.                                   'objet' => Colonne::class,
  173.                                   'champ' => 'setProbabilite',
  174.                               ],
  175.                           ],
  176.                           => [
  177.                               'view'   => 'FO/DataTable/actions_modal.html.twig',
  178.                               'params' => [
  179.                                   'edit_route' => 'dtc_kanban_colonne_modifier_modal',
  180.                                   //'supprimer_route'  => 'dtc_kanban_colonne_supprimer',
  181.                                   'id'         => $objet->getId(),
  182.                                   'type'       => $type,
  183.                                   'entite'     => 'colonne',
  184.                                   'objet'      => Colonne::class,
  185.                               ],
  186.                           ],
  187.                       ]
  188.                   )
  189.                   ->setMultiple(
  190.                       [
  191.                           'delete' => [
  192.                               'title' => $translator->trans('Non disponible'),
  193.                               'route' => 'dtc_kanban_colonne_liste',
  194.                           ],
  195.                       ]
  196.                   )
  197.                   ->setOrder("x.position""asc")
  198.                   ->setSearch(true)
  199.                   ->setSearchFields([0123]);
  200.         //$datatable->setSearchFields(array(0,2));
  201.         $where      "";
  202.         $parameters = [];
  203.         $parameters = ['objet' => $objet];
  204.         $where      $type_jointure.' = :objet';
  205.         if ($where != '') {
  206.             //echo $where;
  207.             $datatable->setWhere($where$parameters);
  208.         }
  209.         return $datatable;
  210.     }
  211.     /**
  212.      * Grid action
  213.      * @return Response
  214.      */
  215.     /**
  216.      * @Route("/tunnels-colonne/grid", name="dtc_kanban_colonne_liste_grid")
  217.      */
  218.     public function gridAction(Request $request$id ""$type ""EntityManagerInterface $emDatatable $datatableTranslatorInterface $translator)
  219.     {
  220.         $get $request->query->all();
  221.         if (array_key_exists('id'$get) && $get["id"] != "") {
  222.             $id $get["id"];
  223.         }
  224.         if (array_key_exists('type'$get) && $get["type"] != "") {
  225.             $type $get["type"];
  226.         }
  227.         if ($type == 'kanban') {
  228.             $repo_objet $em->getRepository(Kanban::class);
  229.             $objet      $repo_objet->find($id);
  230.         }
  231.         return $this->datatable($request$datatable$translator$objet$type)->execute();
  232.     }
  233.     /**
  234.      * @Route("/tunnels-colonne/supprimer-multiple", name="dtc_kanban_colonne_liste_supprimer")
  235.      */
  236.     public function supprimerMultipleAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  237.     {
  238.         $url $this->generateUrl('dtc_kanban_colonne_liste', []);
  239.         return new JsonResponse(['url' => $url'valide' => '1']);
  240.         $data $request->get('dataTables');
  241.         $ids  $data['actions'];
  242.         $repo $em->getRepository(Colonne::class);
  243.         for ($i 0$i count($ids); $i++) {
  244.             $v $repo->find($ids[$i]);
  245.             if (is_object($v)) {
  246.                 $em->remove($v);
  247.             }
  248.         }
  249.         $em->flush();
  250.         $this->addFlash(
  251.             'notice',
  252.             'Colonnes supprimées avec succès !'
  253.         );
  254.         $url $this->generateUrl('dtc_kanban_colonne_liste', []);
  255.         return new JsonResponse(['url' => $url'valide' => '1']);
  256.     }
  257.     /**
  258.      * @Route("/tunnels-colonne/supprimer/{objet}/{id}/{type}", name="dtc_kanban_colonne_supprimer")
  259.      */
  260.     public function supprimerAction(Request $requestColonne $objet$id$typeEntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  261.     {
  262.         $colonne     $objet;
  263.         $titre_modal $translator->trans("Demande de confirmation");
  264.         $user        $this->getUser();
  265.         $repo_fiches $em->getRepository(Fiche::class);
  266.         $fiches      $repo_fiches->findBy(["colonne" => $colonne]);
  267.         if (count($fiches) > 0) {
  268.             $erreur "Suppression impossible. Cette étape contient des affaires :<ul>";
  269.             foreach ($fiches as $f) {
  270.                 $erreur .= "<li>".$f->getReference()."</li>";
  271.             }
  272.             $erreur .= "</ul>";
  273.             $rendu $this->renderView('FO/Supprimer/supprimer_impossible.html.twig', ['errors' => $erreur]);
  274.             return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  275.         }
  276.         $form   $this->createForm(SupprimerColonneType::class, $colonne);
  277.         $errors "";
  278.         $form->handleRequest($request);
  279.         //vérifier que la colonne ne contient aucune fiche
  280.         $fiches $colonne->getFiches();
  281.         if (count($fiches) > and != 1) {
  282.             $errors[] = ['message' => 'Ce type d\'action n\'est pas supprimable car elle contient actuellement des actions en cours!'];
  283.         }
  284.         if ($form->isSubmitted()) {
  285.             if ($form->isValid()) {
  286.                 $em->remove($colonne);
  287.                 $em->flush();
  288.                 $this->addFlash(
  289.                     'notice',
  290.                     'Étape supprimée avec succès !'
  291.                 );
  292.                 $url $this->generateUrl('dtc_kanban_colonne_liste', []);
  293.                 $url "";
  294.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  295.             } else {
  296.                 $errors $validator->validate($colonne);
  297.                 $rendu  $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $colonne->getId(), 'type' => '']);
  298.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  299.             }
  300.         }
  301.         $rendu $this->renderView('FO/Supprimer/supprimer.html.twig', ['form' => $form->createView(), 'id' => $colonne->getId(), 'type' => '''errors' => $errors]);
  302.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  303.     }
  304.     /**
  305.      * @Route("/tunnels-colonne/modal/nouveau/{id}/{type}", name="dtc_kanban_colonne_ajouter_modal")
  306.      */
  307.     public function ajouterModalAction(Request $request$id$type ""EntityManagerInterface $emTranslatorInterface $translatorValidatorInterface $validator)
  308.     {
  309.         $titre_modal $translator->trans("Nouvelle étape");
  310.         $colonne     = new Colonne();
  311.         $user        $this->getUser();
  312.         //$contact->setUtilisateur($user);
  313.         if ($type == 'kanban') {
  314.             $repo_objet $em->getRepository(Kanban::class);
  315.             $objet      $repo_objet->find($id);
  316.             $colonne->setKanban($objet);
  317.             $url $this->generateUrl('dtc_kanban_modifier', ['id' => $objet->getId(), 'tab' => 'colonnes']);
  318.         }
  319.         $form   $this->createForm(ColonneType::class, $colonne);
  320.         $errors "";
  321.         $form->handleRequest($request);
  322.         if ($form->isSubmitted()) {
  323.             if ($form->isValid()) {
  324.                 $em->persist($colonne);
  325.                 $em->flush();
  326.                 $em->refresh($colonne);
  327.                 $params = [];
  328.                 $this->addFlash('notice''Colonne ajoutée avec succès !');
  329.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url'type' => $type'params' => $params]);
  330.             } else {
  331.                 $errors $validator->validate($colonne);
  332.                 $rendu  $this->renderView(
  333.                     'Kanban/Colonne/ajouter_modal.html.twig',
  334.                     ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'kanban' => $objet]
  335.                 );
  336.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  337.             }
  338.         }
  339.         $rendu $this->renderView(
  340.             'Kanban/Colonne/ajouter_modal.html.twig',
  341.             ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type'kanban' => $objet]
  342.         );
  343.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  344.     }
  345.     /**
  346.      * @Route("/tunnels-colonne/modal/modifier/{objet}/{id}/{type}", name="dtc_kanban_colonne_modifier_modal")
  347.      */
  348.     public function modifierModalAction(Request            $requestColonne $objet$id$typeEntityManagerInterface $emTranslatorInterface $translator,
  349.                                         ValidatorInterface $validator
  350.     ) {
  351.         $colonne     $objet;
  352.         $titre_modal $translator->trans("Modifier étape");
  353.         $user        $this->getUser();
  354.         //$colonne->setUtilisateur($user);
  355.         $form   $this->createForm(ColonneType::class, $colonne);
  356.         $errors "";
  357.         $form->handleRequest($request);
  358.         if ($form->isSubmitted()) {
  359.             $droit $this->isGranted(EntityVoter::UPDATEColonne::class);
  360.             if ( ! $droit) {
  361.                 $rendu $this->renderView('Kanban/Colonne/ajouter_moal.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  362.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  363.             }
  364.             if ($form->isValid()) {
  365.                 if ($type == 'kanban') {
  366.                     $repo_objet $em->getRepository(Kanban::class);
  367.                     $objet      $repo_objet->find($id);
  368.                     $colonne->setKanban($objet);
  369.                     $url $this->generateUrl('dtc_kanban_modifier', ['id' => $objet->getId(), 'tab' => 'colonnes']);
  370.                 }
  371.                 $get $request->query->all();
  372.                 if (array_key_exists('redirection'$get) && $get["redirection"] != "") {
  373.                     $url $this->generateUrl($get["redirection"], []);
  374.                 }
  375.                 $em->persist($colonne);
  376.                 $em->flush();
  377.                 $this->addFlash('notice''Étape modifiée avec succès !');
  378.                 return new JsonResponse(['rendu' => '''valide' => '1''url' => $url]);
  379.             } else {
  380.                 $errors $validator->validate($colonne);
  381.                 $rendu  $this->renderView('Kanban/Colonne/ajouter_modal.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  382.                 return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  383.             }
  384.         }
  385.         $rendu $this->renderView('Kanban/Colonne/ajouter_modal.html.twig', ['form' => $form->createView(), 'errors' => $errors'id' => $id'type' => $type]);
  386.         return new JsonResponse(['rendu' => $rendu'valide' => '0''url' => '''titre' => $titre_modal]);
  387.     }
  388.     /**
  389.      * @Route("/tunnels-colonne/recherche", name="dtc_kanban_colonne_recherche")
  390.      */
  391.     public function rechercheAction(Request $requestEntityManagerInterface $emTranslatorInterface $translatorPaginatorInterface $paginator)
  392.     {
  393.         $q      $request->query->get('q');
  394.         $kanban $request->query->get('kanban');
  395.         if ( ! empty($kanban)) {
  396.             $kanban $em->getRepository(Kanban::class)->find($kanban);
  397.         }
  398.         $commandeId $request->query->get('commande');
  399.         if ( ! empty($commandeId)) {
  400.             $commande $em->getRepository(Commande::class)->find($commandeId);
  401.             if (is_object($commande) && is_object($commande->getFiche())) {
  402.                 $kanban $commande->getFiche()->getKanban();
  403.             }
  404.         }
  405.         $page    $request->query->getInt('page'1);
  406.         $repo    $em->getRepository(Colonne::class);
  407.         $results $repo->getRecherche($q$kanban);
  408.         $pagination $paginator->paginate(
  409.             $results/* query NOT result */
  410.             $request->query->getInt('page'1)/*page number*/,
  411.             10/*limit per page*/
  412.         );
  413.         $pagination_results $pagination->getItems();
  414.         if ($q == "" && $page 2) {
  415.             //$option_placeholde = array("libelle"=>"Choisir","id"=>"","departement_id"=>"");
  416.             $option_placeholde = ["libelle" => $translator->trans("Sélectionnez"), "id" => "0"];
  417.             array_unshift($pagination_results$option_placeholde);
  418.         } elseif ($page 2) {
  419.             /*
  420.             $origine_saisie_existe = $repo->findOneBy(array('libelle'=>$q));
  421.             if(!is_object($origine_saisie_existe)) {
  422.                 $option_placeholde = array("libelle"=>"Nouvelle origine : ".$q,"id"=>'0',"nouveau"=>$q);
  423.                 array_unshift($pagination_results, $option_placeholde);
  424.                 $option_placeholde = array("libelle" =>$translator->trans("Sélectionnez"),"id"=>"0");
  425.                 array_unshift($pagination_results, $option_placeholde);
  426.             }
  427.             */
  428.         }
  429.         //$option_placeholde = array("libelle" =>$translator->trans("Sélectionnez"),"id"=>"");
  430.         //array_unshift($pagination_results, $option_placeholde);
  431.         $pagination->setItems($pagination_results);
  432.         $serializer SerializerBuilder::create()->build();
  433.         return JsonResponse::fromJsonString($serializer->serialize($pagination'json'));
  434.     }
  435. }