src/Controller/EquipmentSpecificController.php line 324

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Psr\Log\LoggerInterface;
  4. use App\Entity\Site;
  5. use App\Entity\Room;
  6. use App\Entity\Rack;
  7. use App\Entity\RackFace;
  8. use App\Entity\EquipmentSpecific;
  9. use App\Entity\EquipmentGeneric;
  10. use App\Entity\InterfaceSpecific;
  11. use App\Entity\Link;
  12. use App\Entity\LinkExtension;
  13. use App\Entity\Port;
  14. use App\Entity\Trunk;
  15. use App\Entity\TrunkCableFiber;
  16. use App\Entity\TrunkExtension;
  17. use App\Entity\Slot;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\HttpFoundation\Request;
  21. use Symfony\Component\HttpFoundation\Response;
  22. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  23. use Pagerfanta\Pagerfanta;
  24. // use Pagerfanta\Adapter\DoctrineORMAdapter;
  25. use Symfony\Contracts\Translation\TranslatorInterface;
  26. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  27. class EquipmentSpecificController  extends AbstractController
  28. {
  29.     /**
  30.      * @Route("/equipment/specific/create", name="equipment_specific_create")
  31.      */
  32.     public function createAction(Request $requestTranslatorInterface $translator)
  33.     {
  34.         $user $this->getUser();
  35.         // process form
  36.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  37.             // var_dump($request);
  38.             $em $this->getDoctrine()->getManager();
  39.             $eq = new EquipmentSpecific();
  40.             $eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  41.             $eq->setAlias($request->request->get('alias'));
  42.             $eq->setOwner($request->request->get('owner'));
  43.             $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
  44.             $eq->setEquipmentGeneric($equipmentGeneric);
  45.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  46.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  47.             $eq->setPositionRack($request->request->get('positionRack'));
  48.             $em->persist($eq);
  49.             $em->flush();
  50.             // create specific interfaces
  51.             $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
  52.             foreach ($interfacesGeneric as $interfaceGeneric){
  53.                 $interfaceSpecific = new InterfaceSpecific();
  54.                 $interfaceSpecific->setEquipmentSpecific($eq);
  55.                 $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  56.                 $em->persist($interfaceSpecific);
  57.                 $em->flush();
  58.                 $alias null;
  59.                 if ($interfaceGeneric->getAlias()) {
  60.                   $alias json_decode($interfaceGeneric->getAlias(), true);
  61.                 }
  62.                 $portExternes null;
  63.                 $idTemp $interfaceGeneric->getId();
  64.                 // var_dump($_POST["portExterne[$idTemp]"]);
  65.                 if (isset($_POST["portExterne"][$idTemp])) {
  66.                   foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  67.                     $portExternes[$key] = $value;
  68.                   }
  69.                 }
  70.                 // var_dump($portExternes);
  71.                 // create ports
  72.                 $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  73.                 for ($i=1$i<=$numberOfPorts$i++){
  74.                     $port = new Port();
  75.                     $port->setInterfaceSpecific($interfaceSpecific);
  76.                     $port->setOrderNo($i);
  77.                     if ($alias && count($alias) > 0) {
  78.                       $port->setAlias($alias[$i]);
  79.                     }
  80.                     if ($portExternes) {
  81.                       if (isset($portExternes[$i]) && $portExternes[$i]) {
  82.                         $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  83.                         $port->setPortExterne($pe);
  84.                         $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  85.                         if ($interfaceGenericPortExterne != null) {
  86.                             //create interface spécific and attach it to the port
  87.                             $ifPE = new InterfaceSpecific();
  88.                             $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port$port);
  89.                             $port->setInterfaceSpecificPortExterne($ifPE);
  90.                         }
  91.                       }
  92.                     }
  93.                     $em->persist($port);
  94.                     $em->flush();
  95.                 }
  96.             }
  97.             return $this->redirectToRoute('equipment_specific_list');
  98.         // show form
  99.         } else {
  100.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=>false"isModulaire"=>false], ["title"=>"ASC"]);
  101.             $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
  102.             $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  103.             $portExternes $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
  104.             return $this->render('equipment/specific_create.html.twig', [
  105.                 'action' => 'insert',
  106.                 'page_title' => $translator->trans('Specific Equipment'),
  107.                 'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  108.                 'eqGeneric' => $eqGeneric,
  109.                 'racks' => $racks,
  110.                 'rackFaces' => $rackFaces,
  111.                 'portExternes' => $portExternes
  112.             ]);
  113.         }
  114.     }
  115.     public function createInterfaceSpecific($em$interfaceGeneric, &$interfaceSpecific, &$eq, &$portMpo){
  116.         // $interfaceSpecific = new InterfaceSpecific();
  117.         $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  118.         $interfaceSpecific->setEquipmentSpecificMpo($eq);
  119.         $em->persist($interfaceSpecific);
  120.         $em->flush();
  121.         $alias $this->getAlias($interfaceGeneric);
  122.         // create ports
  123.         $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  124.         for ($i=1$i<=$numberOfPorts$i++){
  125.             $port = new Port();
  126.             $port->setInterfaceSpecific($interfaceSpecific);
  127.             $port->setOrderNo($i);
  128.             $port->setPortMpo($portMpo);
  129.             if ($alias && count($alias) > 0) {
  130.               $port->setAlias($alias[$i]);
  131.             }
  132.             $em->persist($port);
  133.             // $em->flush();
  134.         }
  135.         // return $interfaceSpecific;
  136.     }
  137.     public function getAlias($interfaceGeneric){
  138.         $alias null;
  139.         if ($interfaceGeneric->getAlias()) {
  140.           $alias json_decode($interfaceGeneric->getAlias(), true);
  141.         }
  142.         return $alias;
  143.     }
  144.     /**
  145.      * @Route("/equipment/specific/create/ajax", name="ajax_equipment_specific_create")
  146.      */
  147.     public function createAjaxAction(Request $requestTranslatorInterface $translator)
  148.     {
  149.         $em $this->getDoctrine()->getManager();
  150.         $eq = new EquipmentSpecific();
  151.         $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  152.         $eq->setAlias($_POST['alias']);
  153.         $eq->setOwner($_POST['owner']);
  154.         $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
  155.         $eq->setEquipmentGeneric($equipmentGeneric);
  156.         $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($_POST['rack']));
  157.         $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($_POST['rackFace']));
  158.         $eq->setPositionRack($_POST['positionRack']);
  159.         $em->persist($eq);
  160.         $em->flush();
  161.         // create specific interfaces
  162.         $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
  163.         foreach ($interfacesGeneric as $interfaceGeneric){
  164.             $interfaceSpecific = new InterfaceSpecific();
  165.             $interfaceSpecific->setEquipmentSpecific($eq);
  166.             $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  167.             $em->persist($interfaceSpecific);
  168.             $em->flush();
  169.             $alias null;
  170.             if ($interfaceGeneric->getAlias()) {
  171.               $alias json_decode($interfaceGeneric->getAlias(), true);
  172.             }
  173.             // create ports
  174.             $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  175.             for ($i=1$i<=$numberOfPorts$i++){
  176.                 $port = new Port();
  177.                 $port->setInterfaceSpecific($interfaceSpecific);
  178.                 $port->setOrderNo($i);
  179.                 if ($alias && count($alias) > 0) {
  180.                   $port->setAlias($alias[$i]);
  181.                 }
  182.                 $em->persist($port);
  183.                 $em->flush();
  184.             }
  185.         }
  186.         return $this->json(array('title' => $eq->getEquipmentSpecificName(), 'id' => $eq->getId()));
  187.     }
  188.     /**
  189.      * @Route("/equipment/specific/list", name="equipment_specific_list")
  190.      */
  191.     public function listAction(Request $requestTranslatorInterface $translator)
  192.     {
  193.         $eqGenerics $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=> false"isModulaire"=>false]);
  194.         $tempRack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneByTitle("Temp");
  195.         $eqModulaires $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["rack"=> $tempRack"isModulaire" => true]);
  196.         $list $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["isModule"=>false"isModulaire"=>false]);
  197.         // $em = $this->getDoctrine()->getManager();
  198.         // $queryBuilder = $em->createQueryBuilder()
  199.         // ->select('eqs')
  200.         // ->from('App\Entity\EquipmentSpecific', 'eqs')
  201.         // ->where("eqs.isModule = :isModule")
  202.         // ->andWhere("eqs.isModulaire = :isModulaire")
  203.         // ->setParameter("isModule", false)
  204.         // ->setParameter("isModulaire", false)
  205.         // ->orderBy("eqs.equipmentSpecificName", "ASC");
  206.         // $adapter = new DoctrineORMAdapter($queryBuilder);
  207.         // $pagerfanta = new Pagerfanta($adapter);
  208.         // $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
  209.         // if ($pageLength == "Tout") {
  210.         //   $qb = $em->createQueryBuilder()
  211.         //   ->select('COUNT(eqs.id)')
  212.         //   ->from('App\Entity\EquipmentSpecific', 'eqs')
  213.         //   ->where("eqs.isModule = :isModule")
  214.         //   ->andWhere("eqs.isModulaire = :isModulaire")
  215.         //   ->setParameter("isModule", false)
  216.         //   ->setParameter("isModulaire", false)
  217.         //   ->orderBy("eqs.equipmentSpecificName", "ASC");
  218.         //
  219.         //   $count = $qb->getQuery()->getSingleScalarResult();
  220.         //   $pagerfanta->setMaxPerPage($count); // 10 by default
  221.         // }
  222.         // else {
  223.         //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  224.         // }
  225.         // $page = $request->query->get("page", 1);
  226.         // $pagerfanta->setCurrentPage($page);
  227.         /*foreach ($list as $equipmentSpecific){
  228.             $inUse = 'No';
  229.             $interfacesSpecific = $equipmentSpecific->getInterfaceSpecific();
  230.             foreach ($interfacesSpecific as $interfaceSpecific){
  231.                 $ports = $interfaceSpecific->getPort();
  232.                 foreach ($ports as $port){
  233.                     $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  234.                     $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  235.                     if ($usedA || $usedB){
  236.                         $inUse = 'Yes';
  237.                     }
  238.                     $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  239.                     if ($usedExt){
  240.                         $inUse = 'Yes';
  241.                     }
  242.                 }
  243.             }
  244.             $equipmentSpecific->inUse = $inUse;
  245.         }*/
  246.         return $this->render('equipment/specific_list.html.twig', [
  247.             'action' => 'list',
  248.             'page_title' => $translator->trans('Specific Equipment'),
  249.             'path_default' => 'equipment_specific_create',
  250.             'path_update' => 'equipment_specific_update',
  251.             'path_delete' => 'equipment_specific_delete',
  252.             'list' => $list,
  253.             'eqGenerics'=>$eqGenerics,
  254.             'eqModulaires'=>$eqModulaires,
  255.             // 'my_pager' => $pagerfanta,
  256.             // 'pageLength' => $pageLength,
  257.         ]);
  258.     }
  259.     /**
  260.      * @Route("/equipment/specific/overview/list", name="equipment_specific_ovreview_list")
  261.      */
  262.     public function overviewListAction(Request $requestTranslatorInterface $translator)
  263.     {
  264.         // $list = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findByIsModule(false);
  265.         $list $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(['isModule'=>false'isChassisModule'=>false]);
  266.         // $em = $this->getDoctrine()->getManager();
  267.         // $queryBuilder = $em->createQueryBuilder()
  268.         // ->select('eqs')
  269.         // ->from('App\Entity\EquipmentSpecific', 'eqs')
  270.         // ->where("eqs.isModule = :isModule")
  271.         // ->setParameter("isModule", false)
  272.         // ->orderBy("eqs.equipmentSpecificName", "ASC");
  273.         // $adapter = new DoctrineORMAdapter($queryBuilder);
  274.         // $pagerfanta = new Pagerfanta($adapter);
  275.         // $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
  276.         // if ($pageLength == "Tout") {
  277.         //   $qb = $em->createQueryBuilder()
  278.         //   ->select('COUNT(eqs.id)')
  279.         //   ->from('App\Entity\EquipmentSpecific', 'eqs')
  280.         //   ->where("eqs.isModule = :isModule")
  281.         //   ->setParameter("isModule", false)
  282.         //   ->orderBy("eqs.equipmentSpecificName", "ASC");
  283.         //
  284.         //   $count = $qb->getQuery()->getSingleScalarResult();
  285.         //   $pagerfanta->setMaxPerPage($count); // 10 by default
  286.         // }
  287.         // else {
  288.         //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  289.         // }
  290.         // $page = $request->query->get("page", 1);
  291.         // $pagerfanta->setCurrentPage($page);
  292.         return $this->render('overview/specific_list.html.twig', [
  293.             'action' => 'list',
  294.             'page_title' => $translator->trans('Specific Equipment Overview'),
  295.             'path_view' => 'equipment_specific_overview',
  296.             'list' => $list,
  297.             // 'my_pager' => $pagerfanta,
  298.             // 'pageLength' => $pageLength,
  299.         ]);
  300.     }
  301.     /**
  302.      * @Route("/equipment/specific/overview/item/{id}", name="equipment_specific_overview")
  303.      */
  304.     public function overviewAction($idTranslatorInterface $translator)
  305.     {
  306.         $em $this->getDoctrine()->getManager();
  307.         $modules = array();
  308.         $eq $em->getRepository(EquipmentSpecific::class)->find($id);
  309.         $isModulaire false;
  310.         $portList = [];
  311.         //get all the ports used by Links
  312.         $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  313.         $portsAll = array();
  314.         foreach ($portsAllTemp as $tempArray) {
  315.           foreach ($tempArray as $key => $value) {
  316.             $portsAll[] = $value;
  317.           }
  318.         }
  319.         if ($eq->isModulaire()) {
  320.           $isModulaire true;
  321.           $modules $eq->getModules();
  322.           $chassisModule $eq->getChassisModule();
  323.           if($chassisModule){
  324.               $modules->add($chassisModule);
  325.           }
  326.           foreach ($modules as $module) {
  327.             $interfaces $module->getInterfaceSpecific();
  328.             // var_dump($portsAll);
  329.             $tcfs = array();
  330.             foreach ($interfaces as $interface){
  331.                 $ports $interface->getPort();
  332.                 foreach ($ports as $port){
  333.                   if (in_array($port->getId(), $portsAll)) {
  334.                     $port->nPort 0;
  335.                     $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  336.                     if ($nPorts){
  337.                         $nPorts json_decode($nPorts);
  338.                         if (in_array($port->getOrderNo(), $nPorts)){
  339.                             $port->nPort 1;
  340.                         }
  341.                     }
  342.                     $port->used 1;
  343.                     $port->usedLinkID $port->getLink()->getLinkId();
  344.                     $port->usedLink_id $port->getLink()->getId();;
  345.                     $portList[] = $port;
  346.                   }
  347.                 }
  348.             }
  349.           }
  350.         }
  351.         else {
  352.           $interfaces $eq->getInterfaceSpecific();
  353.           // var_dump($portsAll);
  354.           $tcfs = array();
  355.           foreach ($interfaces as $interface){
  356.               $ports $interface->getPort();
  357.               foreach ($ports as $port){
  358.                 if (in_array($port->getId(), $portsAll)) {
  359.                   $port->nPort 0;
  360.                   $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  361.                   if ($nPorts){
  362.                       $nPorts json_decode($nPorts);
  363.                       if (in_array($port->getOrderNo(), $nPorts)){
  364.                           $port->nPort 1;
  365.                       }
  366.                   }
  367.                   $port->used 1;
  368.                   $port->usedLinkID $port->getLink()->getLinkId();
  369.                   $port->usedLink_id $port->getLink()->getId();;
  370.                   $portList[] = $port;
  371.                 }
  372.                   // $port->nPort = 0;
  373.                   //
  374.                   // $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  375.                   // if ($nPorts){
  376.                   //     $nPorts = json_decode($nPorts);
  377.                   //     if (in_array($port->getOrderNo(), $nPorts)){
  378.                   //         $port->nPort = 1;
  379.                   //     }
  380.                   // }
  381.                   //
  382.                   // $used = 0;
  383.                   // $usedLinkID = '';
  384.                   // $usedLink_id = '';
  385.                   // $extremityA = $port->getExtremities()[0];
  386.                   //
  387.                   // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByextremityA($extremityA);
  388.                   // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByextremityB($extremityA);
  389.                   //
  390.                   // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  391.                   // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  392.                   //
  393.                   // if ($usedALink){
  394.                   //     $used = 1;
  395.                   //     $usedLinkID = $usedALink->getLink()->getLinkID();
  396.                   //     $usedLink_id = $usedALink->getLink()->getId();
  397.                   // }
  398.                   //
  399.                   // if ($usedBLink){
  400.                   //     $used = 1;
  401.                   //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  402.                   //     $usedLink_id = $usedBLink->getLink()->getId();
  403.                   // }
  404.                   //
  405.                   // $port->used = $used;
  406.                   // $port->usedLinkID = $usedLinkID;
  407.                   // $port->usedLink_id = $usedLink_id;
  408.                   //
  409.                   // $portList[] = $port;
  410.               }
  411.           }
  412.         }
  413.         return $this->render('overview/specific_view.html.twig', [
  414.             'page_title' => $translator->trans('Specific Equipment Overview'),
  415.             'box_title' => '',
  416.             'eq' => $eq,
  417.             'isModulaire'=> $isModulaire,
  418.             'portList' => $portList,
  419.             'modules' => $modules
  420.         ]);
  421.     }
  422.     /**
  423.      * @Route("/equipment/usage/list", name="equipment_specific_usage_list")
  424.      */
  425.     public function overviewUsageListAction(TranslatorInterface $translator)
  426.     {
  427.         $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  428.         return $this->render('overview/equipment_usage_list.html.twig', [
  429.             'action' => 'list',
  430.             'page_title' => $translator->trans('Equipment Usage'),
  431.             'path_view' => 'equipment_specific_overview',
  432.             'sites' => $sites
  433.         ]);
  434.     }
  435.     /**
  436.      * @Route("/equipment/usage", name="equipment_specific_usage", methods={"GET","POST"})
  437.      */
  438.     public function overviewUsageAction(TranslatorInterface $translator)
  439.     {
  440.         set_time_limit(300);
  441.         $interface null;
  442.         $eqMod null;
  443.         $eqModules null;
  444.         if (isset($_GET['id'])) {
  445.           $interface $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_GET['id']);
  446.         }
  447.         elseif (isset($_GET['modulaire_id'])) {
  448.           $eqMod $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_GET['modulaire_id']);
  449.           $eqModules $eqMod->getModules();
  450.           $chassisModule $eqMod->getChassisModule();
  451.           if ($chassisModule) {
  452.               $eqModules->add($chassisModule);
  453.           }
  454.           if (count($eqModules) > 0) {
  455.               $interface $eqModules[0]->getInterfaceSpecific()[0];
  456.           }
  457.           // $interface = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_GET['id']);
  458.         }
  459.         elseif (isset($_POST['interface'])) {
  460.           $interface $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_POST['interface']);
  461.         }
  462.         if ($interface == null) {
  463.             return $this->redirectToRoute('equipment_specific_usage_list');
  464.         }
  465.         $eq $interface->getEquipmentSpecific();
  466.         if (isset($_POST['module'])) {
  467.           $eqMod $eq->getParent();
  468.           if ($eqMod) {
  469.             $eqModules $eqMod->getModules();
  470.           }
  471.         }
  472.         $rack $interface->getEquipmentSpecific()->getRack();
  473.         $room $interface->getEquipmentSpecific()->getRack()->getRoom();
  474.         $site $interface->getEquipmentSpecific()->getRack()->getRoom()->getSite();
  475.         $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  476.         $rooms $site->getRooms();
  477.         $racks $room->getRacks();
  478.         $eqs =  $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(['rack' => $rack"isModule"=>false], ['equipmentSpecificName' => 'ASC']);
  479.         $intefaces $eq->getInterfaceSpecific();
  480.         $ports $interface->getPort();
  481.         //get all the ports used by Links
  482.         $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  483.         $portsAll = array();
  484.         foreach ($portsAllTemp as $tempArray) {
  485.           foreach ($tempArray as $key => $value) {
  486.             $portsAll[] = $value;
  487.           }
  488.         }
  489.         // var_dump($portsAll);
  490.         $tcfs = array();
  491.         foreach ($ports as $port){
  492.             if (in_array($port->getId(), $portsAll)) {
  493.               $port->nPort 0;
  494.               $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  495.               if ($nPorts){
  496.                   $nPorts json_decode($nPorts);
  497.                   if (in_array($port->getOrderNo(), $nPorts)){
  498.                       $port->nPort 1;
  499.                   }
  500.               }
  501.               // $port->nPort = 0;
  502.               //
  503.               // $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  504.               // if ($nPorts){
  505.               //     $nPorts = json_decode($nPorts);
  506.               //     if (in_array($port->getOrderNo(), $nPorts)){
  507.               //         $port->nPort = 1;
  508.               //     }
  509.               // }
  510.               $linkExtA null;
  511.               $linkExtB null;
  512.               $extremities = array();
  513.               foreach ($port->getExtensionOrder() as $value) {
  514.                 $extremities[] = $value->getExtremity();
  515.               }
  516.               foreach ($extremities as $extremityA) {
  517.                 $linkExtA $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  518.                 $linkExtB $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  519.               }
  520.               // $tcfs[] = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  521.               // $tcfs[] = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  522.               $tcfA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  523.               $tcfB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  524.               $trunkExtension $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  525.               // $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  526.               // $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  527.               // var_dump($linkExtA);
  528.               // var_dump($linkExtB);
  529.               if ($linkExtA){
  530.                   $link $linkExtA->getLink();
  531.                   // var_dump($link);
  532.                   $port->linkID $link->getLinkID();
  533.                   $port->link_id $link->getId();
  534.                   //Modified on 13 juin 2019
  535.                   // $port->usage = $link->getTypeUsage()->getTitle();
  536.                   $port->usage $link->getTypeUsage() ? $link->getTypeUsage()->getTitle() : "";
  537.                   $trunk $linkExtA->getTrunk();
  538.                   if ($trunk){
  539.                       $port->type_cable $trunk->getTypeCable()->getTitle();
  540.                   } else {
  541.                       $port->type_cable $linkExtA->getTypeCable()->getTitle();
  542.                   }
  543.                   $seqNumber $linkExtA->getSequenceNo();
  544.                   $nextSeqNumber $seqNumber 1;
  545.                   $prevSeqNumber $seqNumber 1;
  546.                   if ($seqNumber == 1){
  547.                       $port->extA '';
  548.                       $port->extB '';
  549.                   }
  550.                   if ($seqNumber == 2){
  551.                       $port->extA '';
  552.                       // for extB next extension
  553.                       $linkExtNext $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber'link' => $link]);
  554.                       if ($linkExtNext){
  555.                           $trunk $linkExtNext->getTrunk();
  556.                           if ($trunk){
  557.                               $port->extB $trunk->getTrunkID();
  558.                           } else {
  559.                               $port->extB 'E1';
  560.                           }
  561.                       } else {
  562.                           $port->extB '';
  563.                       }
  564.                   }
  565.                   if ($seqNumber 2){
  566.                       $linkExtPrevNoTrunk $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber$link);
  567.                       $linkExtPrev $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $prevSeqNumber'link' => $link]);
  568.                       // for extA previous extension
  569.                       $trunk $linkExtPrev->getTrunk();
  570.                       if ($trunk){
  571.                           $port->extA $trunk->getTrunkID();
  572.                       } else {
  573.                           $numberOfPrevExts sizeof($linkExtPrevNoTrunk);
  574.                           if ($numberOfPrevExts != ){
  575.                               $port->extA 'E'.$numberOfPrevExts;
  576.                           } else {
  577.                               $port->extA '';
  578.                           }
  579.                       }
  580.                       // for extB current extension
  581.                       $trunk $linkExtA->getTrunk();
  582.                       if ($trunk){
  583.                           $port->extB $trunk->getTrunkID();
  584.                       } else {
  585.                           $numberOfPrevExts sizeof($linkExtPrevNoTrunk);
  586.                           $port->extB 'E'.$numberOfPrevExts;
  587.                       }
  588.                   }
  589.               }
  590.               // var_dump($port);
  591.               if ($linkExtB){
  592.                   $link $linkExtB->getLink();
  593.                   $port->linkID $link->getLinkID();
  594.                   $port->link_id $link->getId();
  595.                   //Modified on 13 juin 2019
  596.                   // $port->usage = $link->getTypeUsage()->getTitle();
  597.                   $port->usage $link->getTypeUsage() ? $link->getTypeUsage()->getTitle() : "";
  598.                   $trunk $linkExtB->getTrunk();
  599.                   if ($trunk){
  600.                       $port->type_cable $trunk->getTypeCable()->getTitle();
  601.                   } else {
  602.                       $port->type_cable $linkExtB->getTypeCable()->getTitle();
  603.                   }
  604.                   $seqNumber $linkExtB->getSequenceNo();
  605.                   $nextSeqNumber $seqNumber 1;
  606.                   $prevSeqNumber $seqNumber 1;
  607.                   $lastSeqNumber $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getLastNextSequenceNo($link);
  608.                   if ($seqNumber == 1){
  609.                       $port->extA '';
  610.                       // for extB next extension
  611.                       $linkExtNext $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber'link' => $link]);
  612.                       if ($linkExtNext){
  613.                           $trunk $linkExtNext->getTrunk();
  614.                           if ($trunk){
  615.                               $port->extB $trunk->getTrunkID();
  616.                           } else {
  617.                               $port->extB 'E1';
  618.                           }
  619.                       } else {
  620.                           $port->extB '';
  621.                       }
  622.                   }
  623.                   if ($seqNumber && $seqNumber $lastSeqNumber){
  624.                       $linkExtPrevNoTrunk $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber$link);
  625.                       // for extA current extension
  626.                       $trunk $linkExtB->getTrunk();
  627.                       if ($trunk){
  628.                           $port->extA $trunk->getTrunkID();
  629.                       } else {
  630.                           $numberOfPrevExts sizeof($linkExtPrevNoTrunk);
  631.                           if ($numberOfPrevExts != ){
  632.                               $port->extA 'E'.$numberOfPrevExts;
  633.                           } else {
  634.                               $port->extA '';
  635.                           }
  636.                       }
  637.                       // for extB next extension
  638.                       $linkExtNext $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber'link' => $link]);
  639.                       if ($linkExtNext){
  640.                           $trunk $linkExtNext->getTrunk();
  641.                           if ($trunk){
  642.                               $port->extB $trunk->getTrunkID();
  643.                           } else {
  644.                               $port->extB 'E'.$numberOfPrevExts;
  645.                           }
  646.                       } else {
  647.                           $port->extB '';
  648.                       }
  649.                   }
  650.                   if ($seqNumber && $seqNumber == $lastSeqNumber){
  651.                       $linkExtPrevNoTrunk $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber$link);
  652.                       $linkExtPrev $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $prevSeqNumber'link' => $link]);
  653.                       // for extA current extension
  654.                       $trunk $linkExtB->getTrunk();
  655.                       if ($trunk){
  656.                           $port->extA $trunk->getTrunkID();
  657.                       } else {
  658.                           $numberOfPrevExts sizeof($linkExtPrevNoTrunk);
  659.                           if ($numberOfPrevExts != ){
  660.                               $port->extA 'E'.$numberOfPrevExts;
  661.                           } else {
  662.                               $port->extA '';
  663.                           }
  664.                       }
  665.                       // for extB no extension
  666.                       $port->extB '';
  667.                   }
  668.               }
  669.               if (!$linkExtA && !$linkExtB) {
  670.                   $port->linkID '';
  671.                   $port->link_id '';
  672.                   $port->type_cable '';
  673.                   $port->extA '';
  674.                   $port->extB '';
  675.                   $port->usage '';
  676.                   $port->nPort 0;
  677.               }
  678.               if (($trunkExtension && $linkExtA) || ($trunkExtension && $linkExtB)) {
  679.               }
  680.               else if($trunkExtension) {
  681.                 // var_dump("Got it");
  682.                 $port->linkID $port->getLink()->getLinkID();
  683.                 $port->link_id $port->getLink()->getId();
  684.                 // $port->usage = $port->getLink()->getTypeUsage()->getTitle();
  685.                 $port->usage $port->getLink()->getTypeUsage() ? $port->getLink()->getTypeUsage()->getTitle() : "";
  686.                 $port->type_cable $trunkExtension->getTrunkCableFiber()->getTrunk()->getTypeCable()->getTitle();
  687.                 $port->extA $trunkExtension->getTrunkCableFiber()->getTrunk()->getTrunkID();
  688.               }
  689.               if ($tcfB && $linkExtB) {
  690.               }
  691.               else if($tcfB){
  692.                 $port->linkID $port->getLink()->getLinkID();
  693.                 $port->link_id $port->getLink()->getId();
  694.                 // $port->usage = $port->getLink()->getTypeUsage()->getTitle();
  695.                 $port->usage $port->getLink()->getTypeUsage() ? $port->getLink()->getTypeUsage()->getTitle() : "";
  696.                 $port->type_cable $tcfB->getTrunk()->getTypeCable()->getTitle();
  697.                 $port->extA $tcfB->getTrunk()->getTrunkID();
  698.               }
  699.               // var_dump($trunkExtension);
  700.               if ($port->nPort == 1){
  701.                   $port->linkID '';
  702.                   $port->link_id '';
  703.                   $port->extB '';
  704.                   $port->usage '';
  705.                   $port->extA '';
  706.                   $port->type_cable '';
  707.                   $usedTcfA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
  708.                   $usedTcfB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
  709.                   $usedTExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  710.                   if ($usedTcfA){
  711.                       $port->extA $usedTcfA->getTrunk()->getTrunkID();
  712.                       $port->type_cable $usedTcfA->getTrunk()->getTypeCable()->getTitle();
  713.                   }
  714.                   if ($usedTcfB){
  715.                       $port->extA $usedTcfB->getTrunk()->getTrunkID();
  716.                       $port->type_cable $usedTcfB->getTrunk()->getTypeCable()->getTitle();
  717.                   }
  718.                   if ($usedTExt){
  719.                       $port->extA $usedTExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
  720.                       $port->type_cable $usedTExt->getTrunkCableFiber()->getTrunk()->getTypeCable()->getTitle();
  721.                   }
  722.               }
  723.             }
  724.             // var_dump($port->nPort);
  725.             else{
  726.                 $tcfATemp $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  727.                 if($tcfATemp){
  728.                     $port->extB $tcfATemp->getTrunk()->getTrunkID();
  729.                 }
  730.                 else{
  731.                     $tcfBTemp $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  732.                     if($tcfBTemp){
  733.                         $port->extB $tcfBTemp->getTrunk()->getTrunkID();
  734.                     }
  735.                     else {
  736.                         $tcfExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  737.                         if($tcfExtTemp){
  738.                             $port->extB $tcfExtTemp->getTrunkCableFiber()->getTrunk()->getTrunkID();
  739.                         }
  740.                     }
  741.                 }
  742.             }
  743.         }
  744.         // var_dump($tcfs);
  745.         return $this->render('overview/equipment_usage.html.twig', [
  746.             'action' => 'list',
  747.             'page_title' => $translator->trans('Equipment Usage'),
  748.             'path_view' => 'equipment_specific_overview',
  749.             'sites' => $sites,
  750.             'rooms' => $rooms,
  751.             'racks' => $racks,
  752.             'eqs' => $eqs,
  753.             'site' => $site,
  754.             'room' => $room,
  755.             'rack' => $rack,
  756.             'eq' => $eq,
  757.             'eqMod' => $eqMod,
  758.             'eqModules' => $eqModules,
  759.             'interface' => $interface,
  760.             'interfaces' => $intefaces,
  761.             'ports' => $ports
  762.         ]);
  763.     }
  764.     /**
  765.      * @Route("/equipment/specific/edit/{id}", name="equipment_specific_update")
  766.      */
  767.     public function updateAction(Request $request$idTranslatorInterface $translator)
  768.     {
  769.         $user $this->getUser();
  770.         // process form
  771.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  772.             $em $this->getDoctrine()->getManager();
  773.             $eq $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
  774.             // find in usage
  775.             /*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
  776.             if ($specific){
  777.                 $eq->setTitle($request->request->get('title'));
  778.                 $em->persist($eq);
  779.                 $em->flush();
  780.                 $error = array('error' => 'title');
  781.                 return $this->redirectToRoute('equipment_generic_list', $error);
  782.             }*/
  783.             $eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  784.             $eq->setAlias($request->request->get('alias'));
  785.             $eq->setOwner($request->request->get('owner'));
  786.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  787.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  788.             $eq->setPositionRack($request->request->get('positionRack'));
  789.             $em->persist($eq);
  790.             $em->flush();
  791.             return $this->redirectToRoute('equipment_specific_list');
  792.         } else {
  793.             $em $this->getDoctrine()->getManager();
  794.             $eq $em->getRepository(EquipmentSpecific::class)->find($id);
  795.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findAll();
  796.             $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
  797.             $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  798.             $portExternes $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
  799.             $portList = [];
  800.             $interfaces $eq->getInterfaceSpecific();
  801.             foreach ($interfaces as $interface){
  802.                 $ports $interface->getPort();
  803.                 $typeLnk $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  804.                 foreach ($ports as $port){
  805.                     $port->nPort 0;
  806.                     $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  807.                     if ($nPorts){
  808.                         $nPorts json_decode($nPorts);
  809.                         if (in_array($port->getOrderNo(), $nPorts)){
  810.                             $port->nPort 1;
  811.                         }
  812.                     }
  813.                     $used 0;
  814.                     $trunk 0;
  815.                     $connected 0;
  816.                     $usedLinkID '';
  817.                     $usedLink_id '';
  818.                     $usedALink null;
  819.                     $usedBLink null;
  820.                     $usedTrunkId 0;
  821.                     $usedTrunk_Id 0;
  822.                     $mpo 0;
  823.                     $mpoPorts null;
  824.                     if (count($port->getExtensionOrder()) > 0) {
  825.                       $extremityA $port->getExtensionOrder()[0]->getExtremity();
  826.                       $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  827.                       $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  828.                     }
  829.                     $tcfA $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
  830.                     $tcfB $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
  831.                     $tExt $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
  832.                     if($tcfA || $tcfB || $tExt){
  833.                         $trunk 1;
  834.                         if ($tcfA ) {
  835.                              $usedTrunkId $tcfA->getTrunk()->getTrunkID();
  836.                              $usedTrunk_Id $tcfA->getTrunk()->getId();
  837.                         }elseif ($tcfB) {
  838.                             $usedTrunkId $tcfB->getTrunk()->getTrunkID();
  839.                             $usedTrunk_Id $tcfB->getTrunk()->getId();
  840.                         }
  841.                         else {
  842.                             $usedTrunkId $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
  843.                             $usedTrunk_Id $tExt->getTrunkCableFiber()->getTrunk()->getId();
  844.                         }
  845.                     }
  846.                     // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  847.                     // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  848.                     if ($usedALink){
  849.                         $used 1;
  850.                         $usedLinkID $usedALink->getLink()->getLinkID();
  851.                         $usedLink_id $usedALink->getLink()->getId();
  852.                     }
  853.                     if ($usedBLink){
  854.                         $used 1;
  855.                         $usedLinkID $usedBLink->getLink()->getLinkID();
  856.                         $usedLink_id $usedBLink->getLink()->getId();
  857.                     }
  858.                     if ($typeLnk == "Port Externe") {
  859.                       if ($port->getPortExterne()) {
  860.                         $connected 1;
  861.                       }
  862.                       else {
  863.                         $connected 0;
  864.                       }
  865.                     }
  866.                     if ($connected == && $port->getInterfaceSpecificPortExterne() != null) {
  867.                         $ifPE $port->getInterfaceSpecificPortExterne();
  868.                         $mpo 1;
  869.                         $mpoPorts $this->getPortDetails($ifPE);
  870.                     }
  871.                     $port->trunk $trunk;
  872.                     $port->used $used;
  873.                     $port->connected $connected;
  874.                     $port->usedLinkID $usedLinkID;
  875.                     $port->usedLink_id $usedLink_id;
  876.                     $port->usedTrunkId $usedTrunkId;
  877.                     $port->usedTrunk_Id $usedTrunk_Id;
  878.                     $port->mpo $mpo;
  879.                     $port->mpoPorts $mpoPorts;
  880.                     $portList[] = $port;
  881.                 }
  882.             }
  883.             return $this->render('equipment/specific_edit.html.twig', [
  884.                 'action' => 'process',
  885.                 'page_title' => $translator->trans('Specific Equipment'),
  886.                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  887.                 'path_process' => 'equipment_specific_update_process',
  888.                 'eqGeneric' => $eqGeneric,
  889.                 'racks' => $racks,
  890.                 'rackFaces' => $rackFaces,
  891.                 'eq' => $eq,
  892.                 'portList' => $portList,
  893.                 'portExternes' => $portExternes
  894.             ]);
  895.         }
  896.     }
  897.     public function getPortDetails($interface){
  898.         $portList = array();
  899.         $ports $interface->getPort();
  900.         $typeLnk $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  901.         foreach ($ports as $port){
  902.             $port->nPort 0;
  903.             $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  904.             if ($nPorts){
  905.                 $nPorts json_decode($nPorts);
  906.                 if (in_array($port->getOrderNo(), $nPorts)){
  907.                     $port->nPort 1;
  908.                 }
  909.             }
  910.             $used 0;
  911.             $trunk 0;
  912.             $connected 0;
  913.             $usedLinkID '';
  914.             $usedLink_id '';
  915.             $usedALink null;
  916.             $usedBLink null;
  917.             $usedTrunkId 0;
  918.             $usedTrunk_Id 0;
  919.             $mpo 0;
  920.             $mpoPorts null;
  921.             if (count($port->getExtensionOrder()) > 0) {
  922.               $extremityA $port->getExtensionOrder()[0]->getExtremity();
  923.               $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  924.               $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  925.             }
  926.             $tcfA $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
  927.             $tcfB $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
  928.             $tExt $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
  929.             if($tcfA || $tcfB || $tExt){
  930.                 $trunk 1;
  931.                 if ($tcfA ) {
  932.                      $usedTrunkId $tcfA->getTrunk()->getTrunkID();
  933.                      $usedTrunk_Id $tcfA->getTrunk()->getId();
  934.                 }elseif ($tcfB) {
  935.                     $usedTrunkId $tcfB->getTrunk()->getTrunkID();
  936.                     $usedTrunk_Id $tcfB->getTrunk()->getId();
  937.                 }
  938.                 else {
  939.                     $usedTrunkId $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
  940.                     $usedTrunk_Id $tExt->getTrunkCableFiber()->getTrunk()->getId();
  941.                 }
  942.             }
  943.             // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  944.             // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  945.             if ($usedALink){
  946.                 $used 1;
  947.                 $usedLinkID $usedALink->getLink()->getLinkID();
  948.                 $usedLink_id $usedALink->getLink()->getId();
  949.             }
  950.             if ($usedBLink){
  951.                 $used 1;
  952.                 $usedLinkID $usedBLink->getLink()->getLinkID();
  953.                 $usedLink_id $usedBLink->getLink()->getId();
  954.             }
  955.             if ($typeLnk == "Port Externe") {
  956.               if ($port->getPortExterne()) {
  957.                 $connected 1;
  958.               }
  959.               else {
  960.                 $connected 0;
  961.               }
  962.             }
  963.             if ($connected == && $port->getInterfaceSpecificPortExterne() != null) {
  964.                 $ifPE $port->getInterfaceSpecificPortExterne();
  965.                 $mpo 1;
  966.                 $mpoPorts $this->getPortDetails($em$ifPE);
  967.             }
  968.             $port->trunk $trunk;
  969.             $port->used $used;
  970.             $port->connected $connected;
  971.             $port->usedLinkID $usedLinkID;
  972.             $port->usedLink_id $usedLink_id;
  973.             $port->usedTrunkId $usedTrunkId;
  974.             $port->usedTrunk_Id $usedTrunk_Id;
  975.             $port->mpo $mpo;
  976.             $portList[] = $port;
  977.         }
  978.         return $portList;
  979.     }
  980.     /**
  981.      * @Route("/equipment/specific/port-externe/edit", name="equipment_specific_port_externe_edit")
  982.      */
  983.     public function updatePortExterneAction(Request $requestTranslatorInterface $translator)
  984.     {
  985.           $idTemp $_POST["id"];
  986.           $em $this->getDoctrine()->getManager();
  987.           $interfaceSpecific $em->getRepository(InterfaceSpecific::class)->find($idTemp);
  988.           $ports $interfaceSpecific->getPort();
  989.           foreach ($ports as $port) {
  990.             $idPortExt $_POST["portExterne"][$port->getId()];
  991.             $interfaceSpecificPortExterne $port->getInterfaceSpecificPortExterne();
  992.             if ($idPortExt) {
  993.               $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($idPortExt);
  994.               $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  995.               if ($port->getPortExterne() == null) {
  996.                   $port->setPortExterne($pe);
  997.                   if ($interfaceGenericPortExterne != null) {
  998.                       //create interface spécific and attach it to the port
  999.                       $ifPE = new InterfaceSpecific();
  1000.                       $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$interfaceSpecific->getEquipmentSpecific(), $port);
  1001.                       $port->setInterfaceSpecificPortExterne($ifPE);
  1002.                   }
  1003.               }
  1004.               elseif ($interfaceGenericPortExterne == null && $interfaceSpecificPortExterne == null) {
  1005.                   $port->setPortExterne($pe);
  1006.               } elseif ($interfaceGenericPortExterne != null && $interfaceSpecificPortExterne == null) {
  1007.                     //create interface spécific and attach it to the port
  1008.                     $port->setPortExterne($pe);
  1009.                     $ifPE = new InterfaceSpecific();
  1010.                     $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$interfaceSpecific->getEquipmentSpecific(), $port);
  1011.                     $port->setInterfaceSpecificPortExterne($ifPE);
  1012.               }
  1013.               elseif($interfaceSpecificPortExterne != null){
  1014.                 $inUse 0;
  1015.                 foreach ($interfaceSpecificPortExterne->getPort() as $pMpo){
  1016.                     $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
  1017.                     $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
  1018.                     if ($usedA || $usedB){
  1019.                         $inUse 1;
  1020.                         break;
  1021.                     }
  1022.                     $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
  1023.                     if ($usedExt){
  1024.                         $inUse 1;
  1025.                         break;
  1026.                     }
  1027.                     $usedALink null;
  1028.                     $usedBLink null;
  1029.                     if (count($pMpo->getExtensionOrder()) > 0) {
  1030.                         $extremityA $pMpo->getExtensionOrder()[0]->getExtremity();
  1031.                         $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1032.                         $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1033.                     }
  1034.                     if ($usedALink || $usedBLink){
  1035.                         $inUse 1;
  1036.                         break;
  1037.                     }
  1038.                 }
  1039.                 if ($inUse == 0){
  1040.                     // $sql = "delete from port where port_mpo_id = " . $interfaceSpecificPortExterne->getId();
  1041.                     // $conn = $em->getConnection();
  1042.                     // $stmt = $conn->prepare($sql);
  1043.                     // $stmt->execute();
  1044.                     // $em->remove($interfaceSpecificPortExterne);
  1045.                     // $em->flush();
  1046.                     //create interface spécific and attach it to the port
  1047.                     $port->setPortExterne($pe);
  1048.                     if ($interfaceGenericPortExterne != null) {
  1049.                         $ifPE = new InterfaceSpecific();
  1050.                         $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$interfaceSpecific->getEquipmentSpecific(), $port);
  1051.                         $port->setInterfaceSpecificPortExterne($ifPE); 
  1052.                     }
  1053.                     else {
  1054.                         $port->setInterfaceSpecificPortExterne(null); 
  1055.                     }
  1056.                     
  1057.                 } else {
  1058.                     $this->addFlash(
  1059.                         'error',
  1060.                         'usage'
  1061.                     );
  1062.                 }
  1063.               }
  1064.             }
  1065.             else {
  1066.               $port->setPortExterne(null);
  1067.             }
  1068.             $em->persist($port);
  1069.           }
  1070.           $em->flush();
  1071.           if ($_POST["ref"] == "module") {
  1072.             return $this->redirectToRoute('equipment_specific_module_update', ["id"=>$_POST["moduleId"]]);
  1073.           }
  1074.           else {
  1075.             return $this->redirectToRoute('equipment_specific_update', ["id"=>$_POST["eqId"]]);
  1076.           }
  1077.     }
  1078.     /**
  1079.      * @IsGranted("ROLE_CRUD")
  1080.      * @Route("/equipment/specific/delete/{id}", name="equipment_specific_delete")
  1081.      */
  1082.     public function deleteAction(Request $request$idTranslatorInterface $translator)
  1083.     {
  1084.         $em $this->getDoctrine()->getManager();
  1085.         $equipmentSpecific $em->getRepository(EquipmentSpecific::class)->find($id);
  1086.         $inUse 0;
  1087.         if ($equipmentSpecific->isModulaire()) {
  1088.             $modules $equipmentSpecific->getModules();
  1089.             $chassisModule $equipmentSpecific->getChassisModule();
  1090.             if ($chassisModule) {
  1091.                 $modules->add($chassisModule);
  1092.             }
  1093.           foreach ($modules as $value) {
  1094.             $interfacesSpecific $value->getInterfaceSpecific();
  1095.             foreach ($interfacesSpecific as $interfaceSpecific){
  1096.                 $ports $interfaceSpecific->getPort();
  1097.                 foreach ($ports as $port){
  1098.                     $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  1099.                     $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1100.                     if ($usedA || $usedB){
  1101.                         $inUse 1;
  1102.                     }
  1103.                     $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1104.                     if ($usedExt){
  1105.                         $inUse 1;
  1106.                     }
  1107.                     $usedALink null;
  1108.                     $usedBLink null;
  1109.                     if (count($port->getExtensionOrder()) > 0) {
  1110.                       $extremityA $port->getExtensionOrder()[0]->getExtremity();
  1111.                       $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1112.                       $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1113.                     }
  1114.                     // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  1115.                     // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1116.                     if ($usedALink || $usedBLink){
  1117.                         $inUse 1;
  1118.                     }
  1119.                     if ($port->getInterfaceSpecificPortExterne()) {
  1120.                         foreach ($port->getInterfaceSpecificPortExterne()->getPort() as $pMpo){
  1121.                             $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
  1122.                             $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
  1123.                             if ($usedA || $usedB){
  1124.                                 $inUse 1;
  1125.                             }
  1126.                             $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
  1127.                             if ($usedExt){
  1128.                                 $inUse 1;
  1129.                             }
  1130.                             $usedALink null;
  1131.                             $usedBLink null;
  1132.                             if (count($pMpo->getExtensionOrder()) > 0) {
  1133.                               $extremityA $pMpo->getExtensionOrder()[0]->getExtremity();
  1134.                               $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1135.                               $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1136.                             }
  1137.                             // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($pMpo);
  1138.                             // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1139.                             if ($usedALink || $usedBLink){
  1140.                                 $inUse 1;
  1141.                             }
  1142.                             if ($inUse) {
  1143.                               break;
  1144.                             }
  1145.                         }
  1146.                     }
  1147.                     if ($inUse) {
  1148.                       break;
  1149.                     }
  1150.                 }
  1151.                 if ($inUse) {
  1152.                   break;
  1153.                 }
  1154.             }
  1155.             if ($inUse) {
  1156.               break;
  1157.             }
  1158.           }
  1159.         }
  1160.         else {
  1161.           $interfacesSpecific $equipmentSpecific->getInterfaceSpecific();
  1162.           foreach ($interfacesSpecific as $interfaceSpecific){
  1163.               $ports $interfaceSpecific->getPort();
  1164.               foreach ($ports as $port){
  1165.                   $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  1166.                   $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1167.                   if ($usedA || $usedB){
  1168.                       $inUse 1;
  1169.                   }
  1170.                   $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1171.                   if ($usedExt){
  1172.                       $inUse 1;
  1173.                   }
  1174.                   $usedALink null;
  1175.                   $usedBLink null;
  1176.                   if (count($port->getExtensionOrder()) > 0) {
  1177.                     $extremityA $port->getExtensionOrder()[0]->getExtremity();
  1178.                     $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1179.                     $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1180.                   }
  1181.                   // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  1182.                   // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1183.                   if ($usedALink || $usedBLink){
  1184.                       $inUse 1;
  1185.                   }
  1186.                   if ($port->getInterfaceSpecificPortExterne()) {
  1187.                       foreach ($port->getInterfaceSpecificPortExterne()->getPort() as $pMpo){
  1188.                           $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
  1189.                           $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
  1190.                           if ($usedA || $usedB){
  1191.                               $inUse 1;
  1192.                           }
  1193.                           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
  1194.                           if ($usedExt){
  1195.                               $inUse 1;
  1196.                           }
  1197.                           $usedALink null;
  1198.                           $usedBLink null;
  1199.                           if (count($pMpo->getExtensionOrder()) > 0) {
  1200.                             $extremityA $pMpo->getExtensionOrder()[0]->getExtremity();
  1201.                             $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1202.                             $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1203.                           }
  1204.                           // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($pMpo);
  1205.                           // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1206.                           if ($usedALink || $usedBLink){
  1207.                               $inUse 1;
  1208.                           }
  1209.                           if ($inUse) {
  1210.                             break;
  1211.                           }
  1212.                       }
  1213.                   }
  1214.                   if ($inUse) {
  1215.                     break;
  1216.                   }
  1217.               }
  1218.               if ($inUse) {
  1219.                 break;
  1220.               }
  1221.           }
  1222.         }
  1223.         $error = [];
  1224.         if ($inUse == 0){
  1225.             $sql "update slot set module_id=null where module_id = " $equipmentSpecific->getId() ." or modulaire_id=" $equipmentSpecific->getId();
  1226.             // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  1227.             $conn $em->getConnection();
  1228.             $stmt $conn->prepare($sql);
  1229.             $stmt->execute();
  1230.             $sql1 "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " $equipmentSpecific->getId();
  1231.             $conn $em->getConnection();
  1232.             $stmt $conn->prepare($sql1);
  1233.             $stmt->execute();
  1234.             $sql "update equipment_specific set chassis_module_id=null where id = " $equipmentSpecific->getId();
  1235.             // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  1236.             $stmt $conn->prepare($sql);
  1237.             $stmt->execute();
  1238.             $em->remove($equipmentSpecific);
  1239.             $em->flush();
  1240.             $error = array('error' => null);
  1241.         } else {
  1242.             $error = array('error' => 'usage');
  1243.         }
  1244.         if ($error['error']) {
  1245.           $this->addFlash(
  1246.               'error',
  1247.               'usage'
  1248.           );
  1249.         }
  1250.         if ($request->query->get('ref') == 'module') {
  1251.           return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$equipmentSpecific->getParent()->getId()]);
  1252.         }
  1253.         elseif ($request->query->get('ref') == 'modulaire') {
  1254.           return $this->redirectToRoute('equipment_specific_modulaire_list', ['id'=>$id]);        }
  1255.         else {
  1256.             // return $this->redirect($request->headers->get('referer'));
  1257.           return $this->redirectToRoute('equipment_specific_list');
  1258.         }
  1259.     }
  1260.     /**
  1261.      * @Route("/equipment/specific/modulaire/create", name="equipment_specific_modulaire_create")
  1262.      */
  1263.     public function createModulaireAction(Request $requestTranslatorInterface $translator)
  1264.     {
  1265.         $user $this->getUser();
  1266.         // process form
  1267.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  1268.             // var_dump($request->request->all());
  1269.             $em $this->getDoctrine()->getManager();
  1270.             $eqParent = new EquipmentSpecific();
  1271.             $eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  1272.             $eqParent->setAlias($request->request->get('alias'));
  1273.             $eqParent->setOwner($request->request->get('owner'));
  1274.             $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
  1275.             $eqParent->setEquipmentGeneric($equipmentGeneric);
  1276.             $eqParent->setIsModulaire(true);
  1277.             $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack'));
  1278.             $eqParent->setRack($rack);
  1279.             $eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1280.             $eqParent->setPositionRack($request->request->get('positionRack'));
  1281.             //create and attach slots to modulaire equipments
  1282.             for ($i=0$i $equipmentGeneric->getNumberOfSlots(); $i++) {
  1283.               $slot = new Slot();
  1284.               $slot->setSlotNumber($i+1);
  1285.               $slot->setModulaire($eqParent);
  1286.               $em->persist($slot);
  1287.             }
  1288.             $em->persist($eqParent);
  1289.             $em->flush();
  1290.             //module chassis
  1291.             $chassisModule $equipmentGeneric->getChassisModule();
  1292.             if($chassisModule){
  1293.                 $eq = new EquipmentSpecific();
  1294.                 $eq->setEquipmentSpecificName("CHASSIS");
  1295.                 $eq->setAlias("CHASSIS");
  1296.                 $eq->setEquipmentGeneric($chassisModule);
  1297.                 $eq->setChassisParent($eqParent);
  1298.                 $eq->setRack($rack);
  1299.                 $eq->setIsChassisModule(true);
  1300.                 $eqParent->setChassisModule($eq);
  1301.                 $em->persist($eqParent);
  1302.                 // $em->persist($eq);
  1303.                 $em->flush();
  1304.                 // create specific interfaces
  1305.                 $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($chassisModule);
  1306.                 foreach ($interfacesGeneric as $interfaceGeneric){
  1307.                     $interfaceSpecific = new InterfaceSpecific();
  1308.                     $interfaceSpecific->setEquipmentSpecific($eq);
  1309.                     $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1310.                     $em->persist($interfaceSpecific);
  1311.                     $em->flush();
  1312.                     $alias null;
  1313.                     if ($interfaceGeneric->getAlias()) {
  1314.                       $alias json_decode($interfaceGeneric->getAlias(), true);
  1315.                     }
  1316.                     $portExternes null;
  1317.                     $idTemp $interfaceGeneric->getId();
  1318.                     // var_dump($_POST["portExterne[$idTemp]"]);
  1319.                     if (isset($_POST["portExterne"][$idTemp])) {
  1320.                       foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  1321.                         $portExternes[$key] = $value;
  1322.                       }
  1323.                     }
  1324.                     // var_dump($portExternes);
  1325.                     // create ports
  1326.                     $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  1327.                     for ($i=1$i<=$numberOfPorts$i++){
  1328.                         $port = new Port();
  1329.                         $port->setInterfaceSpecific($interfaceSpecific);
  1330.                         $port->setOrderNo($i);
  1331.                         if ($alias && count($alias) > 0) {
  1332.                           $port->setAlias($alias[$i]);
  1333.                         }
  1334.                         if ($portExternes) {
  1335.                           if (isset($portExternes[$i]) && $portExternes[$i]) {
  1336.                             // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  1337.                             $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  1338.                             $port->setPortExterne($pe);
  1339.                             $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  1340.                             if ($interfaceGenericPortExterne != null) {
  1341.                                 //create interface spécific and attach it to the port
  1342.                                 $ifPE = new InterfaceSpecific();
  1343.                                 $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  1344.                                 $port->setInterfaceSpecificPortExterne($ifPE);
  1345.                             }
  1346.                           }
  1347.                         }
  1348.                         $em->persist($port);
  1349.                         $em->flush();
  1350.                     }
  1351.                     // create ports
  1352.                     // $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
  1353.                     // for ($j=1; $j<=$numberOfPorts; $j++){
  1354.                     //
  1355.                     //     $port = new Port();
  1356.                     //     $port->setInterfaceSpecific($interfaceSpecific);
  1357.                     //     $port->setOrderNo($j);
  1358.                     //
  1359.                     //     $em->persist($port);
  1360.                     //     $em->flush();
  1361.                     //
  1362.                     // }
  1363.                 }
  1364.             }
  1365.             return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  1366.         } else {
  1367.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findByIsModulaire(true);
  1368.             $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
  1369.             $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1370.             return $this->render('equipment/specific_modulaire_create.html.twig', [
  1371.                 'action' => 'insert',
  1372.                 'page_title' => $translator->trans('Equipement Spécifique Modulaire'),
  1373.                 'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  1374.                 'eqGeneric' => $eqGeneric,
  1375.                 'racks' => $racks,
  1376.                 'rackFaces' => $rackFaces
  1377.             ]);
  1378.         }
  1379.     }
  1380.     /**
  1381.      * @Route("/equipment/specific/modulaire/create_temp", name="equipment_specific_modulaire_create_temp")
  1382.      */
  1383.     public function createModulaireTempAction(Request $requestTranslatorInterface $translator)
  1384.     {
  1385.         $user $this->getUser();
  1386.         $em $this->getDoctrine()->getManager();
  1387.         // process form
  1388.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  1389.             // var_dump($request->request->all());
  1390.             $eqParent = new EquipmentSpecific();
  1391.             $eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  1392.             $eqParent->setAlias($request->request->get('alias'));
  1393.             $eqParent->setOwner($request->request->get('owner'));
  1394.             $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
  1395.             $eqParent->setEquipmentGeneric($equipmentGeneric);
  1396.             $eqParent->setIsModulaire(true);
  1397.             $eqParent->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1398.             $eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1399.             $eqParent->setPositionRack($request->request->get('positionRack'));
  1400.             //create and attach slots to modulaire equipments
  1401.             for ($i=0$i $equipmentGeneric->getNumberOfSlots(); $i++) {
  1402.               $slot = new Slot();
  1403.               $slot->setSlotNumber($i+1);
  1404.               $slot->setModulaire($eqParent);
  1405.               $em->persist($slot);
  1406.             }
  1407.             $em->persist($eqParent);
  1408.             $em->flush();
  1409.             //module chassis
  1410.             $chassisModule $equipmentGeneric->getChassisModule();
  1411.             if($chassisModule){
  1412.                 $eq = new EquipmentSpecific();
  1413.                 $eq->setEquipmentSpecificName("CHASSIS");
  1414.                 $eq->setAlias("CHASSIS");
  1415.                 $eq->setEquipmentGeneric($chassisModule);
  1416.                 $eq->setChassisParent($eqParent);
  1417.                 $eq->setRack($rack);
  1418.                 $eq->setIsChassisModule(true);
  1419.                 $eqParent->setChassisModule($eq);
  1420.                 $em->persist($eqParent);
  1421.                 // $em->persist($eq);
  1422.                 $em->flush();
  1423.                 // create specific interfaces
  1424.                 $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($chassisModule);
  1425.                 foreach ($interfacesGeneric as $interfaceGeneric){
  1426.                     $interfaceSpecific = new InterfaceSpecific();
  1427.                     $interfaceSpecific->setEquipmentSpecific($eq);
  1428.                     $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1429.                     $em->persist($interfaceSpecific);
  1430.                     $em->flush();
  1431.                     $alias null;
  1432.                     if ($interfaceGeneric->getAlias()) {
  1433.                       $alias json_decode($interfaceGeneric->getAlias(), true);
  1434.                     }
  1435.                     $portExternes null;
  1436.                     $idTemp $interfaceGeneric->getId();
  1437.                     // var_dump($_POST["portExterne[$idTemp]"]);
  1438.                     if (isset($_POST["portExterne"][$idTemp])) {
  1439.                       foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  1440.                         $portExternes[$key] = $value;
  1441.                       }
  1442.                     }
  1443.                     // var_dump($portExternes);
  1444.                     // create ports
  1445.                     $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  1446.                     for ($i=1$i<=$numberOfPorts$i++){
  1447.                         $port = new Port();
  1448.                         $port->setInterfaceSpecific($interfaceSpecific);
  1449.                         $port->setOrderNo($i);
  1450.                         if ($alias && count($alias) > 0) {
  1451.                           $port->setAlias($alias[$i]);
  1452.                         }
  1453.                         if ($portExternes) {
  1454.                           if (isset($portExternes[$i]) && $portExternes[$i]) {
  1455.                             // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  1456.                             $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  1457.                             $port->setPortExterne($pe);
  1458.                             $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  1459.                             if ($interfaceGenericPortExterne != null) {
  1460.                                 //create interface spécific and attach it to the port
  1461.                                 $ifPE = new InterfaceSpecific();
  1462.                                 $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  1463.                                 $port->setInterfaceSpecificPortExterne($ifPE);
  1464.                             }
  1465.                           }
  1466.                         }
  1467.                         $em->persist($port);
  1468.                         $em->flush();
  1469.                     }
  1470.                 }
  1471.             }
  1472.             return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  1473.         } else {
  1474.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findByIsModulaire(true);
  1475.             $site $this->getDoctrine()->getRepository('App\Entity\Site')->findOneByTitle("Temp");
  1476.             if (is_null($site)) {
  1477.                 $site = new Site();
  1478.                 $site->setTitle("Temp");
  1479.                 $em->persist($site);
  1480.                 $em->flush();
  1481.             }
  1482.             $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["site"=>$site"title"=>"Temp"]);
  1483.             if (is_null($room)) {
  1484.                 $room = new Room();
  1485.                 $room->setTitle("Temp");
  1486.                 $room->setSite($site);
  1487.                 $em->persist($room);
  1488.                 $em->flush();
  1489.             }
  1490.             $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneBy(["room"=>$room"title"=>"Temp"]);
  1491.             if (is_null($rack)) {
  1492.                 $rack = new Rack();
  1493.                 $rack->setTitle("Temp");
  1494.                 $rack->setNumberOfUnits(80);
  1495.                 $rack->setRoom($room);
  1496.                 $em->persist($rack);
  1497.                 $em->flush();
  1498.             }
  1499.             $rackFace $this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneByTitle("Front");
  1500.             return $this->render('equipment/specific_modulaire_create_temp.html.twig', [
  1501.                 'action' => 'insert',
  1502.                 'page_title' => $translator->trans('Equipement Spécifique Modulaire Temporaire'),
  1503.                 'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  1504.                 'eqGeneric' => $eqGeneric,
  1505.                 'tempRack' => $rack->getId(),
  1506.                 'tempRackFace' => $rackFace->getId(),
  1507.                 'tempPositionRack' => 1
  1508.             ]);
  1509.         }
  1510.     }
  1511.     /**
  1512.      * @Route("/equipment/specific/modulaire/list", name="equipment_specific_modulaire_list")
  1513.      */
  1514.     public function listModulaireAction(Request $requestTranslatorInterface $translator)
  1515.     {
  1516.         $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
  1517.         $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1518.         $eqGenerics $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=> false"isModulaire"=>false]);
  1519.         $tempRack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneByTitle("Temp");
  1520.         $eqModulaires $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["rack"=> $tempRack"isModulaire" => true]);
  1521.         $list $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findByIsModulaire(true);
  1522.         // $em = $this->getDoctrine()->getManager();
  1523.         // $queryBuilder = $em->createQueryBuilder()
  1524.         // ->select('eqs')
  1525.         // ->from('App\Entity\EquipmentSpecific', 'eqs')
  1526.         // ->where("eqs.isModulaire = :isModulaire")
  1527.         // ->setParameter("isModulaire", true)
  1528.         // ->orderBy("eqs.equipmentSpecificName", "ASC");
  1529.         // $adapter = new DoctrineORMAdapter($queryBuilder);
  1530.         // $pagerfanta = new Pagerfanta($adapter);
  1531.         // $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
  1532.         // if ($pageLength == "Tout") {
  1533.         //   $qb = $em->createQueryBuilder()
  1534.         //   ->select('COUNT(eqs.id)')
  1535.         //   ->from('App\Entity\EquipmentSpecific', 'eqs')
  1536.         //   ->where("eqs.isModulaire = :isModulaire")
  1537.         //   ->setParameter("isModulaire", true)
  1538.         //   ->orderBy("eqs.equipmentSpecificName", "ASC");
  1539.         //
  1540.         //   $count = $qb->getQuery()->getSingleScalarResult();
  1541.         //   $pagerfanta->setMaxPerPage($count); // 10 by default
  1542.         // }
  1543.         // else {
  1544.         //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  1545.         // }
  1546.         // $page = $request->query->get("page", 1);
  1547.         // $pagerfanta->setCurrentPage($page);
  1548.         return $this->render('equipment/specific_modulaire_list.html.twig', [
  1549.             'action' => 'list',
  1550.             'page_title' => $translator->trans('Specific Equipment') . " - Modulaire",
  1551.             'path_default' => 'equipment_specific_modulaire_create',
  1552.             'path_update' => 'equipment_specific_modulaire_update',
  1553.             'path_delete' => 'equipment_specific_delete',
  1554.             'racks' => $racks,
  1555.             'rackFaces' => $rackFaces,
  1556.             "eqGenerics" => $eqGenerics,
  1557.             "eqModulaires" => $eqModulaires,
  1558.             'list' => $list,
  1559.             // 'my_pager' => $pagerfanta,
  1560.             // 'pageLength' => $pageLength,
  1561.         ]);
  1562.     }
  1563.     /**
  1564.      * @Route("/equipment/specific/modulaire/edit/{id}", name="equipment_specific_modulaire_update")
  1565.      */
  1566.     public function updateModulaireAction(Request $request$idTranslatorInterface $translator)
  1567.     {
  1568.         $user $this->getUser();
  1569.         // process form
  1570.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  1571.             $em $this->getDoctrine()->getManager();
  1572.             $eq $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
  1573.             // find in usage
  1574.             /*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
  1575.             if ($specific){
  1576.                 $eq->setTitle($request->request->get('title'));
  1577.                 $em->persist($eq);
  1578.                 $em->flush();
  1579.                 $error = array('error' => 'title');
  1580.                 return $this->redirectToRoute('equipment_generic_list', $error);
  1581.             }*/
  1582.             $eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  1583.             $eq->setAlias($request->request->get('alias'));
  1584.             $eq->setOwner($request->request->get('owner'));
  1585.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1586.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1587.             $eq->setPositionRack($request->request->get('positionRack'));
  1588.             foreach ($eq->getModules() as $value) {
  1589.               $value->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1590.               $em->persist($value);
  1591.             }
  1592.             $em->persist($eq);
  1593.             $em->flush();
  1594.             return $this->redirectToRoute('equipment_specific_modulaire_list');
  1595.         } else {
  1596.             $em $this->getDoctrine()->getManager();
  1597.             $eq $em->getRepository(EquipmentSpecific::class)->find($id);
  1598.             $moduleGenerics $eq->getEquipmentGeneric()->getModules();
  1599.             $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
  1600.             $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1601.             $modules $eq->getModules();
  1602.             $slots $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($id);
  1603.             return $this->render('equipment/specific_modulaire_edit.html.twig', [
  1604.                 'action' => 'process',
  1605.                 'page_title' => $translator->trans('Specific Equipment') . " - Modulaire",
  1606.                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1607.                 'path_process' => 'equipment_specific_update_process',
  1608.                 'eqGeneric' => $moduleGenerics,
  1609.                 'racks' => $racks,
  1610.                 'rackFaces' => $rackFaces,
  1611.                 'eq' => $eq,
  1612.                 'modules' => $modules,
  1613.                 'slots' => $slots
  1614.             ]);
  1615.         }
  1616.     }
  1617.     /**
  1618.      * @Route("/equipment/specific/module/create/{id}", name="equipment_specific_module_create")
  1619.      */
  1620.     public function createModuleAction(Request $request$idTranslatorInterface $translator)
  1621.     {
  1622.         $user $this->getUser();
  1623.         // process form
  1624.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  1625.             // var_dump($request->request->all());
  1626.             $em $this->getDoctrine()->getManager();
  1627.             $eqParent $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  1628.             $eq = new EquipmentSpecific();
  1629.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  1630.             $eq->setAlias($_POST['alias']);
  1631.             $moduleGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
  1632.             $eq->setEquipmentGeneric($moduleGeneric);
  1633.             foreach ($_POST['slots'] as $key => $value) {
  1634.               $slot $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
  1635.               $slot->setModule($eq);
  1636.               $em->persist($slot);
  1637.             }
  1638.             $eq->setIsModule(true);
  1639.             $eq->setParent($eqParent);
  1640.             //
  1641.             // $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1642.             // $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1643.             // $eq->setPositionRack($request->request->get('positionRack'));
  1644.             $em->persist($eq);
  1645.             $em->flush();
  1646.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1647.             // create specific interfaces
  1648.             $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  1649.             foreach ($interfacesGeneric as $interfaceGeneric){
  1650.                 $interfaceSpecific = new InterfaceSpecific();
  1651.                 $interfaceSpecific->setEquipmentSpecific($eq);
  1652.                 $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1653.                 $em->persist($interfaceSpecific);
  1654.                 $em->flush();
  1655.                 $alias null;
  1656.                 if ($interfaceGeneric->getAlias()) {
  1657.                   $alias json_decode($interfaceGeneric->getAlias(), true);
  1658.                 }
  1659.                 $portExternes null;
  1660.                 $idTemp $interfaceGeneric->getId();
  1661.                 // var_dump($_POST["portExterne[$idTemp]"]);
  1662.                 if (isset($_POST["portExterne"][$idTemp])) {
  1663.                   foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  1664.                     $portExternes[$key] = $value;
  1665.                   }
  1666.                 }
  1667.                 // var_dump($portExternes);
  1668.                 // create ports
  1669.                 $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  1670.                 for ($i=1$i<=$numberOfPorts$i++){
  1671.                     $port = new Port();
  1672.                     $port->setInterfaceSpecific($interfaceSpecific);
  1673.                     $port->setOrderNo($i);
  1674.                     if ($alias && count($alias) > 0) {
  1675.                       $port->setAlias($alias[$i]);
  1676.                     }
  1677.                     if ($portExternes) {
  1678.                       if (isset($portExternes[$i]) && $portExternes[$i]) {
  1679.                         // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  1680.                         $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  1681.                         $port->setPortExterne($pe);
  1682.                         $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  1683.                         if ($interfaceGenericPortExterne != null) {
  1684.                             //create interface spécific and attach it to the port
  1685.                             $ifPE = new InterfaceSpecific();
  1686.                             $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  1687.                             $port->setInterfaceSpecificPortExterne($ifPE);
  1688.                         }
  1689.                       }
  1690.                     }
  1691.                     $em->persist($port);
  1692.                     $em->flush();
  1693.                 }
  1694.                 // create ports
  1695.                 // $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
  1696.                 // for ($j=1; $j<=$numberOfPorts; $j++){
  1697.                 //
  1698.                 //     $port = new Port();
  1699.                 //     $port->setInterfaceSpecific($interfaceSpecific);
  1700.                 //     $port->setOrderNo($j);
  1701.                 //
  1702.                 //     $em->persist($port);
  1703.                 //     $em->flush();
  1704.                 //
  1705.                 // }
  1706.             }
  1707.             // var_dump($request->request->all());
  1708.             // for ($i=0; $i < $equipmentGeneric->getNumberOfModules() ; $i++) {
  1709.             //   $eq = new EquipmentSpecific();
  1710.             //
  1711.             //   $eq->setEquipmentSpecificName($_POST['moduleName'][$i]);
  1712.             //   $eq->setAlias($_POST['moduleAlias'][$i]);
  1713.             //
  1714.             //   $moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['moduleGeneric'][$i]);
  1715.             //
  1716.             //   $eq->setEquipmentGeneric($moduleGeneric);
  1717.             //   $slots = implode($_POST['slots'][$i], '/');
  1718.             //   $eq->setSlots($slots);
  1719.             //   $eq->setIsModule(true);
  1720.             //   $eq->setParent($eqParent);
  1721.             //   //
  1722.             //   // $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  1723.             //   // $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1724.             //   // $eq->setPositionRack($request->request->get('positionRack'));
  1725.             //
  1726.             //   $em->persist($eq);
  1727.             //   $em->flush();
  1728.             //
  1729.             //   // create specific interfaces
  1730.             //   $interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  1731.             //   foreach ($interfacesGeneric as $interfaceGeneric){
  1732.             //
  1733.             //       $interfaceSpecific = new InterfaceSpecific();
  1734.             //       $interfaceSpecific->setEquipmentSpecific($eq);
  1735.             //       $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1736.             //
  1737.             //       $em->persist($interfaceSpecific);
  1738.             //       $em->flush();
  1739.             //
  1740.             //       // create ports
  1741.             //       $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
  1742.             //       for ($j=1; $j<=$numberOfPorts; $j++){
  1743.             //
  1744.             //           $port = new Port();
  1745.             //           $port->setInterfaceSpecific($interfaceSpecific);
  1746.             //           $port->setOrderNo($j);
  1747.             //
  1748.             //           $em->persist($port);
  1749.             //           $em->flush();
  1750.             //
  1751.             //       }
  1752.             //
  1753.             //   }
  1754.             // }
  1755.             // create specific interfaces
  1756.             // $interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
  1757.             // foreach ($interfacesGeneric as $interfaceGeneric){
  1758.             //
  1759.             //     $interfaceSpecific = new InterfaceSpecific();
  1760.             //     $interfaceSpecific->setEquipmentSpecific($eq);
  1761.             //     $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1762.             //
  1763.             //     $em->persist($interfaceSpecific);
  1764.             //     $em->flush();
  1765.             //
  1766.             //     // create ports
  1767.             //     $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
  1768.             //     for ($i=1; $i<=$numberOfPorts; $i++){
  1769.             //
  1770.             //         $port = new Port();
  1771.             //         $port->setInterfaceSpecific($interfaceSpecific);
  1772.             //         $port->setOrderNo($i);
  1773.             //
  1774.             //         $em->persist($port);
  1775.             //         $em->flush();
  1776.             //
  1777.             //     }
  1778.             //
  1779.             // }
  1780.             return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  1781.         }
  1782.     }
  1783.     /**
  1784.      * @Route("/equipment/specific/module/edit/{id}", name="equipment_specific_module_update")
  1785.      */
  1786.     public function updateModuleAction(Request $request$idTranslatorInterface $translator)
  1787.     {
  1788.         $user $this->getUser();
  1789.         $chassisModule $request->query->get("chassisModule");
  1790.         // process form
  1791.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  1792.             $em $this->getDoctrine()->getManager();
  1793.             $eq $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
  1794.             // find in usage
  1795.             /*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
  1796.             if ($specific){
  1797.                 $eq->setTitle($request->request->get('title'));
  1798.                 $em->persist($eq);
  1799.                 $em->flush();
  1800.                 $error = array('error' => 'title');
  1801.                 return $this->redirectToRoute('equipment_generic_list', $error);
  1802.             }*/
  1803.             $eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  1804.             $eq->setAlias($request->request->get('alias'));
  1805.             foreach ($eq->getSlotModule() as $slot) {
  1806.               $slot->setModule(null);
  1807.               $em->persist($slot);
  1808.             }
  1809.             foreach ($_POST['slots'] as $key => $value) {
  1810.               $slot $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
  1811.               $slot->setModule($eq);
  1812.               $em->persist($slot);
  1813.             }
  1814.             $em->persist($eq);
  1815.             $em->flush();
  1816.             return $this->redirectToRoute('equipment_specific_modulaire_update', ["id" => $eq->getParent()->getId()]);
  1817.         } else {
  1818.             $em $this->getDoctrine()->getManager();
  1819.             $eq null;
  1820.             if (!$id) {
  1821.               $eq $em->getRepository(EquipmentSpecific::class)->find($request->request->get("id"));
  1822.             }
  1823.             else {
  1824.               $eq $em->getRepository(EquipmentSpecific::class)->find($id);
  1825.             }
  1826.             $portExternes $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
  1827.             $slots null;
  1828.             $isChassisModule 1;
  1829.             if ($chassisModule != 1) {
  1830.                 $slots $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eq->getParent()->getId());
  1831.                 $isChassisModule 0;
  1832.             }
  1833.             $portList = [];
  1834.             $interfaces $eq->getInterfaceSpecific();
  1835.             foreach ($interfaces as $interface){
  1836.                 $ports $interface->getPort();
  1837.                 $typeLnk $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  1838.                 foreach ($ports as $port){
  1839.                     $port->nPort 0;
  1840.                     $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  1841.                     if ($nPorts){
  1842.                         $nPorts json_decode($nPorts);
  1843.                         if (in_array($port->getOrderNo(), $nPorts)){
  1844.                             $port->nPort 1;
  1845.                         }
  1846.                     }
  1847.                     $used 0;
  1848.                     $trunk 0;
  1849.                     $connected 0;
  1850.                     $usedLinkID '';
  1851.                     $usedLink_id '';
  1852.                     $usedALink null;
  1853.                     $usedBLink null;
  1854.                     $usedTrunkId 0;
  1855.                     $usedTrunk_Id 0;
  1856.                     if (count($port->getExtensionOrder()) > 0) {
  1857.                       $extremityA $port->getExtensionOrder()[0]->getExtremity();
  1858.                       $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  1859.                       $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  1860.                     }
  1861.                     $tcfA $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
  1862.                     $tcfB $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
  1863.                     $tExt $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
  1864.                     if($tcfA || $tcfB || $tExt){
  1865.                         $trunk 1;
  1866.                         if ($tcfA ) {
  1867.                              $usedTrunkId $tcfA->getTrunk()->getTrunkID();
  1868.                              $usedTrunk_Id $tcfA->getTrunk()->getId();
  1869.                         }elseif ($tcfB) {
  1870.                             $usedTrunkId $tcfB->getTrunk()->getTrunkID();
  1871.                             $usedTrunk_Id $tcfB->getTrunk()->getId();
  1872.                         }
  1873.                         else {
  1874.                             $usedTrunkId $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
  1875.                             $usedTrunk_Id $tExt->getTrunkCableFiber()->getTrunk()->getId();
  1876.                         }
  1877.                     }
  1878.                     // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  1879.                     // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1880.                     if ($usedALink){
  1881.                         $used 1;
  1882.                         $usedLinkID $usedALink->getLink()->getLinkID();
  1883.                         $usedLink_id $usedALink->getLink()->getId();
  1884.                     }
  1885.                     if ($usedBLink){
  1886.                         $used 1;
  1887.                         $usedLinkID $usedBLink->getLink()->getLinkID();
  1888.                         $usedLink_id $usedBLink->getLink()->getId();
  1889.                     }
  1890.                     if ($typeLnk == "Port Externe") {
  1891.                       if ($port->getPortExterne()) {
  1892.                         $connected 1;
  1893.                       }
  1894.                       else {
  1895.                         $connected 0;
  1896.                       }
  1897.                     }
  1898.                     $port->trunk $trunk;
  1899.                     $port->used $used;
  1900.                     $port->connected $connected;
  1901.                     $port->usedLinkID $usedLinkID;
  1902.                     $port->usedLink_id $usedLink_id;
  1903.                     $port->usedTrunkId $usedTrunkId;
  1904.                     $port->usedTrunk_Id $usedTrunk_Id;
  1905.                     $portList[] = $port;
  1906.                 }
  1907.             }
  1908.             return $this->render('equipment/specific_module_edit.html.twig', [
  1909.                 'action' => 'process',
  1910.                 'page_title' => $translator->trans('Specific Equipment'),
  1911.                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1912.                 'path_process' => 'equipment_specific_update_process',
  1913.                 'eq' => $eq,
  1914.                 'portList' => $portList,
  1915.                 "slots" => $slots,
  1916.                 'portExternes' => $portExternes,
  1917.                 'isChassisModule'=> $isChassisModule
  1918.             ]);
  1919.         }
  1920.     }
  1921.     /**
  1922.      * @Route("/equipment/specific/modulaire/duplicate", name="equipment_specific_modulaire_duplicate")
  1923.      */
  1924.     public function duplicateModulaireAction(Request $requestTranslatorInterface $translator)
  1925.     {
  1926.       $em $this->getDoctrine()->getManager();
  1927.       $eqParent = new EquipmentSpecific();
  1928.       $eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
  1929.       $eqParent->setAlias($request->request->get('alias'));
  1930.       $eqParent->setOwner($request->request->get('owner'));
  1931.       $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
  1932.       $eqParent->setEquipmentGeneric($equipmentGeneric);
  1933.       $eqParent->setIsModulaire(true);
  1934.       $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack'));
  1935.       $eqParent->setRack($rack);
  1936.       $eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  1937.       $eqParent->setPositionRack($request->request->get('positionRack'));
  1938.       //create and attach slots to modulaire equipments
  1939.       for ($i=0$i $equipmentGeneric->getNumberOfSlots(); $i++) {
  1940.         $slot = new Slot();
  1941.         $slot->setSlotNumber($i+1);
  1942.         $slot->setModulaire($eqParent);
  1943.         $em->persist($slot);
  1944.       }
  1945.       $em->persist($eqParent);
  1946.       $em->flush();
  1947.       $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('idEquipment'));
  1948.       //get all the modules associated with old equipment
  1949.       $modulesOld $eqOld->getModules();
  1950.       $chassisModule $eqOld->getChassisModule();
  1951.       if ($chassisModule) {
  1952.           $eq = new EquipmentSpecific();
  1953.           $eq->setEquipmentSpecificName($chassisModule->getEquipmentSpecificName());
  1954.           $eq->setAlias($chassisModule->getAlias());
  1955.           $moduleGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->find($chassisModule->getEquipmentGeneric());
  1956.           $eq->setEquipmentGeneric($moduleGeneric);
  1957.           $eq->setIsChassisModule(true);
  1958.           $eqParent->setChassisModule($eq);
  1959.           $eq->setRack($rack);
  1960.           $em->persist($eqParent);
  1961.           $em->flush();
  1962.           // create specific interfaces
  1963.           $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  1964.           foreach ($interfacesGeneric as $interfaceGeneric){
  1965.               $interfaceSpecific = new InterfaceSpecific();
  1966.               $interfaceSpecific->setEquipmentSpecific($eq);
  1967.               $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  1968.               $em->persist($interfaceSpecific);
  1969.               $em->flush();
  1970.               $alias null;
  1971.               if ($interfaceGeneric->getAlias()) {
  1972.                 $alias json_decode($interfaceGeneric->getAlias(), true);
  1973.               }
  1974.               // create ports
  1975.               $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  1976.               for ($j=1$j<=$numberOfPorts$j++){
  1977.                   $port = new Port();
  1978.                   $port->setInterfaceSpecific($interfaceSpecific);
  1979.                   $port->setOrderNo($j);
  1980.                   if ($alias && count($alias) > 0) {
  1981.                     $port->setAlias($alias[$j]);
  1982.                   }
  1983.                   $em->persist($port);
  1984.                   $em->flush();
  1985.               }
  1986.           }
  1987.       }
  1988.       foreach ($modulesOld as $moduleOld) {
  1989.         $eq = new EquipmentSpecific();
  1990.         $eq->setEquipmentSpecificName($moduleOld->getEquipmentSpecificName());
  1991.         $eq->setAlias($moduleOld->getAlias());
  1992.         $moduleGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->find($moduleOld->getEquipmentGeneric());
  1993.         $eq->setEquipmentGeneric($moduleGeneric);
  1994.         foreach ($moduleOld->getSlotModule() as $key => $value) {
  1995.           $slot $this->getDoctrine()->getRepository('App\Entity\Slot')->findOneBy(["modulaire"=>$eqParent"slotNumber"=>$value->getSlotNumber()]);
  1996.           $slot->setModule($eq);
  1997.           $em->persist($slot);
  1998.         }
  1999.         $eq->setIsModule(true);
  2000.         $eq->setParent($eqParent);
  2001.         //
  2002.         // $eq->setRack($rack);
  2003.         // $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  2004.         // $eq->setPositionRack($request->request->get('positionRack'));
  2005.         $em->persist($eq);
  2006.         $em->flush();
  2007.         $eq->setRack($rack);
  2008.         // create specific interfaces
  2009.         $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  2010.         foreach ($interfacesGeneric as $interfaceGeneric){
  2011.             $interfaceSpecific = new InterfaceSpecific();
  2012.             $interfaceSpecific->setEquipmentSpecific($eq);
  2013.             $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  2014.             $em->persist($interfaceSpecific);
  2015.             $em->flush();
  2016.             $alias null;
  2017.             if ($interfaceGeneric->getAlias()) {
  2018.               $alias json_decode($interfaceGeneric->getAlias(), true);
  2019.             }
  2020.             // create ports
  2021.             $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  2022.             for ($j=1$j<=$numberOfPorts$j++){
  2023.                 $port = new Port();
  2024.                 $port->setInterfaceSpecific($interfaceSpecific);
  2025.                 $port->setOrderNo($j);
  2026.                 if ($alias && count($alias) > 0) {
  2027.                   $port->setAlias($alias[$j]);
  2028.                 }
  2029.                 $em->persist($port);
  2030.                 $em->flush();
  2031.             }
  2032.         }
  2033.       }
  2034.       return $this->redirectToRoute('equipment_specific_modulaire_list');
  2035.     }
  2036.     /**
  2037.      * @Route("/equipment/specific/module/substitute/{id}", name="equipment_specific_module_substitute")
  2038.      */
  2039.     public function substituteModuleAction(Request $requestLoggerInterface $logger$idTranslatorInterface $translator)
  2040.     {
  2041.         $user $this->getUser();
  2042.         $em $this->getDoctrine()->getManager();
  2043.         // process form
  2044.         if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  2045.             $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  2046.             // get all the used ports of the old equipment
  2047.             $usedPorts $this->getUsedPortsEquipment($eqOld);
  2048.             $eqParent $eqOld->getParent();
  2049.             $interfaceSpecificOld $_POST['interfaces'];
  2050.             $eq = new EquipmentSpecific();
  2051.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  2052.             $eq->setAlias($_POST['alias']);
  2053.             $moduleGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
  2054.             $eq->setEquipmentGeneric($moduleGeneric);
  2055.             foreach ($_POST['slots'] as $key => $value) {
  2056.               $slot $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
  2057.               $slot->setModule($eq);
  2058.               $em->persist($slot);
  2059.             }
  2060.             $eq->setIsModule(true);
  2061.             $eq->setParent($eqParent);
  2062.             $em->persist($eq);
  2063.             // $em->flush();
  2064.             $eq->setRack($eqParent->getRack());
  2065.             $interfaceGenericPortOrderNoArray = array();
  2066.             if (isset($_POST['port'])) {
  2067.                 foreach ($_POST['port'] as $port => $value) {
  2068.                     foreach ($value as $key => $value1) {
  2069.                         $portOrderNoArray = array("orderNo"=> explode("__"$value1)[1], "port"=>$port);
  2070.                         $interfaceGenericPortOrderNoArray[explode("__"$value1)[0]][] = $portOrderNoArray;
  2071.                     }
  2072.                 }
  2073.                 // var_dump($interfaceGenericPortOrderNoArray);
  2074.             }
  2075.             // create specific interfaces
  2076.             $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  2077.             foreach ($interfacesGeneric as $interfaceGeneric){
  2078.                 $orderPortArray = array();
  2079.                 $portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
  2080.                 if ($portOrderNoArray) {
  2081.                     foreach ($portOrderNoArray as $value) {
  2082.                         $orderPortArray[$value['orderNo']][] = $value['port'];
  2083.                     }
  2084.                 }
  2085.                 // var_dump($orderPortArray);
  2086.                 $interfaceSpecific = new InterfaceSpecific();
  2087.                 $interfaceSpecific->setEquipmentSpecific($eq);
  2088.                 $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  2089.                 $em->persist($interfaceSpecific);
  2090.                 // $em->flush();
  2091.                 $alias null;
  2092.                 if ($interfaceGeneric->getAlias()) {
  2093.                   $alias json_decode($interfaceGeneric->getAlias(), true);
  2094.                 }
  2095.                 $portExternes null;
  2096.                 $idTemp $interfaceGeneric->getId();
  2097.                 // var_dump($_POST["portExterne[$idTemp]"]);
  2098.                 if (isset($_POST["portExterne"][$idTemp])) {
  2099.                   foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  2100.                     $portExternes[$key] = $value;
  2101.                   }
  2102.                 }
  2103.                 // var_dump($portExternes);
  2104.                 // create ports
  2105.                 $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  2106.                 $interfaceGenericNew = array();
  2107.                 foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
  2108.                     foreach ($value as $keyNew => $intGenNew) {
  2109.                         if ($intGenNew == $interfaceGeneric->getId()) {
  2110.                             $interfaceGenericNew[$interfaceSpecificId] = $value;
  2111.                         }
  2112.                     }
  2113.                 }
  2114.                 // var_dump($interfaceGenericNew);
  2115.                 $portsOld = array();
  2116.                 if (count($interfaceGenericNew) == 1) {
  2117.                     $interfaceSpecificId array_keys($interfaceGenericNew)[0];
  2118.                     $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2119.                     $typeLnkSpc $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
  2120.                     $index 0;
  2121.                     foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
  2122.                         if ($value && $value != $interfaceGeneric->getId()) {
  2123.                             $intGenTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
  2124.                             $numPortTemp $intGenTemp->getNumberOfPorts();
  2125.                             $typeLnkGen $intGenTemp->getTypeLink()->getId();
  2126.                             if ($typeLnkSpc == $typeLnkGen) {
  2127.                                 $index += $numPortTemp;
  2128.                             }
  2129.                             elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2130.                                 $index += ($numPortTemp*2);
  2131.                             }
  2132.                             elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2133.                                 $index += ($numPortTemp/2);
  2134.                             }
  2135.                         }
  2136.                     }
  2137.                     $ports $interfaceSpecificTemp->getPort();
  2138.                     $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2139.                     $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2140.                     if ($typeLnkSpc == $typeLnkGen) {
  2141.                         $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2142.                     }
  2143.                     elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2144.                         $lengthTemp $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*$interfaceGeneric->getNumberOfPorts()*$lengthTemp;
  2145.                     }
  2146.                     elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2147.                         $lengthTemp $interfaceGeneric->getNumberOfPorts()/2;
  2148.                     }
  2149.                     for ($i=$index$i $lengthTemp$i++) {
  2150.                         // $portsOld[] = $ports{$i};
  2151.                         $portsOld[] = $ports[$i];
  2152.                     }
  2153.                 }
  2154.                 elseif (count($interfaceGenericNew) > 1) {
  2155.                     foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
  2156.                         $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2157.                         foreach ($interfaceSpecificTemp->getPort() as $value) {
  2158.                             $portsOld[] = $value;
  2159.                         }
  2160.                     }
  2161.                 }
  2162.                 // var_dump($portsOld);
  2163.                 $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2164.                 $k 0;
  2165.                 // if ($numberOfPorts < count($portsOld)) {
  2166.                 //     $this->addFlash(
  2167.                 //         'error',
  2168.                 //         'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
  2169.                 //     );
  2170.                 //     $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
  2171.                 //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2172.                 //     $conn = $em->getConnection();
  2173.                 //     $stmt = $conn->prepare($sql);
  2174.                 //     $stmt->execute();
  2175.                 //
  2176.                 //     $em->remove($equipmentSpecific);
  2177.                 //     $em->flush();
  2178.                 //     return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2179.                 // }
  2180.                 for ($i=1$i<=$numberOfPorts$i++){
  2181.                     $port = new Port();
  2182.                     $port->setInterfaceSpecific($interfaceSpecific);
  2183.                     $port->setOrderNo($i);
  2184.                     if ($alias && count($alias) > 0) {
  2185.                       $port->setAlias($alias[$i]);
  2186.                     }
  2187.                     if ($portExternes) {
  2188.                       if (isset($portExternes[$i]) && $portExternes[$i]) {
  2189.                         // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  2190.                         $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  2191.                         $port->setPortExterne($pe);
  2192.                         $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  2193.                         if ($interfaceGenericPortExterne != null) {
  2194.                             //create interface spécific and attach it to the port
  2195.                             $ifPE = new InterfaceSpecific();
  2196.                             $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  2197.                             $port->setInterfaceSpecificPortExterne($ifPE);
  2198.                         }
  2199.                       }
  2200.                     }
  2201.                     $em->persist($port);
  2202.                     // $em->flush();
  2203.                     if (array_key_exists($i$orderPortArray)) {
  2204.                         foreach ($orderPortArray[$i] as $portOld) {
  2205.                             //remove the replaced port from usedports array
  2206.                             $portOld $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
  2207.                             $usedPorts array_diff($usedPorts, [$portOld->getId()]);
  2208.                             $this->replacePort($port$portOld);
  2209.                         }
  2210.                     }
  2211.                     else {
  2212.                         if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  2213.                             //remove the replaced port from usedports array
  2214.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2215.                             $this->replacePort($port$portsOld[$k]);
  2216.                             // unset($portsOld[$k]);
  2217.                             $k++;
  2218.                         }
  2219.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 1) {
  2220.                             //remove the replaced port from usedports array
  2221.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2222.                             $this->replacePort($port$portsOld[$k]);
  2223.                             // unset($portsOld[$k]);
  2224.                             $port1 = new Port();
  2225.                             $port1->setInterfaceSpecific($interfaceSpecific);
  2226.                             $j $i+1;
  2227.                             $port1->setOrderNo($j);
  2228.                             if ($alias && count($alias) > 0) {
  2229.                               $port1->setAlias($alias[$j]);
  2230.                             }
  2231.                             if ($portExternes) {
  2232.                               if (isset($portExternes[$j]) && $portExternes[$j]) {
  2233.                                 $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
  2234.                               }
  2235.                             }
  2236.                             $em->persist($port1);
  2237.                             // $em->flush();
  2238.                             $this->replacePort($port1$portsOld[$k]);
  2239.                             // unset($portsOld[$k]);
  2240.                             $k++;
  2241.                             $i++;
  2242.                         }
  2243.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 2) {
  2244.                             //remove the replaced port from usedports array
  2245.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2246.                             $this->replacePort($port$portsOld[$k]);
  2247.                             // unset($portsOld[$k]);
  2248.                             $k++;
  2249.                             //remove the replaced port from usedports array
  2250.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2251.                             $this->replacePort($port$portsOld[$k]);
  2252.                             // unset($portsOld[$k]);
  2253.                             $k++;
  2254.                         }
  2255.                     }
  2256.                 }
  2257.             }
  2258.             if (count($usedPorts) > 0) {
  2259.                 $msgTemp "Opération échouée ! ";
  2260.                 $msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés \n";
  2261.                 foreach ($usedPorts as $usedPort) {
  2262.                     $usedPort $em->getRepository(Port::class)->find($usedPort);
  2263.                     $msgTemp " " $msgTemp " "$usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ".  $usedPort->getOrderNo() . "\n";
  2264.                 }
  2265.                 $this->addFlash(
  2266.                         'error',
  2267.                         $msgTemp
  2268.                     );
  2269.                 return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2270.             }
  2271.             else {
  2272.                 $sql "update slot set module_id=null where module_id = " $eqOld->getId() ." or modulaire_id=" $eqOld->getId();
  2273.                 // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2274.                 $conn $em->getConnection();
  2275.                 $stmt $conn->prepare($sql);
  2276.                 $stmt->execute();
  2277.                 $em->remove($eqOld);
  2278.                 $em->flush();
  2279.                 $this->addFlash(
  2280.                         'error',
  2281.                         'Opération terminée avec succès !'
  2282.                     );
  2283.                 return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2284.             }
  2285.             // foreach ($portsOld as $port){
  2286.             //     if($port){
  2287.             //             $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  2288.             //             $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2289.             //
  2290.             //             if ($usedA || $usedB){
  2291.             //                 $this->addFlash(
  2292.             //                         'error',
  2293.             //                         $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2294.             //                     );
  2295.             //                 // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
  2296.             //                 // // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2297.             //                 // $conn = $em->getConnection();
  2298.             //                 // $stmt = $conn->prepare($sql);
  2299.             //                 // $stmt->execute();
  2300.             //                 //
  2301.             //                 // $em->remove($eq);
  2302.             //                 // $em->flush();
  2303.             //                 return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2304.             //             }
  2305.             //
  2306.             //             $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2307.             //
  2308.             //             if ($usedExt){
  2309.             //                 $this->addFlash(
  2310.             //                         'error',
  2311.             //                         $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2312.             //                     );
  2313.             //                 // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
  2314.             //                 // $conn = $em->getConnection();
  2315.             //                 // $stmt = $conn->prepare($sql);
  2316.             //                 // $stmt->execute();
  2317.             //                 //
  2318.             //                 // $em->remove($eq);
  2319.             //                 // $em->flush();
  2320.             //                 return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2321.             //             }
  2322.             //             $usedALink = null;
  2323.             //             $usedBLink = null;
  2324.             //             if (count($port->getExtensionOrder()) > 0) {
  2325.             //               $extremityA = $port->getExtensionOrder()[0]->getExtremity();
  2326.             //               $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  2327.             //               $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  2328.             //             }
  2329.             //
  2330.             //             // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  2331.             //             // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  2332.             //
  2333.             //             if ($usedALink || $usedBLink){
  2334.             //                 $this->addFlash(
  2335.             //                         'error',
  2336.             //                         $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2337.             //                     );
  2338.             //                 // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
  2339.             //                 // // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2340.             //                 // $conn = $em->getConnection();
  2341.             //                 // $stmt = $conn->prepare($sql);
  2342.             //                 // $stmt->execute();
  2343.             //                 //
  2344.             //                 // $em->remove($eq);
  2345.             //                 // $em->flush();
  2346.             //                 return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2347.             //             }
  2348.             //         }
  2349.             //     }
  2350.             //     $sql = "update slot set module_id=null where module_id = " . $eqOld->getId() ." or modulaire_id=" . $eqOld->getId();
  2351.             //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2352.             //     $conn = $em->getConnection();
  2353.             //     $stmt = $conn->prepare($sql);
  2354.             //     $stmt->execute();
  2355.             //     $em->remove($eqOld);
  2356.             //     $em->flush();
  2357.             //
  2358.             //     $eqGeneric = $eqParent->getEquipmentGeneric()->getModules();
  2359.             //     $slots = $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eqParent->getId());
  2360.             //     return $this->render('equipment/module_substitute.html.twig', [
  2361.             //         'page_title' => $translator->trans('Substitution du module'),
  2362.             //         'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution du module'),
  2363.             //         'eq' => $eqOld,
  2364.             //         'eqGeneric' => $eqGeneric,
  2365.             //         "slots" => $slots,
  2366.             //     ]);
  2367.                 // return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2368.             // }
  2369.         }
  2370.         else {
  2371.             $eq $em->getRepository(EquipmentSpecific::class)->find($id);
  2372.             $eqParent $eq->getParent();
  2373.             $eqGeneric $eqParent->getEquipmentGeneric()->getModules();
  2374.             $chassisModule $eqParent->getChassisModule();
  2375.             if ($chassisModule) {
  2376.                 $eqGeneric->add($chassisModule);
  2377.             }
  2378.             $slots $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eqParent->getId());
  2379.             return $this->render('equipment/module_substitute.html.twig', [
  2380.                 'page_title' => $translator->trans('Substitution du module'),
  2381.                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution du module'),
  2382.                 'eq' => $eq,
  2383.                 'eqGeneric' => $eqGeneric,
  2384.                 "slots" => $slots,
  2385.             ]);
  2386.         }
  2387.     }
  2388.     /**
  2389.      * @Route("/equipment/specific/substitute/{id}", name="equipment_specific_substitute")
  2390.      */
  2391.     public function substituteEquipmentAction(Request $request$idTranslatorInterface $translator)
  2392.     {
  2393.         $user $this->getUser();
  2394.         $em $this->getDoctrine()->getManager();
  2395.         // process form
  2396.         if ($request->request->has('equipmentToEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  2397.             //get the old equipment
  2398.             $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  2399.             // get all the used ports of the old equipment
  2400.             $usedPorts $this->getUsedPortsEquipment($eqOld);
  2401.             //$eqParent = $eqOld->getParent();
  2402.             $interfaceSpecificOld $_POST['interfaces'];
  2403.             $eq = new EquipmentSpecific();
  2404.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  2405.             $eq->setAlias($_POST['alias']);
  2406.             $eq->setOwner($_POST['owner']);
  2407.             $eq->setPositionRack($_POST['positionRack']);
  2408.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  2409.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
  2410.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
  2411.             $eq->setEquipmentGeneric($eqGeneric);
  2412.             $em->persist($eq);
  2413.             // $em->flush();
  2414.             $interfaceGenericPortOrderNoArray = array();
  2415.             if (isset($_POST['port'])) {
  2416.                 foreach ($_POST['port'] as $port => $value) {
  2417.                     foreach ($value as $key => $value1) {
  2418.                         $portOrderNoArray = array("orderNo"=> explode("__"$value1)[1], "port"=>$port);
  2419.                         $interfaceGenericPortOrderNoArray[explode("__"$value1)[0]][] = $portOrderNoArray;
  2420.                     }
  2421.                 }
  2422.                 // var_dump($interfaceGenericPortOrderNoArray);
  2423.             }
  2424.             // create specific interfaces
  2425.             $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($eqGeneric);
  2426.             foreach ($interfacesGeneric as $interfaceGeneric){
  2427.                 $orderPortArray = array();
  2428.                 $portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
  2429.                 if ($portOrderNoArray) {
  2430.                     foreach ($portOrderNoArray as $value) {
  2431.                         $orderPortArray[$value['orderNo']][] = $value['port'];
  2432.                     }
  2433.                 }
  2434.                 $interfaceSpecific = new InterfaceSpecific();
  2435.                 $interfaceSpecific->setEquipmentSpecific($eq);
  2436.                 $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  2437.                 $em->persist($interfaceSpecific);
  2438.                 // $em->flush();
  2439.                 $alias null;
  2440.                 if ($interfaceGeneric->getAlias()) {
  2441.                   $alias json_decode($interfaceGeneric->getAlias(), true);
  2442.                 }
  2443.                 $portExternes null;
  2444.                 $idTemp $interfaceGeneric->getId();
  2445.                 // var_dump($_POST["portExterne[$idTemp]"]);
  2446.                 if (isset($_POST["portExterne"][$idTemp])) {
  2447.                   foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  2448.                     $portExternes[$key] = $value;
  2449.                   }
  2450.                 }
  2451.                 // var_dump($portExternes);
  2452.                 // create ports
  2453.                 $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  2454.                 $interfaceGenericNew = array();
  2455.                 foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
  2456.                     foreach ($value as $keyNew => $intGenNew) {
  2457.                         if ($intGenNew == $interfaceGeneric->getId()) {
  2458.                             $interfaceGenericNew[$interfaceSpecificId] = $value;
  2459.                         }
  2460.                     }
  2461.                 }
  2462.                 var_dump($interfaceGenericNew);
  2463.                 $portsOld = array();
  2464.                 if (count($interfaceGenericNew) == 1) {
  2465.                     $interfaceSpecificId array_keys($interfaceGenericNew)[0];
  2466.                     $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2467.                     $typeLnkSpc $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
  2468.                     $index 0;
  2469.                     foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
  2470.                         if ($value && $value != $interfaceGeneric->getId()) {
  2471.                             $intGenTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
  2472.                             $numPortTemp $intGenTemp->getNumberOfPorts();
  2473.                             $typeLnkGen $intGenTemp->getTypeLink()->getId();
  2474.                             if ($typeLnkSpc == $typeLnkGen) {
  2475.                                 $index += $numPortTemp;
  2476.                             }
  2477.                             elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2478.                                 $index += ($numPortTemp*2);
  2479.                             }
  2480.                             elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2481.                                 $index += ($numPortTemp/2);
  2482.                             }
  2483.                         }
  2484.                     }
  2485.                     $ports $interfaceSpecificTemp->getPort();
  2486.                     $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2487.                     $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2488.                     if ($typeLnkSpc == $typeLnkGen) {
  2489.                         $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2490.                     }
  2491.                     elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2492.                         $lengthTemp $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*$interfaceGeneric->getNumberOfPorts()*$lengthTemp;
  2493.                     }
  2494.                     elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2495.                         $lengthTemp $interfaceGeneric->getNumberOfPorts()/2;
  2496.                     }
  2497.                     for ($i=$index$i $lengthTemp$i++) {
  2498.                         // $portsOld[] = $ports{$i};
  2499.                         $portsOld[] = $ports[$i];
  2500.                     }
  2501.                 }
  2502.                 elseif (count($interfaceGenericNew) > 1) {
  2503.                     foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
  2504.                         $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2505.                         foreach ($interfaceSpecificTemp->getPort() as $value) {
  2506.                             $portsOld[] = $value;
  2507.                         }
  2508.                     }
  2509.                 }
  2510.                 // var_dump($portsOld);
  2511.                 $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2512.                 $k 0;
  2513.                 // if ($numberOfPorts < count($portsOld)) {
  2514.                 //     $this->addFlash(
  2515.                 //         'error',
  2516.                 //         'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
  2517.                 //     );
  2518.                 //     $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
  2519.                 //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2520.                 //     $conn = $em->getConnection();
  2521.                 //     $stmt = $conn->prepare($sql);
  2522.                 //     $stmt->execute();
  2523.                 //
  2524.                 //     $em->remove($equipmentSpecific);
  2525.                 //     $em->flush();
  2526.                 //     return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2527.                 // }
  2528.                 for ($i=1$i<=$numberOfPorts$i++){
  2529.                     $port = new Port();
  2530.                     $port->setInterfaceSpecific($interfaceSpecific);
  2531.                     $port->setOrderNo($i);
  2532.                     if ($alias && count($alias) > 0) {
  2533.                       $port->setAlias($alias[$i]);
  2534.                     }
  2535.                     if ($portExternes) {
  2536.                       if (isset($portExternes[$i]) && $portExternes[$i]) {
  2537.                         // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  2538.                         $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  2539.                         $port->setPortExterne($pe);
  2540.                         $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  2541.                         if ($interfaceGenericPortExterne != null) {
  2542.                             //create interface spécific and attach it to the port
  2543.                             $ifPE = new InterfaceSpecific();
  2544.                             $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  2545.                             $port->setInterfaceSpecificPortExterne($ifPE);
  2546.                         }
  2547.                       }
  2548.                     }
  2549.                     $em->persist($port);
  2550.                     // $em->flush();
  2551.                     //port to port
  2552.                     if (array_key_exists($i$orderPortArray)) {
  2553.                         foreach ($orderPortArray[$i] as $portOld) {
  2554.                             //remove the replaced port from usedports array
  2555.                             $portOld $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
  2556.                             $usedPorts array_diff($usedPorts, [$portOld->getId()]);
  2557.                             $this->replacePort($port$portOld);
  2558.                         }
  2559.                     }
  2560.                     else {
  2561.                         if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  2562.                             //remove the replaced port from usedports array
  2563.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2564.                             $this->replacePort($port$portsOld[$k]);
  2565.                             // unset($portsOld[$k]);
  2566.                             $k++;
  2567.                         }
  2568.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 1) {
  2569.                             //remove the replaced port from usedports array
  2570.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2571.                             $this->replacePort($port$portsOld[$k]);
  2572.                             // unset($portsOld[$k]);
  2573.                             $port1 = new Port();
  2574.                             $port1->setInterfaceSpecific($interfaceSpecific);
  2575.                             $j $i+1;
  2576.                             $port1->setOrderNo($j);
  2577.                             if ($alias && count($alias) > 0) {
  2578.                               $port1->setAlias($alias[$j]);
  2579.                             }
  2580.                             if ($portExternes) {
  2581.                               if (isset($portExternes[$j]) && $portExternes[$j]) {
  2582.                                 $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
  2583.                               }
  2584.                             }
  2585.                             $em->persist($port1);
  2586.                             // $em->flush();
  2587.                             $this->replacePort($port1$portsOld[$k]);
  2588.                             // unset($portsOld[$k]);
  2589.                             $k++;
  2590.                             $i++;
  2591.                         }
  2592.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 2) {
  2593.                             //remove the replaced port from usedports array
  2594.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2595.                             $this->replacePort($port$portsOld[$k]);
  2596.                             // unset($portsOld[$k]);
  2597.                             $k++;
  2598.                             //remove the replaced port from usedports array
  2599.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2600.                             $this->replacePort($port$portsOld[$k]);
  2601.                             // unset($portsOld[$k]);
  2602.                             $k++;
  2603.                         }
  2604.                     }
  2605.                     // if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  2606.                     //     $this->replacePort($port, $portsOld[$k]);
  2607.                     //     unset($portsOld[$k]);
  2608.                     //     $k++;
  2609.                     // }
  2610.                     // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
  2611.                     //     $this->replacePort($port, $portsOld[$k]);
  2612.                     //     unset($portsOld[$k]);
  2613.                     //     $k++;
  2614.                     //     $port1 = new Port();
  2615.                     //     $port1->setInterfaceSpecific($interfaceSpecific);
  2616.                     //     $j = $i+1;
  2617.                     //     $port1->setOrderNo($j);
  2618.                     //     if ($alias && count($alias) > 0) {
  2619.                     //       $port1->setAlias($alias[$j]);
  2620.                     //     }
  2621.                     //     if ($portExternes) {
  2622.                     //       if (isset($portExternes[$j]) && $portExternes[$j]) {
  2623.                     //         $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
  2624.                     //       }
  2625.                     //     }
  2626.                     //     $em->persist($port1);
  2627.                     //     // $em->flush();
  2628.                     //     $this->replacePort($port1, $portsOld[$k]);
  2629.                     //     unset($portsOld[$k]);
  2630.                     //     $k++;
  2631.                     //     $i++;
  2632.                     // }
  2633.                     // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
  2634.                     //     $this->replacePort($port, $portsOld[$k]);
  2635.                     //     unset($portsOld[$k]);
  2636.                     //     $k++;
  2637.                     //     $this->replacePort($port, $portsOld[$k]);
  2638.                     //     unset($portsOld[$k]);
  2639.                     //     $k++;
  2640.                     // }
  2641.                     // //interface to interface
  2642.                     // if (array_key_exists($i, $orderPortArray)) {
  2643.                     //     foreach ($orderPortArray[$i] as $portOld) {
  2644.                     //         $this->replacePort($port, $portOld);
  2645.                     //     }
  2646.                     // }
  2647.                 }
  2648.             }
  2649.             // foreach ($portsOld as $port){
  2650.             //     if($port){
  2651.             //         $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  2652.             //         $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2653.             //
  2654.             //         if ($usedA || $usedB){
  2655.             //             $this->addFlash(
  2656.             //                     'error',
  2657.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2658.             //                 );
  2659.             //             $racks = $em->getRepository(Rack::class)->findAll();
  2660.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  2661.             //             return $this->render('equipment/equipment_substitute_equipment.html.twig', [
  2662.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2663.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2664.             //                 'eq' => $eqOld,
  2665.             //                 'eqGen' => $eqGeneric,
  2666.             //                 "racks" =>$racks,
  2667.             //                 "rackFaces" =>$rackFaces
  2668.             //             ]);
  2669.             //         }
  2670.             //
  2671.             //         $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2672.             //
  2673.             //         if ($usedExt){
  2674.             //             $this->addFlash(
  2675.             //                     'error',
  2676.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2677.             //                 );
  2678.             //             $racks = $em->getRepository(Rack::class)->findAll();
  2679.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  2680.             //             return $this->render('equipment/equipment_substitute_equipment.html.twig', [
  2681.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2682.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2683.             //                 'eq' => $eqOld,
  2684.             //                 'eqGen' => $eqGeneric,
  2685.             //                 "racks" =>$racks,
  2686.             //                 "rackFaces" =>$rackFaces
  2687.             //             ]);
  2688.             //         }
  2689.             //         $usedALink = null;
  2690.             //         $usedBLink = null;
  2691.             //         if (count($port->getExtensionOrder()) > 0) {
  2692.             //           $extremityA = $port->getExtensionOrder()[0]->getExtremity();
  2693.             //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  2694.             //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  2695.             //         }
  2696.             //
  2697.             //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  2698.             //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  2699.             //
  2700.             //         if ($usedALink || $usedBLink){
  2701.             //             $this->addFlash(
  2702.             //                     'error',
  2703.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2704.             //                 );
  2705.             //             $racks = $em->getRepository(Rack::class)->findAll();
  2706.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  2707.             //             return $this->render('equipment/equipment_substitute_equipment.html.twig', [
  2708.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2709.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2710.             //                 'eq' => $eqOld,
  2711.             //                 'eqGen' => $eqGeneric,
  2712.             //                 "racks" =>$racks,
  2713.             //                 "rackFaces" =>$rackFaces
  2714.             //             ]);
  2715.             //         }
  2716.             //     }
  2717.             // }
  2718.             //check if all the used ports have been repalced
  2719.             if (count($usedPorts) > 0) {
  2720.                 $msgTemp "Opération échouée !";
  2721.                 $msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
  2722.                 foreach ($usedPorts as $usedPort) {
  2723.                     $usedPort $em->getRepository(Port::class)->find($usedPort);
  2724.                     $msgTemp " " $msgTemp " "$usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() . " - "$usedPort->getOrderNo();
  2725.                 }
  2726.                 $this->addFlash(
  2727.                         'error',
  2728.                         $msgTemp
  2729.                     );
  2730.                 $racks $em->getRepository(Rack::class)->findAll();
  2731.                 $rackFaces $em->getRepository(RackFace::class)->findAll();
  2732.                 return $this->render('equipment/equipment_substitute_equipment.html.twig', [
  2733.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2734.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2735.                     'eq' => $eqOld,
  2736.                     'eqGen' => $eqGeneric,
  2737.                     "racks" =>$racks,
  2738.                     "rackFaces" =>$rackFaces
  2739.                 ]);
  2740.             }
  2741.             else {
  2742.                 $em->remove($eqOld);
  2743.                 $em->flush();
  2744.                 $this->addFlash(
  2745.                         'error',
  2746.                         'Opération terminée avec succès !'
  2747.                     );
  2748.                 return $this->redirectToRoute('equipment_specific_list');
  2749.             }
  2750.         }
  2751.         elseif ($request->request->has('equipmentToModulaire') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  2752.             $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  2753.             // $eqParent = $eqOld->getParent();
  2754.             // get all the used ports of the old equipment
  2755.             $usedPorts $this->getUsedPortsEquipment($eqOld);
  2756.             $interfaceSpecificOld $_POST['interfaces'];
  2757.             $eq $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_POST['equipmentGeneric']);
  2758.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  2759.             $eq->setAlias($_POST['alias']);
  2760.             $eq->setOwner($_POST['owner']);
  2761.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  2762.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
  2763.             $eq->setPositionRack($_POST['positionRack']);
  2764.             $em->persist($eq);
  2765.             $interfaceGenericPortOrderNoArray = array();
  2766.             if (isset($_POST['port'])) {
  2767.                 foreach ($_POST['port'] as $port => $value) {
  2768.                     foreach ($value as $key => $value1) {
  2769.                         $portOrderNoArray = array("orderNo"=> explode("__"$value1)[1], "port"=>$port);
  2770.                         $interfaceGenericPortOrderNoArray[explode("__"$value1)[0]][] = $portOrderNoArray;
  2771.                     }
  2772.                 }
  2773.             }
  2774.             // var_dump($interfaceGenericPortOrderNoArray);
  2775.             $modules $eq->getModules();
  2776.             $chassisModule $eq->getChassisModule();
  2777.             if ($chassisModule) {
  2778.                 $modules->add($chassisModule);
  2779.             }
  2780.             // create specific interfaces
  2781.             foreach ($modules as $module) {
  2782.                 $module->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  2783.                 $em->persist($module);
  2784.                 foreach ($module->getInterfaceSpecific() as $interfaceSpecific) {
  2785.                     $orderPortArray = array();
  2786.                     $portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()] : null;
  2787.                     if ($portOrderNoArray) {
  2788.                         foreach ($portOrderNoArray as $value) {
  2789.                             $orderPortArray[$value['orderNo']][] = $value['port'];
  2790.                         }
  2791.                     }
  2792.                     // var_dump($portExternes);
  2793.                     // create ports
  2794.                     $interfaceGeneric $interfaceSpecific->getInterfaceGeneric();
  2795.                     $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  2796.                     $interfaceGenericNew = array();
  2797.                     foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
  2798.                         foreach ($value as $keyNew => $intGenNew) {
  2799.                             if ($intGenNew == $interfaceSpecific->getId()) {
  2800.                                 $interfaceGenericNew[$interfaceSpecificId] = $value;
  2801.                             }
  2802.                         }
  2803.                     }
  2804.                     // var_dump($interfaceGenericNew);
  2805.                     $portsOld = array();
  2806.                     if (count($interfaceGenericNew) == 1) {
  2807.                         $interfaceSpecificId array_keys($interfaceGenericNew)[0];
  2808.                         $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2809.                         $typeLnkSpc $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
  2810.                         $index 0;
  2811.                         foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
  2812.                             if ($value && $value != $interfaceSpecific->getId()) {
  2813.                                 $intGenTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($value)->getInterfaceGeneric();
  2814.                                 $numPortTemp $intGenTemp->getNumberOfPorts();
  2815.                                 $typeLnkGen $intGenTemp->getTypeLink()->getId();
  2816.                                 if ($typeLnkSpc == $typeLnkGen) {
  2817.                                     $index += $numPortTemp;
  2818.                                 }
  2819.                                 elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2820.                                     $index += ($numPortTemp*2);
  2821.                                 }
  2822.                                 elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2823.                                     $index += ($numPortTemp/2);
  2824.                                 }
  2825.                             }
  2826.                         }
  2827.                         $ports $interfaceSpecificTemp->getPort();
  2828.                         $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2829.                         $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2830.                         if ($typeLnkSpc == $typeLnkGen) {
  2831.                             $lengthTemp $interfaceGeneric->getNumberOfPorts();
  2832.                         }
  2833.                         elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  2834.                             $lengthTemp $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*$interfaceGeneric->getNumberOfPorts()*$lengthTemp;
  2835.                         }
  2836.                         elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  2837.                             $lengthTemp $interfaceGeneric->getNumberOfPorts()/2;
  2838.                         }
  2839.                         for ($i=$index$i $lengthTemp$i++) {
  2840.                             // $portsOld[] = $ports{$i};
  2841.                             $portsOld[] = $ports[$i];
  2842.                         }
  2843.                     }
  2844.                     elseif (count($interfaceGenericNew) > 1) {
  2845.                         foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
  2846.                             $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  2847.                             foreach ($interfaceSpecificTemp->getPort() as $value) {
  2848.                                 $portsOld[] = $value;
  2849.                             }
  2850.                         }
  2851.                     }
  2852.                     // var_dump($portsOld);
  2853.                     $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  2854.                     $k 0;
  2855.                     // if ($numberOfPorts < count($portsOld)) {
  2856.                     //     $this->addFlash(
  2857.                     //         'error',
  2858.                     //         'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
  2859.                     //     );
  2860.                     //     $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
  2861.                     //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  2862.                     //     $conn = $em->getConnection();
  2863.                     //     $stmt = $conn->prepare($sql);
  2864.                     //     $stmt->execute();
  2865.                     //
  2866.                     //     $em->remove($equipmentSpecific);
  2867.                     //     $em->flush();
  2868.                     //     return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  2869.                     // }
  2870.                     $portsTemp $interfaceSpecific->getPort();
  2871.                     for ($i=0$i<$numberOfPorts$i++){
  2872.                         // $port = $portsTemp{$i};
  2873.                         $port $portsTemp[$i];
  2874.                         if (array_key_exists($i$orderPortArray)) {
  2875.                             foreach ($orderPortArray[$i] as $portOld) {
  2876.                                 //remove the replaced port from usedports array
  2877.                                 $portOld $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
  2878.                                 $usedPorts array_diff($usedPorts, [$portOld->getId()]);
  2879.                                 $this->replacePort($port$portOld);
  2880.                             }
  2881.                         }
  2882.                         else {
  2883.                             if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  2884.                                 //remove the replaced port from usedports array
  2885.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2886.                                 $this->replacePort($port$portsOld[$k]);
  2887.                                 // unset($portsOld[$k]);
  2888.                                 $k++;
  2889.                             }
  2890.                             elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 1) {
  2891.                                 //remove the replaced port from usedports array
  2892.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2893.                                 $this->replacePort($port$portsOld[$k]);
  2894.                                 // unset($portsOld[$k]);
  2895.                                 $j $i+1;
  2896.                                 // $port1 = $portsTemp{$j};
  2897.                                 $port1 $portsTemp[$j];
  2898.                                 $this->replacePort($port1$portsOld[$k]);
  2899.                                 $k++;
  2900.                                 $i++;
  2901.                             }
  2902.                             elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 2) {
  2903.                                 //remove the replaced port from usedports array
  2904.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2905.                                 $this->replacePort($port$portsOld[$k]);
  2906.                                 // unset($portsOld[$k]);
  2907.                                 $k++;
  2908.                                 //remove the replaced port from usedports array
  2909.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  2910.                                 $this->replacePort($port$portsOld[$k]);
  2911.                                 // unset($portsOld[$k]);
  2912.                                 $k++;
  2913.                             }
  2914.                         }
  2915.                         // if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  2916.                         //     //remove the replaced port from usedports array
  2917.                         //     $usedPorts = array_diff($usedPorts, [$portOld->getId()]);
  2918.                         //
  2919.                         //     $this->replacePort($port, $portsOld[$k]);
  2920.                         //     unset($portsOld[$k]);
  2921.                         //     $k++;
  2922.                         // }
  2923.                         // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
  2924.                         //     $this->replacePort($port, $portsOld[$k]);
  2925.                         //     unset($portsOld[$k]);
  2926.                         //     $k++;
  2927.                         //     $i++;
  2928.                         //     $port1 = $portsTemp{$i};
  2929.                         //     $this->replacePort($port1, $portsOld[$k]);
  2930.                         //     unset($portsOld[$k]);
  2931.                         //     $k++;
  2932.                         //     $i++;
  2933.                         // }
  2934.                         // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
  2935.                         //     $this->replacePort($port, $portsOld[$k]);
  2936.                         //     unset($portsOld[$k]);
  2937.                         //     $k++;
  2938.                         //     $this->replacePort($port, $portsOld[$k]);
  2939.                         //     unset($portsOld[$k]);
  2940.                         //     $k++;
  2941.                         // }
  2942.                         // if (array_key_exists($i+1, $orderPortArray)) {
  2943.                         //     foreach ($orderPortArray[$i+1] as $portOld) {
  2944.                         //         $this->replacePort($port, $portOld);
  2945.                         //     }
  2946.                         // }
  2947.                     }
  2948.                 }
  2949.             }
  2950.             if (count($usedPorts) > 0) {
  2951.                 $msgTemp "Opération échouée ! ";
  2952.                 $msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
  2953.                 foreach ($usedPorts as $usedPort) {
  2954.                     $usedPort $em->getRepository(Port::class)->find($usedPort);
  2955.                     $msgTemp " " $msgTemp " "$usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - "$usedPort->getOrderNo();
  2956.                 }
  2957.                 $this->addFlash(
  2958.                         'error',
  2959.                         $msgTemp
  2960.                     );
  2961.                 $racks $em->getRepository(Rack::class)->findAll();
  2962.                 $rackFaces $em->getRepository(RackFace::class)->findAll();
  2963.                 return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
  2964.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2965.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2966.                     'eq' => $eqOld,
  2967.                     'eqMod' => $eq,
  2968.                     "racks" =>$racks,
  2969.                     "rackFaces" =>$rackFaces
  2970.                 ]);
  2971.             }
  2972.             else {
  2973.                 $em->remove($eqOld);
  2974.                 $em->flush();
  2975.                 $this->addFlash(
  2976.                         'error',
  2977.                         'Opération terminée avec succès !'
  2978.                     );
  2979.                 return $this->redirectToRoute('equipment_specific_list');
  2980.             }
  2981.             // foreach ($portsOld as $port){
  2982.             //     if($port){
  2983.             //         $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  2984.             //         $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2985.             //
  2986.             //         if ($usedA || $usedB){
  2987.             //             $this->addFlash(
  2988.             //                     'error',
  2989.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  2990.             //                 );
  2991.             //             $racks = $em->getRepository(Rack::class)->findAll();
  2992.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  2993.             //             return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
  2994.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  2995.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  2996.             //                 'eq' => $eqOld,
  2997.             //                 'eqMod' => $eq,
  2998.             //                 "racks" =>$racks,
  2999.             //                 "rackFaces" =>$rackFaces
  3000.             //             ]);
  3001.             //         }
  3002.             //
  3003.             //         $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3004.             //
  3005.             //         if ($usedExt){
  3006.             //             $this->addFlash(
  3007.             //                     'error',
  3008.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3009.             //                 );
  3010.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3011.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3012.             //             return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
  3013.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3014.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3015.             //                 'eq' => $eqOld,
  3016.             //                 'eqMod' => $eq,
  3017.             //                 "racks" =>$racks,
  3018.             //                 "rackFaces" =>$rackFaces
  3019.             //             ]);
  3020.             //         }
  3021.             //         $usedALink = null;
  3022.             //         $usedBLink = null;
  3023.             //         if (count($port->getExtensionOrder()) > 0) {
  3024.             //           $extremityA = $port->getExtensionOrder()[0]->getExtremity();
  3025.             //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  3026.             //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  3027.             //         }
  3028.             //
  3029.             //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  3030.             //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  3031.             //
  3032.             //         if ($usedALink || $usedBLink){
  3033.             //             $this->addFlash(
  3034.             //                     'error',
  3035.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3036.             //                 );
  3037.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3038.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3039.             //             return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
  3040.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3041.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3042.             //                 'eq' => $eqOld,
  3043.             //                 'eqMod' => $eq,
  3044.             //                 "racks" =>$racks,
  3045.             //                 "rackFaces" =>$rackFaces
  3046.             //             ]);
  3047.             //         }
  3048.             //     }
  3049.             // }
  3050.             //
  3051.             // $em->remove($eqOld);
  3052.             // $em->flush();
  3053.             // return $this->redirectToRoute('equipment_specific_list');
  3054.         }
  3055.         elseif ($request->request->has('idEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  3056.             $eq $em->getRepository(EquipmentSpecific::class)->find($_POST["idEquipment"]);
  3057.             $racks $em->getRepository(Rack::class)->findAll();
  3058.             $rackFaces $em->getRepository(RackFace::class)->findAll();
  3059.             if ($_POST["eqModulaire"]) {
  3060.                 // return $this->render('equipment/test1.html.twig');
  3061.                 $eqMod $em->getRepository(EquipmentSpecific::class)->findOneById($_POST["eqModulaire"]);
  3062.                 return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
  3063.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3064.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3065.                     'eq' => $eq,
  3066.                     'eqMod' => $eqMod,
  3067.                     "racks" =>$racks,
  3068.                     "rackFaces" =>$rackFaces
  3069.                 ]);
  3070.             }
  3071.             elseif ($_POST["eqGeneric"]) {
  3072.                 $eqGen $em->getRepository(EquipmentGeneric::class)->findOneById($_POST["eqGeneric"]);
  3073.                 return $this->render('equipment/equipment_substitute_equipment.html.twig', [
  3074.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3075.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3076.                     'eq' => $eq,
  3077.                     'eqGen' => $eqGen,
  3078.                     "racks" =>$racks,
  3079.                     "rackFaces" =>$rackFaces
  3080.                 ]);
  3081.             }
  3082.         }
  3083.     }
  3084.     /**
  3085.      * @Route("/equipment/modulaire/substitute/{id}", name="equipment_modulaire_substitute")
  3086.      */
  3087.     public function substituteModulaireAction(Request $request$idTranslatorInterface $translator)
  3088.     {
  3089.         $user $this->getUser();
  3090.         $em $this->getDoctrine()->getManager();
  3091.         // process form
  3092.         if ($request->request->has('modulaireToEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
  3093.             //get the old equipment
  3094.             $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  3095.             //$eqParent = $eqOld->getParent();
  3096.             // get all the used ports of the old equipment
  3097.             $usedPorts = [];
  3098.             $modulesTemp $eqOld->getModules();
  3099.             $chassisModule $eqOld->getChassisModule();
  3100.             if ($chassisModule) {
  3101.                 $modulesTemp->add($chassisModule);
  3102.             }
  3103.             foreach ($modulesTemp as $tmpMod) {
  3104.                 $usedPorts array_merge($usedPorts$this->getUsedPortsEquipment($tmpMod));
  3105.             }
  3106.             $interfaceSpecificOld $_POST['interfaces'];
  3107.             $eq = new EquipmentSpecific();
  3108.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  3109.             $eq->setAlias($_POST['alias']);
  3110.             $eq->setOwner($_POST['owner']);
  3111.             $eq->setPositionRack($_POST['positionRack']);
  3112.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  3113.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
  3114.             $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
  3115.             $eq->setEquipmentGeneric($eqGeneric);
  3116.             $em->persist($eq);
  3117.             // $em->flush();
  3118.             $interfaceGenericPortOrderNoArray = array();
  3119.             if (isset($_POST['port'])) {
  3120.                 foreach ($_POST['port'] as $port => $value) {
  3121.                     foreach ($value as $key => $value1) {
  3122.                         $portOrderNoArray = array("orderNo"=> explode("__"$value1)[1], "port"=>$port);
  3123.                         $interfaceGenericPortOrderNoArray[explode("__"$value1)[0]][] = $portOrderNoArray;
  3124.                     }
  3125.                 }
  3126.             }
  3127.             // var_dump($interfaceGenericPortOrderNoArray);
  3128.             // create specific interfaces
  3129.             $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($eqGeneric);
  3130.             foreach ($interfacesGeneric as $interfaceGeneric){
  3131.                 $orderPortArray = array();
  3132.                 $portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
  3133.                 if ($portOrderNoArray) {
  3134.                     foreach ($portOrderNoArray as $value) {
  3135.                         $orderPortArray[$value['orderNo']][] = $value['port'];
  3136.                     }
  3137.                 }
  3138.                 $interfaceSpecific = new InterfaceSpecific();
  3139.                 $interfaceSpecific->setEquipmentSpecific($eq);
  3140.                 $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  3141.                 $em->persist($interfaceSpecific);
  3142.                 // $em->flush();
  3143.                 $alias null;
  3144.                 if ($interfaceGeneric->getAlias()) {
  3145.                   $alias json_decode($interfaceGeneric->getAlias(), true);
  3146.                 }
  3147.                 $portExternes null;
  3148.                 $idTemp $interfaceGeneric->getId();
  3149.                 // var_dump($_POST["portExterne[$idTemp]"]);
  3150.                 if (isset($_POST["portExterne"][$idTemp])) {
  3151.                   foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  3152.                     $portExternes[$key] = $value;
  3153.                   }
  3154.                 }
  3155.                 // var_dump($portExternes);
  3156.                 // create ports
  3157.                 $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  3158.                 $interfaceGenericNew = array();
  3159.                 foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
  3160.                     foreach ($value as $keyNew => $intGenNew) {
  3161.                         if ($intGenNew == $interfaceGeneric->getId()) {
  3162.                             $interfaceGenericNew[$interfaceSpecificId] = $value;
  3163.                         }
  3164.                     }
  3165.                 }
  3166.                 // var_dump($interfaceGenericNew);
  3167.                 $portsOld = array();
  3168.                 if (count($interfaceGenericNew) == 1) {
  3169.                     $interfaceSpecificId array_keys($interfaceGenericNew)[0];
  3170.                     $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  3171.                     $typeLnkSpc $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
  3172.                     $index 0;
  3173.                     foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
  3174.                         if ($value && $value != $interfaceGeneric->getId()) {
  3175.                             $intGenTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
  3176.                             $numPortTemp $intGenTemp->getNumberOfPorts();
  3177.                             $typeLnkGen $intGenTemp->getTypeLink()->getId();
  3178.                             if ($typeLnkSpc == $typeLnkGen) {
  3179.                                 $index += $numPortTemp;
  3180.                             }
  3181.                             elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  3182.                                 $index += ($numPortTemp*2);
  3183.                             }
  3184.                             elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  3185.                                 $index += ($numPortTemp/2);
  3186.                             }
  3187.                         }
  3188.                     }
  3189.                     $ports $interfaceSpecificTemp->getPort();
  3190.                     $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  3191.                     $lengthTemp $interfaceGeneric->getNumberOfPorts();
  3192.                     if ($typeLnkSpc == $typeLnkGen) {
  3193.                         $lengthTemp $interfaceGeneric->getNumberOfPorts();
  3194.                     }
  3195.                     elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  3196.                         $lengthTemp $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*$interfaceGeneric->getNumberOfPorts()*$lengthTemp;
  3197.                     }
  3198.                     elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  3199.                         $lengthTemp $interfaceGeneric->getNumberOfPorts()/2;
  3200.                     }
  3201.                     for ($i=$index$i $lengthTemp$i++) {
  3202.                         // $portsOld[] = $ports{$i};
  3203.                         $portsOld[] = $ports[$i];
  3204.                     }
  3205.                 }
  3206.                 elseif (count($interfaceGenericNew) > 1) {
  3207.                     foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
  3208.                         $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  3209.                         foreach ($interfaceSpecificTemp->getPort() as $value) {
  3210.                             $portsOld[] = $value;
  3211.                         }
  3212.                     }
  3213.                 }
  3214.                 // var_dump($portsOld);
  3215.                 $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  3216.                 $k 0;
  3217.                 // if ($numberOfPorts < count($portsOld)) {
  3218.                 //     $this->addFlash(
  3219.                 //         'error',
  3220.                 //         'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
  3221.                 //     );
  3222.                 //     $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
  3223.                 //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3224.                 //     $conn = $em->getConnection();
  3225.                 //     $stmt = $conn->prepare($sql);
  3226.                 //     $stmt->execute();
  3227.                 //
  3228.                 //     $em->remove($equipmentSpecific);
  3229.                 //     $em->flush();
  3230.                 //     return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  3231.                 // }
  3232.                 for ($i=1$i<=$numberOfPorts$i++){
  3233.                     $port = new Port();
  3234.                     $port->setInterfaceSpecific($interfaceSpecific);
  3235.                     $port->setOrderNo($i);
  3236.                     if ($alias && count($alias) > 0) {
  3237.                       $port->setAlias($alias[$i]);
  3238.                     }
  3239.                     if ($portExternes) {
  3240.                       if (isset($portExternes[$i]) && $portExternes[$i]) {
  3241.                         // $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  3242.                         $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
  3243.                         $port->setPortExterne($pe);
  3244.                         $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  3245.                         if ($interfaceGenericPortExterne != null) {
  3246.                             //create interface spécific and attach it to the port
  3247.                             $ifPE = new InterfaceSpecific();
  3248.                             $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port);
  3249.                             $port->setInterfaceSpecificPortExterne($ifPE);
  3250.                         }
  3251.                       }
  3252.                     }
  3253.                     $em->persist($port);
  3254.                     // $em->flush();
  3255.                     //port to port
  3256.                     if (array_key_exists($i$orderPortArray)) {
  3257.                         foreach ($orderPortArray[$i] as $portOld) {
  3258.                             //remove the replaced port from usedports array
  3259.                             $portOld $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
  3260.                             $usedPorts array_diff($usedPorts, [$portOld->getId()]);
  3261.                             $this->replacePort($port$portOld);
  3262.                         }
  3263.                     }
  3264.                     else {
  3265.                         if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  3266.                             //remove the replaced port from usedports array
  3267.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3268.                             $this->replacePort($port$portsOld[$k]);
  3269.                             // unset($portsOld[$k]);
  3270.                             $k++;
  3271.                         }
  3272.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 1) {
  3273.                             //remove the replaced port from usedports array
  3274.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3275.                             $this->replacePort($port$portsOld[$k]);
  3276.                             // unset($portsOld[$k]);
  3277.                             $port1 = new Port();
  3278.                             $port1->setInterfaceSpecific($interfaceSpecific);
  3279.                             $j $i+1;
  3280.                             $port1->setOrderNo($j);
  3281.                             if ($alias && count($alias) > 0) {
  3282.                               $port1->setAlias($alias[$j]);
  3283.                             }
  3284.                             if ($portExternes) {
  3285.                               if (isset($portExternes[$j]) && $portExternes[$j]) {
  3286.                                 // $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
  3287.                                 $pe $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]);
  3288.                                 $port1->setPortExterne($pe);
  3289.                                 $interfaceGenericPortExterne $pe->getInterfaceGeneric();
  3290.                                 if ($interfaceGenericPortExterne != null) {
  3291.                                     //create interface spécific and attach it to the port
  3292.                                     $ifPE = new InterfaceSpecific();
  3293.                                     $this->createInterfaceSpecific($em$interfaceGenericPortExterne$ifPE$eq$port1);
  3294.                                     $port1->setInterfaceSpecificPortExterne($ifPE);
  3295.                                 }
  3296.                               }
  3297.                             }
  3298.                             $em->persist($port1);
  3299.                             // $em->flush();
  3300.                             $this->replacePort($port1$portsOld[$k]);
  3301.                             // unset($portsOld[$k]);
  3302.                             $k++;
  3303.                             $i++;
  3304.                         }
  3305.                         elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 2) {
  3306.                             //remove the replaced port from usedports array
  3307.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3308.                             $this->replacePort($port$portsOld[$k]);
  3309.                             // unset($portsOld[$k]);
  3310.                             $k++;
  3311.                             //remove the replaced port from usedports array
  3312.                             $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3313.                             $this->replacePort($port$portsOld[$k]);
  3314.                             // unset($portsOld[$k]);
  3315.                             $k++;
  3316.                         }
  3317.                     }
  3318.                     // if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  3319.                     //     $this->replacePort($port, $portsOld[$k]);
  3320.                     //     unset($portsOld[$k]);
  3321.                     //     $k++;
  3322.                     // }
  3323.                     // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
  3324.                     //     $this->replacePort($port, $portsOld[$k]);
  3325.                     //     unset($portsOld[$k]);
  3326.                     //     $k++;
  3327.                     //     $port1 = new Port();
  3328.                     //     $port1->setInterfaceSpecific($interfaceSpecific);
  3329.                     //     $j = $i+1;
  3330.                     //     $port1->setOrderNo($j);
  3331.                     //     if ($alias && count($alias) > 0) {
  3332.                     //       $port1->setAlias($alias[$j]);
  3333.                     //     }
  3334.                     //     if ($portExternes) {
  3335.                     //       if (isset($portExternes[$j]) && $portExternes[$j]) {
  3336.                     //         $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
  3337.                     //       }
  3338.                     //     }
  3339.                     //     $em->persist($port1);
  3340.                     //     // $em->flush();
  3341.                     //     $this->replacePort($port1, $portsOld[$k]);
  3342.                     //     unset($portsOld[$k]);
  3343.                     //     $k++;
  3344.                     //     $i++;
  3345.                     // }
  3346.                     // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
  3347.                     //     $this->replacePort($port, $portsOld[$k]);
  3348.                     //     unset($portsOld[$k]);
  3349.                     //     $k++;
  3350.                     //     $this->replacePort($port, $portsOld[$k]);
  3351.                     //     unset($portsOld[$k]);
  3352.                     //     $k++;
  3353.                     // }
  3354.                     // //interface to interface
  3355.                     // if (array_key_exists($i, $orderPortArray)) {
  3356.                     //     foreach ($orderPortArray[$i] as $portOld) {
  3357.                     //         $this->replacePort($port, $portOld);
  3358.                     //     }
  3359.                     // }
  3360.                 }
  3361.             }
  3362.             if (count($usedPorts) > 0) {
  3363.                 $msgTemp "Opération échouée ! ";
  3364.                 $msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
  3365.                 foreach ($usedPorts as $usedPort) {
  3366.                     $usedPort $em->getRepository(Port::class)->find($usedPort);
  3367.                     $msgTemp " " $msgTemp " "$usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - "$usedPort->getOrderNo();
  3368.                 }
  3369.                 $this->addFlash(
  3370.                         'error',
  3371.                         $msgTemp
  3372.                     );
  3373.                 $racks $em->getRepository(Rack::class)->findAll();
  3374.                             $rackFaces $em->getRepository(RackFace::class)->findAll();
  3375.                             return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
  3376.                                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3377.                                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3378.                                 'eq' => $eqOld,
  3379.                                 'eqGen' => $eqGeneric,
  3380.                                 "racks" =>$racks,
  3381.                                 "rackFaces" =>$rackFaces
  3382.                             ]);
  3383.             }
  3384.             else {
  3385.                 $this->get('logger')->info("inside modulaire_equipment success");
  3386.                 try{
  3387.                     $sql "update slot set module_id=null where module_id = " $eqOld->getId() ." or modulaire_id=" $eqOld->getId();
  3388.                     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3389.                     $conn $em->getConnection();
  3390.                     $stmt $conn->prepare($sql);
  3391.                     $stmt->execute();
  3392.                     $sql1 "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " $eqOld->getId();
  3393.                     $conn $em->getConnection();
  3394.                     $stmt $conn->prepare($sql1);
  3395.                     $stmt->execute();
  3396.                     $sql "update equipment_specific set chassis_module_id=null where id = " $eqOld->getId();
  3397.                     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3398.                     $stmt $conn->prepare($sql);
  3399.                     $stmt->execute();
  3400.                     foreach ($eqOld as $modOld) {
  3401.                         $em->remove($modOld);
  3402.                     }
  3403.                     if ($eqOld->getChassisModule()) {
  3404.                         $em->remove($eqOld->getChassisModule());
  3405.                     }
  3406.                     $em->remove($eqOld);
  3407.                     $this->get('logger')->info("inside modulaire_equipment success");
  3408.                     $em->flush();
  3409.                 }
  3410.                 catch(Exception $ex){
  3411.                     $this->get('logger')->info($ex->getMessage());
  3412.                 }
  3413.                 $this->get('logger')->info("inside modulaire_equipment success");
  3414.                 $this->addFlash(
  3415.                         'error',
  3416.                         'Opération terminée avec succès !'
  3417.                     );
  3418.                 return $this->redirectToRoute('equipment_specific_modulaire_list');
  3419.             }
  3420.             // foreach ($portsOld as $port){
  3421.             //     if($port){
  3422.             //         $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  3423.             //         $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3424.             //
  3425.             //         if ($usedA || $usedB){
  3426.             //             $this->addFlash(
  3427.             //                     'error',
  3428.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3429.             //                 );
  3430.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3431.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3432.             //             return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
  3433.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3434.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3435.             //                 'eq' => $eqOld,
  3436.             //                 'eqGen' => $eqGeneric,
  3437.             //                 "racks" =>$racks,
  3438.             //                 "rackFaces" =>$rackFaces
  3439.             //             ]);
  3440.             //         }
  3441.             //
  3442.             //         $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3443.             //
  3444.             //         if ($usedExt){
  3445.             //             $this->addFlash(
  3446.             //                     'error',
  3447.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3448.             //                 );
  3449.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3450.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3451.             //             return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
  3452.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3453.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3454.             //                 'eq' => $eqOld,
  3455.             //                 'eqGen' => $eqGeneric,
  3456.             //                 "racks" =>$racks,
  3457.             //                 "rackFaces" =>$rackFaces
  3458.             //             ]);
  3459.             //         }
  3460.             //         $usedALink = null;
  3461.             //         $usedBLink = null;
  3462.             //         if (count($port->getExtensionOrder()) > 0) {
  3463.             //           $extremityA = $port->getExtensionOrder()[0]->getExtremity();
  3464.             //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  3465.             //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  3466.             //         }
  3467.             //
  3468.             //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  3469.             //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  3470.             //
  3471.             //         if ($usedALink || $usedBLink){
  3472.             //             $this->addFlash(
  3473.             //                     'error',
  3474.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3475.             //                 );
  3476.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3477.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3478.             //             return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
  3479.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3480.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3481.             //                 'eq' => $eqOld,
  3482.             //                 'eqGen' => $eqGeneric,
  3483.             //                 "racks" =>$racks,
  3484.             //                 "rackFaces" =>$rackFaces
  3485.             //             ]);
  3486.             //         }
  3487.             //     }
  3488.             // }
  3489.         }
  3490.         elseif ($request->request->has('modulaireToModulaire') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  3491.             $eqOld $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
  3492.             // $eqParent = $eqOld->getParent();
  3493.             // get all the used ports of the old equipment
  3494.             $usedPorts = [];
  3495.             $modulesTemp $eqOld->getModules();
  3496.             $chassisModule $eqOld->getChassisModule();
  3497.             if ($chassisModule) {
  3498.                 $modulesTemp->add($chassisModule);
  3499.             }
  3500.             foreach ($modulesTemp as $tmpMod) {
  3501.                 $usedPorts array_merge($usedPorts$this->getUsedPortsEquipment($tmpMod));
  3502.             }
  3503.             $interfaceSpecificOld $_POST['interfaces'];
  3504.             $eq $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_POST['equipmentGeneric']);
  3505.             $eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
  3506.             $eq->setAlias($_POST['alias']);
  3507.             $eq->setOwner($_POST['owner']);
  3508.             $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  3509.             $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
  3510.             $eq->setPositionRack($_POST['positionRack']);
  3511.             $em->persist($eq);
  3512.             $interfaceGenericPortOrderNoArray = array();
  3513.             if (isset($_POST['port'])) {
  3514.                 foreach ($_POST['port'] as $port => $value) {
  3515.                     foreach ($value as $key => $value1) {
  3516.                         $portOrderNoArray = array("orderNo"=> explode("__"$value1)[1], "port"=>$port);
  3517.                         $interfaceGenericPortOrderNoArray[explode("__"$value1)[0]][] = $portOrderNoArray;
  3518.                     }
  3519.                 }
  3520.             }
  3521.             // var_dump($interfaceGenericPortOrderNoArray);
  3522.             $modulesTemp $eq->getModules();
  3523.             $chassisModule $eq->getChassisModule();
  3524.             if ($chassisModule) {
  3525.                 $modulesTemp->add($chassisModule);
  3526.             }
  3527.             // create specific interfaces
  3528.             foreach ($modulesTemp as $module) {
  3529.                 $module->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
  3530.                 $em->persist($module);
  3531.                 foreach ($module->getInterfaceSpecific() as $interfaceSpecific) {
  3532.                     $orderPortArray = array();
  3533.                     $portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()] : null;
  3534.                     if ($portOrderNoArray) {
  3535.                         foreach ($portOrderNoArray as $value) {
  3536.                             $orderPortArray[$value['orderNo']][] = $value['port'];
  3537.                         }
  3538.                     }
  3539.                     // var_dump($portExternes);
  3540.                     // create ports
  3541.                     $interfaceGeneric $interfaceSpecific->getInterfaceGeneric();
  3542.                     $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  3543.                     $interfaceGenericNew = array();
  3544.                     foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
  3545.                         foreach ($value as $keyNew => $intGenNew) {
  3546.                             if ($intGenNew == $interfaceSpecific->getId()) {
  3547.                                 $interfaceGenericNew[$interfaceSpecificId] = $value;
  3548.                             }
  3549.                         }
  3550.                     }
  3551.                     // var_dump($interfaceGenericNew);
  3552.                     $portsOld = array();
  3553.                     if (count($interfaceGenericNew) == 1) {
  3554.                         $interfaceSpecificId array_keys($interfaceGenericNew)[0];
  3555.                         $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  3556.                         $typeLnkSpc $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
  3557.                         $index 0;
  3558.                         foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
  3559.                             if ($value && $value != $interfaceSpecific->getId()) {
  3560.                                 $intGenTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($value)->getInterfaceGeneric();
  3561.                                 $numPortTemp $intGenTemp->getNumberOfPorts();
  3562.                                 $typeLnkGen $intGenTemp->getTypeLink()->getId();
  3563.                                 if ($typeLnkSpc == $typeLnkGen) {
  3564.                                     $index += $numPortTemp;
  3565.                                 }
  3566.                                 elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  3567.                                     $index += ($numPortTemp*2);
  3568.                                 }
  3569.                                 elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  3570.                                     $index += ($numPortTemp/2);
  3571.                                 }
  3572.                             }
  3573.                         }
  3574.                         $ports $interfaceSpecificTemp->getPort();
  3575.                         $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  3576.                         $lengthTemp $interfaceGeneric->getNumberOfPorts();
  3577.                         if ($typeLnkSpc == $typeLnkGen) {
  3578.                             $lengthTemp $interfaceGeneric->getNumberOfPorts();
  3579.                         }
  3580.                         elseif ($typeLnkSpc == && $typeLnkGen == 2) {
  3581.                             $lengthTemp $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*$interfaceGeneric->getNumberOfPorts()*$lengthTemp;
  3582.                         }
  3583.                         elseif ($typeLnkSpc == && $typeLnkGen == 1) {
  3584.                             $lengthTemp $interfaceGeneric->getNumberOfPorts()/2;
  3585.                         }
  3586.                         for ($i=$index$i $lengthTemp$i++) {
  3587.                             // $portsOld[] = $ports{$i};
  3588.                             $portsOld[] = $ports[$i];
  3589.                         }
  3590.                     }
  3591.                     elseif (count($interfaceGenericNew) > 1) {
  3592.                         foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
  3593.                             $interfaceSpecificTemp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
  3594.                             foreach ($interfaceSpecificTemp->getPort() as $value) {
  3595.                                 $portsOld[] = $value;
  3596.                             }
  3597.                         }
  3598.                     }
  3599.                     // var_dump($portsOld);
  3600.                     $typeLnkGen $interfaceGeneric->getTypeLink()->getId();
  3601.                     $k 0;
  3602.                     // if ($numberOfPorts < count($portsOld)) {
  3603.                     //     $this->addFlash(
  3604.                     //         'error',
  3605.                     //         'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
  3606.                     //     );
  3607.                     //     $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
  3608.                     //     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3609.                     //     $conn = $em->getConnection();
  3610.                     //     $stmt = $conn->prepare($sql);
  3611.                     //     $stmt->execute();
  3612.                     //
  3613.                     //     $em->remove($equipmentSpecific);
  3614.                     //     $em->flush();
  3615.                     //     return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
  3616.                     // }
  3617.                     $portsTemp $interfaceSpecific->getPort();
  3618.                     for ($i=0$i<$numberOfPorts$i++){
  3619.                         // $port = $portsTemp{$i};
  3620.                         $port $portsTemp[$i];
  3621.                         if (array_key_exists($i$orderPortArray)) {
  3622.                             foreach ($orderPortArray[$i] as $portOld) {
  3623.                                 //remove the replaced port from usedports array
  3624.                                 $portOld $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
  3625.                                 $usedPorts array_diff($usedPorts, [$portOld->getId()]);
  3626.                                 $this->replacePort($port$portOld);
  3627.                             }
  3628.                         }
  3629.                         else {
  3630.                             if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  3631.                                 //remove the replaced port from usedports array
  3632.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3633.                                 $this->replacePort($port$portsOld[$k]);
  3634.                                 // unset($portsOld[$k]);
  3635.                                 $k++;
  3636.                             }
  3637.                             elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 1) {
  3638.                                 //remove the replaced port from usedports array
  3639.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3640.                                 $this->replacePort($port$portsOld[$k]);
  3641.                                 // unset($portsOld[$k]);
  3642.                                 $j $i+1;
  3643.                                 // $port1 = $portsTemp{$j};
  3644.                                 $port1 $portsTemp[$j];
  3645.                                 $this->replacePort($port1$portsOld[$k]);
  3646.                                 $k++;
  3647.                                 $i++;
  3648.                             }
  3649.                             elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == && $typeLnkGen == 2) {
  3650.                                 //remove the replaced port from usedports array
  3651.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3652.                                 $this->replacePort($port$portsOld[$k]);
  3653.                                 // unset($portsOld[$k]);
  3654.                                 $k++;
  3655.                                 //remove the replaced port from usedports array
  3656.                                 $usedPorts array_diff($usedPorts, [$portsOld[$k]->getId()]);
  3657.                                 $this->replacePort($port$portsOld[$k]);
  3658.                                 // unset($portsOld[$k]);
  3659.                                 $k++;
  3660.                             }
  3661.                         }
  3662.                         // if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
  3663.                         //     $this->replacePort($port, $portsOld[$k]);
  3664.                         //     unset($portsOld[$k]);
  3665.                         //     $k++;
  3666.                         // }
  3667.                         // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
  3668.                         //     $this->replacePort($port, $portsOld[$k]);
  3669.                         //     unset($portsOld[$k]);
  3670.                         //     $k++;
  3671.                         //     $i++;
  3672.                         //     $port1 = $portsTemp{$i};
  3673.                         //     $this->replacePort($port1, $portsOld[$k]);
  3674.                         //     unset($portsOld[$k]);
  3675.                         //     $k++;
  3676.                         //     $i++;
  3677.                         // }
  3678.                         // elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
  3679.                         //     $this->replacePort($port, $portsOld[$k]);
  3680.                         //     unset($portsOld[$k]);
  3681.                         //     $k++;
  3682.                         //     $this->replacePort($port, $portsOld[$k]);
  3683.                         //     unset($portsOld[$k]);
  3684.                         //     $k++;
  3685.                         // }
  3686.                         // if (array_key_exists($i+1, $orderPortArray)) {
  3687.                         //     foreach ($orderPortArray[$i+1] as $portOld) {
  3688.                         //         $this->replacePort($port, $portOld);
  3689.                         //     }
  3690.                         // }
  3691.                     }
  3692.                 }
  3693.             }
  3694.             if (count($usedPorts) > 0) {
  3695.                 $msgTemp "Opération échouée ! ";
  3696.                 $msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
  3697.                 foreach ($usedPorts as $usedPort) {
  3698.                     $usedPort $em->getRepository(Port::class)->find($usedPort);
  3699.                     $msgTemp " " $msgTemp " "$usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ".  $usedPort->getOrderNo();
  3700.                 }
  3701.                 $this->addFlash(
  3702.                         'error',
  3703.                         $msgTemp
  3704.                     );
  3705.                 $this->get('logger')->info("inside modulaire_modulaire failed");
  3706.                 $racks $em->getRepository(Rack::class)->findAll();
  3707.                 $rackFaces $em->getRepository(RackFace::class)->findAll();
  3708.                 return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
  3709.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3710.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3711.                     'eq' => $eqOld,
  3712.                     'eqMod' => $eq,
  3713.                     "racks" =>$racks,
  3714.                     "rackFaces" =>$rackFaces
  3715.                 ]);
  3716.             }
  3717.             else {
  3718.                 $this->get('logger')->info("inside modulaire_modulaire success");
  3719.                 try{
  3720.                     $sql "update slot set module_id=null where module_id = " $eqOld->getId() ." or modulaire_id=" $eqOld->getId();
  3721.                     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3722.                     $conn $em->getConnection();
  3723.                     $stmt $conn->prepare($sql);
  3724.                     $stmt->execute();
  3725.                     $sql1 "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " $eqOld->getId();
  3726.                     $conn $em->getConnection();
  3727.                     $stmt $conn->prepare($sql1);
  3728.                     $stmt->execute();
  3729.                     $sql "update equipment_specific set chassis_module_id=null where id = " $eqOld->getId();
  3730.                     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  3731.                     $stmt $conn->prepare($sql);
  3732.                     $stmt->execute();
  3733.                     foreach ($eqOld as $modOld) {
  3734.                         $em->remove($modOld);
  3735.                     }
  3736.                     if ($eqOld->getChassisModule()) {
  3737.                         $em->remove($eqOld->getChassisModule());
  3738.                     }
  3739.                     $em->remove($eqOld);
  3740.                     $this->get('logger')->info("inside modulaire_modulaire success");
  3741.                     $em->flush();
  3742.                 }
  3743.                 catch(Exception $ex){
  3744.                     $this->get('logger')->info($ex->getMessage());
  3745.                 }
  3746.                 $this->get('logger')->info("inside modulaire_modulaire success");
  3747.                 $this->addFlash(
  3748.                         'error',
  3749.                         'Opération terminée avec succès !'
  3750.                     );
  3751.                 return $this->redirectToRoute('equipment_specific_modulaire_list');
  3752.             }
  3753.             // foreach ($portsOld as $port){
  3754.             //     if($port){
  3755.             //         $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  3756.             //         $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3757.             //
  3758.             //         if ($usedA || $usedB){
  3759.             //             $this->addFlash(
  3760.             //                     'error',
  3761.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3762.             //                 );
  3763.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3764.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3765.             //             return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
  3766.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3767.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3768.             //                 'eq' => $eqOld,
  3769.             //                 'eqMod' => $eq,
  3770.             //                 "racks" =>$racks,
  3771.             //                 "rackFaces" =>$rackFaces
  3772.             //             ]);
  3773.             //         }
  3774.             //
  3775.             //         $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3776.             //
  3777.             //         if ($usedExt){
  3778.             //             $this->addFlash(
  3779.             //                     'error',
  3780.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3781.             //                 );
  3782.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3783.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3784.             //             return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
  3785.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3786.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3787.             //                 'eq' => $eqOld,
  3788.             //                 'eqMod' => $eq,
  3789.             //                 "racks" =>$racks,
  3790.             //                 "rackFaces" =>$rackFaces
  3791.             //             ]);
  3792.             //         }
  3793.             //         $usedALink = null;
  3794.             //         $usedBLink = null;
  3795.             //         if (count($port->getExtensionOrder()) > 0) {
  3796.             //           $extremityA = $port->getExtensionOrder()[0]->getExtremity();
  3797.             //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  3798.             //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  3799.             //         }
  3800.             //
  3801.             //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  3802.             //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  3803.             //
  3804.             //         if ($usedALink || $usedBLink){
  3805.             //             $this->addFlash(
  3806.             //                     'error',
  3807.             //                     $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
  3808.             //                 );
  3809.             //             $racks = $em->getRepository(Rack::class)->findAll();
  3810.             //             $rackFaces = $em->getRepository(RackFace::class)->findAll();
  3811.             //             return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
  3812.             //                 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3813.             //                 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3814.             //                 'eq' => $eqOld,
  3815.             //                 'eqMod' => $eq,
  3816.             //                 "racks" =>$racks,
  3817.             //                 "rackFaces" =>$rackFaces
  3818.             //             ]);
  3819.             //         }
  3820.             //     }
  3821.             // }
  3822.         }
  3823.         elseif ($request->request->has('idEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  3824.             $eq $em->getRepository(EquipmentSpecific::class)->find($_POST["idEquipment"]);
  3825.             $racks $em->getRepository(Rack::class)->findAll();
  3826.             $rackFaces $em->getRepository(RackFace::class)->findAll();
  3827.             if ($_POST["eqModulaire"]) {
  3828.                 // return $this->render('equipment/test1.html.twig');
  3829.                 $eqMod $em->getRepository(EquipmentSpecific::class)->findOneById($_POST["eqModulaire"]);
  3830.                 return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
  3831.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3832.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3833.                     'eq' => $eq,
  3834.                     'eqMod' => $eqMod,
  3835.                     "racks" =>$racks,
  3836.                     "rackFaces" =>$rackFaces
  3837.                 ]);
  3838.             }
  3839.             elseif ($_POST["eqGeneric"]) {
  3840.                 $eqGen $em->getRepository(EquipmentGeneric::class)->findOneById($_POST["eqGeneric"]);
  3841.                 return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
  3842.                     'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
  3843.                     'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
  3844.                     'eq' => $eq,
  3845.                     'eqGen' => $eqGen,
  3846.                     "racks" =>$racks,
  3847.                     "rackFaces" =>$rackFaces
  3848.                 ]);
  3849.             }
  3850.         }
  3851.     }
  3852.     public function replacePort($portNew$portOld)
  3853.     {
  3854.         //   $logger->error("replaceport : new : " .$portNew->getId() . " old : " . $portOld->getId());
  3855.           $em $this->getDoctrine()->getManager();
  3856.           $usedsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findByPortA($portOld);
  3857.           foreach ($usedsA as $usedA) {
  3858.               $usedA->setPortA($portNew);
  3859.               $em->persist($usedA);
  3860.               // $em->flush();
  3861.           }
  3862.           $usedsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findByPortB($portOld);
  3863.           foreach ($usedsB as $usedB) {
  3864.               $usedB->setPortB($portNew);
  3865.               $em->persist($usedB);
  3866.               // $em->flush();
  3867.           }
  3868.           $usedsExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findByPortB($portOld);
  3869.           foreach ($usedsExt as $usedExt) {
  3870.               $usedExt->setPortB($portNew);
  3871.               $em->persist($usedExt);
  3872.               // $em->flush();
  3873.           }
  3874.           $extOrders $portOld->getExtensionOrder();
  3875.           foreach ($extOrders as $extOrder) {
  3876.               $extOrder->setPort($portNew);
  3877.               $em->persist($extOrder);
  3878.               // $em->flush();
  3879.           }
  3880.           $linkExt $portOld->getLinkExtension();
  3881.           if ($linkExt) {
  3882.               $portNew->setLinkExtension($linkExt);
  3883.               $em->persist($portNew);
  3884.               // $em->flush();
  3885.           }
  3886.           $link $portOld->getLink();
  3887.           if ($link) {
  3888.               $portNew->setLink($link);
  3889.               $em->persist($portNew);
  3890.               // $em->flush();
  3891.           }
  3892.     }
  3893.     public function getUsedPortsEquipment($eqOld)
  3894.     {
  3895.         $usedPorts = array();
  3896.         $interfaceSpecifics $eqOld->getInterfaceSpecific();
  3897.         foreach ($interfaceSpecifics as $interfaceSpecific) {
  3898.             foreach ($interfaceSpecific->getPort() as $port) {
  3899.                 $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  3900.                 if ($usedA) {
  3901.                     $usedPorts[] = $port->getId();
  3902.                     continue;
  3903.                 }
  3904.                 $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3905.                 if ($usedB) {
  3906.                     $usedPorts[] = $port->getId();
  3907.                     continue;
  3908.                 }
  3909.                 $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3910.                 if ($usedExt) {
  3911.                     $usedPorts[] = $port->getId();
  3912.                     continue;
  3913.                 }
  3914.                 $usedALink null;
  3915.                 $usedBLink null;
  3916.                 if (count($port->getExtensionOrder()) > 0) {
  3917.                   $extremityA $port->getExtensionOrder()[0]->getExtremity();
  3918.                   $usedALink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
  3919.                   $usedBLink $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
  3920.                 }
  3921.                 if ($usedALink || $usedBLink){
  3922.                     $usedPorts[] = $port->getId();
  3923.                     continue;
  3924.                 }
  3925.             }
  3926.         }
  3927.         return $usedPorts;
  3928.     }
  3929. }