src/Controller/LinkController.php line 1799

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Psr\Log\LoggerInterface;
  4. use App\Entity\Link;
  5. use App\Entity\LinkExtension;
  6. use App\Entity\Trunk;
  7. use App\Entity\TrunkCableFiber;
  8. use App\Entity\TrunkExtension;
  9. use App\Entity\Port;
  10. use App\Entity\Extremity;
  11. use App\Entity\ExtensionOrder;
  12. use App\Entity\LinkValidation;
  13. use App\Entity\Rack;
  14. use App\Entity\EquipmentSpecific;
  15. use App\Entity\EquipmentGeneric;
  16. use App\Entity\InterfaceGeneric;
  17. use App\Entity\InterfaceSpecific;
  18. use Symfony\Component\Routing\Annotation\Route;
  19. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  20. use Symfony\Component\ExpressionLanguage\Tests\Node\Obj;
  21. use Symfony\Component\HttpFoundation\Request;
  22. use Symfony\Component\HttpFoundation\Response;
  23. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  24. use Pagerfanta\Adapter\ArrayAdapter;
  25. use Pagerfanta\Pagerfanta;
  26. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  27. use Symfony\Component\HttpFoundation\BinaryFileResponse;
  28. use Symfony\Contracts\Translation\TranslatorInterface;
  29. use Qipsius\TCPDFBundle\Controller\TCPDFController;
  30. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  31. class LinkController  extends AbstractController
  32. {
  33.   /**
  34.    * @Route("/link/create/step1", name="link_create_form_step1")
  35.    */
  36.   public function createAction(Request $requestTranslatorInterface $translator)
  37.   {
  38.     try {
  39.       $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  40.       $typeUsage $this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findAll();
  41.       $typeLink $this->getDoctrine()->getRepository('App\Entity\TypeLink')->findAll();
  42.       $linkID $this->getDoctrine()->getRepository('App\Entity\Link')->getNewId();
  43.       return $this->render('link/create_step1.html.twig', [
  44.         'action' => 'insert',
  45.         'page_title' => $translator->trans('Create Link - Step 1'),
  46.         'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Add new'),
  47.         'typeCable' => $typeCable,
  48.         'typeUsage' => $typeUsage,
  49.         'typeLink' => $typeLink,
  50.         'linkID' => $linkID
  51.       ]);
  52.     } catch (\Exception $e) {
  53.       return $this->redirect($request->headers->get('referer'));
  54.     }
  55.   }
  56.   /**
  57.    * @IsGranted("ROLE_CRUD")
  58.    * @Route("/link/create/step2", name="link_create_process_step1")
  59.    */
  60.   public function processLinkAction(Request $requestTranslatorInterface $translator)
  61.   {
  62.     try {
  63.       $em $this->getDoctrine()->getManager();
  64.       $link = new Link();
  65.       $link->setLinkID($request->request->get('linkID'));
  66.       $link->setOwner($request->request->get('owner'));
  67.       $link->setTypeUsage($this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findOneById($request->request->get('typeUsage')));
  68.       $link->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneById($request->request->get('typeLink')));
  69.       $em->persist($link);
  70.       $em->flush();
  71.       if ($request->request->get('action') == 'reserve') {
  72.         return $this->redirectToRoute('link_list');
  73.       }
  74.       $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  75.       $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  76.       $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  77.       //$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findAll();
  78.       //$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  79.       $trunks $this->getDoctrine()->getRepository('App\Entity\Trunk')->findBy([], ['trunkID' => 'ASC']);
  80.       $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  81.       //$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findAll();
  82.       $typeConnection $request->request->get('typeConnection');
  83.       switch ($typeConnection) {
  84.           // preassembled
  85.         case 1:
  86.           return $this->render('link/create_step2_preassembled.html.twig', [
  87.             'action' => 'insert',
  88.             'page_title' => $translator->trans('Create Link - Step 2'),
  89.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Add new'),
  90.             'link' => $link,
  91.             'sites' => $sites,
  92.             'rackFaces' => $rackFaces,
  93.             'typeCable' => $typeCable,
  94.             'eqGeneric' => $eqGeneric
  95.           ]);
  96.           break;
  97.           // trunk
  98.         case 2:
  99.           return $this->render('link/create_step2_trunk.html.twig', [
  100.             'action' => 'insert',
  101.             'page_title' => $translator->trans('Create Link - Step 2'),
  102.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Add new'),
  103.             'link' => $link,
  104.             'sites' => $sites,
  105.             'rackFaces' => $rackFaces,
  106.             'trunks' => $trunks
  107.           ]);
  108.           break;
  109.       }
  110.     } catch (\Exception $e) {
  111.       return $this->redirect($request->headers->get('referer'));
  112.     }
  113.   }
  114.   /**
  115.    * @IsGranted("ROLE_CRUD")
  116.    * @Route("/link/add/links", name="link_add_links")
  117.    */
  118.   public function addLinksAction(Request $requestTranslatorInterface $translator)
  119.   {
  120.     try {
  121.       $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  122.       $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  123.       $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule" => false"isModulaire" => false], ['title' => 'ASC']);
  124.       $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  125.       $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  126.       return $this->render('link/create_step2_preassembled.html.twig', [
  127.         'action' => 'edit',
  128.         'page_title' => $translator->trans('Add Links'),
  129.         'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Add new'),
  130.         'link' => $link,
  131.         'sites' => $sites,
  132.         'rackFaces' => $rackFaces,
  133.         'typeCable' => $typeCable,
  134.         'eqGeneric' => $eqGeneric
  135.       ]);
  136.     } catch (\Exception $e) {
  137.       return $this->redirect($request->headers->get('referer'));
  138.     }
  139.   }
  140.   /**
  141.    * @IsGranted("ROLE_CRUD")
  142.    * @Route("/link/add-first/links", name="link_add_first")
  143.    */
  144.   public function addFirstAction(Request $requestLoggerInterface $loggerTranslatorInterface $translator)
  145.   {
  146.     try {
  147.       $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  148.       
  149.       $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  150.       $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule" => false"isModulaire" => false], ['title' => 'ASC']);
  151.       $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  152.       $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  153.       
  154.       $nextExt $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link"sequenceNo"=>1]);
  155.       
  156.       $nextInt $nextExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getPortMpo() ? $nextExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getPortMpo()->getInterfaceSpecific() : $nextExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific();
  157.       // $nextInt = $nextExt->getPortA()->getInterfaceSpecific();
  158.       $nextEq $nextInt->getEquipmentSpecificMpo() ? $nextInt->getEquipmentSpecificMpo() : $nextInt->getEquipmentSpecific();
  159.       // $nextEq = $nextExt->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  160.       $nextPort = [];
  161.       $nextPortTemp $nextExt->getExtremityA()->getExtensionOrder();
  162.       foreach ($nextPortTemp as $value) {
  163.         $nextPort[] = $value->getPort();
  164.       }
  165.       $nextIntType $nextInt->getInterfaceGeneric()->getTypeInterconnection()->getId();
  166.       return $this->render('link/add_first.html.twig', [
  167.         'action' => 'edit',
  168.         'page_title' => $translator->trans('Add Links'),
  169.         'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Add new'),
  170.         'link' => $link,
  171.         'sites' => $sites,
  172.         'rackFaces' => $rackFaces,
  173.         'typeCable' => $typeCable,
  174.         'eqGeneric' => $eqGeneric,
  175.         'nextEq' => $nextEq,
  176.         'nextInt' => $nextInt,
  177.         'nextIntType' => $nextIntType,
  178.         'nextPort' => $nextPort
  179.       ]);
  180.     } catch (\Exception $e) {
  181.       $logger->info($e->getMessage());
  182.       return $this->redirect($request->headers->get('referer'));
  183.     }
  184.   }
  185.   /**
  186.    * @IsGranted("ROLE_CRUD")
  187.    * @Route("/link/create/process/ports", name="link_create_process_step2")
  188.    */
  189.   public function processPortsAction(Request $requestTranslatorInterface $translator)
  190.   {
  191.     // var_dump($request->request);
  192.     $em $this->getDoctrine()->getManager();
  193.     $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  194.     $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  195.     $portA2 null;
  196.     $portA3 null;
  197.     $portA4 null;
  198.     $portA5 null;
  199.     $portA6 null;
  200.     $portA7 null;
  201.     $portA8 null;
  202.     $portA9 null;
  203.     $portA10 null;
  204.     $portA11 null;
  205.     $portA12 null;
  206.     $portB2 null;
  207.     $portB3 null;
  208.     $portB4 null;
  209.     $portB5 null;
  210.     $portB6 null;
  211.     $portB7 null;
  212.     $portB8 null;
  213.     $portB9 null;
  214.     $portB10 null;
  215.     $portB11 null;
  216.     $portB12 null;
  217.     // get selected ports
  218.     $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
  219.     for ($i 2$i <= 12$i++) {
  220.       if ($request->request->get('pointA_' $i) != "") {
  221.         $temp "portA" $i;
  222.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_' $i));
  223.       }
  224.     }
  225.     // if ($request->request->get('pointA_2') != "") {
  226.     //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_2'));
  227.     // }
  228.     $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
  229.     // if ($request->request->get('pointB_2') != "") {
  230.     //   $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_2'));
  231.     // }
  232.     for ($i 2$i <= 12$i++) {
  233.       if ($request->request->get('pointB_' $i) != "") {
  234.         $temp "portB" $i;
  235.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_' $i));
  236.       }
  237.     }
  238.     //
  239.     //i beleive the LinkExtension entity structure has to be modified ??? extremity A/B can have 1 or more ports
  240.     //check if port is $nPort
  241.     $nPortsA $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  242.     if ($nPortsA) {
  243.       $nPortsA json_decode($nPortsA);
  244.     } else {
  245.       $nPortsA = [];
  246.     }
  247.     $nPortsB $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  248.     if ($nPortsB) {
  249.       $nPortsB json_decode($nPortsB);
  250.     } else {
  251.       $nPortsB = [];
  252.     }
  253.     $portsToCheck = array();
  254.     if (!in_array($portA1->getOrderNo(), $nPortsA)) {
  255.       $portsToCheck[] = $portA1;
  256.     }
  257.     if (!in_array($portB1->getOrderNo(), $nPortsB)) {
  258.       $portsToCheck[] = $portB1;
  259.     }
  260.     for ($i 2$i <= 12$i++) {
  261.       $temp "portA" $i;
  262.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsA)) {
  263.         $portsToCheck[] = $$temp;
  264.       }
  265.     }
  266.     for ($i 2$i <= 12$i++) {
  267.       $temp "portB" $i;
  268.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsB)) {
  269.         $portsToCheck[] = $$temp;
  270.       }
  271.     }
  272.     $redirect false;
  273.     foreach ($portsToCheck as $value) {
  274.       if ($value->getLink()) {
  275.         $this->addFlash(
  276.           'error',
  277.           'l\'un des ports Choisis est déjà dans un link'
  278.         );
  279.         $redirect true;
  280.       }
  281.       if ($redirect) {
  282.         break;
  283.       }
  284.     }
  285.     if ($redirect) {
  286.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  287.     } else {
  288.       $extension = new LinkExtension();
  289.       $extA = new Extremity();
  290.       $extensinOrder = new ExtensionOrder();
  291.       $extensinOrder->setOrderNumber(1);
  292.       $extensinOrder->setPort($portA1);
  293.       $extensinOrder->setExtremity($extA);
  294.       $portA1->addExtensionOrder($extensinOrder);
  295.       $extA->addExtensionOrder($extensinOrder);
  296.       $em->persist($extensinOrder);
  297.       // $portA1->setOrderNoExtension(1);
  298.       // $portA1->addExtremity($extA);
  299.       $portA1->setLink($link);
  300.       $portA1->setLinkExtension($extension);
  301.       $em->persist($portA1);
  302.       // $extA->addPort($portA1);
  303.       //generating portAStr
  304.       $portAOrderNos = array();
  305.       $portAOrderNos[0] = $portA1->getAlias() != "" $portA1->getAlias() : $portA1->getOrderNo();
  306.       
  307.       for ($i 2$i <= 12$i++) {
  308.         $temp "portA" $i;
  309.         if ($$temp) {
  310.           $extensinOrder = new ExtensionOrder();
  311.           $extensinOrder->setOrderNumber($i);
  312.           $extensinOrder->setPort($$temp);
  313.           $extensinOrder->setExtremity($extA);
  314.           $$temp->addExtensionOrder($extensinOrder);
  315.           $extA->addExtensionOrder($extensinOrder);
  316.           $em->persist($extensinOrder);
  317.           // $portA2->setOrderNoExtension(2);
  318.           // $portA2->addExtremity($extA);
  319.           $$temp->setLink($link);
  320.           $$temp->setLinkExtension($extension);
  321.           $em->persist($$temp);
  322.           // $extA->addPort($portA2);
  323.           $portAOrderNos[$i 1] = $$temp->getAlias() != "" ? $$temp->getAlias() : $$temp->getOrderNo();
  324.         }
  325.       }
  326.       //generating portAStr
  327.       $portAOrderNos array_unique($portAOrderNos);
  328.       ksort($portAOrderNos);
  329.       $extension->setPortAStr(implode("/"$portAOrderNos));
  330.       $em->persist($extA);
  331.       $extension->setExtremityA($extA);
  332.       // //calculating other values 
  333.       // $eqA = $portA1->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portA1->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portA1->getInterfaceSpecific()->getEquipmentSpecific();
  334.       // $intA = $portA1->getPortMpo() ? $portA1->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  335.       // $rackA = $eqA->getRack();
  336.       // $roomA = $rackA->getRoom();
  337.       // $siteA = $roomA->getSite();
  338.       // //equipementA
  339.       // $equipementAStr = "";
  340.       // if($eqA->isModule()){
  341.       //   $equipementAStr = $eqA->getParent().getEquipmentSpecificName() . " â•‘ " .  $eqA->getEquipmentSpecificName();
  342.       // }
  343.       // elseif($eqA->isChassisModule()){
  344.       //   $equipementAStr = $eqA->getChassisParent().getEquipmentSpecificName() . " â•‘ " .  $eqA->getEquipmentSpecificName();
  345.       // }
  346.       // else{
  347.       //   $equipementAStr = $eqA->getEquipmentSpecificName();
  348.       // }
  349.       // $link->setEquipementA($equipementAStr);
  350.       // $extension->setEquipementA($equipementAStr);
  351.       // //rackA
  352.       // $link->setArmoireA($rack->getTitle());
  353.       // $extension->setArmoireA($rack->getTitle());
  354.       // //roomA
  355.       // $link->setSalleA($room->getTitle());
  356.       // $extension->setSalleA($room->getTitle());
  357.       // //siteA
  358.       // $link->setSiteA($site->getTitle());
  359.       // $extension->setSiteA($site->getTitle());
  360.       // //interfaceA
  361.       // $extension->setInterfaceA($intA);
  362.       $extB = new Extremity();
  363.       $extensinOrder = new ExtensionOrder();
  364.       $extensinOrder->setOrderNumber(1);
  365.       $extensinOrder->setPort($portB1);
  366.       $extensinOrder->setExtremity($extB);
  367.       $portB1->addExtensionOrder($extensinOrder);
  368.       $extB->addExtensionOrder($extensinOrder);
  369.       $em->persist($extensinOrder);
  370.       // $portB1->setOrderNoExtension(1);
  371.       // $portB1->addExtremity($extB);
  372.       $portB1->setLink($link);
  373.       $portB1->setLinkExtension($extension);
  374.       $em->persist($portB1);
  375.       // $extB->addPort($portB1);
  376.       for ($i 2$i <= 12$i++) {
  377.         $temp "portB" $i;
  378.         if ($$temp) {
  379.           $extensinOrder = new ExtensionOrder();
  380.           $extensinOrder->setOrderNumber($i);
  381.           $extensinOrder->setPort($$temp);
  382.           $extensinOrder->setExtremity($extB);
  383.           $$temp->addExtensionOrder($extensinOrder);
  384.           $extB->addExtensionOrder($extensinOrder);
  385.           $em->persist($extensinOrder);
  386.           // $$temp->setOrderNoExtension(2);
  387.           // $$temp->addExtremity($extB);
  388.           $$temp->setLink($link);
  389.           $$temp->setLinkExtension($extension);
  390.           $em->persist($$temp);
  391.           // $extB->addPort($portB2);
  392.         }
  393.       }
  394.       $em->persist($extB);
  395.       $extension->setExtremityB($extB);
  396.       // //calculating other values B
  397.       // $eqB = $portB1->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portB1->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portB1->getInterfaceSpecific()->getEquipmentSpecific();
  398.       // $intB = $portB1->getPortMpo() ? $portB1->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  399.       // $rackB = $eqB->getRack();
  400.       // $roomB = $rackB->getRoom();
  401.       // $siteB = $roomB->getSite();
  402.       // //equipementB
  403.       // $equipementBStr = "";
  404.       // if($eqB->isModule()){
  405.       //   $equipementBStr = $eqB->getParent().getEquipmentSpecificName() . " â•‘ " .  $eqB->getEquipmentSpecificName();
  406.       // }
  407.       // elseif($eqB->isChassisModule()){
  408.       //   $equipementBStr = $eqB->getChassisParent().getEquipmentSpecificName() . " â•‘ " .  $eqB->getEquipmentSpecificName();
  409.       // }
  410.       // else{
  411.       //   $equipementBStr = $eqB->getEquipmentSpecificName();
  412.       // }
  413.       // $link->setEquipementB($equipementBStr);
  414.       // $extension->setEquipementB($equipementBStr);
  415.       // //rackB
  416.       // $link->setBrmoireB($rack->getTitle());
  417.       // $extension->setBrmoireB($rack->getTitle());
  418.       // //roomB
  419.       // $link->setSalleB($room->getTitle());
  420.       // $extension->setSalleB($room->getTitle());
  421.       // //siteB
  422.       // $link->setSiteB($site->getTitle());
  423.       // $extension->setSiteB($site->getTitle());
  424.       // //interfaceB
  425.       // $extension->setInterfaceB($intB);
  426.       $extension->setLink($link);
  427.       $extension->setTypeCable($typeCable);
  428.       $extension->setSequenceNo(1);
  429.       $em->persist($extension);
  430.       $em->flush();
  431.       // AFTER ACTION - REDIRECT
  432.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  433.     }
  434.   }
  435.   /**
  436.    * @IsGranted("ROLE_CRUD")
  437.    * @Route("/link/create/process/first", name="add_first_process")
  438.    */
  439.   public function processAddFirstAction(Request $requestTranslatorInterface $translator)
  440.   {
  441.     // var_dump($request->request);
  442.     $em $this->getDoctrine()->getManager();
  443.     $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  444.     $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  445.     $portA2 null;
  446.     $portA3 null;
  447.     $portA4 null;
  448.     $portA5 null;
  449.     $portA6 null;
  450.     $portA7 null;
  451.     $portA8 null;
  452.     $portA9 null;
  453.     $portA10 null;
  454.     $portA11 null;
  455.     $portA12 null;
  456.     $portB2 null;
  457.     $portB3 null;
  458.     $portB4 null;
  459.     $portB5 null;
  460.     $portB6 null;
  461.     $portB7 null;
  462.     $portB8 null;
  463.     $portB9 null;
  464.     $portB10 null;
  465.     $portB11 null;
  466.     $portB12 null;
  467.     // get selected ports
  468.     $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
  469.     for ($i 2$i <= 12$i++) {
  470.       if ($request->request->get('pointA_' $i) != "") {
  471.         $temp "portA" $i;
  472.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_' $i));
  473.       }
  474.     }
  475.     // if ($request->request->get('pointA_2') != "") {
  476.     //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_2'));
  477.     // }
  478.     $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
  479.     // if ($request->request->get('pointB_2') != "") {
  480.     //   $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_2'));
  481.     // }
  482.     for ($i 2$i <= 12$i++) {
  483.       if ($request->request->get('pointB_' $i) != "") {
  484.         $temp "portB" $i;
  485.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_' $i));
  486.       }
  487.     }
  488.     //
  489.     //i beleive the LinkExtension entity structure has to be modified ??? extremity A/B can have 1 or more ports
  490.     //check if port is $nPort
  491.     $nPortsA $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  492.     if ($nPortsA) {
  493.       $nPortsA json_decode($nPortsA);
  494.     } else {
  495.       $nPortsA = [];
  496.     }
  497.     $nPortsB $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  498.     if ($nPortsB) {
  499.       $nPortsB json_decode($nPortsB);
  500.     } else {
  501.       $nPortsB = [];
  502.     }
  503.     $portsToCheck = array();
  504.     if (!in_array($portA1->getOrderNo(), $nPortsA)) {
  505.       $portsToCheck[] = $portA1;
  506.     }
  507.     if (!in_array($portB1->getOrderNo(), $nPortsB)) {
  508.       $portsToCheck[] = $portB1;
  509.     }
  510.     for ($i 2$i <= 12$i++) {
  511.       $temp "portA" $i;
  512.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsA)) {
  513.         $portsToCheck[] = $$temp;
  514.       }
  515.     }
  516.     for ($i 2$i <= 12$i++) {
  517.       $temp "portB" $i;
  518.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsB)) {
  519.         $portsToCheck[] = $$temp;
  520.       }
  521.     }
  522.     $redirect false;
  523.     foreach ($portsToCheck as $value) {
  524.       if ($value->getLink() && $value->getLink()->getId() != $link->getId()) {
  525.         $this->addFlash(
  526.           'error',
  527.           'l\'un des ports Choisis est déjà dans un link'
  528.         );
  529.         $redirect true;
  530.       }
  531.       if ($redirect) {
  532.         break;
  533.       }
  534.     }
  535.     if ($redirect) {
  536.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  537.     } else {
  538.       $extension = new LinkExtension();
  539.       $extA = new Extremity();
  540.       $extensinOrder = new ExtensionOrder();
  541.       $extensinOrder->setOrderNumber(1);
  542.       $extensinOrder->setPort($portA1);
  543.       $extensinOrder->setExtremity($extA);
  544.       $portA1->addExtensionOrder($extensinOrder);
  545.       $extA->addExtensionOrder($extensinOrder);
  546.       $em->persist($extensinOrder);
  547.       // $portA1->setOrderNoExtension(1);
  548.       // $portA1->addExtremity($extA);
  549.       $portA1->setLink($link);
  550.       $portA1->setLinkExtension($extension);
  551.       $em->persist($portA1);
  552.       // $extA->addPort($portA1);
  553.       //generating portAStr
  554.       $portAOrderNos = array();
  555.       $portAOrderNos[0] = $portA1->getAlias() != "" $portA1->getAlias() : $portA1->getOrderNo();
  556.       
  557.       for ($i 2$i <= 12$i++) {
  558.         $temp "portA" $i;
  559.         if ($$temp) {
  560.           $extensinOrder = new ExtensionOrder();
  561.           $extensinOrder->setOrderNumber($i);
  562.           $extensinOrder->setPort($$temp);
  563.           $extensinOrder->setExtremity($extA);
  564.           $$temp->addExtensionOrder($extensinOrder);
  565.           $extA->addExtensionOrder($extensinOrder);
  566.           $em->persist($extensinOrder);
  567.           // $portA2->setOrderNoExtension(2);
  568.           // $portA2->addExtremity($extA);
  569.           $$temp->setLink($link);
  570.           $$temp->setLinkExtension($extension);
  571.           $em->persist($$temp);
  572.           // $extA->addPort($portA2);
  573.           $portAOrderNos[$i 1] = $$temp->getAlias() != "" ? $$temp->getAlias() : $$temp->getOrderNo();
  574.         }
  575.       }
  576.       //generating portAStr
  577.       $portAOrderNos array_unique($portAOrderNos);
  578.       ksort($portAOrderNos);
  579.       $extension->setPortAStr(implode("/"$portAOrderNos));
  580.       $em->persist($extA);
  581.       $extension->setExtremityA($extA);
  582.       // //calculating other values 
  583.       // $eqA = $portA1->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portA1->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portA1->getInterfaceSpecific()->getEquipmentSpecific();
  584.       // $intA = $portA1->getPortMpo() ? $portA1->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  585.       // $rackA = $eqA->getRack();
  586.       // $roomA = $rackA->getRoom();
  587.       // $siteA = $roomA->getSite();
  588.       // //equipementA
  589.       // $equipementAStr = "";
  590.       // if($eqA->isModule()){
  591.       //   $equipementAStr = $eqA->getParent().getEquipmentSpecificName() . " â•‘ " .  $eqA->getEquipmentSpecificName();
  592.       // }
  593.       // elseif($eqA->isChassisModule()){
  594.       //   $equipementAStr = $eqA->getChassisParent().getEquipmentSpecificName() . " â•‘ " .  $eqA->getEquipmentSpecificName();
  595.       // }
  596.       // else{
  597.       //   $equipementAStr = $eqA->getEquipmentSpecificName();
  598.       // }
  599.       // $link->setEquipementA($equipementAStr);
  600.       // $extension->setEquipementA($equipementAStr);
  601.       // //rackA
  602.       // $link->setArmoireA($rack->getTitle());
  603.       // $extension->setArmoireA($rack->getTitle());
  604.       // //roomA
  605.       // $link->setSalleA($room->getTitle());
  606.       // $extension->setSalleA($room->getTitle());
  607.       // //siteA
  608.       // $link->setSiteA($site->getTitle());
  609.       // $extension->setSiteA($site->getTitle());
  610.       // //interfaceA
  611.       // $extension->setInterfaceA($intA);
  612.       $extB = new Extremity();
  613.       $extensinOrder = new ExtensionOrder();
  614.       $extensinOrder->setOrderNumber(1);
  615.       $extensinOrder->setPort($portB1);
  616.       $extensinOrder->setExtremity($extB);
  617.       $portB1->addExtensionOrder($extensinOrder);
  618.       $extB->addExtensionOrder($extensinOrder);
  619.       $em->persist($extensinOrder);
  620.       // $portB1->setOrderNoExtension(1);
  621.       // $portB1->addExtremity($extB);
  622.       $portB1->setLink($link);
  623.       $portB1->setLinkExtension($extension);
  624.       $em->persist($portB1);
  625.       // $extB->addPort($portB1);
  626.       for ($i 2$i <= 12$i++) {
  627.         $temp "portB" $i;
  628.         if ($$temp) {
  629.           $extensinOrder = new ExtensionOrder();
  630.           $extensinOrder->setOrderNumber($i);
  631.           $extensinOrder->setPort($$temp);
  632.           $extensinOrder->setExtremity($extB);
  633.           $$temp->addExtensionOrder($extensinOrder);
  634.           $extB->addExtensionOrder($extensinOrder);
  635.           $em->persist($extensinOrder);
  636.           // $$temp->setOrderNoExtension(2);
  637.           // $$temp->addExtremity($extB);
  638.           $$temp->setLink($link);
  639.           $$temp->setLinkExtension($extension);
  640.           $em->persist($$temp);
  641.           // $extB->addPort($portB2);
  642.         }
  643.       }
  644.       $em->persist($extB);
  645.       $extension->setExtremityB($extB);
  646.       // //calculating other values B
  647.       // $eqB = $portB1->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portB1->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portB1->getInterfaceSpecific()->getEquipmentSpecific();
  648.       // $intB = $portB1->getPortMpo() ? $portB1->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  649.       // $rackB = $eqB->getRack();
  650.       // $roomB = $rackB->getRoom();
  651.       // $siteB = $roomB->getSite();
  652.       // //equipementB
  653.       // $equipementBStr = "";
  654.       // if($eqB->isModule()){
  655.       //   $equipementBStr = $eqB->getParent().getEquipmentSpecificName() . " â•‘ " .  $eqB->getEquipmentSpecificName();
  656.       // }
  657.       // elseif($eqB->isChassisModule()){
  658.       //   $equipementBStr = $eqB->getChassisParent().getEquipmentSpecificName() . " â•‘ " .  $eqB->getEquipmentSpecificName();
  659.       // }
  660.       // else{
  661.       //   $equipementBStr = $eqB->getEquipmentSpecificName();
  662.       // }
  663.       // $link->setEquipementB($equipementBStr);
  664.       // $extension->setEquipementB($equipementBStr);
  665.       // //rackB
  666.       // $link->setBrmoireB($rack->getTitle());
  667.       // $extension->setBrmoireB($rack->getTitle());
  668.       // //roomB
  669.       // $link->setSalleB($room->getTitle());
  670.       // $extension->setSalleB($room->getTitle());
  671.       // //siteB
  672.       // $link->setSiteB($site->getTitle());
  673.       // $extension->setSiteB($site->getTitle());
  674.       // //interfaceB
  675.       // $extension->setInterfaceB($intB);
  676.       $extension->setLink($link);
  677.       $extension->setTypeCable($typeCable);
  678.       $extension->setSequenceNo(1);
  679.       //update the other link extensions
  680.       $linkExtensions $link->getLinkExtension();
  681.       foreach ($linkExtensions as $linkExtension) {
  682.         $linkExtension->setSequenceNo($linkExtension->getSequenceNo()+1);
  683.         $em->persist($linkExtension);
  684.       }
  685.       $em->persist($extension);
  686.       $em->flush();
  687.       // AFTER ACTION - REDIRECT
  688.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  689.     }
  690.   }
  691.   /**
  692.    * @IsGranted("ROLE_CRUD")
  693.    * @Route("/link/extend/{id}/{typeExtension}/{extensionId}", name="link_extend")
  694.    */
  695.   public function extendLinkAction($id$typeExtension$extensionIdTranslatorInterface $translator)
  696.   {
  697.     $em $this->getDoctrine()->getManager();
  698.     $link $em->getRepository(Link::class)->find($id);
  699.     $lastExt null;
  700.     $lastExt $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extensionId);
  701.     $lastSeq $lastExt->getSequenceNo();
  702.     switch ($typeExtension) {
  703.         // trunk
  704.       case 1:
  705.         // $lastInt = $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getPortMpo() ? $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getPortMpo()->getInterfaceSpecific() : $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific();
  706.         $lastInt $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific();
  707.         $lastEq $lastInt->getEquipmentSpecificMpo() ? $lastInt->getEquipmentSpecificMpo() : $lastInt->getEquipmentSpecific();
  708.         $trunks = [];
  709.         $portsA = [];
  710.         $portsB = [];
  711.         // find last extension(s) of link ???  many links have the same sequenceNos
  712.         $ext $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['link' => $link'sequenceNo' => $lastSeq]);
  713.         //now ther is only one last extension
  714.         // var_dump($ext);
  715.         $portsAtmp = [];
  716.         $portsBtmp = [];
  717.         $portsAtmp1 $ext->getExtremityA()->getExtensionOrder();
  718.         foreach ($portsAtmp1 as $value) {
  719.           $portsAtmp[] = $value->getPort();
  720.         }
  721.         $portsBtmp1 $ext->getExtremityB()->getExtensionOrder();
  722.         foreach ($portsBtmp1 as $value) {
  723.           $portsBtmp[] = $value->getPort();
  724.         }
  725.         $tcfFA null;
  726.         $tcfFB null;
  727.         // var_dump($ext->getExtremityA());
  728.         foreach ($portsBtmp as $portBtmp) {
  729.           // var_dump($portBtmp->getId());
  730.           // get the trunk cable corresponds to the portA
  731.           // $tcfF = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portBtmp);
  732.           $tcfFA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portBtmp);
  733.           $tcfFB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portBtmp);
  734.           //
  735.           // $tcfF = null;
  736.           // $tcfF = ($tcfFA) ? $tcfFA : $tcfFB;
  737.           if ($tcfFA) {
  738.             // var_dump("trunk cable b id: ".$tcfFB->getId());
  739.             $portBtcf $tcfFA->getPortB();
  740.             // var_dump("trunk cable port b id: ".$portBtcf->getId());
  741.             foreach ($portsAtmp as $portAtmp) {
  742.               // var_dump($portAtmp->getId(), $portBtcf->getId());
  743.               if ($portBtcf != $portAtmp) {
  744.                 $trunk $tcfFA->getTrunk();
  745.                 // var_dump("trunk id" . $trunk->getId());
  746.                 if (!in_array($trunk$trunks)) {
  747.                   $trunk->direction 'F';
  748.                   $trunks[] = $trunk;
  749.                 }
  750.                 if (!in_array($portBtmp$portsA)) {
  751.                   $portsA[] = $portBtmp;
  752.                 }
  753.               }
  754.             }
  755.           } elseif ($tcfFB) {
  756.             // var_dump("trunk cable b id: ".$tcfFB->getId());
  757.             $portAtcf $tcfFB->getPortA();
  758.             // var_dump("trunk cable port b id: ".$portAtcf->getId());
  759.             foreach ($portsAtmp as $portAtmp) {
  760.               // var_dump($portAtmp->getId(), $portBtcf->getId());
  761.               if ($portAtcf != $portAtmp) {
  762.                 $trunk $tcfFB->getTrunk();
  763.                 // var_dump("trunk id" . $trunk->getId());
  764.                 if (!in_array($trunk$trunks)) {
  765.                   $trunk->direction 'R';
  766.                   $trunks[] = $trunk;
  767.                 }
  768.                 if (!in_array($portBtmp$portsA)) {
  769.                   $portsA[] = $portBtmp;
  770.                 }
  771.                 // if (!in_array($portAtcf, $portsB)) {
  772.                 //     $portsB[] = $portAtcf;
  773.                 // }
  774.               }
  775.             }
  776.           }
  777.           // check trunk extensions first
  778.           $tExtR $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portBtmp);
  779.           // var_dump($tExtR);
  780.           if ($tExtR) {
  781.             $tcf $tExtR->getTrunkCableFiber();
  782.             $trunk $tExtR->getTrunkCableFiber()->getTrunk();
  783.             $seqNoTrunkExtension $tExtR->getSequenceNo();
  784.             $lastSeqNumber $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getTotalSequenceNo($tcf);
  785.             if ($seqNoTrunkExtension == $lastSeqNumber) {
  786.               $portAtcf $tcf->getPortA();
  787.               foreach ($portsAtmp as $portAtmp) {
  788.                 if ($portAtcf != $portAtmp) {
  789.                   if (!in_array($trunk$trunks)) {
  790.                     $trunk->direction 'R';
  791.                     $trunks[] = $trunk;
  792.                   }
  793.                   // ports B in trunk become port A in link extension
  794.                   if (!in_array($portBtmp$portsA)) {
  795.                     $portsA[] = $portBtmp;
  796.                   }
  797.                 }
  798.               }
  799.             }
  800.             // check not extended trunks
  801.             $tcfR $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portBtmp);
  802.             if (!$tExtR && $tcfR) {
  803.               $portAtcf $tcfR->getPortA();
  804.               // var_dump($portAtcf);
  805.               foreach ($portsAtmp as $portAtmp) {
  806.                 if ($portAtcf != $portAtmp) {
  807.                   // var_dump($portAtcf != $portAtmp);
  808.                   $trunk $tcfR->getTrunk();
  809.                   if (!in_array($trunk$trunks)) {
  810.                     $trunk->direction 'F';
  811.                     $trunks[] = $trunk;
  812.                   }
  813.                   // ports B in trunk become port A in link extension
  814.                   if (!in_array($portBtmp$portsA)) {
  815.                     $portsA[] = $portBtmp;
  816.                   }
  817.                 }
  818.               }
  819.             }
  820.           }
  821.         }
  822.         $trunk null;
  823.         foreach ($trunks as $value) {
  824.           if ($ext->getTrunk()) {
  825.             if ($ext->getTrunk()->getId() != $value->getId()) {
  826.               $trunk $value;
  827.               break;
  828.             }
  829.           } else {
  830.             $trunk $value;
  831.             break;
  832.           }
  833.         }
  834.         if ($trunk) {
  835.           // match - trunk found
  836.           // forward direction
  837.           if ($trunk->direction == 'F') {
  838.             foreach ($portsA as $portA) {
  839.               $tcfs $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['trunk' => $trunk'portA' => $portA]);
  840.               if ($tcfs) {
  841.                 // var_dump($tcfs);
  842.                 foreach ($tcfs as $tcf) {
  843.                   // check if extended
  844.                   $isExtended $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tcf]);
  845.                   if ($isExtended) {
  846.                     $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getLastSequenceExtension($tcf);
  847.                     $portsB[] = $tcf->getPortB();
  848.                     $opInt $tcf->getPortB()->getInterfaceSpecific();
  849.                     $opEq $opInt->getEquipmentSpecificMpo() ? $opInt->getEquipmentSpecificMpo() : $opInt->getEquipmentSpecific();
  850.                   } else {
  851.                     $portsB[] = $tcf->getPortB();
  852.                     $opInt $tcf->getPortB()->getInterfaceSpecific();
  853.                     $opEq $opInt->getEquipmentSpecificMpo() ? $opInt->getEquipmentSpecificMpo() : $opInt->getEquipmentSpecific();
  854.                   }
  855.                 }
  856.               }
  857.             }
  858.             // var_dump($portsB);
  859.             // reverse direction
  860.           } else {
  861.             // we have portA for extension
  862.             foreach ($portsA as $portA) {
  863.               // check if in extension
  864.               $tExts $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findBy(['portB' => $portA]);
  865.               if ($tExts) {
  866.                 foreach ($tExts as $tExt) {
  867.                   $tcf $tExt->getTrunkCableFiber();
  868.                   $portsB[] = $tcf->getPortA();
  869.                   $opInt $tcf->getPortA()->getInterfaceSpecific();
  870.                   $opEq $opInt->getEquipmentSpecificMpo() ? $opInt->getEquipmentSpecificMpo() : $opInt->getEquipmentSpecific();
  871.                 }
  872.               }
  873.               // find trunk fibers that ends with portA
  874.               $tcfs $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['trunk' => $trunk'portB' => $portA]);
  875.               if ($tcfs && !$tExts) {
  876.                 // portsB in extension are reversed - portsA in trunk
  877.                 foreach ($tcfs as $tcf) {
  878.                   $portsB[] = $tcf->getPortA();
  879.                   $opInt $tcf->getPortA()->getInterfaceSpecific();
  880.                   $opEq $opInt->getEquipmentSpecificMpo() ? $opInt->getEquipmentSpecificMpo() : $opInt->getEquipmentSpecific();
  881.                 }
  882.               }
  883.             }
  884.           }
  885.           return $this->render('link/extend_trunk_match.html.twig', [
  886.             'action' => 'insert',
  887.             'page_title' => $translator->trans('Extend Link by Trunk'),
  888.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Extend by Trunk'),
  889.             'link' => $link,
  890.             'trunk' => $trunk,
  891.             'eqA' => $lastEq,
  892.             'intA' => $lastInt,
  893.             'portsA' => $portsA,
  894.             'eqB' => $opEq,
  895.             'intB' => $opInt,
  896.             'portsB' => $portsB,
  897.             'nextSequence' => $lastSeq+1
  898.           ]);
  899.         } else {
  900.           // no match - find other trunks on equipment interface!
  901.           $trunks = array();
  902.           $ports $lastInt->getPort();
  903.           foreach ($ports as $port) {
  904.             $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  905.             if ($tcf) {
  906.               $trunk $tcf->getTrunk();
  907.               if ($ext->getTrunk()) {
  908.                 if (!in_array($trunk$trunks) && $ext->getTrunk()->getId() != $trunk->getId()) {
  909.                   $trunk->direction 'F';
  910.                   $trunks[] = $trunk;
  911.                 }
  912.               } else {
  913.                 if (!in_array($trunk$trunks)) {
  914.                   $trunk->direction 'F';
  915.                   $trunks[] = $trunk;
  916.                 }
  917.               }
  918.             }
  919.             $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  920.             if ($tcf) {
  921.               $trunk $tcf->getTrunk();
  922.               if ($ext->getTrunk()) {
  923.                 if (!in_array($trunk$trunks) && $ext->getTrunk()->getId() != $trunk->getId()) {
  924.                   $trunk->direction 'R';
  925.                   $trunks[] = $trunk;
  926.                 }
  927.               } else {
  928.                 if (!in_array($trunk$trunks)) {
  929.                   $trunk->direction 'R';
  930.                   $trunks[] = $trunk;
  931.                 }
  932.               }
  933.             }
  934.             $tExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  935.             if ($tExt) {
  936.               $tcf $tExt->getTrunkCableFiber();
  937.               $trunk $tcf->getTrunk();
  938.               if ($ext->getTrunk()) {
  939.                 if (!in_array($trunk$trunks) && $ext->getTrunk()->getId() != $trunk->getId()) {
  940.                   $trunk->direction 'R';
  941.                   $trunks[] = $trunk;
  942.                 }
  943.               } else {
  944.                 if (!in_array($trunk$trunks)) {
  945.                   $trunk->direction 'R';
  946.                   $trunks[] = $trunk;
  947.                 }
  948.               }
  949.             }
  950.           }
  951.           return $this->render('link/extend_trunk.html.twig', [
  952.             'action' => 'insert',
  953.             'page_title' => $translator->trans('Extend Link by Trunk'),
  954.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Extend by Trunk'),
  955.             'link' => $link,
  956.             'eqLast' => $lastEq,
  957.             'trunks' => $trunks,
  958.             'nextSequence' => $lastSeq+1
  959.           ]);
  960.         }
  961.         break;
  962.         // preassembled
  963.       case 2:
  964.         $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  965.         $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  966.         $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  967.         $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  968.         // $lastExt = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['link' => $link], ['sequenceNo' => 'DESC']);
  969.         // $lastSeq = $lastExt->getSequenceNo();
  970.         // $lastInt = $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific();
  971.         $lastInt $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getPortMpo() ? $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getPortMpo()->getInterfaceSpecific() : $lastExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific();
  972.         // $lastInt = $lastExt->getPortB()->getInterfaceSpecific();
  973.         $lastEq $lastInt->getEquipmentSpecificMpo() ? $lastInt->getEquipmentSpecificMpo() : $lastInt->getEquipmentSpecific();
  974.         // $lastEq = $lastExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  975.         $lastPort = [];
  976.         $lastPortTemp $lastExt->getExtremityB()->getExtensionOrder();
  977.         foreach ($lastPortTemp as $value) {
  978.           $lastPort[] = $value->getPort();
  979.         }
  980.         // $lastPort = $lastExt->getExtremityB()->getPorts();
  981.         // $lastPort = $lastExt->getPortB();
  982.         $lastIntType $lastInt->getInterfaceGeneric()->getTypeInterconnection()->getId();
  983.         if ($lastIntType != 1) { // 1-n // n-n
  984.           return $this->render('link/extend_cable.html.twig', [
  985.             'action' => 'insert',
  986.             'page_title' => $translator->trans('Extend Link by Preassembled Connection'),
  987.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Extend by Preassembled Connection'),
  988.             'link' => $link,
  989.             'sites' => $sites,
  990.             'rackFaces' => $rackFaces,
  991.             'typeCable' => $typeCable,
  992.             'eqGeneric' => $eqGeneric,
  993.             'eqLast' => $lastEq,
  994.             'nextSequence' => $lastSeq+1
  995.           ]);
  996.         } else {
  997.           return $this->render('link/extend_cable_1-1.html.twig', [
  998.             'action' => 'insert',
  999.             'page_title' => $translator->trans('Extend Link by Preassembled Connection'),
  1000.             'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> ' $translator->trans('Extend by Preassembled Connection'),
  1001.             'link' => $link,
  1002.             'sites' => $sites,
  1003.             'rackFaces' => $rackFaces,
  1004.             'typeCable' => $typeCable,
  1005.             'eqGeneric' => $eqGeneric,
  1006.             'eqLast' => $lastEq,
  1007.             'intLast' => $lastInt,
  1008.             'portLast' => $lastPort,
  1009.             'nextSequence' => $lastSeq+1
  1010.           ]);
  1011.         }
  1012.         break;
  1013.     }
  1014.   }
  1015.   /**
  1016.    * @IsGranted("ROLE_CRUD")
  1017.    * @Route("/link/extend", name="link_process_extend")
  1018.    */
  1019.   public function processExtensionsAction(Request $requestTranslatorInterface $translator)
  1020.   {
  1021.     $em $this->getDoctrine()->getManager();
  1022.     $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  1023.     $typeExtension $request->request->get('typeExtension');
  1024.     // $sequenceNumber = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getNextSequenceNo($link);
  1025.     $sequenceNumber $request->request->get('nextSequence');
  1026.     $nbExtensions count($link->getLinkExtension());
  1027.     $lastExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $sequenceNumber 1]);
  1028.     $nextExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $sequenceNumber 1]);
  1029.     $isIntermediateExtension $sequenceNumber <= $nbExtensions;
  1030.     //sq=2, nbExt>=2; after the addition, nbExt=3, 
  1031.     //we have to modify extension number of all the extensions starting from 2
  1032.     if ($isIntermediateExtension) {
  1033.       foreach($link->getLinkExtension() as $ex){
  1034.         if($ex->getSequenceNo() >= $sequenceNumber){
  1035.           $ex->setSequenceNo($ex->getSequenceNo()+1);
  1036.           $em->persist($ex);
  1037.         }
  1038.       }
  1039.     }
  1040.     $ext = new LinkExtension();
  1041.     $portsB = [];//for validation
  1042.     switch ($typeExtension) {
  1043.         // trunk
  1044.       case 1:
  1045.         $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  1046.         $portsA = array();
  1047.         $portA2 null;
  1048.         $portA3 null;
  1049.         $portA4 null;
  1050.         $portA5 null;
  1051.         $portA6 null;
  1052.         $portA7 null;
  1053.         $portA8 null;
  1054.         $portA9 null;
  1055.         $portA10 null;
  1056.         $portA11 null;
  1057.         $portA12 null;
  1058.         $portB2 null;
  1059.         $portB3 null;
  1060.         $portB4 null;
  1061.         $portB5 null;
  1062.         $portB6 null;
  1063.         $portB7 null;
  1064.         $portB8 null;
  1065.         $portB9 null;
  1066.         $portB10 null;
  1067.         $portB11 null;
  1068.         $portB12 null;
  1069.         // get selected ports
  1070.         $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA1'));
  1071.         //$portsA["portA1"] = $portA1;
  1072.         for ($i 2$i <= 12$i++) {
  1073.           if ($request->request->get('pointA' $i) != "") {
  1074.             $temp "portA" $i;
  1075.             $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA' $i));
  1076.           }
  1077.         }
  1078.         // if ($request->request->get('pointA2') != "") {
  1079.         //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA2'));
  1080.         // }
  1081.         $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB1'));
  1082.         $portsB["portB1"] = $portB1;
  1083.         for ($i 2$i <= 12$i++) {
  1084.           if ($request->request->get('pointB' $i) != "") {
  1085.             $temp "portB" $i;
  1086.             $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB' $i));
  1087.             $portsB["portB" $i] = $$temp;
  1088.           }
  1089.         }
  1090.         // if ($request->request->get('pointB2') != "") {
  1091.         //   $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB2'));
  1092.         // }
  1093.         //
  1094.         //i beleive the LinkExtension entity structure has to be modified ??? extremity A/B can have 1 or more ports
  1095.         // // get selected ports
  1096.         // $portsAselected = $request->request->get('pointA');
  1097.         // $portsAids = explode('|',substr($portsAselected, 0, -1));
  1098.         //
  1099.         // foreach ($portsAids as $id){
  1100.         //     $portsA[] = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($id);
  1101.         // }
  1102.         //
  1103.         // $portsBselected = $request->request->get('pointB');
  1104.         // $portsBids = explode('|',substr($portsBselected, 0, -1));
  1105.         //
  1106.         // foreach ($portsBids as $id){
  1107.         //     $portsB[] = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($id);
  1108.         // }
  1109.         // $iterations = [];
  1110.         //
  1111.         // // new iterations
  1112.         // $i = count($portsA);
  1113.         // $j = count($portsB);
  1114.         //
  1115.         // if ($i == $j){ // equal A = B
  1116.         //     for ($k=0; $k<$i; $k++){
  1117.         //        $iterations[] = array($portsA[$k],$portsB[$k]);
  1118.         //     }
  1119.         // }
  1120.         //
  1121.         // if ($i < $j){ // A < B
  1122.         //     for ($k=0; $k<$i; $k++){
  1123.         //         $iterations[] = array($portsA[$k],$portsB[$k]);
  1124.         //     }
  1125.         //     $lastA = end($portsA);
  1126.         //     for ($m=$k; $m<$j; $m++){
  1127.         //         $iterations[] = array($lastA,$portsB[$m]);
  1128.         //     }
  1129.         // }
  1130.         //
  1131.         // if ($i > $j){ // B < A
  1132.         //     for ($k=0; $k<$j; $k++){
  1133.         //         $iterations[] = array($portsA[$k],$portsB[$k]);
  1134.         //     }
  1135.         //     $lastB = end($portsB);
  1136.         //     for ($m=$k; $m<$i; $m++){
  1137.         //         $iterations[] = array($portsA[$m],$lastB);
  1138.         //     }
  1139.         //
  1140.         // }
  1141.         // iterations option deprecated
  1142.         /*foreach($portsA as $portA){
  1143.                     foreach ($portsB as $portB){
  1144.                         $iterations[] = array($portA, $portB);
  1145.                     }
  1146.                 }*/
  1147.         // foreach ($iterations as $it){
  1148.         //
  1149.         //     $ext = new LinkExtension();
  1150.         //
  1151.         //     $ext->setLink($link);
  1152.         //     $ext->setTrunk($trunk);
  1153.         //     $ext->setPortA($it[0]);
  1154.         //     $ext->setPortB($it[1]);
  1155.         //     $ext->setSequenceNo($sequenceNumber);
  1156.         //
  1157.         //     $em->persist($ext);
  1158.         //     $em->flush();
  1159.         //
  1160.         // }
  1161.         $extA = new Extremity();
  1162.         for ($i 1$i <= 12$i++) {
  1163.           $temp "portA" $i;
  1164.           if ($$temp) {
  1165.             $extensinOrder = new ExtensionOrder();
  1166.             $extensinOrder->setOrderNumber($i);
  1167.             $extensinOrder->setPort($$temp);
  1168.             $extensinOrder->setExtremity($extA);
  1169.             $$temp->addExtensionOrder($extensinOrder);
  1170.             $extA->addExtensionOrder($extensinOrder);
  1171.             $em->persist($extensinOrder);
  1172.             // $portA1->setOrderNoExtension(1);
  1173.             // $portA1->addExtremity($extA);
  1174.             $$temp->setLink($link);
  1175.             $$temp->setLinkExtension($ext);
  1176.             $em->persist($$temp);
  1177.             $portsA[] = $$temp;
  1178.           }
  1179.         }
  1180.         // $extensinOrder = new ExtensionOrder();
  1181.         // $extensinOrder->setOrderNumber(1);
  1182.         // $extensinOrder->setPort($portA1);
  1183.         // $extensinOrder->setExtremity($extA);
  1184.         // $portA1->addExtensionOrder($extensinOrder);
  1185.         // $extA->addExtensionOrder($extensinOrder);
  1186.         // $em->persist($extensinOrder);
  1187.         //
  1188.         // // $portA1->setOrderNoExtension(1);
  1189.         // // $portA1->addExtremity($extA);
  1190.         // $portA1->setLink($link);
  1191.         // $portA1->setLinkExtension($ext);
  1192.         // $em->persist($portA1);
  1193.         // // $extA->addPort($portA1);
  1194.         // $portsA[] = $portA1;
  1195.         // if ($portA2) {
  1196.         //
  1197.         //   $extensinOrder = new ExtensionOrder();
  1198.         //   $extensinOrder->setOrderNumber(2);
  1199.         //   $extensinOrder->setPort($portA2);
  1200.         //   $extensinOrder->setExtremity($extA);
  1201.         //   $portA2->addExtensionOrder($extensinOrder);
  1202.         //   $extA->addExtensionOrder($extensinOrder);
  1203.         //   $em->persist($extensinOrder);
  1204.         //
  1205.         //   // $portA2->setOrderNoExtension(2);
  1206.         //   // $portA2->addExtremity($extA);
  1207.         //   $portA2->setLink($link);
  1208.         //   $portA2->setLinkExtension($ext);
  1209.         //   $em->persist($portA2);
  1210.         //   // $extA->addPort($portA2);
  1211.         //   $portsA[] = $portA2;
  1212.         // }
  1213.         // getOtherPorts used by the link
  1214.         $ports $this->getPorts($trunk$portsA$link->getTypeLink());
  1215.         foreach ($ports as $port) {
  1216.           $port->setLink($link);
  1217.           $port->setLinkExtension($ext);
  1218.           $em->persist($port);
  1219.         }
  1220.         $em->persist($extA);
  1221.         $ext->setExtremityA($extA);
  1222.         $extB = new Extremity();
  1223.         for ($i 1$i <= 12$i++) {
  1224.           $temp "portB" $i;
  1225.           if ($$temp) {
  1226.             $extensinOrder = new ExtensionOrder();
  1227.             $extensinOrder->setOrderNumber($i);
  1228.             $extensinOrder->setPort($$temp);
  1229.             $extensinOrder->setExtremity($extB);
  1230.             $$temp->addExtensionOrder($extensinOrder);
  1231.             $extB->addExtensionOrder($extensinOrder);
  1232.             $em->persist($extensinOrder);
  1233.             $$temp->setLink($link);
  1234.             $$temp->setLinkExtension($ext);
  1235.             $em->persist($$temp);
  1236.           }
  1237.         }
  1238.         // $extensinOrder = new ExtensionOrder();
  1239.         // $extensinOrder->setOrderNumber(1);
  1240.         // $extensinOrder->setPort($portB1);
  1241.         // $extensinOrder->setExtremity($extB);
  1242.         // $portB1->addExtensionOrder($extensinOrder);
  1243.         // $extB->addExtensionOrder($extensinOrder);
  1244.         // $em->persist($extensinOrder);
  1245.         //
  1246.         // // $portB1->setOrderNoExtension(1);
  1247.         // // $portB1->addExtremity($extB);
  1248.         // $portB1->setLink($link);
  1249.         // $portB1->setLinkExtension($ext);
  1250.         // $em->persist($portB1);
  1251.         // // $extB->addPort($portB1);
  1252.         // if ($portB2) {
  1253.         //
  1254.         // $extensinOrder = new ExtensionOrder();
  1255.         // $extensinOrder->setOrderNumber(2);
  1256.         // $extensinOrder->setPort($portB2);
  1257.         // $extensinOrder->setExtremity($extB);
  1258.         // $portB2->addExtensionOrder($extensinOrder);
  1259.         // $extB->addExtensionOrder($extensinOrder);
  1260.         // $em->persist($extensinOrder);
  1261.         //
  1262.         // // $portB2->setOrderNoExtension(2);
  1263.         // // $portB2->addExtremity($extB);
  1264.         // $portB2->setLink($link);
  1265.         // $portB2->setLinkExtension($ext);
  1266.         // $em->persist($portB2);
  1267.         // // $extB->addPort($portB2);
  1268.         // }
  1269.         $em->persist($extB);
  1270.         $ext->setExtremityB($extB);
  1271.         $ext->setTrunk($trunk);
  1272.         $ext->setLink($link);
  1273.         $ext->setSequenceNo($sequenceNumber);
  1274.         // $lastExt = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$sequenceNumber-1]);
  1275.         // $lastExt->setIsValid(true);
  1276.         // $lastExt->setError(null);
  1277.         // $em->persist($lastExt);
  1278.         $em->persist($ext);
  1279.         $em->flush();
  1280.         // $extremityA = new Extremity();
  1281.         // foreach ($portsA as $port) {
  1282.         //   $extremityA->addPort($port);
  1283.         //   $port->addExtremity($extremityA);
  1284.         //   $em->persist($port);
  1285.         // }
  1286.         //
  1287.         // $em->persist($extremityA);
  1288.         // $extremityB = new Extremity();
  1289.         // foreach ($portsB as $port) {
  1290.         //   $extremityB->addPort($port);
  1291.         //   $port->addExtremity($extremityB);
  1292.         //   $em->persist($port);
  1293.         // }
  1294.         //
  1295.         //
  1296.         // $em->persist($extremityB);
  1297.         // $ext->setTrunk($trunk);
  1298.         // $ext->setLink($link);
  1299.         // $ext->setExtremityA($extremityA);
  1300.         // $ext->setExtremityB($extremityB);
  1301.         // // $ext->setPortA($it[0]);
  1302.         // // $ext->setPortB($it[1]);
  1303.         // // $ext->setTypeCable($typeCable);
  1304.         // $ext->setSequenceNo($sequenceNumber);
  1305.         //
  1306.         // $em->persist($ext);
  1307.         // $em->flush();
  1308.         break;
  1309.         // preassembled
  1310.       case 2:
  1311.         $redirect false;
  1312.         $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  1313.         $portA2 null;
  1314.         $portA3 null;
  1315.         $portA4 null;
  1316.         $portA5 null;
  1317.         $portA6 null;
  1318.         $portA7 null;
  1319.         $portA8 null;
  1320.         $portA9 null;
  1321.         $portA10 null;
  1322.         $portA11 null;
  1323.         $portA12 null;
  1324.         $portB2 null;
  1325.         $portB3 null;
  1326.         $portB4 null;
  1327.         $portB5 null;
  1328.         $portB6 null;
  1329.         $portB7 null;
  1330.         $portB8 null;
  1331.         $portB9 null;
  1332.         $portB10 null;
  1333.         $portB11 null;
  1334.         $portB12 null;
  1335.         // get selected ports
  1336.         $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA1'));
  1337.         for ($i 2$i <= 12$i++) {
  1338.           if ($request->request->get('pointA' $i) != "") {
  1339.             $temp "portA" $i;
  1340.             $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA' $i));
  1341.           }
  1342.         }
  1343.         // if ($request->request->get('pointA2') != "") {
  1344.         //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA2'));
  1345.         // }
  1346.         $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB1'));
  1347.         $portsB["portB1"] = $portB1;
  1348.         for ($i 2$i <= 12$i++) {
  1349.           if ($request->request->get('pointB' $i) != "") {
  1350.             $temp "portB" $i;
  1351.             $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB' $i));
  1352.             $portsB["portB" $i] = $$temp;
  1353.           }
  1354.         }
  1355.         // $portA1 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA1'));
  1356.         // if ($request->request->get('pointA2') != "") {
  1357.         //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA2'));
  1358.         // }
  1359.         // $portB1 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB1'));
  1360.         // if ($request->request->get('pointB2') != "") {
  1361.         //   $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB2'));
  1362.         // }
  1363.         $nPortsA $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  1364.         if ($nPortsA) {
  1365.           $nPortsA json_decode($nPortsA);
  1366.         } else {
  1367.           $nPortsA = [];
  1368.         }
  1369.         // $nPortsB = $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  1370.         // if ($nPortsB){
  1371.         //     $nPortsB = json_decode($nPortsB);
  1372.         // } else {
  1373.         //     $nPortsB = [];
  1374.         // }
  1375.         $portsAToCheck = array();
  1376.         // $portsBToCheck = array();
  1377.         if (!in_array($portA1->getOrderNo(), $nPortsA)) {
  1378.           $portsAToCheck[] = $portA1;
  1379.         }
  1380.         // if (!in_array($portB1->getOrderNo(), $nPortsB)){
  1381.         //     $portsBToCheck[] = $portB1;
  1382.         // }
  1383.         for ($i 2$i <= 12$i++) {
  1384.           $temp "portA" $i;
  1385.           if ($$temp && !in_array($$temp->getOrderNo(), $nPortsA)) {
  1386.             $portsToCheck[] = $$temp;
  1387.           }
  1388.         }
  1389.         // if ($portA2 && !in_array($portA2->getOrderNo(), $nPortsA)){
  1390.         //     $portsAToCheck[] = $portA2;
  1391.         // }
  1392.         // if ($portB2 && !in_array($portB2->getOrderNo(), $nPortsB)){
  1393.         //     $portsBToCheck[] = $portB2;
  1394.         // }
  1395.         $lastLinkExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $sequenceNumber 1]);
  1396.         foreach ($portsAToCheck as $value) {
  1397.           if ($value->getLink() && $value->getLink()->getId() != $link->getId()) {
  1398.             $this->addFlash(
  1399.               'error',
  1400.               'l\'un des ports Choisis est déjà dans un link'
  1401.             );
  1402.             $redirect true;
  1403.           } elseif ($value->getLinkExtension() && $value->getLinkExtension()->getId() != $lastLinkExtension->getId()) {
  1404.             $this->addFlash(
  1405.               'error',
  1406.               'l\'un des ports Choisis est déjà dans un link'
  1407.             );
  1408.             $redirect true;
  1409.           }
  1410.           if ($redirect) {
  1411.             break;
  1412.           }
  1413.         }
  1414.         if ($redirect) {
  1415.           return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  1416.         }
  1417.         // foreach ($portsBToCheck as $value) {
  1418.         //   if ($value->getLink()) {
  1419.         //     $this->addFlash(
  1420.         //         'error',
  1421.         //         'l\'un des ports Choisis est déjà dans un link'
  1422.         //     );
  1423.         //     $redirect = true;
  1424.         //   }
  1425.         //   if ($redirect) {
  1426.         //     break;
  1427.         //   }
  1428.         // }
  1429.         // if ($redirect) {
  1430.         //   return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  1431.         // }
  1432.         // // get selected ports
  1433.         // $portsAselected = $request->request->get('pointA');
  1434.         // $portsAids = explode('|',substr($portsAselected, 0, -1));
  1435.         //
  1436.         // foreach ($portsAids as $id){
  1437.         //     $portsA[] = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($id);
  1438.         // }
  1439.         //
  1440.         // $portsBselected = $request->request->get('pointB');
  1441.         // $portsBids = explode('|',substr($portsBselected, 0, -1));
  1442.         //
  1443.         // foreach ($portsBids as $id){
  1444.         //     $portsB[] = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($id);
  1445.         // }
  1446.         // $iterations = [];
  1447.         // new iterations
  1448.         // $i = count($portsA);
  1449.         // $j = count($portsB);
  1450.         //
  1451.         // if ($i == $j){ // equal A = B
  1452.         //     for ($k=0; $k<$i; $k++){
  1453.         //         $iterations[] = array($portsA[$k],$portsB[$k]);
  1454.         //     }
  1455.         // }
  1456.         //
  1457.         // if ($i < $j){ // A < B
  1458.         //     for ($k=0; $k<$i; $k++){
  1459.         //         $iterations[] = array($portsA[$k],$portsB[$k]);
  1460.         //     }
  1461.         //     $lastA = end($portsA);
  1462.         //     for ($m=$k; $m<$j; $m++){
  1463.         //         $iterations[] = array($lastA,$portsB[$m]);
  1464.         //     }
  1465.         // }
  1466.         //
  1467.         // if ($i > $j){ // B < A
  1468.         //     for ($k=0; $k<$j; $k++){
  1469.         //         $iterations[] = array($portsA[$k],$portsB[$k]);
  1470.         //     }
  1471.         //     $lastB = end($portsB);
  1472.         //     for ($m=$k; $m<$i; $m++){
  1473.         //         $iterations[] = array($portsA[$m],$lastB);
  1474.         //     }
  1475.         //
  1476.         // }
  1477.         /*foreach($portsA as $portA){
  1478.                     foreach ($portsB as $portB){
  1479.                         $iterations[] = array($portA, $portB);
  1480.                     }
  1481.                 }*/
  1482.         // foreach ($iterations as $it){
  1483.         //
  1484.         //     $ext = new LinkExtension();
  1485.         //
  1486.         //     $ext->setLink($link);
  1487.         //     $ext->setPortA($it[0]);
  1488.         //     $ext->setPortB($it[1]);
  1489.         //     $ext->setTypeCable($typeCable);
  1490.         //     $ext->setSequenceNo($sequenceNumber);
  1491.         //
  1492.         //     $em->persist($ext);
  1493.         //     $em->flush();
  1494.         //
  1495.         // }
  1496.         // $ext = new LinkExtension();
  1497.         $extA = new Extremity();
  1498.         for ($i 1$i <= 12$i++) {
  1499.           $temp "portA" $i;
  1500.           if ($$temp) {
  1501.             $extensinOrder = new ExtensionOrder();
  1502.             $extensinOrder->setOrderNumber($i);
  1503.             $extensinOrder->setPort($$temp);
  1504.             $extensinOrder->setExtremity($extA);
  1505.             $$temp->addExtensionOrder($extensinOrder);
  1506.             $extA->addExtensionOrder($extensinOrder);
  1507.             $em->persist($extensinOrder);
  1508.             // $portA1->setOrderNoExtension(1);
  1509.             // $portA1->addExtremity($extA);
  1510.             $$temp->setLink($link);
  1511.             $$temp->setLinkExtension($ext);
  1512.             $em->persist($$temp);
  1513.           }
  1514.         }
  1515.         // $extensinOrder = new ExtensionOrder();
  1516.         // $extensinOrder->setOrderNumber(1);
  1517.         // $extensinOrder->setPort($portA1);
  1518.         // $extensinOrder->setExtremity($extA);
  1519.         // $portA1->addExtensionOrder($extensinOrder);
  1520.         // $extA->addExtensionOrder($extensinOrder);
  1521.         // $em->persist($extensinOrder);
  1522.         //
  1523.         // // $portA1->setOrderNoExtension(1);
  1524.         // // $portA1->addExtremity($extA);
  1525.         // $portA1->setLink($link);
  1526.         // $portA1->setLinkExtension($ext);
  1527.         //
  1528.         // $em->persist($portA1);
  1529.         // // $extA->addPort($portA1);
  1530.         //
  1531.         // if ($portA2) {
  1532.         //   $extensinOrder = new ExtensionOrder();
  1533.         //   $extensinOrder->setOrderNumber(2);
  1534.         //   $extensinOrder->setPort($portA2);
  1535.         //   $extensinOrder->setExtremity($extA);
  1536.         //   $portA2->addExtensionOrder($extensinOrder);
  1537.         //   $extA->addExtensionOrder($extensinOrder);
  1538.         //   $em->persist($extensinOrder);
  1539.         //
  1540.         //   // $portA2->setOrderNoExtension(2);
  1541.         //   // $portA2->addExtremity($extA);
  1542.         //   $portA2->setLink($link);
  1543.         //   $portA2->setLinkExtension($ext);
  1544.         //   $em->persist($portA2);
  1545.         //   // $extA->addPort($portA2);
  1546.         // }
  1547.         $em->persist($extA);
  1548.         $ext->setExtremityA($extA);
  1549.         $extB = new Extremity();
  1550.         for ($i 1$i <= 12$i++) {
  1551.           $temp "portB" $i;
  1552.           if ($$temp) {
  1553.             $extensinOrder = new ExtensionOrder();
  1554.             $extensinOrder->setOrderNumber($i);
  1555.             $extensinOrder->setPort($$temp);
  1556.             $extensinOrder->setExtremity($extB);
  1557.             $$temp->addExtensionOrder($extensinOrder);
  1558.             $extB->addExtensionOrder($extensinOrder);
  1559.             $em->persist($extensinOrder);
  1560.             $$temp->setLink($link);
  1561.             $$temp->setLinkExtension($ext);
  1562.             $em->persist($$temp);
  1563.           }
  1564.         }
  1565.         // $extensinOrder = new ExtensionOrder();
  1566.         // $extensinOrder->setOrderNumber(1);
  1567.         // $extensinOrder->setPort($portB1);
  1568.         // $extensinOrder->setExtremity($extB);
  1569.         // $portB1->addExtensionOrder($extensinOrder);
  1570.         // $extB->addExtensionOrder($extensinOrder);
  1571.         // $em->persist($extensinOrder);
  1572.         //
  1573.         // // $portB1->setOrderNoExtension(1);
  1574.         // // $portB1->addExtremity($extB);
  1575.         // $portB1->setLink($link);
  1576.         // $portB1->setLinkExtension($ext);
  1577.         // $em->persist($portB1);
  1578.         // // $extB->addPort($portB1);
  1579.         // if ($portB2) {
  1580.         //   $extensinOrder = new ExtensionOrder();
  1581.         //   $extensinOrder->setOrderNumber(2);
  1582.         //   $extensinOrder->setPort($portB2);
  1583.         //   $extensinOrder->setExtremity($extB);
  1584.         //   $portB2->addExtensionOrder($extensinOrder);
  1585.         //   $extB->addExtensionOrder($extensinOrder);
  1586.         //   $em->persist($extensinOrder);
  1587.         //
  1588.         //   // $portB2->setOrderNoExtension(2);
  1589.         //   // $portB2->addExtremity($extB);
  1590.         //   $portB2->setLink($link);
  1591.         //   $portB2->setLinkExtension($ext);
  1592.         //   $em->persist($portB2);
  1593.         //   // $extB->addPort($portB2);
  1594.         // }
  1595.         $em->persist($extB);
  1596.         $ext->setExtremityB($extB);
  1597.         $ext->setLink($link);
  1598.         $ext->setTypeCable($typeCable);
  1599.         $ext->setSequenceNo($sequenceNumber);
  1600.         // $lastExt = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$sequenceNumber-1]);
  1601.         // $lastExt->setIsValid(true);
  1602.         // $lastExt->setError(null);
  1603.         // $em->persist($lastExt);
  1604.         $em->persist($ext);
  1605.         $em->flush();
  1606.         // $ext = new LinkExtension();
  1607.         // $extremityA = new Extremity();
  1608.         // foreach ($portsA as $port) {
  1609.         //   $extremityA->addPort($port);
  1610.         //   $port->addExtremity($extremityA);
  1611.         //   $em->persist($port);
  1612.         // }
  1613.         //
  1614.         // $em->persist($extremityA);
  1615.         // $extremityB = new Extremity();
  1616.         // foreach ($portsB as $port) {
  1617.         //   $extremityB->addPort($port);
  1618.         //   $port->addExtremity($extremityB);
  1619.         //   $em->persist($port);
  1620.         // }
  1621.         //
  1622.         //
  1623.         // $em->persist($extremityB);
  1624.         // $ext->setTrunk($trunk);
  1625.         // $ext->setLink($link);
  1626.         // $ext->setExtremityA($extremityA);
  1627.         // $ext->setExtremityB($extremityB);
  1628.         // // $ext->setPortA($it[0]);
  1629.         // // $ext->setPortB($it[1]);
  1630.         // $ext->setTypeCable($typeCable);
  1631.         // $ext->setSequenceNo($sequenceNumber);
  1632.         //
  1633.         // $em->persist($ext);
  1634.         // $em->flush();
  1635.         break;
  1636.     }
  1637.     if($isIntermediateExtension){
  1638.       LinkController::validateNextExtension($em$link$ext$portsB);
  1639.     }
  1640.     $lastExtension->setIsValid(true);
  1641.     $lastExtension->setError(null);
  1642.     $em->persist($lastExtension);
  1643.     $em->flush();
  1644.     // redirect to link view
  1645.     return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  1646.   }
  1647.   /**
  1648.    * @Route("/link/list", name="link_list")
  1649.    */
  1650.   public function listAction(Request $requestTranslatorInterface $translator)
  1651.   {
  1652.     // $cache = new FilesystemAdapter();
  1653.     // $linkList = $cache->getItem('pagerfanta.list.link"');
  1654.     // $linkList->expiresAfter(1);
  1655.     $links null;
  1656.     // if (!$linkList->isHit()) {
  1657.     $links $this->getDoctrine()->getRepository('App\Entity\Link')->findAll();
  1658.     foreach ($links as $link) {
  1659.       $extensions $link->getLinkExtension();
  1660.       $link->totalExts=0;
  1661.       if (!($extensions->isEmpty())) {
  1662.         $firstExt $extensions[0];
  1663.         // var_dump($firstExt->getSequenceNo());
  1664.         $portsA = [];
  1665.         $portAOrderNos = array();
  1666.         $portsATemp $firstExt->getExtremityA()->getExtensionOrder();
  1667.         foreach ($portsATemp as $value) {
  1668.           $portsA[] = $value->getPort();
  1669.           // $tempMpo = $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() ? $value->getPort()->getPortMpo()->getAlias() . "|" : $value->getPort()->getPortMpo()->getOrderNo() . "|" : "";
  1670.           $portAOrderNos[$value->getOrderNumber() - 1] = $value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  1671.         }
  1672.         // $portsA = $firstExt->getExtremityA()->getPorts();
  1673.         $eqA $portsA[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portsA[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portsA[0]->getInterfaceSpecific()->getEquipmentSpecific();
  1674.         $intA $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portsA[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  1675.         $link->eqA $eqA;
  1676.         $link->intA $intA;
  1677.         // $portAOrderNos = array();
  1678.         // foreach ($portsA as $portA) {
  1679.         //   $portAOrderNos[$portA->getOrderNoExtension()-1] = $portA->getOrderNo();
  1680.         // }
  1681.         $portAOrderNos array_unique($portAOrderNos);
  1682.         ksort($portAOrderNos);
  1683.         $link->portA implode("/"$portAOrderNos);
  1684.         // $eqB = $firstExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific()->getEquipmentSpecific();
  1685.         $portBOrderNos = array();
  1686.         $lastExt $extensions[count($extensions) - 1];
  1687.         $portsB = [];
  1688.         $portsBTemp $lastExt->getExtremityB()->getExtensionOrder();
  1689.         foreach ($portsBTemp as $value) {
  1690.           $portsB[] = $value->getPort();
  1691.           $portBOrderNos[$value->getOrderNumber() - 1] = $value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  1692.         }
  1693.         // $portsB = $extension->getExtremityB()->getPorts();
  1694.         if (count($portsB) > 0) {
  1695.           $eqB $portsB[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portsB[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portsB[0]->getInterfaceSpecific()->getEquipmentSpecific();
  1696.           $intB $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portsB[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  1697.         }
  1698.         $link->eqB $eqB;
  1699.         $link->intB $intB;
  1700.         $portBOrderNos array_unique($portBOrderNos);
  1701.         ksort($portBOrderNos);
  1702.         $link->portB implode("/"$portBOrderNos);
  1703.         $link->totalExts count($link->getLinkExtension());
  1704.       }
  1705.     }
  1706.     // $linkList->expiresAfter(1);
  1707.     //   $cache->save($linkList->set($links));
  1708.     // }
  1709.     // else {
  1710.     //   $links = $linkList->get();
  1711.     //   // var_dump($links);
  1712.     // }
  1713.     // var_dump($links);
  1714.     //pagerfanta starts
  1715.     // $adapter = new ArrayAdapter($links);
  1716.     // $pagerfanta = new Pagerfanta($adapter);
  1717.     // $pageLength = $request->query->get("pageLength", $this->getParameter("link.maxPerPage"));
  1718.     // if ($pageLength == "Tout") {
  1719.     //   $pagerfanta->setMaxPerPage(count($links)); // 10 by default
  1720.     // }
  1721.     // else {
  1722.     //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  1723.     // }
  1724.     // // $this->container->setParameter("link.maxPerPage", $pageLength);
  1725.     // $page = $request->query->get("page", 1);
  1726.     // $pagerfanta->setCurrentPage($page);
  1727.     //pagerfanta ends
  1728.     // $maxPerPage = $pagerfanta->getMaxPerPage();
  1729.     // $pagerfanta->setCurrentPage($currentPage); // 1 by default
  1730.     // $currentPage = $pagerfanta->getCurrentPage();
  1731.     // $nbResults = $pagerfanta->getNbResults();
  1732.     // $currentPageResults = $pagerfanta->getCurrentPageResults();
  1733.     // var_dump($nbResults);
  1734.     // $pagerfanta->getNbPages();
  1735.     // $pagerfanta->haveToPaginate(); // whether the number of results is higher than the max per page
  1736.     //
  1737.     // $pagerfanta->hasPreviousPage();
  1738.     // $pagerfanta->getPreviousPage();
  1739.     // $pagerfanta->hasNextPage();
  1740.     // $pagerfanta->getNextPage();
  1741.     // $pagerfanta->getCurrentPageOffsetStart();
  1742.     // $pagerfanta->getCurrentPageOffsetEnd();
  1743.     return $this->render('link/list.html.twig', [
  1744.       'action' => 'list',
  1745.       'page_title' => $translator->trans('Links'),
  1746.       'list' => $links,
  1747.       // 'my_pager' => $pagerfanta,
  1748.       // 'pageLength' => $pageLength,
  1749.     ]);
  1750.   }
  1751.   /**
  1752.    * @Route("/link/view/{id}", name="link_view")
  1753.    */
  1754.   public function viewAction($idTranslatorInterface $translator)
  1755.   {
  1756.     $em $this->getDoctrine()->getManager();
  1757.     $link $em->getRepository(Link::class)->find($id);
  1758.     $typeUsage $this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findAll();
  1759.     $typeLink $this->getDoctrine()->getRepository('App\Entity\TypeLink')->findAll();
  1760.     $linkValidationList '';
  1761.     // $validationPorts = [];
  1762.     //
  1763.     // $linkValidations = $em->getRepository(LinkValidation::class)->findBy(['link' => $link]);
  1764.     // if ($linkValidations){
  1765.     //
  1766.     //     $linkValidationList = [];
  1767.     //
  1768.     //     foreach ($linkValidations as $linkValidation){
  1769.     //
  1770.     //         $linkValidationList[] = array('trunk_id' => $linkValidation->getTrunk()->getId(), 'trunkID' =>  $linkValidation->getTrunk()->getTrunkID());
  1771.     //         $validationPorts[] = $linkValidation->getPort();
  1772.     //
  1773.     //     }
  1774.     //
  1775.     // }
  1776.     // $linkExtensions = $link->getLinkExtension();
  1777.     //to be modified
  1778.     // foreach ($linkExtensions as $linkExtension){
  1779.     //
  1780.     //     $portsA = $linkExtension->getExtremityA()->getPorts();
  1781.     //     $portsB = $linkExtension->getExtremityB()->getPorts();
  1782.     //     foreach ($portsA as $portA) {
  1783.     //       if (in_array($portA, $validationPorts)){
  1784.     //
  1785.     //           $linkExtension->toValidate = true;
  1786.     //
  1787.     //       } else {
  1788.     //
  1789.     //           $linkExtension->toValidate = false;
  1790.     //
  1791.     //       }
  1792.     //
  1793.     //
  1794.     //     }
  1795.     //     foreach ($portsB as $portB) {
  1796.     //       if (in_array($portB, $validationPorts)){
  1797.     //
  1798.     //           $linkExtension->toValidate = true;
  1799.     //
  1800.     //       } else {
  1801.     //
  1802.     //           $linkExtension->toValidate = false;
  1803.     //
  1804.     //       }
  1805.     //     }
  1806.     //
  1807.     //
  1808.     //
  1809.     // }
  1810.     // var_dump($link->getLinkExtension()[0]->getExtremityA());
  1811.     return $this->render('link/list_details.html.twig', [
  1812.       'action' => 'list',
  1813.       'page_title' => $translator->trans('Link') . ' ' $link->getLinkID(),
  1814.       'link' => $link,
  1815.       'typeUsage' => $typeUsage,
  1816.       'typeLink' => $typeLink,
  1817.       'linkValidationList' => $linkValidationList
  1818.     ]);
  1819.   }
  1820.   /**
  1821.    * @Route("/link/duplicate/{id}", name="link_duplicate")
  1822.    */
  1823.   public function duplicateAction($idTranslatorInterface $translator)
  1824.   {
  1825.     $em $this->getDoctrine()->getManager();
  1826.     $link $em->getRepository(Link::class)->find($id);
  1827.     $typeUsage $this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findAll();
  1828.     $typeLink $this->getDoctrine()->getRepository('App\Entity\TypeLink')->findAll();
  1829.     $linkID $this->getDoctrine()->getRepository('App\Entity\Link')->getNewId();
  1830.     $extensions = [];
  1831.     $linkExtensions $link->getLinkExtension();
  1832.     $e 1;
  1833.     $t 0;
  1834.     $tsn 0;
  1835.     foreach ($linkExtensions as $linkExtension) {
  1836.       $portA $linkExtension->getExtremityA()->getExtensionOrder()[0]->getPort();
  1837.       $portB $linkExtension->getExtremityB()->getExtensionOrder()[0]->getPort();
  1838.       // $portA = $linkExtension->getPortA();
  1839.       // $portB = $linkExtension->getPortB();
  1840.       $trunk $linkExtension->getTrunk();
  1841.       $typeCable $linkExtension->getTypeCable();
  1842.       if ($trunk) {
  1843.         if ($linkExtension->getSequenceNo() != $tsn) {
  1844.           $t $t 1;
  1845.           $tsn $linkExtension->getSequenceNo();
  1846.         }
  1847.         $extension['connection'] = $trunk->getTrunkID();
  1848.         $extension['isTrunk'] = "true";
  1849.       } else {
  1850.         $e $linkExtension->getSequenceNo() - $t;
  1851.         if ($e 1) {
  1852.           $extension['connection'] = "E" . ($e 1);
  1853.         } else {
  1854.           $extension['connection'] = "";
  1855.         }
  1856.         $extension['isTrunk'] = "false";
  1857.       }
  1858.       $interfaceA $portA->getInterfaceSpecific();
  1859.       $equipmentA $interfaceA->getEquipmentSpecificMpo() ? $interfaceA->getEquipmentSpecificMpo() : $interfaceA->getEquipmentSpecific();
  1860.       $extension['siteA'] = $equipmentA->getRack()->getRoom()->getSite()->getTitle();
  1861.       $extension['roomA'] = $equipmentA->getRack()->getRoom()->getTitle();
  1862.       $extension['rackA'] = $equipmentA->getRack()->getTitle();
  1863.       $extension['equipmentA'] = "";
  1864.       if ($equipmentA->getParent()) {
  1865.         $extension['equipmentA'] = $equipmentA->getParent()->getEquipmentSpecificName() . " â•‘ " $equipmentA->getEquipmentSpecificName();
  1866.       } elseif ($equipmentA->getChassisParent()) {
  1867.         $extension['equipmentA'] = $equipmentA->getChassisParent()->getEquipmentSpecificName() . " â•‘ " $equipmentA->getEquipmentSpecificName();
  1868.       } else {
  1869.         $extension['equipmentA'] = $equipmentA->getEquipmentSpecificName();
  1870.       }
  1871.       $extension['interfaceA'] = $portA->getPortMpo() ? $portA->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portA->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  1872.       $extension['typeLinkA'] = $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
  1873.       $extension['typeInterConnectionA'] = $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeInterconnection()->getTitle();
  1874.       $portsA = [];
  1875.       $ports $interfaceA->getPort();
  1876.       $nPorts $interfaceA->getInterfaceGeneric()->getNPorts();
  1877.       if ($nPorts) {
  1878.         $nPorts json_decode($nPorts);
  1879.       } else {
  1880.         $nPorts = array();
  1881.       }
  1882.       foreach ($ports as $port) {
  1883.         $used 0;
  1884.         // if ($trunk) {
  1885.         //   $tcfsA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  1886.         //   $tcfsB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1887.         //   $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1888.         //   if (!$tcfsA && !$tcfsB && !$usedExt) {
  1889.         //     $used = 1;
  1890.         //   }
  1891.         //   elseif (in_array($port->getOrderNo(), $nPorts)){
  1892.         //     $used = 0;
  1893.         //   }
  1894.         //   else {
  1895.         //     $tcfsB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1896.         //
  1897.         //     if ($tcfsB && count($tcfsB->getExtensions()) > 0) {
  1898.         //       $used = 1;
  1899.         //     }
  1900.         //     $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1901.         //
  1902.         //     if ($usedExt) {
  1903.         //       $tcf = $usedExt->getTrunkCableFiber();
  1904.         //       $len = count($tcf->getExtensions());
  1905.         //       if ($len != $usedExt->getSequenceNo()) {
  1906.         //         $used = 1;
  1907.         //       }
  1908.         //     }
  1909.         //     if (count($port->getExtensionOrder()) > 0) {
  1910.         //       $used = 1;
  1911.         //     }
  1912.         //   }
  1913.         // }
  1914.         // else {
  1915.         //   if (in_array($port->getOrderNo(), $nPorts)){
  1916.         //       $used = 0;
  1917.         //   }
  1918.         //   else {
  1919.         //     $tcfsB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1920.         //
  1921.         //     if ($tcfsB && count($tcfsB->getExtensions()) > 0) {
  1922.         //       $used = 1;
  1923.         //     }
  1924.         //     $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1925.         //
  1926.         //     if ($usedExt) {
  1927.         //       $tcf = $usedExt->getTrunkCableFiber();
  1928.         //       $len = count($tcf->getExtensions());
  1929.         //       if ($len != $usedExt->getSequenceNo()) {
  1930.         //         $used = 1;
  1931.         //       }
  1932.         //     }
  1933.         //     if (count($port->getExtensionOrder()) > 0) {
  1934.         //       $used = 1;
  1935.         //     }
  1936.         //   }
  1937.         // }
  1938.         if (in_array($port->getOrderNo(), $nPorts)) {
  1939.           $used 0;
  1940.         } else {
  1941.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  1942.           if ($tcfsB && count($tcfsB->getExtensions()) > 0) {
  1943.             $used 1;
  1944.           }
  1945.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1946.           if ($usedExt) {
  1947.             $tcf $usedExt->getTrunkCableFiber();
  1948.             $len count($tcf->getExtensions());
  1949.             if ($len != $usedExt->getSequenceNo()) {
  1950.               $used 1;
  1951.             }
  1952.           }
  1953.           if (count($port->getExtensionOrder()) > 0) {
  1954.             $used 1;
  1955.           }
  1956.         }
  1957.         if ($trunk) {
  1958.           $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portA" => $port"trunk" => $trunk]);
  1959.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portB" => $port"trunk" => $trunk]);
  1960.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  1961.           if ($usedExt) {
  1962.             $tcf $usedExt->getTrunkCableFiber();
  1963.             if ($tcf->getTrunk()->getId() == $trunk->getId()) {
  1964.               $usedExt true;
  1965.             } else {
  1966.               $usedExt false;
  1967.             }
  1968.           }
  1969.           if (!$tcfsA && !$tcfsB && !$usedExt) {
  1970.             $used 1;
  1971.           }
  1972.         }
  1973.         // $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  1974.         // $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  1975.         //
  1976.         // if ($linkExtA || $linkExtB){
  1977.         //     $used = 1;
  1978.         // }
  1979.         // $portTemp = new Port();
  1980.         $portTemp = clone $port;
  1981.         $portTemp->used $used;
  1982.         // $port->used = $used;
  1983.         $portsA[] = $portTemp;
  1984.       }
  1985.       $extension['portsA'] = $portsA;
  1986.       $extension['numberOfLoopsA'] = $this->getNumberOfLoops($link->getTypeLink()->getTitle(), $interfaceA->getInterfaceGeneric()->getTypeLink()->getTitle());
  1987.       $interfaceB $portB->getInterfaceSpecific();
  1988.       $equipmentB $interfaceB->getEquipmentSpecificMpo() ? $interfaceB->getEquipmentSpecificMpo() : $interfaceB->getEquipmentSpecific();
  1989.       $extension['siteB'] = $equipmentB->getRack()->getRoom()->getSite()->getTitle();
  1990.       $extension['roomB'] = $equipmentB->getRack()->getRoom()->getTitle();
  1991.       $extension['rackB'] = $equipmentB->getRack()->getTitle();
  1992.       $extension['equipmentB'] = "";
  1993.       if ($equipmentB->getParent()) {
  1994.         $extension['equipmentB'] = $equipmentB->getParent()->getEquipmentSpecificName() . " â•‘ " $equipmentB->getEquipmentSpecificName();
  1995.       } elseif ($equipmentB->getChassisParent()) {
  1996.         $extension['equipmentB'] = $equipmentB->getChassisParent()->getEquipmentSpecificName() . " â•‘ " $equipmentB->getEquipmentSpecificName();
  1997.       } else {
  1998.         $extension['equipmentB'] = $equipmentB->getEquipmentSpecificName();
  1999.       }
  2000.       $extension['interfaceB'] = $portB->getPortMpo() ? $portB->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portB->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2001.       $extension['typeLinkB'] = $portB->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
  2002.       $extension['typeLinkB'] = $portB->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
  2003.       $extension['typeInterConnectionB'] = $portB->getInterfaceSpecific()->getInterfaceGeneric()->getTypeInterconnection()->getTitle();
  2004.       $portsB = [];
  2005.       $ports $interfaceB->getPort();
  2006.       $nPorts $interfaceB->getInterfaceGeneric()->getNPorts();
  2007.       if ($nPorts) {
  2008.         $nPorts json_decode($nPorts);
  2009.       } else {
  2010.         $nPorts = array();
  2011.       }
  2012.       foreach ($ports as $port) {
  2013.         $used 0;
  2014.         if (in_array($port->getOrderNo(), $nPorts)) {
  2015.           $used 0;
  2016.         } else {
  2017.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2018.           if ($tcfsB && count($tcfsB->getExtensions()) > 0) {
  2019.             $used 1;
  2020.           }
  2021.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2022.           if ($usedExt) {
  2023.             $tcf $usedExt->getTrunkCableFiber();
  2024.             $len count($tcf->getExtensions());
  2025.             if ($len != $usedExt->getSequenceNo()) {
  2026.               $used 1;
  2027.             }
  2028.           }
  2029.           if (count($port->getExtensionOrder()) > 0) {
  2030.             $used 1;
  2031.           }
  2032.         }
  2033.         if ($trunk) {
  2034.           $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portA" => $port"trunk" => $trunk]);
  2035.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portB" => $port"trunk" => $trunk]);
  2036.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2037.           if ($usedExt) {
  2038.             $tcf $usedExt->getTrunkCableFiber();
  2039.             if ($tcf->getTrunk()->getId() == $trunk->getId()) {
  2040.               $usedExt true;
  2041.             } else {
  2042.               $usedExt false;
  2043.             }
  2044.           }
  2045.           if (!$tcfsA && !$tcfsB && !$usedExt) {
  2046.             $used 1;
  2047.           }
  2048.         }
  2049.         // if (count($port->getExtensionOrder()) >= 1 ){
  2050.         //   $used = 1;
  2051.         // }
  2052.         // $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  2053.         // $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
  2054.         //
  2055.         // if ($linkExtA || $linkExtB){
  2056.         //     $used = 1;
  2057.         // }
  2058.         $portTemp = clone $port;
  2059.         $portTemp->used $used;
  2060.         // $port->used = $used;
  2061.         $portsB[] = $portTemp;
  2062.         // $port->used = $used;
  2063.         // $portsB[] = $port;
  2064.       }
  2065.       $extension['portsB'] = $portsB;
  2066.       $extension['numberOfLoopsB'] = $this->getNumberOfLoops($link->getTypeLink()->getTitle(), $interfaceB->getInterfaceGeneric()->getTypeLink()->getTitle());
  2067.       $extensions[] = $extension;
  2068.     }
  2069.     return $this->render('link/duplicate.html.twig', [
  2070.       'action' => 'list',
  2071.       'page_title' => $translator->trans('Duplicate Link') . ' ' $link->getLinkID(),
  2072.       'link' => $link,
  2073.       'typeUsage' => $typeUsage,
  2074.       'typeLink' => $typeLink,
  2075.       'extensions' => $extensions,
  2076.       'link_ID' => $linkID
  2077.     ]);
  2078.   }
  2079.   public function getNumberOfLoops($typeLinkTitle$interfaceTypeLinkTitle)
  2080.   {
  2081.     $nbLoop 0;
  2082.     if ($typeLinkTitle == $interfaceTypeLinkTitle) {
  2083.       $nbLoop 0;
  2084.     } else if ($typeLinkTitle == "Duplex" && $interfaceTypeLinkTitle == "Simplex") {
  2085.       $nbLoop 2;
  2086.     } else if ($typeLinkTitle == "Triplex" && $interfaceTypeLinkTitle == "Simplex") {
  2087.       $nbLoop 3;
  2088.     } else if ($typeLinkTitle == "Quadruplex" && $interfaceTypeLinkTitle == "Simplex") {
  2089.       $nbLoop 4;
  2090.     } else if ($typeLinkTitle == "Pentaplex" && $interfaceTypeLinkTitle == "Simplex") {
  2091.       $nbLoop 5;
  2092.     } else if ($typeLinkTitle == "6" && $interfaceTypeLinkTitle == "Simplex") {
  2093.       $nbLoop 6;
  2094.     } else if ($typeLinkTitle == "7" && $interfaceTypeLinkTitle == "Simplex") {
  2095.       $nbLoop 7;
  2096.     } else if ($typeLinkTitle == "8" && $interfaceTypeLinkTitle == "Simplex") {
  2097.       $nbLoop 8;
  2098.     } else if ($typeLinkTitle == "9" && $interfaceTypeLinkTitle == "Simplex") {
  2099.       $nbLoop 9;
  2100.     } else if ($typeLinkTitle == "10" && $interfaceTypeLinkTitle == "Simplex") {
  2101.       $nbLoop 10;
  2102.     } else if ($typeLinkTitle == "11" && $interfaceTypeLinkTitle == "Simplex") {
  2103.       $nbLoop 11;
  2104.     } else if ($typeLinkTitle == "12" && $interfaceTypeLinkTitle == "Simplex") {
  2105.       $nbLoop 12;
  2106.     } else if (($typeLinkTitle == "Triplex" || $typeLinkTitle == "Quadruplex") && $interfaceTypeLinkTitle == "Duplex") {
  2107.       $nbLoop 2;
  2108.     } else if (($typeLinkTitle == "Pentaplex" || $typeLinkTitle == "6") && $interfaceTypeLinkTitle == "Duplex") {
  2109.       $nbLoop 3;
  2110.     } else if (($typeLinkTitle == "7" || $typeLinkTitle == "8") && $interfaceTypeLinkTitle == "Duplex") {
  2111.       $nbLoop 4;
  2112.     } else if (($typeLinkTitle == "9" || $typeLinkTitle == "10") && $interfaceTypeLinkTitle == "Duplex") {
  2113.       $nbLoop 5;
  2114.     } else if (($typeLinkTitle == "11" || $typeLinkTitle == "12") && $interfaceTypeLinkTitle == "Duplex") {
  2115.       $nbLoop 6;
  2116.     } else if (($typeLinkTitle == "Quadruplex" || $typeLinkTitle == "Pentaplex" || $typeLinkTitle == "6") && $interfaceTypeLinkTitle == "Triplex") {
  2117.       $nbLoop 2;
  2118.     } else if (($typeLinkTitle == "8" || $typeLinkTitle == "8" || $typeLinkTitle == "9") && $interfaceTypeLinkTitle == "Triplex") {
  2119.       $nbLoop 3;
  2120.     } else if (($typeLinkTitle == "10" || $typeLinkTitle == "11" || $typeLinkTitle == "12") && $interfaceTypeLinkTitle == "Triplex") {
  2121.       $nbLoop 4;
  2122.     } else if (($typeLinkTitle == "Pentaplex" || $typeLinkTitle == "6" || $typeLinkTitle == "7" || $typeLinkTitle == "8") && $interfaceTypeLinkTitle == "Quadruplex") {
  2123.       $nbLoop 2;
  2124.     } else if (($typeLinkTitle == "9" || $typeLinkTitle == "10" || $typeLinkTitle == "11" || $typeLinkTitle == "12") && $interfaceTypeLinkTitle == "Quadruplex") {
  2125.       $nbLoop 3;
  2126.     } else if (($typeLinkTitle == "6" || $typeLinkTitle == "7" || $typeLinkTitle == "8" || $typeLinkTitle == "9" || $typeLinkTitle == "10") && $interfaceTypeLinkTitle == "Pentaplex") {
  2127.       $nbLoop 2;
  2128.     } else if (($typeLinkTitle == "11" || $typeLinkTitle == "12") && $interfaceTypeLinkTitle == "Pentaplex") {
  2129.       $nbLoop 3;
  2130.     }
  2131.     return $nbLoop;
  2132.   }
  2133.   /**
  2134.    * @Route("/link/process/duplicate", name="link_duplicate_process")
  2135.    */
  2136.   public function duplicateProcessAction(Request $requestTranslatorInterface $translator)
  2137.   {
  2138.     $em $this->getDoctrine()->getManager();
  2139.     $link = new Link();
  2140.     $link->setLinkID($request->request->get('linkID'));
  2141.     $link->setOwner($request->request->get('owner'));
  2142.     $link->setTypeUsage($this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findOneById($request->request->get('typeUsage')));
  2143.     $link->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneById($request->request->get('typeLink')));
  2144.     $em->persist($link);
  2145.     // $em->flush();
  2146.     $duplicatedLink $this->getDoctrine()->getRepository('App\Entity\Link')->find($request->request->get('link_id'));
  2147.     $duplicatedLinkExtensions $duplicatedLink->getLinkExtension();
  2148.     if ($duplicatedLinkExtensions) {
  2149.       $i 1;
  2150.       $portOldB1 null;
  2151.       $portOldB2 null;
  2152.       foreach ($duplicatedLinkExtensions as $duplicatedLinkExtension) {
  2153.         $portsA = array();
  2154.         $trunk $duplicatedLinkExtension->getTrunk();
  2155.         $typeCable $duplicatedLinkExtension->getTypeCable();
  2156.         $ext = new LinkExtension();
  2157.         $portA2 null;
  2158.         $portB2 null;
  2159.         $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['portA1_' $i]);
  2160.         if ($i 1) {
  2161.           if ($portOldB1->getInterfaceSpecific()->getInterfaceGeneric()->getTypeInterconnection()->getTitle() == '1-1') {
  2162.             if ($portA1 != $portOldB1) {
  2163.               $ext->setIsValid(false);
  2164.               if ($ext->getError()) {
  2165.                 $ext->setError($ext->getError() . "," "PortA");
  2166.               } else {
  2167.                 $ext->setError("PortA");
  2168.               }
  2169.             }
  2170.           }
  2171.         }
  2172.         if ($trunk) {
  2173.           $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portA1);
  2174.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portA1);
  2175.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA1);
  2176.           if (!$tcfsA && !$tcfsB && !$usedExt) {
  2177.             $this->addFlash(
  2178.               'error',
  2179.               'Opération Ã©chouée'
  2180.             );
  2181.             return $this->redirectToRoute('link_list');
  2182.           }
  2183.         }
  2184.         if ($_POST['portA2_' $i]) {
  2185.           $portA2 $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['portA2_' $i]);
  2186.           if ($i 1) {
  2187.             if ($portOldB2->getInterfaceSpecific()->getInterfaceGeneric()->getTypeInterconnection()->getTitle() == '1-1') {
  2188.               if ($portA2 != $portOldB2) {
  2189.                 $ext->setIsValid(false);
  2190.                 if ($ext->getError()) {
  2191.                   $ext->setError($ext->getError() . "," "PortA");
  2192.                 } else {
  2193.                   $ext->setError("PortA");
  2194.                 }
  2195.               }
  2196.             }
  2197.           }
  2198.           if ($trunk) {
  2199.             $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portA2);
  2200.             $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portA2);
  2201.             $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA2);
  2202.             if (!$tcfsA && !$tcfsB && !$usedExt) {
  2203.               $this->addFlash(
  2204.                 'error',
  2205.                 'Opération Ã©chouée'
  2206.               );
  2207.               return $this->redirectToRoute('link_list');
  2208.             }
  2209.           }
  2210.         }
  2211.         $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['portB1_' $i]);
  2212.         $portOldB1 $portB1;
  2213.         if ($trunk) {
  2214.           $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portB1);
  2215.           $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portB1);
  2216.           $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB1);
  2217.           if (!$tcfsA && !$tcfsB && !$usedExt) {
  2218.             $this->addFlash(
  2219.               'error',
  2220.               'Opération Ã©chouée'
  2221.             );
  2222.             return $this->redirectToRoute('link_list');
  2223.           }
  2224.         }
  2225.         if ($_POST['portB2_' $i]) {
  2226.           $portB2 $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['portB2_' $i]);
  2227.           $portOldB2 $portB2;
  2228.           if ($trunk) {
  2229.             $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portB2);
  2230.             $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portB2);
  2231.             $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB2);
  2232.             if (!$tcfsA && !$tcfsB && !$usedExt) {
  2233.               $this->addFlash(
  2234.                 'error',
  2235.                 'Opération Ã©chouée'
  2236.               );
  2237.               return $this->redirectToRoute('link_list');
  2238.             }
  2239.           }
  2240.         }
  2241.         $ext->setLink($link);
  2242.         $portsA[] = $portA1;
  2243.         $extA = new Extremity();
  2244.         $extensinOrder = new ExtensionOrder();
  2245.         $extensinOrder->setOrderNumber(1);
  2246.         $extensinOrder->setPort($portA1);
  2247.         $extensinOrder->setExtremity($extA);
  2248.         $portA1->addExtensionOrder($extensinOrder);
  2249.         $extA->addExtensionOrder($extensinOrder);
  2250.         $em->persist($extensinOrder);
  2251.         // $portA1->setOrderNoExtension(1);
  2252.         // $portA1->addExtremity($extA);
  2253.         $portA1->setLink($link);
  2254.         $portA1->setLinkExtension($ext);
  2255.         $em->persist($portA1);
  2256.         // $extA->addPort($portA1);
  2257.         if ($portA2) {
  2258.           $portsA[] = $portA2;
  2259.           $extensinOrder = new ExtensionOrder();
  2260.           $extensinOrder->setOrderNumber(2);
  2261.           $extensinOrder->setPort($portA2);
  2262.           $extensinOrder->setExtremity($extA);
  2263.           $portA2->addExtensionOrder($extensinOrder);
  2264.           $extA->addExtensionOrder($extensinOrder);
  2265.           $em->persist($extensinOrder);
  2266.           // $portA2->setOrderNoExtension(2);
  2267.           // $portA2->addExtremity($extA);
  2268.           $portA2->setLink($link);
  2269.           $portA2->setLinkExtension($ext);
  2270.           $em->persist($portA2);
  2271.           // $extA->addPort($portA2);
  2272.         }
  2273.         $em->persist($extA);
  2274.         $ext->setExtremityA($extA);
  2275.         $extB = new Extremity();
  2276.         $extensinOrder = new ExtensionOrder();
  2277.         $extensinOrder->setOrderNumber(1);
  2278.         $extensinOrder->setPort($portB1);
  2279.         $extensinOrder->setExtremity($extB);
  2280.         $portB1->addExtensionOrder($extensinOrder);
  2281.         $extB->addExtensionOrder($extensinOrder);
  2282.         $em->persist($extensinOrder);
  2283.         // $portB1->setOrderNoExtension(1);
  2284.         // $portB1->addExtremity($extB);
  2285.         $portB1->setLink($link);
  2286.         $portB1->setLinkExtension($ext);
  2287.         $em->persist($portB1);
  2288.         // $extB->addPort($portB1);
  2289.         if ($portB2) {
  2290.           $extensinOrder = new ExtensionOrder();
  2291.           $extensinOrder->setOrderNumber(2);
  2292.           $extensinOrder->setPort($portB2);
  2293.           $extensinOrder->setExtremity($extB);
  2294.           $portB2->addExtensionOrder($extensinOrder);
  2295.           $extB->addExtensionOrder($extensinOrder);
  2296.           $em->persist($extensinOrder);
  2297.           // $portB2->setOrderNoExtension(2);
  2298.           // $portB2->addExtremity($extB);
  2299.           $portB2->setLink($link);
  2300.           $portB2->setLinkExtension($ext);
  2301.           $em->persist($portB2);
  2302.           // $extB->addPort($portB2);
  2303.         }
  2304.         $em->persist($extB);
  2305.         $ext->setExtremityB($extB);
  2306.         // $ext->setPortA($portA);
  2307.         // $ext->setPortB($portB);
  2308.         if ($typeCable) {
  2309.           $ext->setTypeCable($typeCable);
  2310.         }
  2311.         if ($trunk) {
  2312.           $ports $this->getPorts($trunk$portsA$link->getTypeLink());
  2313.           foreach ($ports as $port) {
  2314.             $port->setLink($link);
  2315.             $port->setLinkExtension($ext);
  2316.             $em->persist($port);
  2317.           }
  2318.           $ext->setTrunk($trunk);
  2319.         }
  2320.         $ext->setSequenceNo($i);
  2321.         $em->persist($ext);
  2322.         $i++;
  2323.       }
  2324.     }
  2325.     $em->flush();
  2326.     return $this->redirectToRoute('link_list');
  2327.   }
  2328.   /**
  2329.    * @Route("/link/overview/list", name="link_overview_list")
  2330.    */
  2331.   public function overviewListAction(Request $requestTranslatorInterface $translator)
  2332.   {
  2333.     // $cache = new FilesystemAdapter();
  2334.     // $linkList = $cache->getItem('pagerfanta.list.link"');
  2335.     // $linkList->expiresAfter(1);
  2336.     $links null;
  2337.     // if (!$linkList->isHit()) {
  2338.     $links $this->getDoctrine()->getRepository('App\Entity\Link')->findAll();
  2339.     foreach ($links as $link) {
  2340.       $extensions $link->getLinkExtension();
  2341.       $link->totalExts=0;
  2342.       if (!($extensions->isEmpty())) {
  2343.         $firstExt $extensions[0];
  2344.         $portsA = [];
  2345.         $portAOrderNos = array();
  2346.         $portsATemp $firstExt->getExtremityA()->getExtensionOrder();
  2347.         foreach ($portsATemp as $value) {
  2348.           $portsA[] = $value->getPort();
  2349.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  2350.           $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  2351.         }
  2352.         // $portsA = $firstExt->getExtremityA()->getPorts();
  2353.         $eqA $portsA[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portsA[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portsA[0]->getInterfaceSpecific()->getEquipmentSpecific();
  2354.         $intA $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portsA[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2355.         $link->eqA $eqA;
  2356.         $link->intA $intA;
  2357.         // $portAOrderNos = array();
  2358.         // foreach ($portsA as $portA) {
  2359.         //   $portAOrderNos[$portA->getOrderNoExtension()-1] = $portA->getOrderNo();
  2360.         // }
  2361.         $portAOrderNos array_unique($portAOrderNos);
  2362.         ksort($portAOrderNos);
  2363.         $link->portA implode("/"$portAOrderNos);
  2364.         // $eqB = $firstExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific()->getEquipmentSpecific();
  2365.         $portBOrderNos = array();
  2366.         $lastExt $extensions[count($extensions) - 1];
  2367.         $portsB = [];
  2368.         $portsBTemp $lastExt->getExtremityB()->getExtensionOrder();
  2369.         foreach ($portsBTemp as $value) {
  2370.           $portsB[] = $value->getPort();
  2371.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  2372.           $portBOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  2373.         }
  2374.         // $portsB = $extension->getExtremityB()->getPorts();
  2375.         if (count($portsB) > 0) {
  2376.           $eqB $portsB[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() ? $portsB[0]->getInterfaceSpecific()->getEquipmentSpecificMpo() : $portsB[0]->getInterfaceSpecific()->getEquipmentSpecific();
  2377.           $intB $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() : $portsB[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2378.         }
  2379.         $link->eqB $eqB;
  2380.         $link->intB $intB;
  2381.         $portBOrderNos array_unique($portBOrderNos);
  2382.         ksort($portBOrderNos);
  2383.         $link->portB implode("/"$portBOrderNos);
  2384.         $link->totalExts count($link->getLinkExtension());
  2385.       }
  2386.     }
  2387.     //   $cache->save($linkList->set($links));
  2388.     // }
  2389.     // else {
  2390.     //   $links = $linkList->get();
  2391.     //   // var_dump($links);
  2392.     // }
  2393.     // var_dump($links);
  2394.     //pagerfanta starts
  2395.     // $adapter = new ArrayAdapter($links);
  2396.     // $pagerfanta = new Pagerfanta($adapter);
  2397.     $pageLength $request->query->get("pageLength"$this->getParameter("link.maxPerPage"));
  2398.     // if ($pageLength == "Tout") {
  2399.     //   $pagerfanta->setMaxPerPage(count($links)); // 10 by default
  2400.     // }
  2401.     // else {
  2402.     //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  2403.     // }
  2404.     // // $this->container->setParameter("link.maxPerPage", $pageLength);
  2405.     // $page = $request->query->get("page", 1);
  2406.     // $pagerfanta->setCurrentPage($page);
  2407.     //pagerfanta ends
  2408.     return $this->render('overview/link_list.html.twig', [
  2409.       'action' => 'list',
  2410.       'page_title' => $translator->trans('Link Overview'),
  2411.       'list' => $links,
  2412.       // 'my_pager' => $pagerfanta,
  2413.       'pageLength' => $pageLength,
  2414.     ]);
  2415.   }
  2416.   /**
  2417.    * @Route("/link/overview/item/{id}", name="link_overview")
  2418.    */
  2419.   public function overviewAction($idTranslatorInterface $translator)
  2420.   {
  2421.     $em $this->getDoctrine()->getManager();
  2422.     $link $em->getRepository(Link::class)->find($id);
  2423.     $extensions = [];
  2424.     $sequence = [];
  2425.     $e 1;
  2426.     $t 0;
  2427.     $tsn 0;
  2428.     $linkExtensions $link->getLinkExtension();
  2429.     foreach ($linkExtensions as $ext) {
  2430.       $linkExtensionSequenceNo $ext->getSequenceNo();
  2431.       $linkExtensionTrunk $ext->getTrunk();
  2432.       if (is_null($linkExtensionTrunk)) {
  2433.         $e $linkExtensionSequenceNo $t;
  2434.         if ($e 1) {
  2435.           $extension['id'] = 'E' . ($e 1);
  2436.         } else {
  2437.           $extension['id'] = '';
  2438.           $extension['typeCable'] = $ext->getTypeCable()->getTitle();
  2439.           $extension['color'] = $ext->getTypeCable()->getColor();
  2440.         }
  2441.       } else {
  2442.         if ($linkExtensionSequenceNo != $tsn) {
  2443.           $extension['id'] = $linkExtensionTrunk->getTrunkID();
  2444.           $extension['typeCable'] = $linkExtensionTrunk->getTypeCable()->getTitle();
  2445.           $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  2446.           $tsn $linkExtensionSequenceNo;
  2447.           $t++;
  2448.         }
  2449.       }
  2450.       //set ports on extension object
  2451.       $portsA = [];
  2452.       $portAOrderNos = array();
  2453.       $portsATemp $ext->getExtremityA()->getExtensionOrder();
  2454.       foreach ($portsATemp as $value) {
  2455.         $portsA[] = $value->getPort();
  2456.         $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  2457.         $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  2458.         // $portAOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  2459.       }
  2460.       // $portsA = $ext->getExtremityA()->getPorts();
  2461.       // foreach ($portsA as $p) {
  2462.       //   $portAOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  2463.       // }
  2464.       $portAOrderNos array_unique($portAOrderNos);
  2465.       ksort($portAOrderNos);
  2466.       $extension['portA'] = implode("/"$portAOrderNos);
  2467.       $portsB = [];
  2468.       $portBOrderNos = array();
  2469.       $portsBTemp $ext->getExtremityB()->getExtensionOrder();
  2470.       foreach ($portsBTemp as $value) {
  2471.         $portsB[] = $value->getPort();
  2472.         $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  2473.         $portBOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  2474.         // $portBOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  2475.       }
  2476.       // $portsB = $ext->getExtremityB()->getPorts();
  2477.       // $portBOrderNos = array();
  2478.       // foreach ($portsB as $p) {
  2479.       //   $portBOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  2480.       // }
  2481.       $portBOrderNos array_unique($portBOrderNos);
  2482.       ksort($portBOrderNos);
  2483.       $extension['portB'] = implode("/"$portBOrderNos);
  2484.       // set other properties on side A of extension object
  2485.       $interfaceSpecTemp $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific() : $portsA[0]->getInterfaceSpecific();
  2486.       $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2487.       $roomTemp $rackTemp->getRoom();
  2488.       $extension['siteA'] = $roomTemp->getSite()->getTitle();
  2489.       $extension['roomA'] = $roomTemp->getTitle();
  2490.       $extension['rackA'] = $rackTemp->getTitle();
  2491.       $extension['equipmentA'] = $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecificMpo()->getEquipmentSpecificName() . ')' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2492.       $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2493.       // set other properties on side B of extension object
  2494.       $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  2495.       $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2496.       $roomTemp $rackTemp->getRoom();
  2497.       $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2498.       $extension['roomB'] = $roomTemp->getTitle();
  2499.       $extension['rackB'] = $rackTemp->getTitle();
  2500.       $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecificMpo()->getEquipmentSpecificName() . ')' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2501.       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2502.       $extension['isValid'] = $ext->isValid();
  2503.       // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  2504.       //
  2505.       // if ($fiberNo > 1){
  2506.       //
  2507.       //     $portsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsABySequence($link, $linkExtensionSequenceNo);
  2508.       //     $portsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsBBySequence($link, $linkExtensionSequenceNo);
  2509.       //
  2510.       //     $extension['portA'] = '';
  2511.       //     $extension['portB'] = '';
  2512.       //
  2513.       //     $portsAIDS = [];
  2514.       //     $portsBIDS = [];
  2515.       //
  2516.       //     foreach ($portsA as $portID){
  2517.       //
  2518.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2519.       //
  2520.       //         $extension['siteA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  2521.       //         $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  2522.       //         $extension['rackA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  2523.       //         $extension['equipmentA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  2524.       //         $extension['interfaceA'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2525.       //
  2526.       //         if (!in_array($portID,$portsAIDS)){
  2527.       //             $extension['portA'] .= $port->getOrderNo().'/';
  2528.       //         }
  2529.       //
  2530.       //         $portsAIDS[] = $portID;
  2531.       //
  2532.       //     }
  2533.       //
  2534.       //     $extension['portA'] = substr($extension['portA'], 0, -1);
  2535.       //
  2536.       //     foreach ($portsB as $portID){
  2537.       //
  2538.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2539.       //
  2540.       //         $extension['siteB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  2541.       //         $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  2542.       //         $extension['rackB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  2543.       //         $extension['equipmentB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  2544.       //         $extension['interfaceB'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2545.       //
  2546.       //         if (!in_array($portID,$portsBIDS)){
  2547.       //             $extension['portB'] .= $port->getOrderNo().'/';
  2548.       //         }
  2549.       //
  2550.       //         $portsBIDS[] = $portID;
  2551.       //
  2552.       //     }
  2553.       //
  2554.       //     $extension['portB'] = substr($extension['portB'], 0, -1);
  2555.       //
  2556.       // } else {
  2557.       //
  2558.       //     $extension['siteA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  2559.       //     $extension['roomA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  2560.       //     $extension['rackA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  2561.       //     $extension['equipmentA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  2562.       //     $extension['interfaceA'] = $ext->getPortA()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2563.       //     $extension['portA'] = $ext->getPortA()->getOrderNo();
  2564.       //
  2565.       //     $extension['siteB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  2566.       //     $extension['roomB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  2567.       //     $extension['rackB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  2568.       //     $extension['equipmentB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  2569.       //     $extension['interfaceB'] = $ext->getPortB()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  2570.       //     $extension['portB'] = $ext->getPortA()->getOrderNo();
  2571.       //
  2572.       // }
  2573.       if (!in_array($linkExtensionSequenceNo$sequence)) {
  2574.         $extensions[] = $extension;
  2575.       }
  2576.       $sequence[] = $linkExtensionSequenceNo;
  2577.     }
  2578.     return $this->render('overview/link.html.twig', [
  2579.       'action' => 'list',
  2580.       'page_title' => $translator->trans('Link Overview'),
  2581.       'link' => $link,
  2582.       'extensions' => $extensions
  2583.     ]);
  2584.   }
  2585.   /**
  2586.    * @Route("/link/diagram-pdf/{id}", name="link_diagram_pdf")
  2587.    */
  2588.   public function viewDiagramPdfAction($idTranslatorInterface $translatorTCPDFController $tcpdf)
  2589.   {
  2590.     $em $this->getDoctrine()->getManager();
  2591.     $link $em->getRepository(Link::class)->find($id);
  2592.     $extensions = [];
  2593.     $sequence = [];
  2594.     $e 1;
  2595.     $t 0;
  2596.     $tsn 0;
  2597.     //get all the link extensions
  2598.     $linkExtensions $link->getLinkExtension();
  2599.     foreach ($linkExtensions as $ext) {
  2600.       $reverseTrunk false;
  2601.       // var_dump("link ext: ".$ext->getId());
  2602.       $linkExtensionSequenceNo $ext->getSequenceNo(); //If "1" that means, its first link extension
  2603.       $linkExtensionTrunk $ext->getTrunk(); //get the trunk if exists
  2604.       $extIsTrunkAndHasExtensions 0;
  2605.       if (is_null($linkExtensionTrunk)) { // if it doesn't have trunk
  2606.         // var_dump("trunk is null");
  2607.         $e $linkExtensionSequenceNo $t;
  2608.         if ($e 1) {
  2609.           $extension['ext'] = 'E' . ($e 1);
  2610.         } else {
  2611.           $extension['ext'] = '';
  2612.         }
  2613.         $extension['label'] = $link->getLinkID();
  2614.       } else {
  2615.         // var_dump("trunk id: ".$linkExtensionTrunk->getId());
  2616.         if ($linkExtensionSequenceNo != $tsn) {
  2617.           $tcfs $linkExtensionTrunk->getCableFiber();
  2618.           foreach ($tcfs as $tcf) {
  2619.             $trunkExts $tcf->getExtensions();
  2620.             if (sizeof($trunkExts) > 0) {
  2621.               $extIsTrunkAndHasExtensions 1;
  2622.             }
  2623.           }
  2624.           if ($extIsTrunkAndHasExtensions == 0) {
  2625.             // var_dump("trunk doesn't have extension");
  2626.             $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  2627.             $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2628.           } else {
  2629.             // var_dump("trunk has extensions");
  2630.             $portsA = [];
  2631.             $portAOrderNos = array();
  2632.             $portsATemp $ext->getExtremityA()->getExtensionOrder();
  2633.             foreach ($portsATemp as $value) {
  2634.               $portsA[] = $value->getPort();
  2635.               $portAOrderNos[$value->getOrderNumber() - 1] = ($value->getPort()->getAlias() != "") ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  2636.             }
  2637.             // $portsA = $ext->getExtremityA()->getPorts();
  2638.             // var_dump("extremity A id: ".$ext->getExtremityA()->getId());
  2639.             // var_dump("nombre de ports", count($portsA));
  2640.             // set other properties on side A of extension object
  2641.             $interfaceSpecTemp $portsA[0]->getInterfaceSpecific();
  2642.             $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2643.             $roomTemp $rackTemp->getRoom();
  2644.             $extension['siteA'] = $roomTemp->getSite()->getTitle();
  2645.             $extension['roomA'] = $roomTemp->getTitle();
  2646.             $extension['rackA'] = $rackTemp->getTitle();
  2647.             $extension['equipmentA'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2648.             $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2649.             // first trunk extension
  2650.             $portsB = [];
  2651.             $tcfsForExts = [];
  2652.             $tcfsExts = [];
  2653.             $tcfExtsFromB null;
  2654.             $duplex false;
  2655.             if ($link->getTypeLink()->getTitle() == "Duplex" && count($portsA) == || ($link->getTypeLink()->getTitle() != "Simplex" && count($portsA) == 1)) {
  2656.               $duplex true;
  2657.             }
  2658.             // var_dump($duplex);
  2659.             foreach ($portsA as $port) {
  2660.               // $portAOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2661.               $tcfFromA null;
  2662.               $tcfFromB null;
  2663.               $tcfExtFromB null;
  2664.               if ($duplex) {
  2665.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portA' => $port]);
  2666.                 // var_dump($tcfFromA->getId());
  2667.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portB' => $port]);
  2668.                 // var_dump($tcfFromB->getId());
  2669.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findBy(['portB' => $port]);
  2670.                 foreach ($tcfFromA as $temp) {
  2671.                   $portB $temp->getPortB();
  2672.                   $portsB[] = $portB;
  2673.                   $tcfsForExts[] = $temp;
  2674.                 }
  2675.                 foreach ($tcfFromB as $temp) {
  2676.                   $portB $temp->getPortB();
  2677.                   $portsB[] = $portB;
  2678.                   $tcfsForExts[] = $temp;
  2679.                 }
  2680.                 foreach ($tcfExtFromB as $temp) {
  2681.                   $tcfExtsFromB[] = $temp;
  2682.                   $reverseTrunk true;
  2683.                 }
  2684.               } else {
  2685.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
  2686.                 // var_dump($tcfFromA->getId());
  2687.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
  2688.                 // var_dump($tcfFromB->getId());
  2689.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  2690.                 if ($tcfFromA) {
  2691.                   $portB $tcfFromA->getPortB();
  2692.                   $portsB[] = $portB;
  2693.                   $tcfsForExts[] = $tcfFromA;
  2694.                   // var_dump($portB->getId());
  2695.                 }
  2696.                 if ($tcfFromB) {
  2697.                   $portB $tcfFromB->getPortB();
  2698.                   $portsB[] = $portB;
  2699.                   $tcfsForExts[] = $tcfFromB;
  2700.                   // var_dump($portB->getId());
  2701.                 }
  2702.                 //to treat the reverse case
  2703.                 if ($tcfExtFromB) {
  2704.                   // var_dump($tcfExtFromB);
  2705.                   $tcfExtsFromB[] = $tcfExtFromB;
  2706.                   $reverseTrunk true;
  2707.                 }
  2708.               }
  2709.             }
  2710.             $portAOrderNos array_unique($portAOrderNos);
  2711.             ksort($portAOrderNos);
  2712.             $extension['portA'] = implode("/"$portAOrderNos);
  2713.             if ($reverseTrunk) {
  2714.               // var_dump("in reverse trunk");
  2715.               $portsArrayArray = array();
  2716.               if (count($tcfExtsFromB) > 0) {
  2717.                 $tcfsForExts = array();
  2718.                 foreach ($tcfExtsFromB as $tcfExt) {
  2719.                   $tcfsForExts[] = $tcfExt->getTrunkCableFiber();
  2720.                 }
  2721.                 for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  2722.                   $portArray = [];
  2723.                   foreach ($tcfsForExts as $tempTcf) {
  2724.                     // get the extensions of sequence $i
  2725.                     $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  2726.                     // var_dump($tempExt);
  2727.                     if ($tempExt) {
  2728.                       $portArray[] = $tempExt->getPortB();
  2729.                     }
  2730.                   }
  2731.                   $portsArrayArray[] = $portArray;
  2732.                   // var_dump($portsArrayArray);
  2733.                 }
  2734.                 // var_dump($portsArrayArray);
  2735.                 $tcf $tcfsForExts[0];
  2736.                 $tcfExts $tcf->getExtensions();
  2737.                 // var_dump($tcfExts);
  2738.                 for ($i count($tcfExts) - 1$i >= 0$i--) {
  2739.                   $portsB null;
  2740.                   if ($i == 0) {
  2741.                     foreach ($tcfsForExts as $tempTcf) {
  2742.                       $portsB[] = $tempTcf->getPortB();
  2743.                     }
  2744.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2745.                     $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  2746.                     $extension['portA'] = $extension['portB'];
  2747.                     // $operatorID = $tcfsForExts[0]->getOperatorID();
  2748.                     // $portB = $tcfExt->getPortB();
  2749.                     // $portsB[] = $portB;
  2750.                     $extension['portB'] = '';
  2751.                     $portsBIDS = [];
  2752.                     $extension['portB_temp'] = '';
  2753.                     $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2754.                     $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2755.                     $roomTemp $rackTemp->getRoom();
  2756.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2757.                     $extension['roomB'] = $roomTemp->getTitle();
  2758.                     $extension['rackB'] = $rackTemp->getTitle();
  2759.                     $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2760.                     $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2761.                     $portBOrderNos = array();
  2762.                     foreach ($portsB as $portID) {
  2763.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2764.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2765.                       $portBOrderNos[] = ($port->getAlias() != "") ? $port->getAlias() : $port->getOrderNo();
  2766.                       $portsBIDS[] = $portID;
  2767.                     }
  2768.                     $portBOrderNos array_unique($portBOrderNos);
  2769.                     ksort($portBOrderNos);
  2770.                     $extension['portB'] = implode("/"$portBOrderNos);
  2771.                     // var_dump($extension['portB']);
  2772.                     $extensions[] = $extension;
  2773.                   } else {
  2774.                     $portsB $portsArrayArray[$i 1];
  2775.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2776.                     $extension['ext'] = $tcfExts[$i]->getOperatorID();
  2777.                     $extension['portA'] = $extension['portB'];
  2778.                     $operatorID $tcfExts[$i]->getOperatorID();
  2779.                     // $portB = $tcfExt->getPortB();
  2780.                     // $portsB[] = $portB;
  2781.                     $extension['portB'] = '';
  2782.                     $portsBIDS = [];
  2783.                     $extension['portB_temp'] = '';
  2784.                     $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2785.                     $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2786.                     $roomTemp $rackTemp->getRoom();
  2787.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2788.                     $extension['roomB'] = $roomTemp->getTitle();
  2789.                     $extension['rackB'] = $rackTemp->getTitle();
  2790.                     $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2791.                     $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2792.                     $portBOrderNos = array();
  2793.                     foreach ($portsB as $portID) {
  2794.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2795.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2796.                       $portBOrderNos[] = ($port->getAlias() != "") ? $port->getAlias() : $port->getOrderNo();
  2797.                       $portsBIDS[] = $portID;
  2798.                     }
  2799.                     $portBOrderNos array_unique($portBOrderNos);
  2800.                     ksort($portBOrderNos);
  2801.                     $extension['portB'] = implode("/"$portBOrderNos);
  2802.                     // var_dump($extension['portB']);
  2803.                     $extensions[] = $extension;
  2804.                   }
  2805.                 }
  2806.                 // var_dump($tcfsForExts);
  2807.                 $portsB null;
  2808.                 foreach ($tcfsForExts as $tempTcf) {
  2809.                   $portsB[] = $tempTcf->getPortA();
  2810.                 }
  2811.                 // var_dump($portsB);
  2812.               }
  2813.             } else {
  2814.               $extension['portB_temp'] = '';
  2815.               $portBOrderNos = array();
  2816.               $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2817.               $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2818.               $roomTemp $rackTemp->getRoom();
  2819.               $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2820.               $extension['roomB'] = $roomTemp->getTitle();
  2821.               $extension['rackB'] = $rackTemp->getTitle();
  2822.               $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2823.               $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2824.               foreach ($portsB as $portID) {
  2825.                 $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2826.                 // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2827.                 $portBOrderNos[] = ($port->getAlias() != "") ? $port->getAlias() : $port->getOrderNo();
  2828.               }
  2829.               $portBOrderNos array_unique($portBOrderNos);
  2830.               ksort($portBOrderNos);
  2831.               $extension['portB'] = implode("/"$portBOrderNos);
  2832.               $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  2833.               $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2834.               $extensions[] = $extension;
  2835.               // other trunk extensions
  2836.               // get the ports for the extensions
  2837.               $portsArrayArray = array();
  2838.               if (count($tcfsForExts) > 0) {
  2839.                 for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  2840.                   $portArray = [];
  2841.                   foreach ($tcfsForExts as $tempTcf) {
  2842.                     // get the extensions of sequence $i
  2843.                     $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  2844.                     // var_dump($tempExt);
  2845.                     if ($tempExt) {
  2846.                       $portArray[] = $tempExt->getPortB();
  2847.                     }
  2848.                   }
  2849.                   $portsArrayArray[] = $portArray;
  2850.                 }
  2851.                 // var_dump($portsArrayArray);
  2852.                 $tcf $tcfsForExts[0];
  2853.                 $tcfExts $tcf->getExtensions();
  2854.                 $iterator 0;
  2855.                 foreach ($tcfExts as $tcfExt) {
  2856.                   // var_dump($tcfExt->getId());
  2857.                   $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2858.                   $extension['ext'] = $tcfExt->getOperatorID();
  2859.                   $extension['portA'] = $extension['portB'];
  2860.                   $operatorID $tcfExt->getOperatorID();
  2861.                   $portsB $portsArrayArray[$iterator++];
  2862.                   // $portB = $tcfExt->getPortB();
  2863.                   // $portsB[] = $portB;
  2864.                   $extension['portB'] = '';
  2865.                   $portsBIDS = [];
  2866.                   $extension['portB_temp'] = '';
  2867.                   $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2868.                   $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2869.                   $roomTemp $rackTemp->getRoom();
  2870.                   $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2871.                   $extension['roomB'] = $roomTemp->getTitle();
  2872.                   $extension['rackB'] = $rackTemp->getTitle();
  2873.                   $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2874.                   $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2875.                   $portBOrderNos = array();
  2876.                   foreach ($portsB as $portID) {
  2877.                     $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2878.                     // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2879.                     $portBOrderNos[] = ($port->getAlias() != "") ? $port->getAlias() : $port->getOrderNo();
  2880.                     $portsBIDS[] = $portID;
  2881.                   }
  2882.                   $portBOrderNos array_unique($portBOrderNos);
  2883.                   ksort($portBOrderNos);
  2884.                   $extension['portB'] = implode("/"$portBOrderNos);
  2885.                   // var_dump($extension['portB']);
  2886.                   $extensions[] = $extension;
  2887.                 }
  2888.               }
  2889.             }
  2890.           }
  2891.           $tsn $linkExtensionSequenceNo;
  2892.           $t++;
  2893.         }
  2894.       }
  2895.       if ($reverseTrunk) {
  2896.         $extension['label'] = $linkExtensionTrunk->getTrunkID();
  2897.         $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  2898.         $extension['portA'] = $extension['portB'];
  2899.         // $operatorID = $tcfsForExts[0]->getOperatorID();
  2900.         // $portB = $tcfExt->getPortB();
  2901.         // $portsB[] = $portB;
  2902.         $extension['portB'] = '';
  2903.         $portsBIDS = [];
  2904.         $extension['portB_temp'] = '';
  2905.         $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2906.         $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2907.         $roomTemp $rackTemp->getRoom();
  2908.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2909.         $extension['roomB'] = $roomTemp->getTitle();
  2910.         $extension['rackB'] = $rackTemp->getTitle();
  2911.         $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2912.         $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2913.         $portBOrderNos = array();
  2914.         foreach ($portsB as $portID) {
  2915.           $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2916.           // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  2917.           $portBOrderNos[] = ($port->getAlias() != "") ? $port->getAlias() : $port->getOrderNo();
  2918.           $portsBIDS[] = $portID;
  2919.         }
  2920.         $portBOrderNos array_unique($portBOrderNos);
  2921.         ksort($portBOrderNos);
  2922.         $extension['portB'] = implode("/"$portBOrderNos);
  2923.         // var_dump($extension['portB']);
  2924.         $extensions[] = $extension;
  2925.       } else {
  2926.         if ($ext->getTypeCable()) {
  2927.           $extension['color'] = $ext->getTypeCable()->getColor();
  2928.         } else {
  2929.           $extension['color'] = $ext->getTrunk()->getTypeCable()->getColor();
  2930.         }
  2931.         //set ports on extension object
  2932.         $portsA = [];
  2933.         $portAOrderNos = array();
  2934.         $portsATemp $ext->getExtremityA()->getExtensionOrder();
  2935.         foreach ($portsATemp as $value) {
  2936.           $portsA[] = $value->getPort();
  2937.           $portAOrderNos[$value->getOrderNumber() - 1] = ($value->getPort()->getAlias() != "") ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  2938.         }
  2939.         // $portsA = $ext->getExtremityA()->getPorts();
  2940.         // foreach ($portsA as $p) {
  2941.         //   $portAOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  2942.         // }
  2943.         $portAOrderNos array_unique($portAOrderNos);
  2944.         ksort($portAOrderNos);
  2945.         $extension['portA'] = implode("/"$portAOrderNos);
  2946.         $portsB = [];
  2947.         $portBOrderNos = array();
  2948.         $portsBTemp $ext->getExtremityB()->getExtensionOrder();
  2949.         foreach ($portsBTemp as $value) {
  2950.           $portsB[] = $value->getPort();
  2951.           $portBOrderNos[$value->getOrderNumber() - 1] = ($value->getPort()->getAlias() != "") ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  2952.         }
  2953.         // $portsB = $ext->getExtremityB()->getPorts();
  2954.         // $portBOrderNos = array();
  2955.         // foreach ($portsB as $p) {
  2956.         //   $portBOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  2957.         // }
  2958.         $portBOrderNos array_unique($portBOrderNos);
  2959.         ksort($portBOrderNos);
  2960.         $extension['portB'] = implode("/"$portBOrderNos);
  2961.         // set other properties on side A of extension object
  2962.         $interfaceSpecTemp $portsA[0]->getInterfaceSpecific();
  2963.         $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2964.         $roomTemp $rackTemp->getRoom();
  2965.         $extension['siteA'] = $roomTemp->getSite()->getTitle();
  2966.         $extension['roomA'] = $roomTemp->getTitle();
  2967.         $extension['rackA'] = $rackTemp->getTitle();
  2968.         $extension['equipmentA'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2969.         $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2970.         // set other properties on side B of extension object
  2971.         $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  2972.         $rackTemp $interfaceSpecTemp->getEquipmentSpecific()->getRack();
  2973.         $roomTemp $rackTemp->getRoom();
  2974.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  2975.         $extension['roomB'] = $roomTemp->getTitle();
  2976.         $extension['rackB'] = $rackTemp->getTitle();
  2977.         $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle() . ' (' $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName() . ')';
  2978.         $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  2979.       }
  2980.       // var_dump($extension);
  2981.       // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  2982.       //
  2983.       // if ($fiberNo > 1){
  2984.       //
  2985.       //     $portsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsABySequence($link, $linkExtensionSequenceNo);
  2986.       //     $portsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsBBySequence($link, $linkExtensionSequenceNo);
  2987.       //
  2988.       //     $extension['portA'] = '';
  2989.       //     $extension['portB'] = '';
  2990.       //
  2991.       //     $portsAIDS = [];
  2992.       //     $portsBIDS = [];
  2993.       //
  2994.       //     foreach ($portsA as $portID){
  2995.       //
  2996.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  2997.       //
  2998.       //         $extension['siteA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  2999.       //         $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3000.       //         $extension['rackA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3001.       //         $extension['equipmentA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3002.       //         $extension['interfaceA'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3003.       //
  3004.       //         if (!in_array($portID,$portsAIDS)){
  3005.       //             $extension['portA'] .= $port->getOrderNo().'/';
  3006.       //
  3007.       //         }
  3008.       //
  3009.       //         $portsAIDS[] = $portID;
  3010.       //
  3011.       //     }
  3012.       //
  3013.       //     $extension['portA'] = substr($extension['portA'], 0, -1);
  3014.       //
  3015.       //     $extension['portB_temp'] = '';
  3016.       //
  3017.       //     foreach ($portsB as $portID){
  3018.       //
  3019.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3020.       //
  3021.       //         $extension['siteB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3022.       //         $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3023.       //         $extension['rackB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3024.       //         $extension['equipmentB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3025.       //         $extension['interfaceB'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3026.       //
  3027.       //         if (!in_array($portID,$portsBIDS)){
  3028.       //             $extension['portB_temp'] .= $port->getOrderNo().'/';
  3029.       //         }
  3030.       //
  3031.       //         $portsBIDS[] = $portID;
  3032.       //
  3033.       //     }
  3034.       //
  3035.       //
  3036.       //     $extension['portB'] = substr($extension['portB_temp'], 0, -1);
  3037.       //
  3038.       //
  3039.       // } else {
  3040.       //
  3041.       //     $extension['siteA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3042.       //     $extension['roomA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3043.       //     $extension['rackA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3044.       //     $extension['equipmentA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3045.       //     $extension['interfaceA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3046.       //     $extension['portA'] = $ext->getExtremityA()->getPorts()[0]->getOrderNo();
  3047.       //
  3048.       //     $extension['siteB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3049.       //     $extension['roomB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3050.       //     $extension['rackB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3051.       //     $extension['equipmentB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3052.       //     $extension['interfaceB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3053.       //     $extension['portB'] = $ext->getExtremityB()->getPorts()[0]->getOrderNo();
  3054.       //
  3055.       // }
  3056.       if (!in_array($linkExtensionSequenceNo$sequence) && $extIsTrunkAndHasExtensions == 0) {
  3057.         $extensions[] = $extension;
  3058.       }
  3059.       $sequence[] = $linkExtensionSequenceNo;
  3060.     }
  3061.     $html $this->renderView(
  3062.       'link/list_diagram_pdf.html.twig',
  3063.       [
  3064.         'link' => $link,
  3065.         'extensions' => $extensions
  3066.       ]
  3067.     );
  3068.     $pdf $tcpdf->create('P'PDF_UNIT'A4'true'UTF-8'false);
  3069.     $pdf->SetAuthor('FIBERLINK');
  3070.     $pdf->SetTitle('Link ' $link->getLinkID());
  3071.     $pdf->SetSubject('Link ' $link->getLinkID());
  3072.     $pdf->setFontSubsetting(true);
  3073.     $pdf->SetFont('helvetica'''7''true);
  3074.     $pdf->AddPage();
  3075.     $filename 'link-' $link->getLinkID();
  3076.     $pdf->writeHTML($htmltruefalsetruefalse'');
  3077.     ob_end_clean();
  3078.     $pdf->Output($filename ".pdf"'I'); // This will output the PDF as a response directly
  3079.   }
  3080.   /**
  3081.    * @Route("/link/diagram/{id}", name="link_diagram")
  3082.    */
  3083.   public function viewDiagramAction($idRequest $requestTranslatorInterface $translator)
  3084.   {
  3085.     $em $this->getDoctrine()->getManager();
  3086.     $link $em->getRepository(Link::class)->find($id);
  3087.     $extensions = [];
  3088.     $sequence = [];
  3089.     $e 1;
  3090.     $t 0;
  3091.     $tsn 0;
  3092.     //get all the link extensions
  3093.     $linkExtensions $link->getLinkExtension();
  3094.     foreach ($linkExtensions as $ext) {
  3095.       $reverseTrunk false;
  3096.       // var_dump("link ext: ".$ext->getId());
  3097.       $linkExtensionSequenceNo $ext->getSequenceNo(); //If "1" that means, its first link extension
  3098.       $linkExtensionTrunk $ext->getTrunk(); //get the trunk if exists
  3099.       $extIsTrunkAndHasExtensions 0;
  3100.       $tcfExtsFromB null;
  3101.       if (is_null($linkExtensionTrunk)) { // if it doesn't have trunk
  3102.         // var_dump("trunk is null");
  3103.         $e $linkExtensionSequenceNo $t;
  3104.         if ($e 1) {
  3105.           $extension['ext'] = 'E' . ($e 1);
  3106.         } else {
  3107.           $extension['ext'] = '';
  3108.         }
  3109.         $extension['label'] = $link->getLinkID();
  3110.       } else {
  3111.         // var_dump("trunk id: ".$linkExtensionTrunk->getId());
  3112.         if ($linkExtensionSequenceNo != $tsn) {
  3113.           $tcfs $linkExtensionTrunk->getCableFiber();
  3114.           foreach ($tcfs as $tcf) {
  3115.             $trunkExts $tcf->getExtensions();
  3116.             if (sizeof($trunkExts) > 0) {
  3117.               $extIsTrunkAndHasExtensions 1;
  3118.             }
  3119.           }
  3120.           if ($extIsTrunkAndHasExtensions == 0) {
  3121.             // var_dump("trunk doesn't have extension");
  3122.             $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  3123.             $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3124.           } else {
  3125.             // var_dump("trunk has extensions");
  3126.             $portsA = [];
  3127.             $portAOrderNos = array();
  3128.             $portsATemp $ext->getExtremityA()->getExtensionOrder();
  3129.             foreach ($portsATemp as $value) {
  3130.               $portsA[] = $value->getPort();
  3131.               $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  3132.               $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  3133.               // $portAOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  3134.             }
  3135.             // $portsA = $ext->getExtremityA()->getPorts();
  3136.             // var_dump("extremity A id: ".$ext->getExtremityA()->getId());
  3137.             // var_dump("nombre de ports", count($portsA));
  3138.             // set other properties on side A of extension object
  3139.             $interfaceSpecTemp $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific() : $portsA[0]->getInterfaceSpecific();
  3140.             // $interfaceSpecTemp = $portsA[0]->getInterfaceSpecific();
  3141.             $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3142.             $rackTemp $eqSpe->getRack();
  3143.             $roomTemp $rackTemp->getRoom();
  3144.             $extension['siteA'] = $roomTemp->getSite()->getTitle();
  3145.             $extension['roomA'] = $roomTemp->getTitle();
  3146.             $extension['rackA'] = $rackTemp->getTitle();
  3147.             if ($eqSpe->isModule()) {
  3148.               $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3149.               // $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3150.             } elseif ($eqSpe->isChassisModule()) {
  3151.               $extension['equipmentA'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3152.               // $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3153.             } else {
  3154.               $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3155.             }
  3156.             if ($eqSpe->isModule()) {
  3157.               $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3158.             } elseif ($eqSpe->isChassisModule()) {
  3159.               $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3160.             } else {
  3161.               $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3162.             }
  3163.             // first trunk extension
  3164.             $portsB = [];
  3165.             $tcfsForExts = [];
  3166.             $tcfsExts = [];
  3167.             $tcfExtsFromB null;
  3168.             $duplex false;
  3169.             if ($link->getTypeLink()->getTitle() == "Duplex" && count($portsA) == || ($link->getTypeLink()->getTitle() != "Simplex" && count($portsA) == 1)) {
  3170.               $duplex true;
  3171.             }
  3172.             // var_dump($duplex);
  3173.             foreach ($portsA as $port) {
  3174.               // $portAOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3175.               $tcfFromA null;
  3176.               $tcfFromB null;
  3177.               $tcfExtFromB null;
  3178.               if ($duplex) {
  3179.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portA' => $port]);
  3180.                 // var_dump($tcfFromA->getId());
  3181.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portB' => $port]);
  3182.                 // var_dump($tcfFromB->getId());
  3183.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findBy(['portB' => $port]);
  3184.                 foreach ($tcfFromA as $temp) {
  3185.                   $portB $temp->getPortB();
  3186.                   $portsB[] = $portB;
  3187.                   $tcfsForExts[] = $temp;
  3188.                 }
  3189.                 foreach ($tcfFromB as $temp) {
  3190.                   $portB $temp->getPortB();
  3191.                   $portsB[] = $portB;
  3192.                   $tcfsForExts[] = $temp;
  3193.                 }
  3194.                 foreach ($tcfExtFromB as $temp) {
  3195.                   $tcfExtsFromB[] = $temp;
  3196.                   $reverseTrunk true;
  3197.                 }
  3198.               } else {
  3199.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
  3200.                 // var_dump($tcfFromA->getId());
  3201.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
  3202.                 // var_dump($tcfFromB->getId());
  3203.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  3204.                 if ($tcfFromA) {
  3205.                   $portB $tcfFromA->getPortB();
  3206.                   $portsB[] = $portB;
  3207.                   $tcfsForExts[] = $tcfFromA;
  3208.                   // var_dump($portB->getId());
  3209.                 }
  3210.                 if ($tcfFromB) {
  3211.                   $portB $tcfFromB->getPortB();
  3212.                   $portsB[] = $portB;
  3213.                   $tcfsForExts[] = $tcfFromB;
  3214.                   // var_dump($portB->getId());
  3215.                 }
  3216.                 //to treat the reverse case
  3217.                 if ($tcfExtFromB) {
  3218.                   // var_dump($tcfExtFromB);
  3219.                   $tcfExtsFromB[] = $tcfExtFromB;
  3220.                   $reverseTrunk true;
  3221.                 }
  3222.               }
  3223.             }
  3224.             $portAOrderNos array_unique($portAOrderNos);
  3225.             ksort($portAOrderNos);
  3226.             $extension['portA'] = implode("/"$portAOrderNos);
  3227.             if ($reverseTrunk) {
  3228.               // var_dump("in reverse trunk");
  3229.               $portsArrayArray = array();
  3230.               if (count($tcfExtsFromB) > 0) {
  3231.                 $tcfsForExts = array();
  3232.                 foreach ($tcfExtsFromB as $tcfExt) {
  3233.                   $tcfsForExts[] = $tcfExt->getTrunkCableFiber();
  3234.                 }
  3235.                 for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  3236.                   $portArray = [];
  3237.                   foreach ($tcfsForExts as $tempTcf) {
  3238.                     // get the extensions of sequence $i
  3239.                     $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  3240.                     // var_dump($tempExt);
  3241.                     if ($tempExt) {
  3242.                       $portArray[] = $tempExt->getPortB();
  3243.                     }
  3244.                   }
  3245.                   $portsArrayArray[] = $portArray;
  3246.                   // var_dump($portsArrayArray);
  3247.                 }
  3248.                 // var_dump($portsArrayArray);
  3249.                 $tcf $tcfsForExts[0];
  3250.                 $tcfExts $tcf->getExtensions();
  3251.                 // var_dump($tcfExts);
  3252.                 for ($i count($tcfExts) - 1$i >= 0$i--) {
  3253.                   $portsB null;
  3254.                   if ($i == 0) {
  3255.                     foreach ($tcfsForExts as $tempTcf) {
  3256.                       $portsB[] = $tempTcf->getPortB();
  3257.                     }
  3258.                     $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3259.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3260.                     $extension['ext'] = $tcfExts[$i]->getOperatorID();
  3261.                     $extension['portA'] = $extension['portB'];
  3262.                     // $operatorID = $tcfsForExts[0]->getOperatorID();
  3263.                     // $portB = $tcfExt->getPortB();
  3264.                     // $portsB[] = $portB;
  3265.                     $extension['portB'] = '';
  3266.                     $portsBIDS = [];
  3267.                     $extension['portB_temp'] = '';
  3268.                     $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3269.                     // $interfaceSpecTemp = $portsB[0]->getInterfaceSpecific();
  3270.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3271.                     $rackTemp $eqSpe->getRack();
  3272.                     $roomTemp $rackTemp->getRoom();
  3273.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3274.                     $extension['roomB'] = $roomTemp->getTitle();
  3275.                     $extension['rackB'] = $rackTemp->getTitle();
  3276.                     if ($eqSpe->isModule()) {
  3277.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3278.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3279.                     } elseif ($eqSpe->isChassisModule()) {
  3280.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3281.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3282.                     } else {
  3283.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3284.                     }
  3285.                     if ($eqSpe->isModule()) {
  3286.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3287.                     } elseif ($eqSpe->isChassisModule()) {
  3288.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3289.                     } else {
  3290.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3291.                     }
  3292.                     // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3293.                     $portBOrderNos = array();
  3294.                     foreach ($portsB as $portID) {
  3295.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3296.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3297.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3298.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3299.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3300.                       $portsBIDS[] = $portID;
  3301.                     }
  3302.                     $portBOrderNos array_unique($portBOrderNos);
  3303.                     ksort($portBOrderNos);
  3304.                     $extension['portB'] = implode("/"$portBOrderNos);
  3305.                     // var_dump($extension['portB']);
  3306.                     $extensions[] = $extension;
  3307.                   } else {
  3308.                     $portsB $portsArrayArray[$i 1];
  3309.                     $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3310.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3311.                     $extension['ext'] = $tcfExts[$i]->getOperatorID();
  3312.                     $extension['portA'] = $extension['portB'];
  3313.                     $operatorID $tcfExts[$i]->getOperatorID();
  3314.                     // $portB = $tcfExt->getPortB();
  3315.                     // $portsB[] = $portB;
  3316.                     $extension['portB'] = '';
  3317.                     $portsBIDS = [];
  3318.                     $extension['portB_temp'] = '';
  3319.                     $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3320.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3321.                     $rackTemp $eqSpe->getRack();
  3322.                     $roomTemp $rackTemp->getRoom();
  3323.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3324.                     $extension['roomB'] = $roomTemp->getTitle();
  3325.                     $extension['rackB'] = $rackTemp->getTitle();
  3326.                     if ($eqSpe->isModule()) {
  3327.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3328.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3329.                     } elseif ($eqSpe->isChassisModule()) {
  3330.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3331.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3332.                     } else {
  3333.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3334.                     }
  3335.                     if ($eqSpe->isModule()) {
  3336.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3337.                     } elseif ($eqSpe->isChassisModule()) {
  3338.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3339.                     } else {
  3340.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3341.                     }
  3342.                     // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3343.                     $portBOrderNos = array();
  3344.                     foreach ($portsB as $portID) {
  3345.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3346.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3347.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3348.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3349.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3350.                       $portsBIDS[] = $portID;
  3351.                     }
  3352.                     $portBOrderNos array_unique($portBOrderNos);
  3353.                     ksort($portBOrderNos);
  3354.                     $extension['portB'] = implode("/"$portBOrderNos);
  3355.                     // var_dump($extension['portB']);
  3356.                     $extensions[] = $extension;
  3357.                   }
  3358.                 }
  3359.                 // var_dump($tcfsForExts);
  3360.                 $portsB null;
  3361.                 foreach ($tcfsForExts as $tempTcf) {
  3362.                   $portsB[] = $tempTcf->getPortA();
  3363.                 }
  3364.                 // var_dump($portsB);
  3365.               }
  3366.             } else {
  3367.               $extension['portB_temp'] = '';
  3368.               $portBOrderNos = array();
  3369.               if ($portsB[0]) {
  3370.                 $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3371.                 $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3372.                 $rackTemp $eqSpe->getRack();
  3373.                 $roomTemp $rackTemp->getRoom();
  3374.                 $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3375.                 $extension['roomB'] = $roomTemp->getTitle();
  3376.                 $extension['rackB'] = $rackTemp->getTitle();
  3377.                 if ($eqSpe->isModule()) {
  3378.                   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3379.                   // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3380.                 } elseif ($eqSpe->isChassisModule()) {
  3381.                   $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3382.                   // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3383.                 } else {
  3384.                   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3385.                 }
  3386.                 if ($eqSpe->isModule()) {
  3387.                   $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3388.                 } elseif ($eqSpe->isChassisModule()) {
  3389.                   $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3390.                 } else {
  3391.                   $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3392.                 }
  3393.                 // if ($eqSpe->isModule()) {
  3394.                 //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3395.                 // }
  3396.                 // else {
  3397.                 //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  3398.                 // }
  3399.                 // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3400.                 // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3401.                 foreach ($portsB as $portID) {
  3402.                   $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3403.                   $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3404.                   $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3405.                   // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3406.                   // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3407.                 }
  3408.                 $portBOrderNos array_unique($portBOrderNos);
  3409.                 ksort($portBOrderNos);
  3410.                 $extension['portB'] = implode("/"$portBOrderNos);
  3411.                 $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  3412.                 $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3413.                 $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3414.                 $extensions[] = $extension;
  3415.                 // other trunk extensions
  3416.                 // get the ports for the extensions
  3417.                 $portsArrayArray = array();
  3418.                 if (count($tcfsForExts) > 0) {
  3419.                   for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  3420.                     $portArray = [];
  3421.                     foreach ($tcfsForExts as $tempTcf) {
  3422.                       // get the extensions of sequence $i
  3423.                       $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  3424.                       // var_dump($tempExt);
  3425.                       if ($tempExt) {
  3426.                         $portArray[] = $tempExt->getPortB();
  3427.                       }
  3428.                     }
  3429.                     $portsArrayArray[] = $portArray;
  3430.                   }
  3431.                   // var_dump($portsArrayArray);
  3432.                   $tcf $tcfsForExts[0];
  3433.                   $tcfExts $tcf->getExtensions();
  3434.                   $iterator 0;
  3435.                   foreach ($tcfExts as $tcfExt) {
  3436.                     // var_dump($tcfExt->getId());
  3437.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3438.                     $extension['ext'] = $tcfExt->getOperatorID();
  3439.                     $extension['color'] = $tcfExt->getTypeCable()->getColor();
  3440.                     $extension['portA'] = $extension['portB'];
  3441.                     $operatorID $tcfExt->getOperatorID();
  3442.                     $portsB $portsArrayArray[$iterator++];
  3443.                     // $portB = $tcfExt->getPortB();
  3444.                     // $portsB[] = $portB;
  3445.                     $extension['portB'] = '';
  3446.                     $portsBIDS = [];
  3447.                     $extension['portB_temp'] = '';
  3448.                     $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  3449.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3450.                     $rackTemp $eqSpe->getRack();
  3451.                     $roomTemp $rackTemp->getRoom();
  3452.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3453.                     $extension['roomB'] = $roomTemp->getTitle();
  3454.                     $extension['rackB'] = $rackTemp->getTitle();
  3455.                     if ($eqSpe->isModule()) {
  3456.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3457.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3458.                     } elseif ($eqSpe->isChassisModule()) {
  3459.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3460.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3461.                     } else {
  3462.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3463.                     }
  3464.                     if ($eqSpe->isModule()) {
  3465.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3466.                     } elseif ($eqSpe->isChassisModule()) {
  3467.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3468.                     } else {
  3469.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3470.                     }
  3471.                     // if ($eqSpe->isModule()) {
  3472.                     //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3473.                     // }
  3474.                     // else {
  3475.                     //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  3476.                     // }
  3477.                     // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3478.                     // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3479.                     $portBOrderNos = array();
  3480.                     foreach ($portsB as $portID) {
  3481.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3482.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3483.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3484.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3485.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3486.                       $portsBIDS[] = $portID;
  3487.                     }
  3488.                     $portBOrderNos array_unique($portBOrderNos);
  3489.                     ksort($portBOrderNos);
  3490.                     $extension['portB'] = implode("/"$portBOrderNos);
  3491.                     // var_dump($extension['portB']);
  3492.                     $extensions[] = $extension;
  3493.                   }
  3494.                 }
  3495.               }
  3496.             }
  3497.           }
  3498.           $tsn $linkExtensionSequenceNo;
  3499.           $t++;
  3500.         }
  3501.       }
  3502.       if ($reverseTrunk) {
  3503.         $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3504.         $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3505.         $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  3506.         $extension['portA'] = $extension['portB'];
  3507.         // $operatorID = $tcfsForExts[0]->getOperatorID();
  3508.         // $portB = $tcfExt->getPortB();
  3509.         // $portsB[] = $portB;
  3510.         $extension['portB'] = '';
  3511.         $portsBIDS = [];
  3512.         $extension['portB_temp'] = '';
  3513.         $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3514.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3515.         $rackTemp $eqSpe->getRack();
  3516.         $roomTemp $rackTemp->getRoom();
  3517.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3518.         $extension['roomB'] = $roomTemp->getTitle();
  3519.         $extension['rackB'] = $rackTemp->getTitle();
  3520.         if ($eqSpe->isModule()) {
  3521.           $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3522.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3523.         } elseif ($eqSpe->isChassisModule()) {
  3524.           $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3525.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3526.         } else {
  3527.           $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3528.         }
  3529.         if ($eqSpe->isModule()) {
  3530.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3531.         } elseif ($eqSpe->isChassisModule()) {
  3532.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3533.         } else {
  3534.           $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3535.         }
  3536.         // if ($eqSpe->isModule()) {
  3537.         //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3538.         // }
  3539.         // else {
  3540.         //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  3541.         // }
  3542.         // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3543.         // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3544.         $portBOrderNos = array();
  3545.         foreach ($portsB as $portID) {
  3546.           $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3547.           // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3548.           $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3549.           $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3550.           // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3551.           $portsBIDS[] = $portID;
  3552.         }
  3553.         $portBOrderNos array_unique($portBOrderNos);
  3554.         ksort($portBOrderNos);
  3555.         $extension['portB'] = implode("/"$portBOrderNos);
  3556.         // var_dump($extension['portB']);
  3557.         $extensions[] = $extension;
  3558.       } else {
  3559.         if ($ext->getTypeCable()) {
  3560.           $extension['color'] = $ext->getTypeCable()->getColor();
  3561.         } else {
  3562.           $extension['color'] = $ext->getTrunk()->getTypeCable()->getColor();
  3563.         }
  3564.         //set ports on extension object
  3565.         $portsA = [];
  3566.         $portAOrderNos = array();
  3567.         $portsATemp $ext->getExtremityA()->getExtensionOrder();
  3568.         foreach ($portsATemp as $value) {
  3569.           $portsA[] = $value->getPort();
  3570.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  3571.           $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  3572.           // $portAOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  3573.         }
  3574.         // $portsA = $ext->getExtremityA()->getPorts();
  3575.         // foreach ($portsA as $p) {
  3576.         //   $portAOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  3577.         // }
  3578.         $portAOrderNos array_unique($portAOrderNos);
  3579.         ksort($portAOrderNos);
  3580.         $extension['portA'] = implode("/"$portAOrderNos);
  3581.         $portsB = [];
  3582.         $portBOrderNos = array();
  3583.         $portsBTemp $ext->getExtremityB()->getExtensionOrder();
  3584.         foreach ($portsBTemp as $value) {
  3585.           $portsB[] = $value->getPort();
  3586.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  3587.           $portBOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  3588.           // $portBOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  3589.         }
  3590.         // $portsB = $ext->getExtremityB()->getPorts();
  3591.         // $portBOrderNos = array();
  3592.         // foreach ($portsB as $p) {
  3593.         //   $portBOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  3594.         // }
  3595.         $portBOrderNos array_unique($portBOrderNos);
  3596.         ksort($portBOrderNos);
  3597.         $extension['portB'] = implode("/"$portBOrderNos);
  3598.         // set other properties on side A of extension object
  3599.         $interfaceSpecTemp $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific() : $portsA[0]->getInterfaceSpecific();
  3600.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3601.         $rackTemp $eqSpe->getRack();
  3602.         $roomTemp $rackTemp->getRoom();
  3603.         $extension['siteA'] = $roomTemp->getSite()->getTitle();
  3604.         $extension['roomA'] = $roomTemp->getTitle();
  3605.         $extension['rackA'] = $rackTemp->getTitle();
  3606.         if ($eqSpe->isModule()) {
  3607.           $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3608.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3609.         } elseif ($eqSpe->isChassisModule()) {
  3610.           $extension['equipmentA'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3611.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3612.         } else {
  3613.           $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3614.         }
  3615.         if ($eqSpe->isModule()) {
  3616.           $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3617.         } elseif ($eqSpe->isChassisModule()) {
  3618.           $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3619.         } else {
  3620.           $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3621.         }
  3622.         // if ($eqSpe->isModule()) {
  3623.         //   $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3624.         // }
  3625.         // else {
  3626.         //   $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  3627.         // }
  3628.         // // $extension['equipmentA'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3629.         // $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3630.         // set other properties on side B of extension object
  3631.         $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3632.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3633.         $rackTemp $eqSpe->getRack();
  3634.         $roomTemp $rackTemp->getRoom();
  3635.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3636.         $extension['roomB'] = $roomTemp->getTitle();
  3637.         $extension['rackB'] = $rackTemp->getTitle();
  3638.         if ($eqSpe->isModule()) {
  3639.           $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3640.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3641.         } elseif ($eqSpe->isChassisModule()) {
  3642.           $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3643.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3644.         } else {
  3645.           $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3646.         }
  3647.         if ($eqSpe->isModule()) {
  3648.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3649.         } elseif ($eqSpe->isChassisModule()) {
  3650.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3651.         } else {
  3652.           $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3653.         }
  3654.         // if ($eqSpe->isModule()) {
  3655.         //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3656.         // }
  3657.         // else {
  3658.         //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  3659.         // }
  3660.         // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3661.         // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3662.       }
  3663.       // var_dump($extension);
  3664.       // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  3665.       //
  3666.       // if ($fiberNo > 1){
  3667.       //
  3668.       //     $portsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsABySequence($link, $linkExtensionSequenceNo);
  3669.       //     $portsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsBBySequence($link, $linkExtensionSequenceNo);
  3670.       //
  3671.       //     $extension['portA'] = '';
  3672.       //     $extension['portB'] = '';
  3673.       //
  3674.       //     $portsAIDS = [];
  3675.       //     $portsBIDS = [];
  3676.       //
  3677.       //     foreach ($portsA as $portID){
  3678.       //
  3679.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3680.       //
  3681.       //         $extension['siteA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3682.       //         $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3683.       //         $extension['rackA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3684.       //         $extension['equipmentA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3685.       //         $extension['interfaceA'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3686.       //
  3687.       //         if (!in_array($portID,$portsAIDS)){
  3688.       //             $extension['portA'] .= $port->getOrderNo().'/';
  3689.       //
  3690.       //         }
  3691.       //
  3692.       //         $portsAIDS[] = $portID;
  3693.       //
  3694.       //     }
  3695.       //
  3696.       //     $extension['portA'] = substr($extension['portA'], 0, -1);
  3697.       //
  3698.       //     $extension['portB_temp'] = '';
  3699.       //
  3700.       //     foreach ($portsB as $portID){
  3701.       //
  3702.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3703.       //
  3704.       //         $extension['siteB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3705.       //         $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3706.       //         $extension['rackB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3707.       //         $extension['equipmentB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3708.       //         $extension['interfaceB'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3709.       //
  3710.       //         if (!in_array($portID,$portsBIDS)){
  3711.       //             $extension['portB_temp'] .= $port->getOrderNo().'/';
  3712.       //         }
  3713.       //
  3714.       //         $portsBIDS[] = $portID;
  3715.       //
  3716.       //     }
  3717.       //
  3718.       //
  3719.       //     $extension['portB'] = substr($extension['portB_temp'], 0, -1);
  3720.       //
  3721.       //
  3722.       // } else {
  3723.       //
  3724.       //     $extension['siteA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3725.       //     $extension['roomA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3726.       //     $extension['rackA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3727.       //     $extension['equipmentA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3728.       //     $extension['interfaceA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3729.       //     $extension['portA'] = $ext->getExtremityA()->getPorts()[0]->getOrderNo();
  3730.       //
  3731.       //     $extension['siteB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  3732.       //     $extension['roomB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  3733.       //     $extension['rackB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  3734.       //     $extension['equipmentB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3735.       //     $extension['interfaceB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  3736.       //     $extension['portB'] = $ext->getExtremityB()->getPorts()[0]->getOrderNo();
  3737.       //
  3738.       // }
  3739.       if (!in_array($linkExtensionSequenceNo$sequence) && $extIsTrunkAndHasExtensions == 0) {
  3740.         $extensions[] = $extension;
  3741.       }
  3742.       $sequence[] = $linkExtensionSequenceNo;
  3743.     }
  3744.     for ($i 0$i count($extensions); $i++) {
  3745.       if ($i count($extensions) - 1) {
  3746.         if ($extensions[$i]['portB'] == $extensions[$i 1]['portA']) {
  3747.           $extensions[$i]['portsB'] = $extensions[$i]['portB'];
  3748.         } else {
  3749.           $extensions[$i]['portsB'] = 'E: ' $extensions[$i]['portB'] . ' | S: ' $extensions[$i 1]['portA'];
  3750.         }
  3751.       } else {
  3752.         $extensions[$i]['portsB'] =  $extensions[$i]['portB'];
  3753.       }
  3754.     }
  3755.     //return $this->json($extensions);
  3756.     return $this->render('link/diagram.html.twig', [
  3757.       'page_title' => $translator->trans('Link Diagram'),
  3758.       'link' => $link,
  3759.       'extensions' => $extensions,
  3760.       "referer" => $request->headers->get('referer')
  3761.     ]);
  3762.   }
  3763.   /**
  3764.    * @Route("/api/link/diagram/{id}", name="api_link_diagram")
  3765.    */
  3766.   public function apiLinkDiagramAction($idRequest $requestTranslatorInterface $translatorTCPDFController $tcpdf)
  3767.   {
  3768.     $em $this->getDoctrine()->getManager();
  3769.     $id strtoupper($id);
  3770.     $link $em->getRepository(Link::class)->findOneByLinkID($id);
  3771.     if (!$link) {
  3772.       return $this->json(['error' => 'Link ' $id ' n\'existe pas']);
  3773.     }
  3774.     $extensions = [];
  3775.     $sequence = [];
  3776.     $e 1;
  3777.     $t 0;
  3778.     $tsn 0;
  3779.     //get all the link extensions
  3780.     $linkExtensions $link->getLinkExtension();
  3781.     foreach ($linkExtensions as $ext) {
  3782.       $reverseTrunk false;
  3783.       // var_dump("link ext: ".$ext->getId());
  3784.       $linkExtensionSequenceNo $ext->getSequenceNo(); //If "1" that means, its first link extension
  3785.       $linkExtensionTrunk $ext->getTrunk(); //get the trunk if exists
  3786.       $extIsTrunkAndHasExtensions 0;
  3787.       $tcfExtsFromB null;
  3788.       if (is_null($linkExtensionTrunk)) { // if it doesn't have trunk
  3789.         // var_dump("trunk is null");
  3790.         $e $linkExtensionSequenceNo $t;
  3791.         if ($e 1) {
  3792.           $extension['ext'] = 'E' . ($e 1);
  3793.         } else {
  3794.           $extension['ext'] = '';
  3795.         }
  3796.         $extension['label'] = $link->getLinkID();
  3797.       } else {
  3798.         // var_dump("trunk id: ".$linkExtensionTrunk->getId());
  3799.         if ($linkExtensionSequenceNo != $tsn) {
  3800.           $tcfs $linkExtensionTrunk->getCableFiber();
  3801.           foreach ($tcfs as $tcf) {
  3802.             $trunkExts $tcf->getExtensions();
  3803.             if (sizeof($trunkExts) > 0) {
  3804.               $extIsTrunkAndHasExtensions 1;
  3805.             }
  3806.           }
  3807.           if ($extIsTrunkAndHasExtensions == 0) {
  3808.             // var_dump("trunk doesn't have extension");
  3809.             $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  3810.             $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3811.           } else {
  3812.             // var_dump("trunk has extensions");
  3813.             $portsA = [];
  3814.             $portAOrderNos = array();
  3815.             $portsATemp $ext->getExtremityA()->getExtensionOrder();
  3816.             foreach ($portsATemp as $value) {
  3817.               $portsA[] = $value->getPort();
  3818.               $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  3819.               $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  3820.               // $portAOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  3821.             }
  3822.             // $portsA = $ext->getExtremityA()->getPorts();
  3823.             // var_dump("extremity A id: ".$ext->getExtremityA()->getId());
  3824.             // var_dump("nombre de ports", count($portsA));
  3825.             // set other properties on side A of extension object
  3826.             $interfaceSpecTemp $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific() : $portsA[0]->getInterfaceSpecific();
  3827.             $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3828.             $rackTemp $eqSpe->getRack();
  3829.             $roomTemp $rackTemp->getRoom();
  3830.             $extension['siteA'] = $roomTemp->getSite()->getTitle();
  3831.             $extension['roomA'] = $roomTemp->getTitle();
  3832.             $extension['rackA'] = $rackTemp->getTitle();
  3833.             if ($eqSpe->isModule()) {
  3834.               $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3835.               // $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3836.             } elseif ($eqSpe->isChassisModule()) {
  3837.               $extension['equipmentA'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3838.               // $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3839.             } else {
  3840.               $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3841.             }
  3842.             if ($eqSpe->isModule()) {
  3843.               $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3844.             } elseif ($eqSpe->isChassisModule()) {
  3845.               $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3846.             } else {
  3847.               $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3848.             }
  3849.             // first trunk extension
  3850.             $portsB = [];
  3851.             $tcfsForExts = [];
  3852.             $tcfsExts = [];
  3853.             $tcfExtsFromB null;
  3854.             $duplex false;
  3855.             if ($link->getTypeLink()->getTitle() == "Duplex" && count($portsA) == || ($link->getTypeLink()->getTitle() != "Simplex" && count($portsA) == 1)) {
  3856.               $duplex true;
  3857.             }
  3858.             // var_dump($duplex);
  3859.             foreach ($portsA as $port) {
  3860.               // $portAOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3861.               $tcfFromA null;
  3862.               $tcfFromB null;
  3863.               $tcfExtFromB null;
  3864.               if ($duplex) {
  3865.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portA' => $port]);
  3866.                 // var_dump($tcfFromA->getId());
  3867.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portB' => $port]);
  3868.                 // var_dump($tcfFromB->getId());
  3869.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findBy(['portB' => $port]);
  3870.                 foreach ($tcfFromA as $temp) {
  3871.                   $portB $temp->getPortB();
  3872.                   $portsB[] = $portB;
  3873.                   $tcfsForExts[] = $temp;
  3874.                 }
  3875.                 foreach ($tcfFromB as $temp) {
  3876.                   $portB $temp->getPortB();
  3877.                   $portsB[] = $portB;
  3878.                   $tcfsForExts[] = $temp;
  3879.                 }
  3880.                 foreach ($tcfExtFromB as $temp) {
  3881.                   $tcfExtsFromB[] = $temp;
  3882.                   $reverseTrunk true;
  3883.                 }
  3884.               } else {
  3885.                 $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
  3886.                 // var_dump($tcfFromA->getId());
  3887.                 $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
  3888.                 // var_dump($tcfFromB->getId());
  3889.                 $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  3890.                 if ($tcfFromA) {
  3891.                   $portB $tcfFromA->getPortB();
  3892.                   $portsB[] = $portB;
  3893.                   $tcfsForExts[] = $tcfFromA;
  3894.                   // var_dump($portB->getId());
  3895.                 }
  3896.                 if ($tcfFromB) {
  3897.                   $portB $tcfFromB->getPortB();
  3898.                   $portsB[] = $portB;
  3899.                   $tcfsForExts[] = $tcfFromB;
  3900.                   // var_dump($portB->getId());
  3901.                 }
  3902.                 //to treat the reverse case
  3903.                 if ($tcfExtFromB) {
  3904.                   // var_dump($tcfExtFromB);
  3905.                   $tcfExtsFromB[] = $tcfExtFromB;
  3906.                   $reverseTrunk true;
  3907.                 }
  3908.               }
  3909.             }
  3910.             $portAOrderNos array_unique($portAOrderNos);
  3911.             ksort($portAOrderNos);
  3912.             $extension['portA'] = implode("/"$portAOrderNos);
  3913.             if ($reverseTrunk) {
  3914.               // var_dump("in reverse trunk");
  3915.               $portsArrayArray = array();
  3916.               if (count($tcfExtsFromB) > 0) {
  3917.                 $tcfsForExts = array();
  3918.                 foreach ($tcfExtsFromB as $tcfExt) {
  3919.                   $tcfsForExts[] = $tcfExt->getTrunkCableFiber();
  3920.                 }
  3921.                 for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  3922.                   $portArray = [];
  3923.                   foreach ($tcfsForExts as $tempTcf) {
  3924.                     // get the extensions of sequence $i
  3925.                     $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  3926.                     // var_dump($tempExt);
  3927.                     if ($tempExt) {
  3928.                       $portArray[] = $tempExt->getPortB();
  3929.                     }
  3930.                   }
  3931.                   $portsArrayArray[] = $portArray;
  3932.                   // var_dump($portsArrayArray);
  3933.                 }
  3934.                 // var_dump($portsArrayArray);
  3935.                 $tcf $tcfsForExts[0];
  3936.                 $tcfExts $tcf->getExtensions();
  3937.                 // var_dump($tcfExts);
  3938.                 for ($i count($tcfExts) - 1$i >= 0$i--) {
  3939.                   $portsB null;
  3940.                   if ($i == 0) {
  3941.                     foreach ($tcfsForExts as $tempTcf) {
  3942.                       $portsB[] = $tempTcf->getPortB();
  3943.                     }
  3944.                     $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3945.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3946.                     $extension['ext'] = $tcfExts[$i]->getOperatorID();
  3947.                     $extension['portA'] = $extension['portB'];
  3948.                     // $operatorID = $tcfsForExts[0]->getOperatorID();
  3949.                     // $portB = $tcfExt->getPortB();
  3950.                     // $portsB[] = $portB;
  3951.                     $extension['portB'] = '';
  3952.                     $portsBIDS = [];
  3953.                     $extension['portB_temp'] = '';
  3954.                     $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  3955.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  3956.                     $rackTemp $eqSpe->getRack();
  3957.                     $roomTemp $rackTemp->getRoom();
  3958.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  3959.                     $extension['roomB'] = $roomTemp->getTitle();
  3960.                     $extension['rackB'] = $rackTemp->getTitle();
  3961.                     if ($eqSpe->isModule()) {
  3962.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  3963.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3964.                     } elseif ($eqSpe->isChassisModule()) {
  3965.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  3966.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  3967.                     } else {
  3968.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  3969.                     }
  3970.                     if ($eqSpe->isModule()) {
  3971.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3972.                     } elseif ($eqSpe->isChassisModule()) {
  3973.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3974.                     } else {
  3975.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  3976.                     }
  3977.                     // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  3978.                     $portBOrderNos = array();
  3979.                     foreach ($portsB as $portID) {
  3980.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  3981.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  3982.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  3983.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  3984.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  3985.                       $portsBIDS[] = $portID;
  3986.                     }
  3987.                     $portBOrderNos array_unique($portBOrderNos);
  3988.                     ksort($portBOrderNos);
  3989.                     $extension['portB'] = implode("/"$portBOrderNos);
  3990.                     // var_dump($extension['portB']);
  3991.                     $extensions[] = $extension;
  3992.                   } else {
  3993.                     $portsB $portsArrayArray[$i 1];
  3994.                     $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  3995.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  3996.                     $extension['ext'] = $tcfExts[$i]->getOperatorID();
  3997.                     $extension['portA'] = $extension['portB'];
  3998.                     $operatorID $tcfExts[$i]->getOperatorID();
  3999.                     // $portB = $tcfExt->getPortB();
  4000.                     // $portsB[] = $portB;
  4001.                     $extension['portB'] = '';
  4002.                     $portsBIDS = [];
  4003.                     $extension['portB_temp'] = '';
  4004.                     $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  4005.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4006.                     $rackTemp $eqSpe->getRack();
  4007.                     $roomTemp $rackTemp->getRoom();
  4008.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  4009.                     $extension['roomB'] = $roomTemp->getTitle();
  4010.                     $extension['rackB'] = $rackTemp->getTitle();
  4011.                     if ($eqSpe->isModule()) {
  4012.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4013.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4014.                     } elseif ($eqSpe->isChassisModule()) {
  4015.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4016.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4017.                     } else {
  4018.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4019.                     }
  4020.                     if ($eqSpe->isModule()) {
  4021.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4022.                     } elseif ($eqSpe->isChassisModule()) {
  4023.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4024.                     } else {
  4025.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4026.                     }
  4027.                     // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4028.                     $portBOrderNos = array();
  4029.                     foreach ($portsB as $portID) {
  4030.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4031.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  4032.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  4033.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  4034.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  4035.                       $portsBIDS[] = $portID;
  4036.                     }
  4037.                     $portBOrderNos array_unique($portBOrderNos);
  4038.                     ksort($portBOrderNos);
  4039.                     $extension['portB'] = implode("/"$portBOrderNos);
  4040.                     // var_dump($extension['portB']);
  4041.                     $extensions[] = $extension;
  4042.                   }
  4043.                 }
  4044.                 // var_dump($tcfsForExts);
  4045.                 $portsB null;
  4046.                 foreach ($tcfsForExts as $tempTcf) {
  4047.                   $portsB[] = $tempTcf->getPortA();
  4048.                 }
  4049.                 // var_dump($portsB);
  4050.               }
  4051.             } else {
  4052.               $extension['portB_temp'] = '';
  4053.               $portBOrderNos = array();
  4054.               if ($portsB[0]) {
  4055.                 $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  4056.                 $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4057.                 $rackTemp $eqSpe->getRack();
  4058.                 $roomTemp $rackTemp->getRoom();
  4059.                 $extension['siteB'] = $roomTemp->getSite()->getTitle();
  4060.                 $extension['roomB'] = $roomTemp->getTitle();
  4061.                 $extension['rackB'] = $rackTemp->getTitle();
  4062.                 if ($eqSpe->isModule()) {
  4063.                   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4064.                   // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4065.                 } elseif ($eqSpe->isChassisModule()) {
  4066.                   $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4067.                   // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4068.                 } else {
  4069.                   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4070.                 }
  4071.                 if ($eqSpe->isModule()) {
  4072.                   $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4073.                 } elseif ($eqSpe->isChassisModule()) {
  4074.                   $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4075.                 } else {
  4076.                   $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4077.                 }
  4078.                 // if ($eqSpe->isModule()) {
  4079.                 //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4080.                 // }
  4081.                 // else {
  4082.                 //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  4083.                 // }
  4084.                 // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4085.                 // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4086.                 foreach ($portsB as $portID) {
  4087.                   $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4088.                   $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  4089.                   $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  4090.                   // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  4091.                   // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  4092.                 }
  4093.                 $portBOrderNos array_unique($portBOrderNos);
  4094.                 ksort($portBOrderNos);
  4095.                 $extension['portB'] = implode("/"$portBOrderNos);
  4096.                 $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  4097.                 $extension['label'] = $linkExtensionTrunk->getTrunkID();
  4098.                 $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  4099.                 $extensions[] = $extension;
  4100.                 // other trunk extensions
  4101.                 // get the ports for the extensions
  4102.                 $portsArrayArray = array();
  4103.                 if (count($tcfsForExts) > 0) {
  4104.                   for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  4105.                     $portArray = [];
  4106.                     foreach ($tcfsForExts as $tempTcf) {
  4107.                       // get the extensions of sequence $i
  4108.                       $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  4109.                       // var_dump($tempExt);
  4110.                       if ($tempExt) {
  4111.                         $portArray[] = $tempExt->getPortB();
  4112.                       }
  4113.                     }
  4114.                     $portsArrayArray[] = $portArray;
  4115.                   }
  4116.                   // var_dump($portsArrayArray);
  4117.                   $tcf $tcfsForExts[0];
  4118.                   $tcfExts $tcf->getExtensions();
  4119.                   $iterator 0;
  4120.                   foreach ($tcfExts as $tcfExt) {
  4121.                     // var_dump($tcfExt->getId());
  4122.                     $extension['label'] = $linkExtensionTrunk->getTrunkID();
  4123.                     $extension['ext'] = $tcfExt->getOperatorID();
  4124.                     $extension['color'] = $tcfExt->getTypeCable()->getColor();
  4125.                     $extension['portA'] = $extension['portB'];
  4126.                     $operatorID $tcfExt->getOperatorID();
  4127.                     $portsB $portsArrayArray[$iterator++];
  4128.                     // $portB = $tcfExt->getPortB();
  4129.                     // $portsB[] = $portB;
  4130.                     $extension['portB'] = '';
  4131.                     $portsBIDS = [];
  4132.                     $extension['portB_temp'] = '';
  4133.                     $interfaceSpecTemp $portsB[0]->getInterfaceSpecific();
  4134.                     $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4135.                     $rackTemp $eqSpe->getRack();
  4136.                     $roomTemp $rackTemp->getRoom();
  4137.                     $extension['siteB'] = $roomTemp->getSite()->getTitle();
  4138.                     $extension['roomB'] = $roomTemp->getTitle();
  4139.                     $extension['rackB'] = $rackTemp->getTitle();
  4140.                     if ($eqSpe->isModule()) {
  4141.                       $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4142.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4143.                     } elseif ($eqSpe->isChassisModule()) {
  4144.                       $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4145.                       // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4146.                     } else {
  4147.                       $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4148.                     }
  4149.                     if ($eqSpe->isModule()) {
  4150.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4151.                     } elseif ($eqSpe->isChassisModule()) {
  4152.                       $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4153.                     } else {
  4154.                       $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4155.                     }
  4156.                     // if ($eqSpe->isModule()) {
  4157.                     //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4158.                     // }
  4159.                     // else {
  4160.                     //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  4161.                     // }
  4162.                     // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4163.                     // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4164.                     $portBOrderNos = array();
  4165.                     foreach ($portsB as $portID) {
  4166.                       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4167.                       // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  4168.                       $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  4169.                       $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  4170.                       // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  4171.                       $portsBIDS[] = $portID;
  4172.                     }
  4173.                     $portBOrderNos array_unique($portBOrderNos);
  4174.                     ksort($portBOrderNos);
  4175.                     $extension['portB'] = implode("/"$portBOrderNos);
  4176.                     // var_dump($extension['portB']);
  4177.                     $extensions[] = $extension;
  4178.                   }
  4179.                 }
  4180.               }
  4181.             }
  4182.           }
  4183.           $tsn $linkExtensionSequenceNo;
  4184.           $t++;
  4185.         }
  4186.       }
  4187.       if ($reverseTrunk) {
  4188.         $extension['color'] = $linkExtensionTrunk->getTypeCable()->getColor();
  4189.         $extension['label'] = $linkExtensionTrunk->getTrunkID();
  4190.         $extension['ext'] = $linkExtensionTrunk->getOperatorID();
  4191.         $extension['portA'] = $extension['portB'];
  4192.         // $operatorID = $tcfsForExts[0]->getOperatorID();
  4193.         // $portB = $tcfExt->getPortB();
  4194.         // $portsB[] = $portB;
  4195.         $extension['portB'] = '';
  4196.         $portsBIDS = [];
  4197.         $extension['portB_temp'] = '';
  4198.         $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  4199.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4200.         $rackTemp $eqSpe->getRack();
  4201.         $roomTemp $rackTemp->getRoom();
  4202.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  4203.         $extension['roomB'] = $roomTemp->getTitle();
  4204.         $extension['rackB'] = $rackTemp->getTitle();
  4205.         if ($eqSpe->isModule()) {
  4206.           $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4207.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4208.         } elseif ($eqSpe->isChassisModule()) {
  4209.           $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4210.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4211.         } else {
  4212.           $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4213.         }
  4214.         if ($eqSpe->isModule()) {
  4215.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4216.         } elseif ($eqSpe->isChassisModule()) {
  4217.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4218.         } else {
  4219.           $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4220.         }
  4221.         // if ($eqSpe->isModule()) {
  4222.         //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4223.         // }
  4224.         // else {
  4225.         //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  4226.         // }
  4227.         // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4228.         // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4229.         $portBOrderNos = array();
  4230.         foreach ($portsB as $portID) {
  4231.           $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4232.           // $portBOrderNos[$port->getOrderNoExtension()-1] = $port->getOrderNo();
  4233.           $tempMpo $port->getPortMpo() ? $port->getPortMpo()->getAlias() != "" $port->getPortMpo()->getAlias() . "|" $port->getPortMpo()->getOrderNo() . "|" "";
  4234.           $portBOrderNos[] = $tempMpo . ($port->getAlias() != "" $port->getAlias() : $port->getOrderNo());
  4235.           // $portBOrderNos[] = ($port->getAlias()) ? $port->getAlias() : $port->getOrderNo();
  4236.           $portsBIDS[] = $portID;
  4237.         }
  4238.         $portBOrderNos array_unique($portBOrderNos);
  4239.         ksort($portBOrderNos);
  4240.         $extension['portB'] = implode("/"$portBOrderNos);
  4241.         // var_dump($extension['portB']);
  4242.         $extensions[] = $extension;
  4243.       } else {
  4244.         if ($ext->getTypeCable()) {
  4245.           $extension['color'] = $ext->getTypeCable()->getColor();
  4246.         } else {
  4247.           $extension['color'] = $ext->getTrunk()->getTypeCable()->getColor();
  4248.         }
  4249.         //set ports on extension object
  4250.         $portsA = [];
  4251.         $portAOrderNos = array();
  4252.         $portsATemp $ext->getExtremityA()->getExtensionOrder();
  4253.         foreach ($portsATemp as $value) {
  4254.           $portsA[] = $value->getPort();
  4255.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  4256.           $portAOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  4257.           // $portAOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  4258.         }
  4259.         // $portsA = $ext->getExtremityA()->getPorts();
  4260.         // foreach ($portsA as $p) {
  4261.         //   $portAOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  4262.         // }
  4263.         $portAOrderNos array_unique($portAOrderNos);
  4264.         ksort($portAOrderNos);
  4265.         $extension['portA'] = implode("/"$portAOrderNos);
  4266.         $portsB = [];
  4267.         $portBOrderNos = array();
  4268.         $portsBTemp $ext->getExtremityB()->getExtensionOrder();
  4269.         foreach ($portsBTemp as $value) {
  4270.           $portsB[] = $value->getPort();
  4271.           $tempMpo $value->getPort()->getPortMpo() ? $value->getPort()->getPortMpo()->getAlias() != "" $value->getPort()->getPortMpo()->getAlias() . "|" $value->getPort()->getPortMpo()->getOrderNo() . "|" "";
  4272.           $portBOrderNos[$value->getOrderNumber() - 1] = $tempMpo . ($value->getPort()->getAlias() != "" $value->getPort()->getAlias() : $value->getPort()->getOrderNo());
  4273.           // $portBOrderNos[$value->getOrderNumber()-1] = ($value->getPort()->getAlias()) ? $value->getPort()->getAlias() : $value->getPort()->getOrderNo();
  4274.         }
  4275.         // $portsB = $ext->getExtremityB()->getPorts();
  4276.         // $portBOrderNos = array();
  4277.         // foreach ($portsB as $p) {
  4278.         //   $portBOrderNos[$p->getOrderNoExtension()-1] = $p->getOrderNo();
  4279.         // }
  4280.         $portBOrderNos array_unique($portBOrderNos);
  4281.         ksort($portBOrderNos);
  4282.         $extension['portB'] = implode("/"$portBOrderNos);
  4283.         // set other properties on side A of extension object
  4284.         $interfaceSpecTemp $portsA[0]->getPortMpo() ? $portsA[0]->getPortMpo()->getInterfaceSpecific() : $portsA[0]->getInterfaceSpecific();
  4285.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4286.         $rackTemp $eqSpe->getRack();
  4287.         $roomTemp $rackTemp->getRoom();
  4288.         $extension['siteA'] = $roomTemp->getSite()->getTitle();
  4289.         $extension['roomA'] = $roomTemp->getTitle();
  4290.         $extension['rackA'] = $rackTemp->getTitle();
  4291.         if ($eqSpe->isModule()) {
  4292.           $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4293.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4294.         } elseif ($eqSpe->isChassisModule()) {
  4295.           $extension['equipmentA'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4296.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4297.         } else {
  4298.           $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4299.         }
  4300.         if ($eqSpe->isModule()) {
  4301.           $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4302.         } elseif ($eqSpe->isChassisModule()) {
  4303.           $extension['interfaceA'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4304.         } else {
  4305.           $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4306.         }
  4307.         // if ($eqSpe->isModule()) {
  4308.         //   $extension['equipmentA'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4309.         // }
  4310.         // else {
  4311.         //   $extension['equipmentA'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  4312.         // }
  4313.         // // $extension['equipmentA'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4314.         // $extension['interfaceA'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4315.         // set other properties on side B of extension object
  4316.         $interfaceSpecTemp $portsB[0]->getPortMpo() ? $portsB[0]->getPortMpo()->getInterfaceSpecific() : $portsB[0]->getInterfaceSpecific();
  4317.         $eqSpe $interfaceSpecTemp->getEquipmentSpecificMpo() ? $interfaceSpecTemp->getEquipmentSpecificMpo() : $interfaceSpecTemp->getEquipmentSpecific();
  4318.         $rackTemp $eqSpe->getRack();
  4319.         $roomTemp $rackTemp->getRoom();
  4320.         $extension['siteB'] = $roomTemp->getSite()->getTitle();
  4321.         $extension['roomB'] = $roomTemp->getTitle();
  4322.         $extension['rackB'] = $rackTemp->getTitle();
  4323.         if ($eqSpe->isModule()) {
  4324.           $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName() . ' (' $eqSpe->getParent()->getEquipmentGeneric()->getTitle() . ')';
  4325.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4326.         } elseif ($eqSpe->isChassisModule()) {
  4327.           $extension['equipmentB'] = $eqSpe->getChassisParent()->getEquipmentSpecificName() . ' (' $eqSpe->getChassisParent()->getEquipmentGeneric()->getTitle() . ')';
  4328.           // $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4329.         } else {
  4330.           $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName() . ' (' $eqSpe->getEquipmentGeneric()->getTitle() . ')';
  4331.         }
  4332.         if ($eqSpe->isModule()) {
  4333.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4334.         } elseif ($eqSpe->isChassisModule()) {
  4335.           $extension['interfaceB'] = $eqSpe->getEquipmentSpecificName() . '-' $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4336.         } else {
  4337.           $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4338.         }
  4339.         // if ($eqSpe->isModule()) {
  4340.         //   $extension['equipmentB'] = $eqSpe->getParent()->getEquipmentSpecificName(). 'â•‘' . $eqSpe->getEquipmentSpecificName() .' ('.$eqSpe->getParent()->getEquipmentGeneric()->getTitle().')';
  4341.         // }
  4342.         // else {
  4343.         //   $extension['equipmentB'] = $eqSpe->getEquipmentSpecificName().' ('.$eqSpe->getEquipmentGeneric()->getTitle().')';
  4344.         // }
  4345.         // // $extension['equipmentB'] = $interfaceSpecTemp->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$interfaceSpecTemp->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4346.         // $extension['interfaceB'] = $interfaceSpecTemp->getInterfaceGeneric()->getInterfaceNumber();
  4347.       }
  4348.       // var_dump($extension);
  4349.       // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  4350.       //
  4351.       // if ($fiberNo > 1){
  4352.       //
  4353.       //     $portsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsABySequence($link, $linkExtensionSequenceNo);
  4354.       //     $portsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsBBySequence($link, $linkExtensionSequenceNo);
  4355.       //
  4356.       //     $extension['portA'] = '';
  4357.       //     $extension['portB'] = '';
  4358.       //
  4359.       //     $portsAIDS = [];
  4360.       //     $portsBIDS = [];
  4361.       //
  4362.       //     foreach ($portsA as $portID){
  4363.       //
  4364.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4365.       //
  4366.       //         $extension['siteA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  4367.       //         $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  4368.       //         $extension['rackA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  4369.       //         $extension['equipmentA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4370.       //         $extension['interfaceA'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  4371.       //
  4372.       //         if (!in_array($portID,$portsAIDS)){
  4373.       //             $extension['portA'] .= $port->getOrderNo().'/';
  4374.       //
  4375.       //         }
  4376.       //
  4377.       //         $portsAIDS[] = $portID;
  4378.       //
  4379.       //     }
  4380.       //
  4381.       //     $extension['portA'] = substr($extension['portA'], 0, -1);
  4382.       //
  4383.       //     $extension['portB_temp'] = '';
  4384.       //
  4385.       //     foreach ($portsB as $portID){
  4386.       //
  4387.       //         $port = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  4388.       //
  4389.       //         $extension['siteB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  4390.       //         $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  4391.       //         $extension['rackB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  4392.       //         $extension['equipmentB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4393.       //         $extension['interfaceB'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  4394.       //
  4395.       //         if (!in_array($portID,$portsBIDS)){
  4396.       //             $extension['portB_temp'] .= $port->getOrderNo().'/';
  4397.       //         }
  4398.       //
  4399.       //         $portsBIDS[] = $portID;
  4400.       //
  4401.       //     }
  4402.       //
  4403.       //
  4404.       //     $extension['portB'] = substr($extension['portB_temp'], 0, -1);
  4405.       //
  4406.       //
  4407.       // } else {
  4408.       //
  4409.       //     $extension['siteA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  4410.       //     $extension['roomA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  4411.       //     $extension['rackA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  4412.       //     $extension['equipmentA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4413.       //     $extension['interfaceA'] = $ext->getExtremityA()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  4414.       //     $extension['portA'] = $ext->getExtremityA()->getPorts()[0]->getOrderNo();
  4415.       //
  4416.       //     $extension['siteB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  4417.       //     $extension['roomB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  4418.       //     $extension['rackB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  4419.       //     $extension['equipmentB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentGeneric()->getTitle().' ('.$ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName().')';
  4420.       //     $extension['interfaceB'] = $ext->getExtremityB()->getPorts()[0]->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  4421.       //     $extension['portB'] = $ext->getExtremityB()->getPorts()[0]->getOrderNo();
  4422.       //
  4423.       // }
  4424.       if (!in_array($linkExtensionSequenceNo$sequence) && $extIsTrunkAndHasExtensions == 0) {
  4425.         $extensions[] = $extension;
  4426.       }
  4427.       $sequence[] = $linkExtensionSequenceNo;
  4428.     }
  4429.     for ($i 0$i count($extensions); $i++) {
  4430.       if ($i count($extensions) - 1) {
  4431.         if ($extensions[$i]['portB'] == $extensions[$i 1]['portA']) {
  4432.           $extensions[$i]['portsB'] = $extensions[$i]['portB'];
  4433.         } else {
  4434.           $extensions[$i]['portsB'] = 'E: ' $extensions[$i]['portB'] . ' | S: ' $extensions[$i 1]['portA'];
  4435.         }
  4436.       } else {
  4437.         $extensions[$i]['portsB'] =  $extensions[$i]['portB'];
  4438.       }
  4439.     }
  4440.     // return $this->render('link/diagram_pdf.html.twig', [
  4441.     //     'page_title' => $translator->trans('Link Diagram'),
  4442.     //     'link' => $link,
  4443.     //     'extensions' => $extensions,
  4444.     //     "referer" => $request->headers->get('referer')
  4445.     // ]);
  4446.     $html $this->renderView(
  4447.       'link/diagram_pdf.html.twig',
  4448.       [
  4449.         'link' => $link,
  4450.         'extensions' => $extensions
  4451.       ]
  4452.     );
  4453.     $heightExt 30 + (sizeof($extensions) + 1) * 48;
  4454.     $pdf $tcpdf->create('P'PDF_UNIT, array(120$heightExt), true'UTF-8'false);
  4455.     $pdf->SetAuthor('FIBERLINK');
  4456.     $pdf->SetTitle('Link ' $link->getLinkID());
  4457.     $pdf->SetSubject('Link ' $link->getLinkID());
  4458.     $pdf->setFontSubsetting(true);
  4459.     $pdf->SetFont('helvetica'''7''true);
  4460.     // remove default header/footer
  4461.     $pdf->setPrintHeader(false);
  4462.     $pdf->setPrintFooter(false);
  4463.     $pdf->setMargins(2, -32false); //left, top, right
  4464.     $pdf->SetAutoPageBreak(TRUE0);
  4465.     $pdf->AddPage();
  4466.     $filename $this->container->get('kernel')->getRootDir() . '/../web/uploads/link-' $link->getLinkID();
  4467.     // $filename = 'link-'.$link->getLinkID();
  4468.     $pdf->writeHTML($htmltruefalsetruefalse'');
  4469.     ob_end_clean();
  4470.     $pdf->Output($filename ".pdf"'F'); // This will save the PDF to the directory
  4471.     $pdf = new \Spatie\PdfToImage\Pdf($filename ".pdf");
  4472.     $pdf->setOutputFormat('png')
  4473.       ->saveImage($filename '.png');
  4474.     // ob_end_clean();
  4475.     return new BinaryFileResponse(
  4476.       $filename ".png"
  4477.     );
  4478.     // return null;
  4479.     // $html = $this->renderView('link/diagram_pdf.html.twig', [
  4480.     //         'link' => $link,
  4481.     //         'extensions' => $extensions
  4482.     //     ]
  4483.     // );
  4484.     // $filename = 'link-'.$link->getLinkID() . '.png';
  4485.     // return new JpegResponse(
  4486.     //     $this->get('knp_snappy.image')->getOutputFromHtml($html),
  4487.     //     $filename
  4488.     // );
  4489.   }
  4490.   /**
  4491.    * @IsGranted("ROLE_CRUD")
  4492.    * @Route("/link/process/basic", name="link_edit_basic")
  4493.    */
  4494.   public function editBasicAction(Request $requestTranslatorInterface $translator)
  4495.   {
  4496.     $em $this->getDoctrine()->getManager();
  4497.     $link $this->getDoctrine()->getRepository('App\Entity\Link')->findOneById($request->request->get('link_id'));
  4498.     $link->setLinkID($request->request->get('linkID'));
  4499.     $link->setOwner($request->request->get('owner'));
  4500.     $link->setTypeUsage($this->getDoctrine()->getRepository('App\Entity\TypeUsage')->findOneById($request->request->get('typeUsage')));
  4501.     $link->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneById($request->request->get('typeLink')));
  4502.     $em->persist($link);
  4503.     $em->flush();
  4504.     return $this->redirectToRoute('link_list');
  4505.   }
  4506.   /**
  4507.    * @IsGranted("ROLE_CRUD")
  4508.    * @Route("/link/edit/fiber/{id}", name="link_edit_fiber")
  4509.    */
  4510.   public function editFiberAction($idTranslatorInterface $translator)
  4511.   {
  4512.     $em $this->getDoctrine()->getManager();
  4513.     $extension $em->getRepository(LinkExtension::class)->find($id);
  4514.     $link $extension->getLink();
  4515.     $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  4516.     $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  4517.     $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  4518.     $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  4519.     $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  4520.     // $portsATemp = $extension->getExtremityA()->getPorts();
  4521.     $portsATemp $extension->getExtremityA()->getExtensionOrder();
  4522.     // $portsBTemp = $extension->getExtremityB()->getPorts();
  4523.     $portsBTemp $extension->getExtremityB()->getExtensionOrder();
  4524.     $portsA = array();
  4525.     foreach ($portsATemp as $p) {
  4526.       $portsA[] = $p->getPort();
  4527.     }
  4528.     $portsB = array();
  4529.     foreach ($portsBTemp as $p) {
  4530.       $portsB[] = $p->getPort();
  4531.     }
  4532.     return $this->render('link/edit_fiber.html.twig', [
  4533.       'action' => 'insert',
  4534.       'page_title' => $translator->trans('Edit Cable / Fiber'),
  4535.       'box_title' => '<i class="fa fa-edit fa-fw"></i> ' $translator->trans('Edit'),
  4536.       'extension' => $extension,
  4537.       'sites' => $sites,
  4538.       'eqGeneric' => $eqGeneric,
  4539.       'racks' => $racks,
  4540.       'rackFaces' => $rackFaces,
  4541.       'link' => $link,
  4542.       'typeCable' => $typeCable,
  4543.       'portsA' => $portsA,
  4544.       'portsB' => $portsB
  4545.     ]);
  4546.   }
  4547.   /**
  4548.    * @IsGranted("ROLE_CRUD")
  4549.    * @Route("/link/edit/process/fiber", name="link_edit_process_fiber")
  4550.    */
  4551.   public function editProcessFiberAction(Request $requestTranslatorInterface $translator)
  4552.   {
  4553.     $em $this->getDoctrine()->getManager();
  4554.     $extension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneById($request->request->get('extension_id'));
  4555.     $trunk $extension->getTrunk();
  4556.     $link $extension->getLink();
  4557.     $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  4558.     $portsA = array();
  4559.     $portsB = array();
  4560.     $portsAOld = array();
  4561.     $portA2 null;
  4562.     $portA3 null;
  4563.     $portA4 null;
  4564.     $portA5 null;
  4565.     $portA6 null;
  4566.     $portA7 null;
  4567.     $portA8 null;
  4568.     $portA9 null;
  4569.     $portA10 null;
  4570.     $portA11 null;
  4571.     $portA12 null;
  4572.     $portB2 null;
  4573.     $portB3 null;
  4574.     $portB4 null;
  4575.     $portB5 null;
  4576.     $portB6 null;
  4577.     $portB7 null;
  4578.     $portB8 null;
  4579.     $portB9 null;
  4580.     $portB10 null;
  4581.     $portB11 null;
  4582.     $portB12 null;
  4583.     // get selected ports
  4584.     $portA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
  4585.     $portsA["portA1"] = $portA1;
  4586.     for ($i 2$i <= 12$i++) {
  4587.       if ($request->request->get('pointA_' $i) != "") {
  4588.         $temp "portA" $i;
  4589.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_' $i));
  4590.         $portsA[$temp] = $$temp;
  4591.       }
  4592.     }
  4593.     // if ($request->request->get('pointA_2') != "") {
  4594.     //   $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_2'));
  4595.     // }
  4596.     $portB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
  4597.     $portsB[] = $portB1;
  4598.     for ($i 2$i <= 12$i++) {
  4599.       if ($request->request->get('pointB_' $i) != "") {
  4600.         $temp "portB" $i;
  4601.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_' $i));
  4602.         $portsB[$temp] = $$temp;
  4603.       }
  4604.     }
  4605.     // if ($request->request->get('pointB_2') != "") {
  4606.     //   $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_2'));
  4607.     // }
  4608.     //get old ports
  4609.     $portOldA2 null;
  4610.     $portOldA3 null;
  4611.     $portOldA4 null;
  4612.     $portOldA5 null;
  4613.     $portOldA6 null;
  4614.     $portOldA7 null;
  4615.     $portOldA8 null;
  4616.     $portOldA9 null;
  4617.     $portOldA10 null;
  4618.     $portOldA11 null;
  4619.     $portOldA12 null;
  4620.     $portOldB2 null;
  4621.     $portOldB3 null;
  4622.     $portOldB4 null;
  4623.     $portOldB5 null;
  4624.     $portOldB6 null;
  4625.     $portOldB7 null;
  4626.     $portOldB8 null;
  4627.     $portOldB9 null;
  4628.     $portOldB10 null;
  4629.     $portOldB11 null;
  4630.     $portOldB12 null;
  4631.     // get selected portOlds
  4632.     $portOldA1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldA_1'));
  4633.     $portsAOld[] = $portOldA1;
  4634.     // if ($request->request->get('pointOldA_2') != "") {
  4635.     //   $portOldA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldA_2'));
  4636.     //   $portsAOld[] = $portOldA2;
  4637.     // }
  4638.     for ($i 2$i <= 12$i++) {
  4639.       if ($request->request->get('pointOldA_' $i) != "") {
  4640.         $temp "portOldA" $i;
  4641.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldA_' $i));
  4642.         $portsAOld[] = $$temp;
  4643.       }
  4644.     }
  4645.     $portOldB1 $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldB_1'));
  4646.     for ($i 2$i <= 12$i++) {
  4647.       if ($request->request->get('pointOldB_' $i) != "") {
  4648.         $temp "portOldB" $i;
  4649.         $$temp $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldB_' $i));
  4650.         // $portsBOld[] = $$temp;
  4651.       }
  4652.     }
  4653.     // if ($request->request->get('pointOldB_2') != "") {
  4654.     //   $portOldB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointOldB_2'));
  4655.     // }
  4656.     //check if it's a trunk
  4657.     if ($trunk) {
  4658.       for ($i 1$i <= 12$i++) {
  4659.         $temp "portA" $i;
  4660.         if ($$temp && !$this->isInTrunk($$temp)) {
  4661.           $this->addFlash(
  4662.             'error',
  4663.             'l\'un des ports Choisis n\'est pas dans trunk'
  4664.           );
  4665.           $redirect true;
  4666.           break;
  4667.         }
  4668.       }
  4669.       // if (!$this->isInTrunk($portA1)) {
  4670.       //   $this->addFlash(
  4671.       //       'error',
  4672.       //       'l\'un des ports Choisis n\'est pas dans trunk'
  4673.       //   );
  4674.       //   $redirect = true;
  4675.       // }
  4676.       //
  4677.       // if ($portA2 && !$this->isInTrunk($portA2)) {
  4678.       //   $this->addFlash(
  4679.       //       'error',
  4680.       //       'l\'un des ports Choisis n\'est pas dans trunk'
  4681.       //   );
  4682.       //   $redirect = true;
  4683.       // }
  4684.       for ($i 1$i <= 12$i++) {
  4685.         $temp "portB" $i;
  4686.         if ($$temp && !$this->isInTrunk($$temp)) {
  4687.           $this->addFlash(
  4688.             'error',
  4689.             'l\'un des ports Choisis n\'est pas dans trunk'
  4690.           );
  4691.           $redirect true;
  4692.           break;
  4693.         }
  4694.       }
  4695.       // if (!$this->isInTrunk($portB1)) {
  4696.       //   $this->addFlash(
  4697.       //       'error',
  4698.       //       'l\'un des ports Choisis n\'est pas dans trunk'
  4699.       //   );
  4700.       //   $redirect = true;
  4701.       // }
  4702.       // if ($portB2 && !$this->isInTrunk($portB2)) {
  4703.       //   $this->addFlash(
  4704.       //       'error',
  4705.       //       'l\'un des ports Choisis n\'est pas dans trunk'
  4706.       //   );
  4707.       //   $redirect = true;
  4708.       // }
  4709.       if ($redirect) {
  4710.         return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  4711.       }
  4712.       // getOtherPorts used by the link
  4713.       //unset old ports
  4714.       $ports $this->getPorts($trunk$portsAOld$link->getTypeLink());
  4715.       foreach ($ports as $port) {
  4716.         $port->setLink(null);
  4717.         $port->setLinkExtension(null);
  4718.         $em->persist($port);
  4719.       }
  4720.       if (($portA1->getId() != $portOldA1->getId() && $portB1->getId() != $portOldB1->getId()) || $portA1->getId() != $portOldA1->getId()) {
  4721.         for ($i 1$i <= 12$i++) {
  4722.           $temp "portA" $i;
  4723.           if ($$temp) {
  4724.             $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($$temp);
  4725.             if ($trunkExtTemp) {
  4726.               $tcfTemp $trunkExtTemp->getTrunkCableFiber();
  4727.               if ($i 1) {
  4728.                 $tempPortB2 $tcfTemp->getPortA();
  4729.                 $temp1 "portB" . ($i 1);
  4730.                 if ($$temp1->getId() != $tempPortB2->getId()) {
  4731.                   $temp2 "portB" $i;
  4732.                   $$temp2 $tempPortB2;
  4733.                 }
  4734.               } else {
  4735.                 $portB1 $tcfTemp->getPortA();
  4736.               }
  4737.             } else {
  4738.               $tcfTemp $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($$temp);
  4739.               if ($tcfTemp) {
  4740.                 $lenTemp count($tcfTemp->getExtensions());
  4741.                 if ($lenTemp 0) {
  4742.                   $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber" => $tcfTemp"sequenceNo" => $lenTemp]);
  4743.                   if ($i 1) {
  4744.                     $tempPortB2 $trunkExtTemp->getPortB();
  4745.                     $temp1 "portB" . ($i 1);
  4746.                     if ($$temp1->getId() != $tempPortB2->getId()) {
  4747.                       $temp2 "portB" $i;
  4748.                       $$temp2 $tempPortB2;
  4749.                     }
  4750.                   } else {
  4751.                     $portB1 $trunkExtTemp->getPortB();
  4752.                   }
  4753.                 } else {
  4754.                   if ($i 1) {
  4755.                     $tempPortB2 $tcfTemp->getPortB();
  4756.                     $temp1 "portB" . ($i 1);
  4757.                     if ($$temp1->getId() != $tempPortB2->getId()) {
  4758.                       $temp2 "portB" $i;
  4759.                       $$temp2 $tempPortB2;
  4760.                     }
  4761.                   } else {
  4762.                     $portB1 $tcfTemp->getPortB();
  4763.                   }
  4764.                 }
  4765.               }
  4766.             }
  4767.           }
  4768.         }
  4769.         // $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA1);
  4770.         // if ($trunkExtTemp) {
  4771.         //   $tcfTemp = $trunkExtTemp->getTrunkCableFiber();
  4772.         //   $portB1 = $tcfTemp->getPortA();
  4773.         // }
  4774.         // else {
  4775.         //   $tcfTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portA1);
  4776.         //   if ($tcfTemp) {
  4777.         //     $lenTemp = count($tcfTemp->getExtensions());
  4778.         //     if ($lenTemp > 0) {
  4779.         //       $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcfTemp, "sequenceNo"=>$lenTemp]);
  4780.         //       $portB1 = $trunkExtTemp->getPortB();
  4781.         //     }
  4782.         //     else {
  4783.         //       $portB1 = $tcfTemp->getPortB();
  4784.         //     }
  4785.         //   }
  4786.         //
  4787.         // }
  4788.         // if ($portA2) {
  4789.         //   $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA2);
  4790.         //   if ($trunkExtTemp) {
  4791.         //     $tcfTemp = $trunkExtTemp->getTrunkCableFiber();
  4792.         //     $tempPortB2 = $tcfTemp->getPortA();
  4793.         //     if ($portB1->getId() != $tempPortB2->getId()) {
  4794.         //       $portB2 = $tempPortB2;
  4795.         //     }
  4796.         //   }
  4797.         //   else {
  4798.         //     $tcfTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portA2);
  4799.         //     if ($tcfTemp) {
  4800.         //       $lenTemp = count($tcfTemp->getExtensions());
  4801.         //       if ($lenTemp > 0) {
  4802.         //         $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcfTemp, "sequenceNo"=>$lenTemp]);
  4803.         //         $tempPortB2 = $trunkExtTemp->getPortB();
  4804.         //         if ($portB1->getId() != $tempPortB2->getId()) {
  4805.         //           $portB2 = $tempPortB2;
  4806.         //         }
  4807.         //       }
  4808.         //       else {
  4809.         //         $tempPortB2 = $tcfTemp->getPortB();
  4810.         //         if ($portB1->getId() != $tempPortB2->getId()) {
  4811.         //           $portB2 = $tempPortB2;
  4812.         //         }
  4813.         //       }
  4814.         //     }
  4815.         //   }
  4816.         // }
  4817.       } elseif ($portB1->getId() != $portOldB1->getId()) {
  4818.         for ($i 1$i <= 12$i++) {
  4819.           $temp "portB" $i;
  4820.           if ($$temp) {
  4821.             $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($$temp);
  4822.             if ($trunkExtTemp) {
  4823.               $tcfTemp $trunkExtTemp->getTrunkCableFiber();
  4824.               if ($i 1) {
  4825.                 $tempPortA2 $tcfTemp->getPortA();
  4826.                 $temp1 "portA" . ($i 1);
  4827.                 if ($$temp1->getId() != $tempPortA2->getId()) {
  4828.                   $temp2 "portA" $i;
  4829.                   $$temp2 $tempPortA2;
  4830.                 }
  4831.               } else {
  4832.                 $portA1 $tcfTemp->getPortA();
  4833.               }
  4834.             } else {
  4835.               $tcfTemp $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($$temp);
  4836.               if ($tcfTemp) {
  4837.                 $lenTemp count($tcfTemp->getExtensions());
  4838.                 if ($lenTemp 0) {
  4839.                   $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber" => $tcfTemp"sequenceNo" => $lenTemp]);
  4840.                   if ($i 1) {
  4841.                     $tempPortA2 $trunkExtTemp->getPortB();
  4842.                     $temp1 "portA" . ($i 1);
  4843.                     if ($$temp1->getId() != $tempPortA2->getId()) {
  4844.                       $temp2 "portA" $i;
  4845.                       $$temp2 $tempPortA2;
  4846.                     }
  4847.                   } else {
  4848.                     $portA1 $trunkExtTemp->getPortB();
  4849.                   }
  4850.                 } else {
  4851.                   if ($i 1) {
  4852.                     $tempPortA2 $tcfTemp->getPortB();
  4853.                     $temp1 "portA" . ($i 1);
  4854.                     if ($$temp1->getId() != $tempPortA2->getId()) {
  4855.                       $temp2 "portA" $i;
  4856.                       $$temp2 $tempPortA2;
  4857.                     }
  4858.                   } else {
  4859.                     $portA1 $tcfTemp->getPortB();
  4860.                   }
  4861.                 }
  4862.               }
  4863.             }
  4864.           }
  4865.         }
  4866.         // $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB1);
  4867.         // if ($trunkExtTemp) {
  4868.         //   $tcfTemp = $trunkExtTemp->getTrunkCableFiber();
  4869.         //   $portA1 = $tcfTemp->getPortA();
  4870.         // }
  4871.         // else {
  4872.         //   $tcfTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portB1);
  4873.         //   if ($tcfTemp) {
  4874.         //     $lenTemp = count($tcfTemp->getExtensions());
  4875.         //     if ($lenTemp > 0) {
  4876.         //       $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcfTemp, "sequenceNo"=>$lenTemp]);
  4877.         //       $portA1 = $trunkExtTemp->getPortB();
  4878.         //     }
  4879.         //     else {
  4880.         //       $portA1 = $tcfTemp->getPortB();
  4881.         //     }
  4882.         //   }
  4883.         // }
  4884.         // if ($portB2) {
  4885.         //   $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB2);
  4886.         //   if ($trunkExtTemp) {
  4887.         //     $tcfTemp = $trunkExtTemp->getTrunkCableFiber();
  4888.         //     $tempPortA2 = $tcfTemp->getPortA();
  4889.         //     if ($portA1->getId() != $tempPortA2->getId()) {
  4890.         //       $portA2 = $tempPortA2;
  4891.         //     }
  4892.         //   }
  4893.         //   else {
  4894.         //     $tcfTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portB2);
  4895.         //     if ($tcfTemp) {
  4896.         //       $lenTemp = count($tcfTemp->getExtensions());
  4897.         //       if ($lenTemp > 0) {
  4898.         //         $trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcfTemp, "sequenceNo"=>$lenTemp]);
  4899.         //         $tempPortA2 = $trunkExtTemp->getPortB();
  4900.         //         if ($portA1->getId() != $tempPortA2->getId()) {
  4901.         //           $portA2 = $tempPortA2;
  4902.         //         }
  4903.         //       }
  4904.         //       else {
  4905.         //         $tempPortA2 = $tcfTemp->getPortB();
  4906.         //         if ($portA1->getId() != $tempPortA2->getId()) {
  4907.         //           $portA2 = $tempPortA2;
  4908.         //         }
  4909.         //       }
  4910.         //     }
  4911.         //
  4912.         //   }
  4913.         // }
  4914.       }
  4915.       //set new ports
  4916.       //ADDED on 16/01/2020
  4917.       $trunk $this->getTrunkByPortId($portA1);
  4918.       //END
  4919.       $ports $this->getPorts($trunk$portsA$link->getTypeLink());
  4920.       foreach ($ports as $port) {
  4921.         $port->setLink($link);
  4922.         $port->setLinkExtension($extension);
  4923.         $em->persist($port);
  4924.       }
  4925.     }
  4926.     $nPortsA $portA1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4927.     if ($nPortsA) {
  4928.       $nPortsA json_decode($nPortsA);
  4929.     } else {
  4930.       $nPortsA = [];
  4931.     }
  4932.     $nPortsB $portB1->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4933.     if ($nPortsB) {
  4934.       $nPortsB json_decode($nPortsB);
  4935.     } else {
  4936.       $nPortsB = [];
  4937.     }
  4938.     $portsAToCheck = array();
  4939.     $portsBToCheck = array();
  4940.     if (!in_array($portA1->getOrderNo(), $nPortsA)) {
  4941.       $portsAToCheck[] = $portA1;
  4942.     }
  4943.     for ($i 2$i <= 12$i++) {
  4944.       $temp "portA" $i;
  4945.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsA)) {
  4946.         $portsToCheck[] = $$temp;
  4947.       }
  4948.     }
  4949.     if (!in_array($portB1->getOrderNo(), $nPortsB)) {
  4950.       $portsBToCheck[] = $portB1;
  4951.     }
  4952.     for ($i 2$i <= 12$i++) {
  4953.       $temp "portB" $i;
  4954.       if ($$temp && !in_array($$temp->getOrderNo(), $nPortsB)) {
  4955.         $portsToCheck[] = $$temp;
  4956.       }
  4957.     }
  4958.     // if ($portA2 && !in_array($portA2->getOrderNo(), $nPortsA)){
  4959.     //     $portsAToCheck[] = $portA2;
  4960.     // }
  4961.     // if ($portB2 && !in_array($portB2->getOrderNo(), $nPortsB)){
  4962.     //     $portsBToCheck[] = $portB2;
  4963.     // }
  4964.     $lastLinkExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() - 1]);
  4965.     $nextLinkExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() + 1]);
  4966.     $redirect false;
  4967.     foreach ($portsAToCheck as $value) {
  4968.       if ($value->getLink() && $value->getLink()->getId() != $link->getId()) {
  4969.         $this->addFlash(
  4970.           'error',
  4971.           'l\'un des ports Choisis est déjà dans un link'
  4972.         );
  4973.         $redirect true;
  4974.       }
  4975.       // elseif ($lastLinkExtension && $value->getLinkExtension() && !$lastLinkExtension) {
  4976.       //   $this->addFlash(
  4977.       //       'error',
  4978.       //       '2-l\'un des ports Choisis est déjà dans un link'
  4979.       //   );
  4980.       //   $redirect = true;
  4981.       // }
  4982.       elseif ($lastLinkExtension && $value->getLinkExtension() && ($value->getLinkExtension()->getId() != $extension->getid() && $value->getLinkExtension()->getId() != $lastLinkExtension->getId())) {
  4983.         $this->addFlash(
  4984.           'error',
  4985.           'l\'un des ports Choisis est déjà dans un link'
  4986.         );
  4987.         $redirect true;
  4988.       }
  4989.       if ($redirect) {
  4990.         break;
  4991.       }
  4992.     }
  4993.     if ($redirect) {
  4994.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  4995.     }
  4996.     foreach ($portsBToCheck as $value) {
  4997.       if ($value->getLink() && $value->getLink()->getId() != $link->getId()) {
  4998.         $this->addFlash(
  4999.           'error',
  5000.           'l\'un des ports Choisis est déjà dans un link link'
  5001.         );
  5002.         $redirect true;
  5003.       }
  5004.       // elseif ($value->getLinkExtension() && !$nextLinkExtension ) {
  5005.       //   var_dump("linkextension exist");
  5006.       //   $this->addFlash(
  5007.       //       'error',
  5008.       //       'linkextension exist - l\'un des ports Choisis est déjà dans un link'
  5009.       //   );
  5010.       //   $redirect = true;
  5011.       // }
  5012.       elseif ($value->getLinkExtension() && $nextLinkExtension && ($value->getLinkExtension()->getId() != $extension->getid() && $value->getLinkExtension()->getId() != $nextLinkExtension->getId())) {
  5013.         // var_dump("linkextension ids not match");
  5014.         $this->addFlash(
  5015.           'error',
  5016.           'l\'un des ports Choisis est déjà dans un link link extension'
  5017.         );
  5018.         $redirect true;
  5019.       }
  5020.       if ($redirect) {
  5021.         break;
  5022.       }
  5023.     }
  5024.     if ($redirect) {
  5025.       return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  5026.     }
  5027.     //
  5028.     //check for continuity Extremity B of last link extension
  5029.     //check if it's first link extension
  5030.     //if it's first, DO NOTHING
  5031.     if ($extension->getSequenceNo() > 1) {
  5032.       // //else get the last extension's extremity B's equipment
  5033.       // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$extension->getSequenceNo()-1]);
  5034.       // $lastExtB = $lastExtension->getExtremityB();
  5035.       // $lastPorts = [];
  5036.       // $lastPortsTemp = $lastExtB->getExtensionOrder();
  5037.       // foreach ($lastPortsTemp as $value) {
  5038.       //   $lastPorts[] = $value->getPort();
  5039.       // }
  5040.       // // $lastPorts = $lastExtB->getPorts();
  5041.       // // var_dump($lastPorts);
  5042.       // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  5043.       // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  5044.       // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  5045.       //
  5046.       // $currentInterfaceSpecific = $portA1->getInterfaceSpecific();
  5047.       // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  5048.       //
  5049.       // //check if it's same as current modified link ext
  5050.       // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  5051.       //   //if false, set the link and las link extension as INVALID
  5052.       //   $lastExtension->setIsValid(false);
  5053.       //   if ($lastExtension->getError()) {
  5054.       //     $lastExtension->setError($lastExtension->getError() . "," . "EquipmentB");
  5055.       //   }
  5056.       //   else {
  5057.       //     $lastExtension->setError("EquipmentB");
  5058.       //   }
  5059.       //   $em->persist($lastExtension);
  5060.       // }
  5061.       // else {
  5062.       //   // var_dump('hi');
  5063.       //   $errMsg = $lastExtension->getError();
  5064.       //   $errMsg = str_replace("EquipmentB", "", $errMsg);
  5065.       //   $lastExtension->setError($errMsg);
  5066.       //   if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
  5067.       //        $lastExtension->setIsValid(false);
  5068.       //    }
  5069.       //    else {
  5070.       //      $lastExtension->setIsValid(true);
  5071.       //      $lastExtension->setError(null);
  5072.       //    }
  5073.       //   $em->persist($lastExtension);
  5074.       //   //else get the last extension's extremity B's interface
  5075.       //   //check if it's 1:1
  5076.       //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  5077.       //     // if true, check ports are the same
  5078.       //     //if true, DO NOTHING
  5079.       //     //else set the link and las link extension as INVALID
  5080.       //     foreach ($lastPorts as $lastPort) {
  5081.       //       // var_dump($lastPort);
  5082.       //       $extensionOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$lastPort, "extremity"=>$lastExtB]);
  5083.       //
  5084.       //       if ($extensionOrder->getOrderNumber() == 1) {
  5085.       //         if ($lastPort->getId() != $portA1->getId()) {
  5086.       //           $lastExtension->setIsValid(false);
  5087.       //           if ($lastExtension->getError()) {
  5088.       //             $lastExtension->setError($lastExtension->getError() . "," . "PortB");
  5089.       //           }
  5090.       //           else {
  5091.       //             $lastExtension->setError("PortB");
  5092.       //           }
  5093.       //           $em->persist($lastExtension);
  5094.       //         }
  5095.       //         else {
  5096.       //           $lastExtension->setIsValid(true);
  5097.       //           $lastExtension->setError(null);
  5098.       //           $em->persist($lastExtension);
  5099.       //         }
  5100.       //       }
  5101.       //       elseif ($extensionOrder->getOrderNumber() == 2) {
  5102.       //         if ($lastPort->getId() != $portA2->getId()) {
  5103.       //           $lastExtension->setIsValid(false);
  5104.       //           if ($lastExtension->getError()) {
  5105.       //             $lastExtension->setError($lastExtension->getError() . "," . "PortB");
  5106.       //           }
  5107.       //           else {
  5108.       //             $lastExtension->setError("PortB");
  5109.       //           }
  5110.       //           $em->persist($lastExtension);
  5111.       //         }
  5112.       //         else {
  5113.       //           $lastExtension->setIsValid(true);
  5114.       //           $lastExtension->setError(null);
  5115.       //           $em->persist($lastExtension);
  5116.       //         }
  5117.       //       }
  5118.       //     }
  5119.       //   }
  5120.       // }
  5121.       LinkController::validateLastExtension($em$link$extension$portsA);
  5122.       // LinkController::validateLastExtension($em, $link, $extension, $portA1, $portA2);
  5123.     }
  5124.     //check for continuity Extremity A of next link extension
  5125.     //check if it's last link extension
  5126.     //if it's last, DO NOTHING
  5127.     if ($extension->getSequenceNo() != count($link->getLinkExtension())) {
  5128.       // //else get the last extension's extremity B's equipment
  5129.       // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$extension->getSequenceNo()+1]);
  5130.       // $nextExtA = $nextExtension->getExtremityA();
  5131.       // $nextPorts = [];
  5132.       // $nextPortsTemp = $nextExtA->getExtensionOrder();
  5133.       // foreach ($nextPortsTemp as $value) {
  5134.       //   $nextPorts[] = $value->getPort();
  5135.       // }
  5136.       // // $nextPorts = $nextExtA->getPorts();
  5137.       // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  5138.       // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  5139.       // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  5140.       //
  5141.       // $currentInterfaceSpecific = $portB1->getInterfaceSpecific();
  5142.       // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  5143.       //
  5144.       // //check if it's same as current modified link ext
  5145.       // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  5146.       //   //if false, set the link and las link extension as INVALID
  5147.       //   $nextExtension->setIsValid(false);
  5148.       //   if ($nextExtension->getError()) {
  5149.       //     $nextExtension->setError($nextExtension->getError() . "," . "EquipmentA");
  5150.       //   }
  5151.       //   else {
  5152.       //     $nextExtension->setError("EquipmentA");
  5153.       //   }
  5154.       //   $em->persist($nextExtension);
  5155.       // }
  5156.       // else {
  5157.       //     $nextExtension->setIsValid(true);
  5158.       //     $nextExtension->setError(null);
  5159.       //     $em->persist($nextExtension);
  5160.       //   //else get the next extension's extremity B's interface
  5161.       //   //check if it's 1:1
  5162.       //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  5163.       //     // if true, check ports are the same
  5164.       //     //if true, DO NOTHING
  5165.       //     //else set the link and las link extension as INVALID
  5166.       //     foreach ($nextPorts as $nextPort) {
  5167.       //       $extensionOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$nextPort, "extremity"=>$nextExtA]);
  5168.       //
  5169.       //       if ($extensionOrder->getOrderNumber() == 1) {
  5170.       //         if ($nextPort->getId() != $portB1->getId()) {
  5171.       //           $nextExtension->setIsValid(false);
  5172.       //           if ($nextExtension->getError()) {
  5173.       //             $nextExtension->setError($nextExtension->getError() . "," . "PortA");
  5174.       //           }
  5175.       //           else {
  5176.       //             $nextExtension->setError("PortA");
  5177.       //           }
  5178.       //           $em->persist($nextExtension);
  5179.       //         }
  5180.       //         else {
  5181.       //           $nextExtension->setIsValid(true);
  5182.       //           $nextExtension->setError(null);
  5183.       //           $em->persist($nextExtension);
  5184.       //         }
  5185.       //       }
  5186.       //       elseif ($extensionOrder->getOrderNumber() == 2) {
  5187.       //         if ($nextPort->getId() != $portB2->getId()) {
  5188.       //           $nextExtension->setIsValid(false);
  5189.       //           if ($nextExtension->getError()) {
  5190.       //             $nextExtension->setError($nextExtension->getError() . "," . "PortA");
  5191.       //           }
  5192.       //           else {
  5193.       //             $nextExtension->setError("PortA");
  5194.       //           }
  5195.       //           $em->persist($nextExtension);
  5196.       //         }
  5197.       //         else {
  5198.       //           $nextExtension->setIsValid(true);
  5199.       //           $nextExtension->setError(null);
  5200.       //           $em->persist($nextExtension);
  5201.       //         }
  5202.       //       }
  5203.       //     }
  5204.       //   }
  5205.       // }
  5206.       LinkController::validateNextExtension($em$link$extension$portsB);
  5207.       // LinkController::validateNextExtension($em, $link, $extension, $portB1, $portB2);
  5208.     }
  5209.     //i beleive the LinkExtension entity structure has to be modified ??? extremity A/B can have 1 or more ports
  5210.     for ($i 1$i <= 12$i++) {
  5211.       $temp "portOldA" $i;
  5212.       if ($$temp) {
  5213.         if (count($$temp->getExtensionOrder()) <= 1) {
  5214.           $$temp->setLink(null);
  5215.         }
  5216.         $extA $extension->getExtremityA();
  5217.         $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $$temp"extremity" => $extA"orderNumber" => $i]);
  5218.         $em->remove($extensinOrder);
  5219.         // $extA->removePort($portOldA1);
  5220.         // $portOldA1->setLink(null);
  5221.         $$temp->setLinkExtension(null);
  5222.         // $portOldA1->setOrderNoExtension(1);
  5223.         $em->persist($$temp);
  5224.       }
  5225.     }
  5226.     // if (count($portOldA1->getExtensionOrder()) <= 1) {
  5227.     //   $portOldA1->setLink(null);
  5228.     // }
  5229.     //
  5230.     // $extA = $extension->getExtremityA();
  5231.     // $extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portOldA1, "extremity"=>$extA, "orderNumber"=>1]);
  5232.     // $em->remove($extensinOrder);
  5233.     //
  5234.     // // $extA->removePort($portOldA1);
  5235.     // // $portOldA1->setLink(null);
  5236.     // $portOldA1->setLinkExtension(null);
  5237.     // // $portOldA1->setOrderNoExtension(1);
  5238.     // $em->persist($portOldA1);
  5239.     //
  5240.     // if ($portOldA2) {
  5241.     //   if (count($portOldA2->getExtensionOrder()) <= 1) {
  5242.     //     $portOldA2->setLink(null);
  5243.     //   }
  5244.     //   $extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portOldA2, "extremity"=>$extA, "orderNumber"=>2]);
  5245.     //   $em->remove($extensinOrder);
  5246.     //
  5247.     //   // $extA->removePort($portOldA2);
  5248.     //   // $portOldA2->setLink(null);
  5249.     //   $portOldA2->setLinkExtension(null);
  5250.     //   // $portOldA2->setOrderNoExtension(1);
  5251.     //   $em->persist($portOldA2);
  5252.     // }
  5253.     for ($i 1$i <= 12$i++) {
  5254.       $temp "portA" $i;
  5255.       if ($$temp) {
  5256.         $extensinOrder = new ExtensionOrder();
  5257.         $extensinOrder->setOrderNumber($i);
  5258.         $extensinOrder->setPort($$temp);
  5259.         $extensinOrder->setExtremity($extA);
  5260.         $$temp->addExtensionOrder($extensinOrder);
  5261.         $extA->addExtensionOrder($extensinOrder);
  5262.         $em->persist($extensinOrder);
  5263.         // $portA1->setOrderNoExtension(1);
  5264.         // $portA1->addExtremity($extA);
  5265.         $$temp->setLink($link);
  5266.         $$temp->setLinkExtension($extension);
  5267.         $em->persist($$temp);
  5268.       }
  5269.     }
  5270.     // $extensinOrder = new ExtensionOrder();
  5271.     // $extensinOrder->setOrderNumber(1);
  5272.     // $extensinOrder->setPort($portA1);
  5273.     // $extensinOrder->setExtremity($extA);
  5274.     // $portA1->addExtensionOrder($extensinOrder);
  5275.     // $extA->addExtensionOrder($extensinOrder);
  5276.     // $em->persist($extensinOrder);
  5277.     //
  5278.     // // $portA1->setOrderNoExtension(1);
  5279.     // // $portA1->addExtremity($extA);
  5280.     // $portA1->setLink($link);
  5281.     // $portA1->setLinkExtension($extension);
  5282.     // $em->persist($portA1);
  5283.     // // $extA->addPort($portA1);
  5284.     //
  5285.     //
  5286.     // if ($portA2) {
  5287.     //   $portsA[] = $portA2;
  5288.     //   $extensinOrder = new ExtensionOrder();
  5289.     //   $extensinOrder->setOrderNumber(2);
  5290.     //   $extensinOrder->setPort($portA2);
  5291.     //   $extensinOrder->setExtremity($extA);
  5292.     //   $portA2->addExtensionOrder($extensinOrder);
  5293.     //   $extA->addExtensionOrder($extensinOrder);
  5294.     //   $em->persist($extensinOrder);
  5295.     //
  5296.     //   // $portA2->setOrderNoExtension(2);
  5297.     //   // $portA2->addExtremity($extA);
  5298.     //   $portA2->setLink($link);
  5299.     //   $portA2->setLinkExtension($extension);
  5300.     //   $em->persist($portA2);
  5301.     //   // $extA->addPort($portA2);
  5302.     // }
  5303.     $em->persist($extA);
  5304.     $extension->setExtremityA($extA);
  5305.     $extB $extension->getExtremityB();
  5306.     for ($i 1$i <= 12$i++) {
  5307.       $temp "portOldB" $i;
  5308.       if ($$temp) {
  5309.         if (count($$temp->getExtensionOrder()) <= 1) {
  5310.           $$temp->setLink(null);
  5311.         }
  5312.         $extB $extension->getExtremityB();
  5313.         $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $$temp"extremity" => $extB"orderNumber" => $i]);
  5314.         $em->remove($extensinOrder);
  5315.         // $extA->removePort($portOldA1);
  5316.         // $portOldA1->setLink(null);
  5317.         $$temp->setLinkExtension(null);
  5318.         // $portOldA1->setOrderNoExtension(1);
  5319.         $em->persist($$temp);
  5320.       }
  5321.     }
  5322.     // if (count($portOldB1->getExtensionOrder()) <= 1) {
  5323.     //   $portOldB1->setLink(null);
  5324.     // }
  5325.     // $extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portOldB1, "extremity"=>$extB, "orderNumber"=>1]);
  5326.     // $em->remove($extensinOrder);
  5327.     //
  5328.     // // $extB->removePort($portOldB1);
  5329.     // // $portOldB1->setLink(null);
  5330.     // $portOldB1->setLinkExtension(null);
  5331.     // // $portOldB1->setOrderNoExtension(1);
  5332.     // $em->persist($portOldB1);
  5333.     // if ($portOldB2) {
  5334.     //   if (count($portOldB2->getExtensionOrder()) <= 1) {
  5335.     //     $portOldB2->setLink(null);
  5336.     //   }
  5337.     //   $extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portOldB2, "extremity"=>$extB, "orderNumber"=>2]);
  5338.     //   $em->remove($extensinOrder);
  5339.     //
  5340.     //   // $extB->removePort($portOldB2);
  5341.     //   // $portOldB2->setLink(null);
  5342.     //   $portOldB2->setLinkExtension(null);
  5343.     //   // $portOldB2->setOrderNoExtension(1);
  5344.     //   $em->persist($portOldB2);
  5345.     // }
  5346.     for ($i 1$i <= 12$i++) {
  5347.       $temp "portB" $i;
  5348.       if ($$temp) {
  5349.         $extensinOrder = new ExtensionOrder();
  5350.         $extensinOrder->setOrderNumber($i);
  5351.         $extensinOrder->setPort($$temp);
  5352.         $extensinOrder->setExtremity($extB);
  5353.         $$temp->addExtensionOrder($extensinOrder);
  5354.         $extB->addExtensionOrder($extensinOrder);
  5355.         $em->persist($extensinOrder);
  5356.         $$temp->setLink($link);
  5357.         $$temp->setLinkExtension($extension);
  5358.         $em->persist($$temp);
  5359.       }
  5360.     }
  5361.     // $extensinOrder = new ExtensionOrder();
  5362.     // $extensinOrder->setOrderNumber(1);
  5363.     // $extensinOrder->setPort($portB1);
  5364.     // $extensinOrder->setExtremity($extB);
  5365.     // $portB1->addExtensionOrder($extensinOrder);
  5366.     // $extB->addExtensionOrder($extensinOrder);
  5367.     // $em->persist($extensinOrder);
  5368.     //
  5369.     // // $portB1->setOrderNoExtension(1);
  5370.     // // $portB1->addExtremity($extB);
  5371.     // $portB1->setLink($link);
  5372.     // $portB1->setLinkExtension($extension);
  5373.     // $em->persist($portB1);
  5374.     // // $extB->addPort($portB1);
  5375.     //
  5376.     // if ($portB2) {
  5377.     //   $extensinOrder = new ExtensionOrder();
  5378.     //   $extensinOrder->setOrderNumber(2);
  5379.     //   $extensinOrder->setPort($portB2);
  5380.     //   $extensinOrder->setExtremity($extB);
  5381.     //   $portB2->addExtensionOrder($extensinOrder);
  5382.     //   $extB->addExtensionOrder($extensinOrder);
  5383.     //   $em->persist($extensinOrder);
  5384.     //
  5385.     //   // $portB2->setOrderNoExtension(2);
  5386.     //   // $portB2->addExtremity($extB);
  5387.     //   $portB2->setLink($link);
  5388.     //   $portB2->setLinkExtension($extension);
  5389.     //   $em->persist($portB2);
  5390.     //   // $extB->addPort($portB2);
  5391.     //
  5392.     // }
  5393.     $em->persist($extB);
  5394.     $extension->setExtremityB($extB);
  5395.     // $extension->setLink($link);
  5396.     $extension->setTypeCable($typeCable);
  5397.     if ($trunk) {
  5398.       $trunk->setTypeCable($typeCable);
  5399.       //ADDED on 16/01/2020
  5400.       $extension->setTrunk($trunk);
  5401.       //END
  5402.     }
  5403.     // $extension->setSequenceNo(1);
  5404.     $extension->setIsValid(true);
  5405.     $extension->setError(null);
  5406.     $em->persist($extension);
  5407.     $em->flush();
  5408.     //
  5409.     // $portA1 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
  5410.     // $portA2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_2'));
  5411.     // $portB1 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
  5412.     // $portB2 = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_2'));
  5413.     //
  5414.     // $typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  5415.     //
  5416.     // $extA = new Extremity();
  5417.     // $extA->addPort($portA1);
  5418.     // if ($portA2) {
  5419.     //   $portA2->setOrderNoExtension(2);
  5420.     //   $em->persist($portA2);
  5421.     //   $extA->addPort($portA2);
  5422.     // }
  5423.     //
  5424.     // $em->persist($extA);
  5425.     // $extension->setExtremityA($extA);
  5426.     //
  5427.     // $extB = new Extremity();
  5428.     // $extB->addPort($portB);
  5429.     // if ($portB2) {
  5430.     //   $portB2->setOrderNoExtension(2);
  5431.     //   $em->persist($portB2);
  5432.     //   $extB->addPort($portB2);
  5433.     // }
  5434.     // $em->persist($extB);
  5435.     // $extension->setExtremityB($extB);
  5436.     //
  5437.     // $extension->setTypeCable($typeCable);
  5438.     //
  5439.     // $em->persist($extension);
  5440.     // $em->flush();
  5441.     $link $extension->getLink();
  5442.     return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  5443.   }
  5444.   /**
  5445.    * @IsGranted("ROLE_CRUD")
  5446.    * @Route("/link/delete/{id}", name="link_delete")
  5447.    */
  5448.   public function deleteAction(Request $request$idTranslatorInterface $translator)
  5449.   {
  5450.     $em $this->getDoctrine()->getManager();
  5451.     $link $em->getRepository(Link::class)->find($id);
  5452.     $exts $link->getLinkExtension();
  5453.     $conn $em->getConnection();
  5454.     $sql "update port set link_id=null where link_id = " $link->getId();
  5455.     // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  5456.     $stmt $conn->prepare($sql);
  5457.     $stmt->execute();
  5458.     foreach ($exts as $ext) {
  5459.       $sql "update port set link_extension_id=null where link_extension_id = " $ext->getId();
  5460.       $stmt $conn->prepare($sql);
  5461.       $stmt->execute();
  5462.       $sql "delete from link_extension where id = " $ext->getId();
  5463.       // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
  5464.       $stmt $conn->prepare($sql);
  5465.       $stmt->execute();
  5466.       $sql "delete from extremity where id in  (" $ext->getExtremityA()->getId() . " , " $ext->getExtremityB()->getId() . ")";
  5467.       $stmt $conn->prepare($sql);
  5468.       $stmt->execute();
  5469.     }
  5470.     // $sql = "delete from link where id =". $id;
  5471.     // $stmt = $conn->prepare($sql);
  5472.     // $stmt->execute();
  5473.     $em->remove($link);
  5474.     $em->flush();
  5475.     return $this->redirect($request->headers->get('referer'));
  5476.     // return $this->redirectToRoute('link_list');
  5477.   }
  5478.   /**
  5479.    * @IsGranted("ROLE_CRUD")
  5480.    * @Route("/link/delete/extension/{id}", name="link_delete_extension")
  5481.    */
  5482.   public function deleteExtensionAction($idTranslatorInterface $translatorLoggerInterface $logger)
  5483.   {
  5484.     $em $this->getDoctrine()->getManager();
  5485.     $linkExtension $em->getRepository(LinkExtension::class)->find($id);
  5486.     $linkExtensionSequenceNo $linkExtension->getSequenceNo();
  5487.     $link $linkExtension->getLink();
  5488.     $lastExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $linkExtensionSequenceNo 1]);
  5489.     $nextExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $linkExtensionSequenceNo 1]);
  5490.     if ($linkExtensionSequenceNo && $linkExtensionSequenceNo != count($link->getLinkExtension())) {
  5491.       $lastExtension->setIsValid(false);
  5492.       if ($lastExtension->getError()) {
  5493.         $lastExtension->setError($lastExtension->getError() . "," "EquipmentB");
  5494.       } else {
  5495.         $lastExtension->setError("EquipmentB");
  5496.       }
  5497.       $em->persist($lastExtension);
  5498.       // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link, "sequenceNo" => $linkExtensionSequenceNo + 1]);
  5499.       $nextExtension->setIsValid(false);
  5500.       if ($nextExtension->getError()) {
  5501.         $nextExtension->setError($nextExtension->getError() . "," "EquipmentA");
  5502.       } else {
  5503.         $nextExtension->setError("EquipmentA");
  5504.       }
  5505.       $em->persist($nextExtension);
  5506.     } else if ($linkExtensionSequenceNo == && == count($link->getLinkExtension())) {
  5507.       $lastExtension->setIsValid(true);
  5508.       $lastExtension->setError(null);
  5509.       $em->persist($lastExtension);
  5510.     } elseif ($linkExtensionSequenceNo == count($link->getLinkExtension()) && $linkExtensionSequenceNo != 1) {
  5511.       $errMsg $lastExtension->getError();
  5512.       $errMsg str_replace("EquipmentB"""$errMsg);
  5513.       $lastExtension->setError($errMsg);
  5514.       if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  5515.         $lastExtension->setIsValid(false);
  5516.       } else {
  5517.         $lastExtension->setIsValid(true);
  5518.         $lastExtension->setError(null);
  5519.       }
  5520.       $em->persist($lastExtension);
  5521.     }
  5522.     $ports $em->getRepository(Port::class)->findByLinkExtension($id);
  5523.     // var_dump($ports);
  5524.     foreach ($ports as $port) {
  5525.       $port->setLinkExtension(null);
  5526.       // var_dump($port);
  5527.       // var_dump($port->getExtensionOrder());
  5528.       // var_dump(count($port->getExtensionOrder()));
  5529.       $logger->info("extension count: ".count($port->getExtensionOrder()));
  5530.       if (count($port->getExtensionOrder()) <= 1) {
  5531.         // var_dump($port->getid());
  5532.         // var_dump("hi");
  5533.         $port->setLink(null);
  5534.       }
  5535.       $em->persist($port);
  5536.     }
  5537.     $em->flush();
  5538.     $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->deleteExtension($link$linkExtension$linkExtensionSequenceNo);
  5539.     // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  5540.     // if ($fiberNo == 1){
  5541.     //     $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->deleteExtension($link, $linkExtensionSequenceNo);
  5542.     // } else {
  5543.     //     $em->remove($linkExtension);
  5544.     //     $em->flush();
  5545.     // }
  5546.     return $this->redirectToRoute('link_view', array('id' => $link->getId()));
  5547.   }
  5548.   /**
  5549.    * @IsGranted("ROLE_CRUD")
  5550.    * @Route("/link/delete/extensions/selected", name="link_delete_extensions")
  5551.    */
  5552.   public function deleteExtensionsAction(LoggerInterface $loggerTranslatorInterface $translator)
  5553.   {
  5554.     $em $this->getDoctrine()->getManager();
  5555.     $logger $logger;
  5556.     $ids json_decode($_POST["ids"]);
  5557.     
  5558.     $logger->debug("extension ids: ");
  5559.     $logger->debug($ids);
  5560.     foreach(array_reverse($ids) as $id ){
  5561.       $linkExtension $em->getRepository(LinkExtension::class)->find($id);
  5562.       $linkExtensionSequenceNo $linkExtension->getSequenceNo();
  5563.       $link $linkExtension->getLink();
  5564.       $lastExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $linkExtensionSequenceNo 1]);
  5565.       $nextExtension $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $linkExtensionSequenceNo 1]);
  5566.       if ($linkExtensionSequenceNo && $linkExtensionSequenceNo != count($link->getLinkExtension())) {
  5567.         $lastExtension->setIsValid(false);
  5568.         if ($lastExtension->getError()) {
  5569.           $lastExtension->setError($lastExtension->getError() . "," "EquipmentB");
  5570.         } else {
  5571.           $lastExtension->setError("EquipmentB");
  5572.         }
  5573.         $em->persist($lastExtension);
  5574.         if($nextExtension != null){
  5575.           $nextExtension->setIsValid(false);
  5576.           if ($nextExtension->getError()) {
  5577.             $nextExtension->setError($nextExtension->getError() . "," "EquipmentA");
  5578.           } else {
  5579.             $nextExtension->setError("EquipmentA");
  5580.           }
  5581.           $em->persist($nextExtension);
  5582.         }
  5583.       } else if ($linkExtensionSequenceNo == && == count($link->getLinkExtension())) {
  5584.         $lastExtension->setIsValid(true);
  5585.         $lastExtension->setError(null);
  5586.         $em->persist($lastExtension);
  5587.       } elseif ($linkExtensionSequenceNo == count($link->getLinkExtension()) && $linkExtensionSequenceNo != 1) {
  5588.         $errMsg $lastExtension->getError();
  5589.         $errMsg str_replace("EquipmentB"""$errMsg);
  5590.         $lastExtension->setError($errMsg);
  5591.         if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  5592.           $lastExtension->setIsValid(false);
  5593.         } else {
  5594.           $lastExtension->setIsValid(true);
  5595.           $lastExtension->setError(null);
  5596.         }
  5597.         $em->persist($lastExtension);
  5598.       }
  5599.       $ports $em->getRepository(Port::class)->findByLinkExtension($id);
  5600.       foreach ($ports as $port) {
  5601.         $port->setLinkExtension(null);
  5602.         $em->persist($port);
  5603.       }
  5604.       $em->flush();
  5605.       $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->deleteExtension($link$linkExtension$linkExtensionSequenceNo);
  5606.       // $em->flush();
  5607.     }
  5608.     //update link attribute on ports
  5609.     $ports $em->getRepository(Port::class)->findByLink($link);
  5610.     foreach ($ports as $port) {
  5611.       if (count($port->getExtensionOrder()) == 0) {
  5612.         $port->setLink(null);
  5613.       }
  5614.       $em->persist($port);
  5615.     }
  5616.     $em->flush();
  5617.     return $this->json(array("OK"=>true));
  5618.   }
  5619.   /**
  5620.    * @Route("/link/findLinkIdDuplicate", name="ajax_find_link_id")
  5621.    */
  5622.   public function findLinkIdDuplicate()
  5623.   {
  5624.     $response $this->getDoctrine()->getRepository('App\Entity\Link')->findLinkIdDuplicate($_POST['linkID']);
  5625.     return $this->json($response);
  5626.   }
  5627.   /**
  5628.    * @Route("/link/findLinkIdDuplicateOther", name="ajax_find_link_id_other")
  5629.    */
  5630.   public function findLinkIdDuplicateOther()
  5631.   {
  5632.     $response $this->getDoctrine()->getRepository('App\Entity\Link')->findLinkIdDuplicateOther($_POST['linkID'], $_POST['id']);
  5633.     return $this->json($response);
  5634.   }
  5635.   /**
  5636.    * @Route("/link/validate", name="link_validate")
  5637.    */
  5638.   public function validateAction()
  5639.   {
  5640.     $link_id $_POST['link_id'];
  5641.     $em $this->getDoctrine()->getManager();
  5642.     $link $em->getRepository(Link::class)->find($link_id);
  5643.     $linkValidations $em->getRepository(LinkValidation::class)->findBy(['link' => $link]);
  5644.     foreach ($linkValidations as $linkValidation) {
  5645.       $em->remove($linkValidation);
  5646.       $em->flush();
  5647.     }
  5648.     return $this->json($link_id);
  5649.   }
  5650.   /**
  5651.    * @Route("/link/validate/list", name="link_validate_list")
  5652.    */
  5653.   public function validateListAction(TranslatorInterface $translator)
  5654.   {
  5655.     $linkValidations =  $this->getDoctrine()->getRepository('App\Entity\LinkValidation')->findAll();
  5656.     return $this->render('link/list_validation.html.twig', [
  5657.       'action' => 'list',
  5658.       'page_title' => $translator->trans('Link Validation'),
  5659.       'list' => $linkValidations
  5660.     ]);
  5661.   }
  5662.   public static function startsWith($haystack$needle)
  5663.   {
  5664.     $length strlen($needle);
  5665.     return (substr($haystack0$length) === $needle);
  5666.   }
  5667.   public static function endsWith($haystack$needle)
  5668.   {
  5669.     $length strlen($needle);
  5670.     if ($length == 0) {
  5671.       return true;
  5672.     }
  5673.     return (substr($haystack, -$length) === $needle);
  5674.   }
  5675.   /**
  5676.    * @Route("/link/import/csv", name="link_import_csv")
  5677.    */
  5678.   public function importCSVAction(Request $requestTranslatorInterface $translator)
  5679.   {
  5680.     set_time_limit(0);
  5681.     $user $this->getUser();
  5682.     $defaultPortExterne 6;
  5683.     // process form
  5684.     if (isset($_FILES['csvFile']) && $_FILES['csvFile']['tmp_name'] && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  5685.       $em $this->getDoctrine()->getManager();
  5686.       //to be used for creating fake equipments
  5687.       $equipmentsArray = array();
  5688.       if (is_uploaded_file($_FILES['csvFile']['tmp_name'])) {
  5689.         $file $_FILES['csvFile']['tmp_name'];
  5690.         // $row = 1;
  5691.         $extractedData = array();
  5692.         if (($handle fopen($file"r")) !== FALSE) {
  5693.           $linkTitle "";
  5694.           while (($data fgetcsv($handle1000",")) !== FALSE) {
  5695.             $linkExtension = array();
  5696.             if (LinkController::startsWith($data[0], "F0")) {
  5697.               // $num = count($data);
  5698.               // for ($c=0; $c < $num; $c++) {
  5699.               for ($c 0$c 19$c++) {
  5700.                 switch ($c) {
  5701.                     //Link title
  5702.                   case 1:
  5703.                     $linkTitle trim($data[$c]);
  5704.                     if (!array_key_exists($linkTitle$extractedData)) {
  5705.                       $extractedData[$linkTitle] = array();
  5706.                     }
  5707.                     break;
  5708.                     // extension ex: trunk title, e1, e2
  5709.                   case 2:
  5710.                     $linkExtension["extension"] = trim($data[$c]);
  5711.                     break;
  5712.                     // connecteur extremity A ex: LC PC, SC PC, etc...
  5713.                   case 3:
  5714.                     $linkExtension["connecteurTypeExtrmityA"] = trim($data[$c]);
  5715.                     break;
  5716.                     // connecteur extremity A ex: LC PC, SC PC, etc...
  5717.                   case 4:
  5718.                     $linkExtension["connecteurTypeExtrmityB"] = trim($data[$c]);
  5719.                     break;
  5720.                     // Type de lien  ex: single monoservice, single multiservice, duplex multiservice, duplex monoservice, etc...
  5721.                   case 5:
  5722.                     $linkExtension["typeLien"] = explode(" "trim($data[$c]))[0];
  5723.                     break;
  5724.                     // Type de cable  ex: OS2, OM4, etc...
  5725.                   case 6:
  5726.                     $linkExtension["typeCable"] = trim($data[$c]);
  5727.                     break;
  5728.                     // Site title  ex: @46, @89, etc...
  5729.                   case 7:
  5730.                     $linkExtension["siteExtremityA"] = trim($data[$c]);
  5731.                     break;
  5732.                     // room title
  5733.                   case 8:
  5734.                     $linkExtension["roomExtremityA"] = trim($data[$c]);
  5735.                     break;
  5736.                     // rack title
  5737.                   case 9:
  5738.                     $linkExtension["rackExtremityA"] = trim($data[$c]);
  5739.                     break;
  5740.                     // equipment title
  5741.                   case 10:
  5742.                     $linkExtension["equipmentExtremityA"] = trim($data[$c]);
  5743.                     break;
  5744.                     // slot
  5745.                   case 11:
  5746.                     $linkExtension["slotExtremityA"] = trim($data[$c]);
  5747.                     if (!array_key_exists($linkExtension["equipmentExtremityA"], $equipmentsArray)) {
  5748.                       $equipmentsArray[$linkExtension["equipmentExtremityA"]] = array();
  5749.                     }
  5750.                     $equipmentsArray[$linkExtension["equipmentExtremityA"]][] = explode("-"trim($data[$c]))[0];
  5751.                     break;
  5752.                     // port
  5753.                   case 12:
  5754.                     $tempPorts trim($data[$c]);
  5755.                     $tempPortsAArray explode("/"$tempPorts);
  5756.                     if (count($tempPortsAArray) > && $linkExtension["typeLien"] == "Duplex" && $tempPortsAArray[1] == "0") {
  5757.                       $tempPortsAArray[1] = $tempPortsAArray[0] + 1;
  5758.                       $tempPorts implode("/"$tempPortsAArray);
  5759.                     } elseif (count($tempPortsAArray) > && $linkExtension["typeLien"] == "Single" && $tempPortsAArray[1] == "0") {
  5760.                       $tempPorts $tempPortsAArray[0];
  5761.                     }
  5762.                     if (LinkController::endsWith($linkExtension["equipmentExtremityA"], "ACE48FO")) {
  5763.                       $slot LinkController::startsWith($linkExtension["slotExtremityA"], "0") ? substr($linkExtension["slotExtremityA"], 1) : $linkExtension["slotExtremityA"];
  5764.                       $tempPortsAArray explode("/"$tempPorts);
  5765.                       $resPorts = array();
  5766.                       foreach ($tempPortsAArray as $value) {
  5767.                         switch ($slot) {
  5768.                           case '1':
  5769.                             $resPorts[] = $value 12 $value 12 $value;
  5770.                             break;
  5771.                           case '2':
  5772.                             $resPorts[] = $value 13 || $value 24 12 + ($value 12) : $value;
  5773.                             break;
  5774.                           case '3':
  5775.                             $resPorts[] = $value 25 || $value 36 24 + ($value 12) : $value;
  5776.                             break;
  5777.                           case '4':
  5778.                             $resPorts[] = $value 37 || $value 48 36 + ($value 12) : $value;
  5779.                             break;
  5780.                           case '5':
  5781.                             $resPorts[] = $value 49 || $value 60 48 + ($value 12) : $value;
  5782.                             break;
  5783.                           default:
  5784.                             // code...
  5785.                             break;
  5786.                         }
  5787.                       }
  5788.                       $tempPorts implode("/"$resPorts);
  5789.                     }
  5790.                     $linkExtension["portExtremityA"] = $tempPorts;
  5791.                     break;
  5792.                     // Site title  ex: @46, @89, etc...
  5793.                   case 13:
  5794.                     $linkExtension["siteExtremityB"] = trim($data[$c]);
  5795.                     break;
  5796.                     // room title
  5797.                   case 14:
  5798.                     $linkExtension["roomExtremityB"] = trim($data[$c]);
  5799.                     break;
  5800.                     // rack title
  5801.                   case 15:
  5802.                     $linkExtension["rackExtremityB"] = trim($data[$c]);
  5803.                     break;
  5804.                     // equipment title
  5805.                   case 16:
  5806.                     $linkExtension["equipmentExtremityB"] = trim($data[$c]);
  5807.                     break;
  5808.                     // slot
  5809.                   case 17:
  5810.                     $linkExtension["slotExtremityB"] = trim($data[$c]);
  5811.                     if (!array_key_exists($linkExtension["equipmentExtremityB"], $equipmentsArray)) {
  5812.                       $equipmentsArray[$linkExtension["equipmentExtremityB"]] = array();
  5813.                     }
  5814.                     $equipmentsArray[$linkExtension["equipmentExtremityB"]][] = explode("-"trim($data[$c]))[0];
  5815.                     break;
  5816.                     // port
  5817.                   case 18:
  5818.                     $tempPorts trim($data[$c]);
  5819.                     $tempPortsBArray explode("/"$tempPorts);
  5820.                     if (count($tempPortsBArray) > && $linkExtension["typeLien"] == "Duplex" && $tempPortsBArray[1] == "0") {
  5821.                       $tempPortsBArray[1] = $tempPortsBArray[0] + 1;
  5822.                       $tempPorts implode("/"$tempPortsBArray);
  5823.                     } elseif (count($tempPortsBArray) > && $linkExtension["typeLien"] == "Single" && $tempPortsBArray[1] == "0") {
  5824.                       $tempPorts $tempPortsBArray[0];
  5825.                     }
  5826.                     if (LinkController::endsWith($linkExtension["equipmentExtremityB"], "ACE48FO")) {
  5827.                       $slot LinkController::startsWith($linkExtension["slotExtremityB"], "0") ? substr($linkExtension["slotExtremityB"], 1) : $linkExtension["slotExtremityB"];
  5828.                       $tempPortsBArray explode("/"$tempPorts);
  5829.                       $resPorts = array();
  5830.                       foreach ($tempPortsBArray as $value) {
  5831.                         switch ($slot) {
  5832.                           case '1':
  5833.                             $resPorts[] = $value 12 $value 12 $value;
  5834.                             break;
  5835.                           case '2':
  5836.                             $resPorts[] = $value 13 || $value 24 12 + ($value 12) : $value;
  5837.                             break;
  5838.                           case '3':
  5839.                             $resPorts[] = $value 25 || $value 36 24 + ($value 12) : $value;
  5840.                             break;
  5841.                           case '4':
  5842.                             $resPorts[] = $value 37 || $value 48 36 + ($value 12) : $value;
  5843.                             break;
  5844.                           case '5':
  5845.                             $resPorts[] = $value 49 || $value 60 48 + ($value 12) : $value;
  5846.                             break;
  5847.                           default:
  5848.                             $resPorts[] = $value;
  5849.                             break;
  5850.                         }
  5851.                       }
  5852.                       $tempPorts implode("/"$resPorts);
  5853.                     }
  5854.                     $linkExtension["portExtremityB"] = $tempPorts;
  5855.                     break;
  5856.                   default:
  5857.                     // code...
  5858.                     break;
  5859.                 }
  5860.               }
  5861.               $extractedData[$linkTitle]["linkExtensions"][] = $linkExtension;
  5862.             }
  5863.             // $row++;
  5864.           }
  5865.           fclose($handle);
  5866.         }
  5867.         // print_r($extractedData["F00030"]);
  5868.         $corresFile $_FILES['corresCsvFile']['tmp_name'];
  5869.         $row 1;
  5870.         $corresExtractedData = array();
  5871.         if (($handle fopen($corresFile"r")) !== FALSE) {
  5872.           while (($data fgetcsv($handle1000",")) !== FALSE) {
  5873.             if ($row 2) {
  5874.               $num count($data);
  5875.               $keyWithoutSlot "";
  5876.               $keyWithSlot "";
  5877.               $modulaireId null;
  5878.               $moduleId null;
  5879.               $equipmentId null;
  5880.               $equipmentName null;
  5881.               for ($c 0$c $num$c++) {
  5882.                 switch ($c) {
  5883.                     //Link title
  5884.                   case 1:
  5885.                   case 2:
  5886.                   case 3:
  5887.                   case 4:
  5888.                     $keyWithoutSlot .= trim($data[$c]);
  5889.                     break;
  5890.                   case 5:
  5891.                     $keyWithSlot $keyWithoutSlot trim($data[$c]);
  5892.                     break;
  5893.                   case 7:
  5894.                     $comment trim($data[$c]);
  5895.                     break;
  5896.                   case 9:
  5897.                     $equipmentName trim($data[$c]);
  5898.                     break;
  5899.                   case 10:
  5900.                     $modulaireId trim($data[$c]);
  5901.                     break;
  5902.                   case 11:
  5903.                     $moduleId trim($data[$c]);
  5904.                     break;
  5905.                   case 12:
  5906.                     $equipmentId trim($data[$c]);
  5907.                     break;
  5908.                   default:
  5909.                     break;
  5910.                 }
  5911.               }
  5912.               $corresExtractedData[$keyWithoutSlot] = array(
  5913.                 "equipmentName" => $equipmentName,
  5914.                 "modulaireId" => $modulaireId,
  5915.                 "moduleId" => $moduleId,
  5916.                 "equipmentId" => $equipmentId
  5917.               );
  5918.               $corresExtractedData[$keyWithSlot] = array(
  5919.                 "equipmentName" => $equipmentName,
  5920.                 "modulaireId" => $modulaireId,
  5921.                 "moduleId" => $moduleId,
  5922.                 "equipmentId" => $equipmentId
  5923.               );
  5924.             }
  5925.             $row++;
  5926.           }
  5927.           fclose($handle);
  5928.         }
  5929.         $linkErrorFile $_FILES['linkErrorFile']['tmp_name'];
  5930.         $row 1;
  5931.         $linkErrorFileExtractedData = array();
  5932.         if (($handle fopen($linkErrorFile"r")) !== FALSE) {
  5933.           while (($data fgetcsv($handle1000",")) !== FALSE) {
  5934.             if (LinkController::startsWith($data[0], "F0")) {
  5935.               $num count($data);
  5936.               $test1 "";
  5937.               $test2 "";
  5938.               for ($c 0$c $num$c++) {
  5939.                 switch ($c) {
  5940.                   case 21:
  5941.                     $test1 trim($data[$c]);
  5942.                     break;
  5943.                   case 22:
  5944.                     $test2 trim($data[$c]);
  5945.                     break;
  5946.                   default:
  5947.                     break;
  5948.                 }
  5949.               }
  5950.               // var_dump($test1);
  5951.               // var_dump($test2);
  5952.               if ($test1 === "TRUE" || $test2 === "TRUE") {
  5953.                 $linkErrorFileExtractedData[trim($data[1])] = null;
  5954.               }
  5955.             }
  5956.           }
  5957.           fclose($handle);
  5958.         }
  5959.         // print_r($corresExtractedData);
  5960.         // foreach ($extractedData as $linkArray) {
  5961.         //         foreach ($linkArray["linkExtensions"] as $linkExtensionArray) {
  5962.         //             $tempArrayA = array("site"=>$linkExtensionArray["siteExtremityA"],
  5963.         //                                 "room"=>$linkExtensionArray["roomExtremityA"],
  5964.         //                                 "rack"=>$linkExtensionArray["rackExtremityA"],
  5965.         //                                 "equipment"=>$linkExtensionArray["equipmentExtremityA"],
  5966.         //                                 "slot"=>$linkExtensionArray["slotExtremityA"]
  5967.         //                                             );
  5968.         //             $equipementAArray = $this->getEquipmentId($tempArrayA, $corresExtractedData);
  5969.         //             // var_dump($tempArrayA["equipment"]);
  5970.         //             if($equipementAArray == null || !($equipementAArray["equipmentId"] || $equipementAArray["moduleId"])){
  5971.         //                 $equipementAArray = $this->createFakeEquipment($tempArrayA, $equipmentsArray, 65, 1, 16, 3, 11);
  5972.         //                 $keyWithSlot = implode($tempArrayA);
  5973.         //                 $keyWithoutSlot = $tempArrayA["site"].$tempArrayA["room"].$tempArrayA["rack"].$tempArrayA["equipment"];
  5974.         //                 $corresExtractedData[$keyWithSlot] = $equipementAArray;
  5975.         //                 $corresExtractedData[$keyWithoutSlot] = $equipementAArray;
  5976.         //                 // continue;
  5977.         //             }
  5978.         //             $tempArrayB = array("site"=>$linkExtensionArray["siteExtremityB"],
  5979.         //                                 "room"=>$linkExtensionArray["roomExtremityB"],
  5980.         //                                 "rack"=>$linkExtensionArray["rackExtremityB"],
  5981.         //                                 "equipment"=>$linkExtensionArray["equipmentExtremityB"],
  5982.         //                                 "slot"=>$linkExtensionArray["slotExtremityB"]
  5983.         //                                             );
  5984.         //             $equipementBArray = $this->getEquipmentId($tempArrayB, $corresExtractedData);
  5985.         //             if($equipementBArray == null || !($equipementBArray["equipmentId"] || $equipementBArray["moduleId"])){
  5986.         //
  5987.         //                 $equipementBArray = $this->createFakeEquipment($tempArrayB, $equipmentsArray, 65, 1, 16, 3, 11);
  5988.         //                 $keyWithSlot = implode($tempArrayB);
  5989.         //                 $keyWithoutSlot = $tempArrayB["site"].$tempArrayB["room"].$tempArrayB["rack"].$tempArrayB["equipment"];
  5990.         //                 $corresExtractedData[$keyWithSlot] = $equipementBArray;
  5991.         //                 $corresExtractedData[$keyWithoutSlot] = $equipementBArray;
  5992.         //             }
  5993.         //             $em->flush();
  5994.         //         }
  5995.         //
  5996.         //     }
  5997.         $em $this->getDoctrine()->getManager();
  5998.         $error = array();
  5999.         $test 1;
  6000.         foreach ($extractedData as $linkID => $linkArray) {
  6001.           if ($test 606) {
  6002.             break;
  6003.           }
  6004.           $test++;
  6005.           if (in_array($linkIDLinkController::getLinkExceptions())) {
  6006.             continue;
  6007.           }
  6008.           if ($this->getDoctrine()->getRepository('App\Entity\Link')->findOneByLinkID($linkID)) {
  6009.             if (!array_key_exists($linkID$error)) {
  6010.               $error[$linkID] = array();
  6011.             }
  6012.             $error[$linkID]["exists"][] = "Link déjà existe !";
  6013.             continue;
  6014.           }
  6015.           $typeLink "Simplex";
  6016.           $link = new Link();
  6017.           try {
  6018.             $link->setLinkID($linkID);
  6019.             $link->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneByTitle($typeLink));
  6020.             try {
  6021.               $em->persist($link);
  6022.               $em->flush();
  6023.             } catch (\Exception $e) {
  6024.               if (!array_key_exists($linkID$error)) {
  6025.                 $error[$linkID] = array();
  6026.               }
  6027.               $error[$linkID]["errors"][] = $e->getMessage();
  6028.               continue;
  6029.             }
  6030.             $sequenceNo 0;
  6031.             foreach ($linkArray["linkExtensions"] as $linkExtensionArray) {
  6032.               $sequenceNo++;
  6033.               $typeCable $linkExtensionArray["typeCable"];
  6034.               $portA1 null;
  6035.               $portA2 null;
  6036.               $portB1 null;
  6037.               $portB2 null;
  6038.               $tempArrayA = array(
  6039.                 "site" => $linkExtensionArray["siteExtremityA"],
  6040.                 "room" => $linkExtensionArray["roomExtremityA"],
  6041.                 "rack" => $linkExtensionArray["rackExtremityA"],
  6042.                 "equipment" => $linkExtensionArray["equipmentExtremityA"],
  6043.                 "slot" => $linkExtensionArray["slotExtremityA"]
  6044.               );
  6045.               $equipementAArray $this->getEquipmentId($tempArrayA$corresExtractedData);
  6046.               // if($equipementAArray == null || !($equipementAArray["equipmentId"] || $equipementAArray["moduleId"])){
  6047.               //     $equipementAArray = $this->createFakeEquipment($tempArrayA, $equipmentsArray, 65, 1, 16, 3, 11);
  6048.               //     $keyWithSlot = implode($tempArrayA);
  6049.               //     $keyWithoutSlot = $tempArrayA["site"].$tempArrayA["room"].$tempArrayA["rack"].$tempArrayA["equipment"];
  6050.               //     $corresExtractedData[$keyWithSlot] = $equipementAArray;
  6051.               //     $corresExtractedData[$keyWithoutSlot] = $equipementAArray;
  6052.               //     // continue;
  6053.               // }
  6054.               if ($equipementAArray == null || !($equipementAArray["equipmentId"] || $equipementAArray["moduleId"])) {
  6055.                 if (!array_key_exists($linkID$error)) {
  6056.                   $error[$linkID] = array();
  6057.                 }
  6058.                 $error[$linkID]["errors"][] = $sequenceNo " - ExtremityA - " $linkExtensionArray["equipmentExtremityA"] . " n'a pas Ã©té trouvé !";
  6059.                 $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6060.               }
  6061.               if (isset($error[$linkID]) && isset($error[$linkID]["errors"]) && count($error[$linkID]["errors"]) > 0) {
  6062.                 continue;
  6063.               }
  6064.               //Extremity A
  6065.               $interfaceSpecificA $this->getInterfaceSpecific($equipementAArray$linkExtensionArray"A");
  6066.               $interfaceSpecificATypeId null;
  6067.               // var_dump($interfaceSpecificA);
  6068.               if ($interfaceSpecificA) {
  6069.                 // var_dump($interfaceSpecificA->getId());
  6070.                 $interfaceSpecificATypeId $interfaceSpecificA->getInterfaceGeneric()->getTypeLink()->getId();
  6071.                 if ($interfaceSpecificATypeId == 2) {
  6072.                   $typeLink "Duplex";
  6073.                 }
  6074.               } else {
  6075.                 // var_dump("fault");
  6076.                 if (!array_key_exists($linkID$error)) {
  6077.                   $error[$linkID] = array();
  6078.                 }
  6079.                 $error[$linkID]["errors"][] = $sequenceNo " - ExtremityA - " $linkExtensionArray["equipmentExtremityA"] . " - slot " $linkExtensionArray["slotExtremityA"] . " n'a pas Ã©té trouvé !";
  6080.                 $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6081.                 continue;
  6082.               }
  6083.               // var_dump($interfaceSpecificA->getId());
  6084.               $portsAArray explode("/"$linkExtensionArray["portExtremityA"]);
  6085.               if (count($portsAArray) == 2) {
  6086.                 $typeLink "Duplex";
  6087.               }
  6088.               $portsA $this->getPortsCSV($interfaceSpecificA$portsAArray);
  6089.               foreach ($portsA as $value) {
  6090.                 if ($value == null) {
  6091.                   $interfaceSpecificA $this->getInterfaceSpecificV2($equipementAArray$linkExtensionArray["portExtremityA"]);
  6092.                   // var_dump($interfaceSpecificA);
  6093.                   if ($interfaceSpecificA) {
  6094.                     $this->get('logger')->error("4931 : " $interfaceSpecificA->getId());
  6095.                     $portsA $this->getPortsCSV2($interfaceSpecificA$portsAArray);
  6096.                     $error[$linkID]["check"][] = $sequenceNo " - ExtremityA - " $linkExtensionArray["equipmentExtremityA"] . " - Interface: " $interfaceSpecificA->getId() . " Ã  vérifier !";
  6097.                   }
  6098.                   break;
  6099.                 }
  6100.               }
  6101.               //Check for port externe
  6102.               if (count($portsA) > && $interfaceSpecificATypeId == 3) {
  6103.                 foreach ($portsA as $temp) {
  6104.                   if ($temp && is_null($temp->getPortExterne())) {
  6105.                     $temp->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->find($defaultPortExterne));
  6106.                     $em->persist($temp);
  6107.                     $em->flush();
  6108.                   }
  6109.                   if ($temp && $temp->getPortExterne() && $temp->getPortExterne()->getTypeLink()->getId() == 2) {
  6110.                     $typeLink "Duplex";
  6111.                   }
  6112.                 }
  6113.               }
  6114.               for ($i 0$i count($portsA); $i++) {
  6115.                 if (is_null($portsA[$i])) {
  6116.                   if (!array_key_exists($linkID$error)) {
  6117.                     $error[$linkID] = array();
  6118.                   }
  6119.                   $error[$linkID]["errors"][] = $sequenceNo " - ExtremityA - " $linkExtensionArray["equipmentExtremityA"] . " PortA: " $portsAArray[$i] . " n'a pas Ã©té trouvé !";
  6120.                   $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6121.                   continue;
  6122.                 }
  6123.                 if ($i == 0) {
  6124.                   $portA1 $portsA[$i];
  6125.                 } elseif ($i == 1) {
  6126.                   $portA2 $portsA[$i];
  6127.                 }
  6128.               }
  6129.               if (isset($error[$linkID]) && isset($error[$linkID]["errors"]) && count($error[$linkID]["errors"]) > 0) {
  6130.                 continue;
  6131.               }
  6132.               $tempArrayB = array(
  6133.                 "site" => $linkExtensionArray["siteExtremityB"],
  6134.                 "room" => $linkExtensionArray["roomExtremityB"],
  6135.                 "rack" => $linkExtensionArray["rackExtremityB"],
  6136.                 "equipment" => $linkExtensionArray["equipmentExtremityB"],
  6137.                 "slot" => $linkExtensionArray["slotExtremityB"]
  6138.               );
  6139.               $equipementBArray $this->getEquipmentId($tempArrayB$corresExtractedData);
  6140.               // if($equipementBArray == null || !($equipementBArray["equipmentId"] || $equipementBArray["moduleId"])){
  6141.               //
  6142.               //     $equipementBArray = $this->createFakeEquipment($tempArrayB, $equipmentsArray, 65, 1, 16, 3, 11);
  6143.               //     $keyWithSlot = implode($tempArrayB);
  6144.               //     $keyWithoutSlot = $tempArrayB["site"].$tempArrayB["room"].$tempArrayB["rack"].$tempArrayB["equipment"];
  6145.               //     $corresExtractedData[$keyWithSlot] = $equipementBArray;
  6146.               //     $corresExtractedData[$keyWithoutSlot] = $equipementBArray;
  6147.               // }
  6148.               if ($equipementBArray == null || !($equipementBArray["equipmentId"] || $equipementBArray["moduleId"])) {
  6149.                 if (!array_key_exists($linkID$error)) {
  6150.                   $error[$linkID] = array();
  6151.                 }
  6152.                 $error[$linkID]["errors"][] = $sequenceNo " - ExtremityB - " $linkExtensionArray["equipmentExtremityB"] . " n'a pas Ã©té trouvé !";
  6153.                 $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6154.               }
  6155.               if (isset($error[$linkID]) && isset($error[$linkID]["errors"]) && count($error[$linkID]["errors"]) > 0) {
  6156.                 continue;
  6157.               }
  6158.               // var_dump($portsA);
  6159.               //Extremity B
  6160.               $interfaceSpecificB $this->getInterfaceSpecific($equipementBArray$linkExtensionArray"B");
  6161.               $interfaceSpecificBTypeId null;
  6162.               if ($interfaceSpecificB) {
  6163.                 $this->get('logger')->error("5017 : " $interfaceSpecificB->getId());
  6164.                 // var_dump($interfaceSpecificB->getId());
  6165.                 $interfaceSpecificBTypeId $interfaceSpecificB->getInterfaceGeneric()->getTypeLink()->getId();
  6166.                 if ($interfaceSpecificBTypeId == 2) {
  6167.                   $typeLink "Duplex";
  6168.                 }
  6169.               } else {
  6170.                 if (!array_key_exists($linkID$error)) {
  6171.                   $error[$linkID] = array();
  6172.                 }
  6173.                 $error[$linkID]["errors"][] = $sequenceNo " - ExtremityB - " $linkExtensionArray["equipmentExtremityB"] . " - slot " $linkExtensionArray["slotExtremityB"] . " n'a pas Ã©té trouvé !";
  6174.                 $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6175.                 continue;
  6176.               }
  6177.               // var_dump($interfaceSpecificB->getId());
  6178.               $portsBArray explode("/"$linkExtensionArray["portExtremityB"]);
  6179.               // print_r($portsBArray);
  6180.               if (count($portsBArray) == 2) {
  6181.                 $typeLink "Duplex";
  6182.               }
  6183.               $portsB $this->getPortsCSV($interfaceSpecificB$portsBArray);
  6184.               foreach ($portsB as $value) {
  6185.                 if ($value == null) {
  6186.                   $interfaceSpecificB $this->getInterfaceSpecificV2($equipementBArray$linkExtensionArray["portExtremityB"]);
  6187.                   if ($interfaceSpecificB) {
  6188.                     $portsB $this->getPortsCSV2($interfaceSpecificB$portsBArray);
  6189.                     $error[$linkID]["check"][] = $sequenceNo " - ExtremityB - " $linkExtensionArray["equipmentExtremityB"] . " - Interface: " $interfaceSpecificB->getId() . " Ã  vérifier !";
  6190.                   }
  6191.                   break;
  6192.                 }
  6193.               }
  6194.               //Check for port externe
  6195.               if (count($portsB) > && $interfaceSpecificBTypeId == 3) {
  6196.                 foreach ($portsB as $temp) {
  6197.                   if ($temp && is_null($temp->getPortExterne())) {
  6198.                     $temp->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->find($defaultPortExterne));
  6199.                     $em->persist($temp);
  6200.                     $em->flush();
  6201.                   }
  6202.                   if ($temp && $temp->getPortExterne() && $temp->getPortExterne()->getTypeLink()->getId() == 2) {
  6203.                     $typeLink "Duplex";
  6204.                   }
  6205.                 }
  6206.               }
  6207.               for ($i 0$i count($portsB); $i++) {
  6208.                 if (is_null($portsB[$i])) {
  6209.                   if (!array_key_exists($linkID$error)) {
  6210.                     $error[$linkID] = array();
  6211.                   }
  6212.                   $error[$linkID]["errors"][] = $sequenceNo " - ExtremityB - " $linkExtensionArray["equipmentExtremityB"] . " PortB: " $portsBArray[$i] . " n'a pas Ã©té trouvé !";
  6213.                   $error[$linkID]["faultLink"] = array_key_exists($linkID$linkErrorFileExtractedData);
  6214.                   continue;
  6215.                 }
  6216.                 if ($i == 0) {
  6217.                   $portB1 $portsB[$i];
  6218.                 } elseif ($i == 1) {
  6219.                   $portB2 $portsB[$i];
  6220.                 }
  6221.               }
  6222.               if (isset($error[$linkID]) && isset($error[$linkID]["errors"]) && count($error[$linkID]["errors"]) > 0) {
  6223.                 continue;
  6224.               }
  6225.               //used to set the interface's typelink to newly created equipments
  6226.               if (count($portsB) == && count($portsA) == 1) {
  6227.                 $ifg $portsA[0]->getInterfaceSpecific()->getInterfaceGeneric();
  6228.                 $ifg->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->find(2));
  6229.                 $em->persist($ifg);
  6230.                 $em->flush();
  6231.               }
  6232.               if (count($portsB) == && count($portsA) == 2) {
  6233.                 $ifg $portsB[0]->getInterfaceSpecific()->getInterfaceGeneric();
  6234.                 $ifg->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->find(2));
  6235.                 $em->persist($ifg);
  6236.                 $em->flush();
  6237.               }
  6238.               // var_dump($portsB);
  6239.               $trunk null;
  6240.               if ($linkExtensionArray["extension"] && LinkController::startsWith($linkExtensionArray["extension"], "T0")) {
  6241.                 $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneByTrunkID($linkExtensionArray["extension"]);
  6242.                 //check if ports are in the trunk
  6243.                 $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portA1);
  6244.                 $usedExtA $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA1);
  6245.                 $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portB1);
  6246.                 $usedExtB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB1);
  6247.                 $usedARev $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($portB1);
  6248.                 $usedExtARev $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portB1);
  6249.                 $usedBRev $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($portA1);
  6250.                 $usedExtBRev $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($portA1);
  6251.                 if ((($usedA || $usedExtA) && ($usedB || $usedExtB)) || (($usedARev || $usedExtARev) && ($usedBRev || $usedExtBRev))) {
  6252.                   //do nothing
  6253.                 } else {
  6254.                   if ($trunk == null) {
  6255.                     $trunk = new Trunk();
  6256.                     $trunk->setTrunkID($linkExtensionArray["extension"]);
  6257.                     $trunk->setTypeCreation(2);
  6258.                     $trunk->setCapacity(48);
  6259.                     $trunk->setCreatedBy($user);
  6260.                     $trunk->setUpdatedBy($user);
  6261.                     $em->persist($trunk);
  6262.                     $em->flush();
  6263.                   }
  6264.                   $error[$linkID]["check"][] = $sequenceNo " - Trunk - " $trunk->getTrunkID() . " Ã  vérifier !";
  6265.                   $trunkCables $trunk->getCableFiber();
  6266.                   if (count($trunkCables) > 0) {
  6267.                     $first true;
  6268.                     foreach ($trunkCables as $tcf) {
  6269.                       $typeCable $tcf->getTrunk()->getTypeCable();
  6270.                       $tcfExts $tcf->getExtensions();
  6271.                       if (count($tcfExts) == 0) {
  6272.                         $tcfPortB $tcf->getPortB()->getId();
  6273.                         if (count($portsB) == && count($portsA) == 1) {
  6274.                           if ($first) {
  6275.                             if ($tcfPortB == $portA1->getId()) {
  6276.                               $ext = new TrunkExtension();
  6277.                               $ext->setTrunkCableFiber($tcf);
  6278.                               $ext->setTypeCable($typeCable);
  6279.                               $ext->setPortB($portB1);
  6280.                               $ext->setSequenceNo(1);
  6281.                               $em->persist($ext);
  6282.                               $em->flush();
  6283.                               $first false;
  6284.                             }
  6285.                           } else {
  6286.                             if ($tcfPortB == $portA1->getId()) {
  6287.                               $ext = new TrunkExtension();
  6288.                               $ext->setTrunkCableFiber($tcf);
  6289.                               $ext->setTypeCable($typeCable);
  6290.                               $ext->setPortB($portB2);
  6291.                               $ext->setSequenceNo(1);
  6292.                               $em->persist($ext);
  6293.                               $em->flush();
  6294.                               break;
  6295.                             }
  6296.                           }
  6297.                         } elseif (count($portsB) == && count($portsA) == 2) {
  6298.                           if ($first) {
  6299.                             if ($tcfPortB == $portA1->getId()) {
  6300.                               $ext = new TrunkExtension();
  6301.                               $ext->setTrunkCableFiber($tcf);
  6302.                               $ext->setTypeCable($typeCable);
  6303.                               $ext->setPortB($portB1);
  6304.                               $ext->setSequenceNo(1);
  6305.                               $em->persist($ext);
  6306.                               $em->flush();
  6307.                               $first false;
  6308.                             }
  6309.                           } else {
  6310.                             if ($tcfPortB == $portA2->getId()) {
  6311.                               $ext = new TrunkExtension();
  6312.                               $ext->setTrunkCableFiber($tcf);
  6313.                               $ext->setTypeCable($typeCable);
  6314.                               $ext->setPortB($portB1);
  6315.                               $ext->setSequenceNo(1);
  6316.                               $em->persist($ext);
  6317.                               $em->flush();
  6318.                               break;
  6319.                             }
  6320.                           }
  6321.                         } elseif (count($portsB) == && count($portsA) == 2) {
  6322.                           if ($first) {
  6323.                             if ($tcfPortB == $portA1->getId()) {
  6324.                               $ext = new TrunkExtension();
  6325.                               $ext->setTrunkCableFiber($tcf);
  6326.                               $ext->setTypeCable($typeCable);
  6327.                               $ext->setPortB($portB1);
  6328.                               $ext->setSequenceNo(1);
  6329.                               $em->persist($ext);
  6330.                               $em->flush();
  6331.                               $first false;
  6332.                             }
  6333.                           } else {
  6334.                             if ($tcfPortB == $portA2->getId()) {
  6335.                               $ext = new TrunkExtension();
  6336.                               $ext->setTrunkCableFiber($tcf);
  6337.                               $ext->setTypeCable($typeCable);
  6338.                               $ext->setPortB($portB2);
  6339.                               $ext->setSequenceNo(1);
  6340.                               $em->persist($ext);
  6341.                               $em->flush();
  6342.                               break;
  6343.                             }
  6344.                           }
  6345.                         } elseif (count($portsB) == && count($portsA) == 1) {
  6346.                           if ($tcfPortB == $portA1->getId()) {
  6347.                             $ext = new TrunkExtension();
  6348.                             $ext->setTrunkCableFiber($tcf);
  6349.                             $ext->setTypeCable($typeCable);
  6350.                             $ext->setPortB($portB1);
  6351.                             $ext->setSequenceNo(1);
  6352.                             $em->persist($ext);
  6353.                             $em->flush();
  6354.                             break;
  6355.                           }
  6356.                         }
  6357.                       } else {
  6358.                         // $lastExt = $tcfExts{
  6359.                         // count($tcfExts) - 1};
  6360.                         $lastExt $tcfExts[count($tcfExts) - 1];
  6361.                         $tcfPortB $lastExt->getPortB()->getId();
  6362.                         if (count($portsB) == && count($portsA) == 1) {
  6363.                           if ($first) {
  6364.                             if ($tcfPortB == $portA1->getId()) {
  6365.                               $ext = new TrunkExtension();
  6366.                               $ext->setTrunkCableFiber($tcf);
  6367.                               $ext->setTypeCable($typeCable);
  6368.                               $ext->setPortB($portB1);
  6369.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6370.                               $em->persist($ext);
  6371.                               $em->flush();
  6372.                               $first false;
  6373.                             }
  6374.                           } else {
  6375.                             if ($tcfPortB == $portA1->getId()) {
  6376.                               $ext = new TrunkExtension();
  6377.                               $ext->setTrunkCableFiber($tcf);
  6378.                               $ext->setTypeCable($typeCable);
  6379.                               $ext->setPortB($portB2);
  6380.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6381.                               $em->persist($ext);
  6382.                               $em->flush();
  6383.                               break;
  6384.                             }
  6385.                           }
  6386.                         } elseif (count($portsB) == && count($portsA) == 2) {
  6387.                           if ($first) {
  6388.                             if ($tcfPortB == $portA1->getId()) {
  6389.                               $ext = new TrunkExtension();
  6390.                               $ext->setTrunkCableFiber($tcf);
  6391.                               $ext->setTypeCable($typeCable);
  6392.                               $ext->setPortB($portB1);
  6393.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6394.                               $em->persist($ext);
  6395.                               $em->flush();
  6396.                               $first false;
  6397.                             }
  6398.                           } else {
  6399.                             if ($tcfPortB == $portA2->getId()) {
  6400.                               $ext = new TrunkExtension();
  6401.                               $ext->setTrunkCableFiber($tcf);
  6402.                               $ext->setTypeCable($typeCable);
  6403.                               $ext->setPortB($portB1);
  6404.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6405.                               $em->persist($ext);
  6406.                               $em->flush();
  6407.                               break;
  6408.                             }
  6409.                           }
  6410.                         } elseif (count($portsB) == && count($portsA) == 2) {
  6411.                           if ($first) {
  6412.                             if ($tcfPortB == $portA1->getId()) {
  6413.                               $ext = new TrunkExtension();
  6414.                               $ext->setTrunkCableFiber($tcf);
  6415.                               $ext->setTypeCable($typeCable);
  6416.                               $ext->setPortB($portB1);
  6417.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6418.                               $em->persist($ext);
  6419.                               $em->flush();
  6420.                               $first false;
  6421.                             }
  6422.                           } else {
  6423.                             if ($tcfPortB == $portA2->getId()) {
  6424.                               $ext = new TrunkExtension();
  6425.                               $ext->setTrunkCableFiber($tcf);
  6426.                               $ext->setTypeCable($typeCable);
  6427.                               $ext->setPortB($portB2);
  6428.                               $ext->setSequenceNo(count($tcfExts) + 1);
  6429.                               $em->persist($ext);
  6430.                               $em->flush();
  6431.                               break;
  6432.                             }
  6433.                           }
  6434.                         } elseif (count($portsB) == && count($portsA) == 1) {
  6435.                           if ($tcfPortB == $portA1->getId()) {
  6436.                             $ext = new TrunkExtension();
  6437.                             $ext->setTrunkCableFiber($tcf);
  6438.                             $ext->setTypeCable($typeCable);
  6439.                             $ext->setPortB($portB1);
  6440.                             $ext->setSequenceNo(count($tcfExts) + 1);
  6441.                             $em->persist($ext);
  6442.                             $em->flush();
  6443.                             break;
  6444.                           }
  6445.                         }
  6446.                       }
  6447.                     }
  6448.                   } else {
  6449.                     if (count($portsB) == && count($portsA) == 1) {
  6450.                       $tcf1 = new TrunkCableFiber();
  6451.                       $tcf1->setTrunk($trunk);
  6452.                       $tcf1->setPortA($portA1);
  6453.                       $tcf1->setPortB($portB1);
  6454.                       $em->persist($tcf1);
  6455.                       $tcf2 = new TrunkCableFiber();
  6456.                       $tcf2->setTrunk($trunk);
  6457.                       $tcf2->setPortA($portA1);
  6458.                       $tcf2->setPortB($portB2);
  6459.                       $em->persist($tcf2);
  6460.                       $em->flush();
  6461.                     } elseif (count($portsB) == && count($portsA) == 2) {
  6462.                       $tcf1 = new TrunkCableFiber();
  6463.                       $tcf1->setTrunk($trunk);
  6464.                       $tcf1->setPortA($portA1);
  6465.                       $tcf1->setPortB($portB1);
  6466.                       $em->persist($tcf1);
  6467.                       $tcf2 = new TrunkCableFiber();
  6468.                       $tcf2->setTrunk($trunk);
  6469.                       $tcf2->setPortA($portA2);
  6470.                       $tcf2->setPortB($portB1);
  6471.                       $em->persist($tcf2);
  6472.                       $em->flush();
  6473.                     } elseif (count($portsB) == && count($portsA) == 2) {
  6474.                       $tcf1 = new TrunkCableFiber();
  6475.                       $tcf1->setTrunk($trunk);
  6476.                       $tcf1->setPortA($portA1);
  6477.                       $tcf1->setPortB($portB1);
  6478.                       $em->persist($tcf1);
  6479.                       $tcf2 = new TrunkCableFiber();
  6480.                       $tcf2->setTrunk($trunk);
  6481.                       $tcf2->setPortA($portA2);
  6482.                       $tcf2->setPortB($portB2);
  6483.                       $em->persist($tcf2);
  6484.                       $em->flush();
  6485.                     } elseif (count($portsB) == && count($portsA) == 1) {
  6486.                       $tcf1 = new TrunkCableFiber();
  6487.                       $tcf1->setTrunk($trunk);
  6488.                       $tcf1->setPortA($portA1);
  6489.                       $tcf1->setPortB($portB1);
  6490.                       $em->persist($tcf1);
  6491.                       $em->flush();
  6492.                     }
  6493.                   }
  6494.                 }
  6495.               }
  6496.               //Start Link Extension création
  6497.               $extension = new LinkExtension();
  6498.               $extA = new Extremity();
  6499.               $extensinOrder = new ExtensionOrder();
  6500.               $extensinOrder->setOrderNumber(1);
  6501.               $extensinOrder->setPort($portA1);
  6502.               $extensinOrder->setExtremity($extA);
  6503.               $portA1->addExtensionOrder($extensinOrder);
  6504.               $extA->addExtensionOrder($extensinOrder);
  6505.               $em->persist($extensinOrder);
  6506.               // $portA1->setOrderNoExtension(1);
  6507.               // $portA1->addExtremity($extA);
  6508.               $portA1->setLink($link);
  6509.               $portA1->setLinkExtension($extension);
  6510.               $em->persist($portA1);
  6511.               // $extA->addPort($portA1);
  6512.               if ($portA2) {
  6513.                 $extensinOrder = new ExtensionOrder();
  6514.                 $extensinOrder->setOrderNumber(2);
  6515.                 $extensinOrder->setPort($portA2);
  6516.                 $extensinOrder->setExtremity($extA);
  6517.                 $portA2->addExtensionOrder($extensinOrder);
  6518.                 $extA->addExtensionOrder($extensinOrder);
  6519.                 $em->persist($extensinOrder);
  6520.                 // $portA2->setOrderNoExtension(2);
  6521.                 // $portA2->addExtremity($extA);
  6522.                 $portA2->setLink($link);
  6523.                 $portA2->setLinkExtension($extension);
  6524.                 $em->persist($portA2);
  6525.                 // $extA->addPort($portA2);
  6526.               }
  6527.               $em->persist($extA);
  6528.               $extension->setExtremityA($extA);
  6529.               $extB = new Extremity();
  6530.               $extensinOrder = new ExtensionOrder();
  6531.               $extensinOrder->setOrderNumber(1);
  6532.               $extensinOrder->setPort($portB1);
  6533.               $extensinOrder->setExtremity($extB);
  6534.               $portB1->addExtensionOrder($extensinOrder);
  6535.               $extB->addExtensionOrder($extensinOrder);
  6536.               $em->persist($extensinOrder);
  6537.               // $portB1->setOrderNoExtension(1);
  6538.               // $portB1->addExtremity($extB);
  6539.               $portB1->setLink($link);
  6540.               $portB1->setLinkExtension($extension);
  6541.               $em->persist($portB1);
  6542.               // $extB->addPort($portB1);
  6543.               if ($portB2) {
  6544.                 $extensinOrder = new ExtensionOrder();
  6545.                 $extensinOrder->setOrderNumber(2);
  6546.                 $extensinOrder->setPort($portB2);
  6547.                 $extensinOrder->setExtremity($extB);
  6548.                 $portB2->addExtensionOrder($extensinOrder);
  6549.                 $extB->addExtensionOrder($extensinOrder);
  6550.                 $em->persist($extensinOrder);
  6551.                 // $portB2->setOrderNoExtension(2);
  6552.                 // $portB2->addExtremity($extB);
  6553.                 $portB2->setLink($link);
  6554.                 $portB2->setLinkExtension($extension);
  6555.                 $em->persist($portB2);
  6556.                 // $extB->addPort($portB2);
  6557.               }
  6558.               $em->persist($extB);
  6559.               $extension->setExtremityB($extB);
  6560.               $extension->setLink($link);
  6561.               $extension->setTypeCable($this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneByTitle($typeCable));
  6562.               $extension->setSequenceNo($sequenceNo);
  6563.               if ($trunk) {
  6564.                 $extension->setTrunk($trunk);
  6565.               }
  6566.               $em->persist($extension);
  6567.               $em->flush();
  6568.               //End Link Extension création
  6569.             }
  6570.           } catch (\Exception $e) {
  6571.             if (!array_key_exists($linkID$error)) {
  6572.               $error[$linkID] = array();
  6573.             }
  6574.             $error[$linkID] = $e->getMessage();
  6575.             $this->get('logger')->error($e->getMessage());
  6576.           }
  6577.           $link->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneByTitle($typeLink));
  6578.           $em->persist($link);
  6579.           $em->flush();
  6580.           // var_dump($link);
  6581.         }
  6582.         $html $this->renderView(
  6583.           // app/Resources/views/Emails/registration.html.twig
  6584.           'link/error_file.html.twig',
  6585.           array('error' => $error)
  6586.         );
  6587.         $errorPath $this->get("kernel")->getLogDir() . '/error_file.html';
  6588.         file_put_contents($errorPath$html);
  6589.         return $this->file($errorPath);
  6590.         // print_r($error);
  6591.       }
  6592.       // show form
  6593.     }
  6594.     return $this->render('link/import_csv.html.twig', [
  6595.       'page_title' => $translator->trans('Générer link - CSV'),
  6596.       'box_title' => "Choisir un Fichier CSV"
  6597.     ]);
  6598.   }
  6599.   /**
  6600.    * @Route("/link/create/fakeEquipment", name="link_create_fake_equipment")
  6601.    */
  6602.   public function linkCreatefakeEquipment(Request $requestTranslatorInterface $translator)
  6603.   {
  6604.     set_time_limit(0);
  6605.     $user $this->getUser();
  6606.     // process form
  6607.     if (isset($_FILES['csvFile']) && $_FILES['csvFile']['tmp_name'] && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
  6608.       $em $this->getDoctrine()->getManager();
  6609.       //to be used for creating fake equipments
  6610.       $equipmentsArray = array();
  6611.       if (is_uploaded_file($_FILES['csvFile']['tmp_name'])) {
  6612.         $file $_FILES['csvFile']['tmp_name'];
  6613.         // $row = 1;
  6614.         $extractedData = array();
  6615.         if (($handle fopen($file"r")) !== FALSE) {
  6616.           $linkTitle "";
  6617.           while (($data fgetcsv($handle1000",")) !== FALSE) {
  6618.             $linkExtension = array();
  6619.             if (LinkController::startsWith($data[0], "F0")) {
  6620.               // $num = count($data);
  6621.               // for ($c=0; $c < $num; $c++) {
  6622.               for ($c 0$c 19$c++) {
  6623.                 switch ($c) {
  6624.                     //Link title
  6625.                   case 1:
  6626.                     $linkTitle trim($data[$c]);
  6627.                     if (!array_key_exists($linkTitle$extractedData)) {
  6628.                       $extractedData[$linkTitle] = array();
  6629.                     }
  6630.                     break;
  6631.                     // extension ex: trunk title, e1, e2
  6632.                   case 2:
  6633.                     $linkExtension["extension"] = trim($data[$c]);
  6634.                     break;
  6635.                     // connecteur extremity A ex: LC PC, SC PC, etc...
  6636.                   case 3:
  6637.                     $linkExtension["connecteurTypeExtrmityA"] = trim($data[$c]);
  6638.                     break;
  6639.                     // connecteur extremity A ex: LC PC, SC PC, etc...
  6640.                   case 4:
  6641.                     $linkExtension["connecteurTypeExtrmityB"] = trim($data[$c]);
  6642.                     break;
  6643.                     // Type de lien  ex: single monoservice, single multiservice, duplex multiservice, duplex monoservice, etc...
  6644.                   case 5:
  6645.                     $linkExtension["typeLien"] = explode(" "trim($data[$c]))[0];
  6646.                     break;
  6647.                     // Type de cable  ex: OS2, OM4, etc...
  6648.                   case 6:
  6649.                     $linkExtension["typeCable"] = trim($data[$c]);
  6650.                     break;
  6651.                     // Site title  ex: @46, @89, etc...
  6652.                   case 7:
  6653.                     $linkExtension["siteExtremityA"] = trim($data[$c]);
  6654.                     break;
  6655.                     // room title
  6656.                   case 8:
  6657.                     $linkExtension["roomExtremityA"] = trim($data[$c]);
  6658.                     break;
  6659.                     // rack title
  6660.                   case 9:
  6661.                     $linkExtension["rackExtremityA"] = trim($data[$c]);
  6662.                     break;
  6663.                     // equipment title
  6664.                   case 10:
  6665.                     $linkExtension["equipmentExtremityA"] = trim($data[$c]);
  6666.                     break;
  6667.                     // slot
  6668.                   case 11:
  6669.                     $linkExtension["slotExtremityA"] = trim($data[$c]);
  6670.                     if (!array_key_exists($linkExtension["equipmentExtremityA"], $equipmentsArray)) {
  6671.                       $equipmentsArray[$linkExtension["equipmentExtremityA"]] = array();
  6672.                     }
  6673.                     if (!array_key_exists(explode("-"trim($data[$c]))[0], $equipmentsArray[$linkExtension["equipmentExtremityA"]])) {
  6674.                       $equipmentsArray[$linkExtension["equipmentExtremityA"]][explode("-"trim($data[$c]))[0]] = 0;
  6675.                     }
  6676.                     // $equipmentsArray[$linkExtension["equipmentExtremityA"]][explode("-", trim($data[$c]))[0]] = 0;
  6677.                     break;
  6678.                     // port
  6679.                   case 12:
  6680.                     $tempPorts trim($data[$c]);
  6681.                     $tempPortsAArray explode("/"$tempPorts);
  6682.                     if (count($tempPortsAArray) > && $linkExtension["typeLien"] == "Duplex" && $tempPortsAArray[1] == "0") {
  6683.                       $tempPortsAArray[1] = $tempPortsAArray[0] + 1;
  6684.                       $tempPorts implode("/"$tempPortsAArray);
  6685.                     } elseif (count($tempPortsAArray) > && $linkExtension["typeLien"] == "Single" && $tempPortsAArray[1] == "0") {
  6686.                       $tempPorts $tempPortsAArray[0];
  6687.                     }
  6688.                     if (LinkController::endsWith($linkExtension["equipmentExtremityA"], "ACE48FO")) {
  6689.                       $slot LinkController::startsWith($linkExtension["slotExtremityA"], "0") ? substr($linkExtension["slotExtremityA"], 1) : $linkExtension["slotExtremityA"];
  6690.                       $tempPortsAArray explode("/"$tempPorts);
  6691.                       $resPorts = array();
  6692.                       foreach ($tempPortsAArray as $value) {
  6693.                         switch ($slot) {
  6694.                           case '1':
  6695.                             $resPorts[] = $value 12 $value 12 $value;
  6696.                             break;
  6697.                           case '2':
  6698.                             $resPorts[] = $value 13 || $value 24 12 + ($value 12) : $value;
  6699.                             break;
  6700.                           case '3':
  6701.                             $resPorts[] = $value 25 || $value 36 24 + ($value 12) : $value;
  6702.                             break;
  6703.                           case '4':
  6704.                             $resPorts[] = $value 37 || $value 48 36 + ($value 12) : $value;
  6705.                             break;
  6706.                           case '5':
  6707.                             $resPorts[] = $value 49 || $value 60 48 + ($value 12) : $value;
  6708.                             break;
  6709.                           default:
  6710.                             // code...
  6711.                             break;
  6712.                         }
  6713.                       }
  6714.                       $tempPorts implode("/"$resPorts);
  6715.                     }
  6716.                     $tempPortsAArray explode("/"$tempPorts);
  6717.                     foreach ($tempPortsAArray as $value) {
  6718.                       $this->get('logger')->error("5614 : " $value);
  6719.                       $this->get('logger')->error("5615 : " $equipmentsArray[$linkExtension["equipmentExtremityA"]][explode("-"$linkExtension["slotExtremityA"])[0]]);
  6720.                       $this->get('logger')->error("5616 : " explode("-"$linkExtension["slotExtremityA"])[0]);
  6721.                       if ($equipmentsArray[$linkExtension["equipmentExtremityA"]][explode("-"$linkExtension["slotExtremityA"])[0]] < $value) {
  6722.                         $equipmentsArray[$linkExtension["equipmentExtremityA"]][explode("-"$linkExtension["slotExtremityA"])[0]] = $value;
  6723.                       }
  6724.                     }
  6725.                     $linkExtension["portExtremityA"] = $tempPorts;
  6726.                     break;
  6727.                     // Site title  ex: @46, @89, etc...
  6728.                   case 13:
  6729.                     $linkExtension["siteExtremityB"] = trim($data[$c]);
  6730.                     break;
  6731.                     // room title
  6732.                   case 14:
  6733.                     $linkExtension["roomExtremityB"] = trim($data[$c]);
  6734.                     break;
  6735.                     // rack title
  6736.                   case 15:
  6737.                     $linkExtension["rackExtremityB"] = trim($data[$c]);
  6738.                     break;
  6739.                     // equipment title
  6740.                   case 16:
  6741.                     $linkExtension["equipmentExtremityB"] = trim($data[$c]);
  6742.                     break;
  6743.                     // slot
  6744.                   case 17:
  6745.                     $linkExtension["slotExtremityB"] = trim($data[$c]);
  6746.                     if (!array_key_exists($linkExtension["equipmentExtremityB"], $equipmentsArray)) {
  6747.                       $equipmentsArray[$linkExtension["equipmentExtremityB"]] = array();
  6748.                     }
  6749.                     if (!array_key_exists(explode("-"trim($data[$c]))[0], $equipmentsArray[$linkExtension["equipmentExtremityB"]])) {
  6750.                       $equipmentsArray[$linkExtension["equipmentExtremityB"]][explode("-"trim($data[$c]))[0]] = 0;
  6751.                     }
  6752.                     // $equipmentsArray[$linkExtension["equipmentExtremityB"]][explode("-", trim($data[$c]))[0]] = 0;
  6753.                     break;
  6754.                     // port
  6755.                   case 18:
  6756.                     $tempPorts trim($data[$c]);
  6757.                     $tempPortsBArray explode("/"$tempPorts);
  6758.                     if (count($tempPortsBArray) > && $linkExtension["typeLien"] == "Duplex" && $tempPortsBArray[1] == "0") {
  6759.                       $tempPortsBArray[1] = $tempPortsBArray[0] + 1;
  6760.                       $tempPorts implode("/"$tempPortsBArray);
  6761.                     } elseif (count($tempPortsBArray) > && $linkExtension["typeLien"] == "Single" && $tempPortsBArray[1] == "0") {
  6762.                       $tempPorts $tempPortsBArray[0];
  6763.                     }
  6764.                     if (LinkController::endsWith($linkExtension["equipmentExtremityB"], "ACE48FO")) {
  6765.                       $slot LinkController::startsWith($linkExtension["slotExtremityB"], "0") ? substr($linkExtension["slotExtremityB"], 1) : $linkExtension["slotExtremityB"];
  6766.                       $tempPortsBArray explode("/"$tempPorts);
  6767.                       $resPorts = array();
  6768.                       foreach ($tempPortsBArray as $value) {
  6769.                         switch ($slot) {
  6770.                           case '1':
  6771.                             $resPorts[] = $value 12 $value 12 $value;
  6772.                             break;
  6773.                           case '2':
  6774.                             $resPorts[] = $value 13 || $value 24 12 + ($value 12) : $value;
  6775.                             break;
  6776.                           case '3':
  6777.                             $resPorts[] = $value 25 || $value 36 24 + ($value 12) : $value;
  6778.                             break;
  6779.                           case '4':
  6780.                             $resPorts[] = $value 37 || $value 48 36 + ($value 12) : $value;
  6781.                             break;
  6782.                           case '5':
  6783.                             $resPorts[] = $value 49 || $value 60 48 + ($value 12) : $value;
  6784.                             break;
  6785.                           default:
  6786.                             $resPorts[] = $value;
  6787.                             break;
  6788.                         }
  6789.                       }
  6790.                       $tempPorts implode("/"$resPorts);
  6791.                     }
  6792.                     $tempPortsBArray explode("/"$tempPorts);
  6793.                     foreach ($tempPortsBArray as $value) {
  6794.                       if ($equipmentsArray[$linkExtension["equipmentExtremityB"]][explode("-"$linkExtension["slotExtremityB"])[0]] < $value) {
  6795.                         $equipmentsArray[$linkExtension["equipmentExtremityB"]][explode("-"$linkExtension["slotExtremityB"])[0]] = $value;
  6796.                       }
  6797.                     }
  6798.                     $linkExtension["portExtremityB"] = $tempPorts;
  6799.                     break;
  6800.                   default:
  6801.                     // code...
  6802.                     break;
  6803.                 }
  6804.               }
  6805.               $extractedData[$linkTitle]["linkExtensions"][] = $linkExtension;
  6806.             }
  6807.             // $row++;
  6808.           }
  6809.           fclose($handle);
  6810.         }
  6811.         // print_r($extractedData["F00030"]);
  6812.         $corresFile $_FILES['corresCsvFile']['tmp_name'];
  6813.         $row 1;
  6814.         $corresExtractedData = array();
  6815.         if (($handle fopen($corresFile"r")) !== FALSE) {
  6816.           while (($data fgetcsv($handle1000",")) !== FALSE) {
  6817.             if ($row 2) {
  6818.               $num count($data);
  6819.               $keyWithoutSlot "";
  6820.               $keyWithSlot "";
  6821.               $modulaireId null;
  6822.               $moduleId null;
  6823.               $equipmentId null;
  6824.               $equipmentName null;
  6825.               for ($c 0$c $num$c++) {
  6826.                 switch ($c) {
  6827.                     //Link title
  6828.                   case 1:
  6829.                   case 2:
  6830.                   case 3:
  6831.                   case 4:
  6832.                     $keyWithoutSlot .= trim($data[$c]);
  6833.                     break;
  6834.                   case 5:
  6835.                     $keyWithSlot $keyWithoutSlot trim($data[$c]);
  6836.                     break;
  6837.                   case 7:
  6838.                     $comment trim($data[$c]);
  6839.                     break;
  6840.                   case 9:
  6841.                     $equipmentName trim($data[$c]);
  6842.                     break;
  6843.                   case 10:
  6844.                     $modulaireId trim($data[$c]);
  6845.                     break;
  6846.                   case 11:
  6847.                     $moduleId trim($data[$c]);
  6848.                     break;
  6849.                   case 12:
  6850.                     $equipmentId trim($data[$c]);
  6851.                     break;
  6852.                   default:
  6853.                     break;
  6854.                 }
  6855.               }
  6856.               $corresExtractedData[$keyWithoutSlot] = array(
  6857.                 "equipmentName" => $equipmentName,
  6858.                 "modulaireId" => $modulaireId,
  6859.                 "moduleId" => $moduleId,
  6860.                 "equipmentId" => $equipmentId
  6861.               );
  6862.               $corresExtractedData[$keyWithSlot] = array(
  6863.                 "equipmentName" => $equipmentName,
  6864.                 "modulaireId" => $modulaireId,
  6865.                 "moduleId" => $moduleId,
  6866.                 "equipmentId" => $equipmentId
  6867.               );
  6868.             }
  6869.             $row++;
  6870.           }
  6871.           fclose($handle);
  6872.         }
  6873.         $upload_dir $this->get("kernel")->getLogDir();
  6874.         $fullPathImage $upload_dir "/table de correspondabce.csv";
  6875.         move_uploaded_file($corresFile$fullPathImage);
  6876.         $fp fopen($fullPathImage'ab');
  6877.         // fputs($fp, "\r\n");
  6878.         // print_r($corresExtractedData);
  6879.         $test 1;
  6880.         foreach ($extractedData as $key => $linkArray) {
  6881.           if ($test 606) {
  6882.             break;
  6883.           }
  6884.           $test++;
  6885.           if (in_array($keyLinkController::getLinkExceptions())) {
  6886.             continue;
  6887.           }
  6888.           foreach ($linkArray["linkExtensions"] as $linkExtensionArray) {
  6889.             $tempArrayA = array(
  6890.               "site" => $linkExtensionArray["siteExtremityA"],
  6891.               "room" => $linkExtensionArray["roomExtremityA"],
  6892.               "rack" => $linkExtensionArray["rackExtremityA"],
  6893.               "equipment" => $linkExtensionArray["equipmentExtremityA"],
  6894.               "slot" => $linkExtensionArray["slotExtremityA"]
  6895.             );
  6896.             $equipementAArray $this->getEquipmentId($tempArrayA$corresExtractedData);
  6897.             // var_dump($tempArrayA["equipment"]);
  6898.             if ($equipementAArray == null || !($equipementAArray["equipmentId"] || $equipementAArray["moduleId"])) {
  6899.               $equipementAArray $this->createFakeEquipment($tempArrayA$equipmentsArray116311);
  6900.               $keyWithSlot implode($tempArrayA);
  6901.               $keyWithoutSlot $tempArrayA["site"] . $tempArrayA["room"] . $tempArrayA["rack"] . $tempArrayA["equipment"];
  6902.               $corresExtractedData[$keyWithSlot] = $equipementAArray;
  6903.               $corresExtractedData[$keyWithoutSlot] = $equipementAArray;
  6904.               $line = array(""$tempArrayA["site"], $tempArrayA["room"], $tempArrayA["rack"], $tempArrayA["equipment"], $tempArrayA["slot"], """"""""""""$equipementAArray["equipmentId"]);
  6905.               // $val = implode(",", $line);
  6906.               fputcsv($fp$line);
  6907.               // continue;
  6908.             }
  6909.             $tempArrayB = array(
  6910.               "site" => $linkExtensionArray["siteExtremityB"],
  6911.               "room" => $linkExtensionArray["roomExtremityB"],
  6912.               "rack" => $linkExtensionArray["rackExtremityB"],
  6913.               "equipment" => $linkExtensionArray["equipmentExtremityB"],
  6914.               "slot" => $linkExtensionArray["slotExtremityB"]
  6915.             );
  6916.             $equipementBArray $this->getEquipmentId($tempArrayB$corresExtractedData);
  6917.             if ($equipementBArray == null || !($equipementBArray["equipmentId"] || $equipementBArray["moduleId"])) {
  6918.               $equipementBArray $this->createFakeEquipment($tempArrayB$equipmentsArray116311);
  6919.               $keyWithSlot implode($tempArrayB);
  6920.               $keyWithoutSlot $tempArrayB["site"] . $tempArrayB["room"] . $tempArrayB["rack"] . $tempArrayB["equipment"];
  6921.               $corresExtractedData[$keyWithSlot] = $equipementBArray;
  6922.               $corresExtractedData[$keyWithoutSlot] = $equipementBArray;
  6923.               $line = array(""$tempArrayB["site"], $tempArrayB["room"], $tempArrayB["rack"], $tempArrayB["equipment"], $tempArrayB["slot"], """"""""""""$equipementBArray["equipmentId"]);
  6924.               // $val = implode(",", $line);
  6925.               fputcsv($fp$line);
  6926.             }
  6927.             $em->flush();
  6928.           }
  6929.         }
  6930.         fclose($fp);
  6931.         return $this->file($fullPathImage);
  6932.         // print_r($error);
  6933.       }
  6934.       // show form
  6935.     }
  6936.     return $this->render('link/import_csv.html.twig', [
  6937.       'page_title' => $translator->trans('Générer link - CSV'),
  6938.       'box_title' => "Choisir un Fichier CSV"
  6939.     ]);
  6940.   }
  6941.   /**
  6942.    * @Route("/link/verification", name="link_verification")
  6943.    */
  6944.   public function linkVerification(Request $requestTranslatorInterface $translator)
  6945.   {
  6946.     set_time_limit(0);
  6947.     $user $this->getUser();
  6948.     // process form
  6949.     if ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN")) {
  6950.       $em $this->getDoctrine()->getManager();
  6951.       $links $em->getRepository(Link::class)->findAll();
  6952.       foreach ($links as $link) {
  6953.         LinkController::validateLink($em$link);
  6954.       }
  6955.     }
  6956.     return $this->redirect($request->headers->get('referer'));
  6957.   }
  6958.   public static function validateLink($em$link)
  6959.   {
  6960.     $linkExts $em->getRepository(LinkExtension::class)->findBy(["link" => $link]);
  6961.     foreach ($linkExts as $linkExt) {
  6962.       if ($linkExt->getSequenceNo() > 1) {
  6963.         // validate last extension
  6964.         // $portA1 = null;
  6965.         // $portA2 = null;
  6966.         $portsA = array();
  6967.         $extOrders $linkExt->getExtremityA()->getExtensionOrder();
  6968.         foreach ($extOrders as $extOrder) {
  6969.           for ($i 1$i <= 12$i++) {
  6970.             if ($extOrder->getOrderNumber() == $i) {
  6971.               $portsA["portA" $i] = $extOrder->getPort();
  6972.             }
  6973.           }
  6974.           // if ($extOrder->getOrderNumber() == 1) {
  6975.           //     $portA1 = $extOrder->getPort();
  6976.           //     $portsA["portA1"] = $portA1;
  6977.           // }
  6978.           // elseif ($extOrder->getOrderNumber() == 2) {
  6979.           //     $portA2 = $extOrder->getPort();
  6980.           //     $portsA["portA2"] = $portA2;
  6981.           // }
  6982.         }
  6983.         LinkController::validateLastExtension($em$link$linkExt$portsA);
  6984.       }
  6985.       if ($linkExt->getSequenceNo() < count($link->getLinkExtension())) {
  6986.         // validate next extension
  6987.         // $portB1 = null;
  6988.         // $portB2 = null;
  6989.         $portsB = array();
  6990.         $extOrders $linkExt->getExtremityB()->getExtensionOrder();
  6991.         foreach ($extOrders as $extOrder) {
  6992.           for ($i 1$i <= 12$i++) {
  6993.             if ($extOrder->getOrderNumber() == $i) {
  6994.               // $portB1 = $extOrder->getPort();
  6995.               $portsB["portB" $i] = $extOrder->getPort();
  6996.             }
  6997.           }
  6998.           // if ($extOrder->getOrderNumber() == 1) {
  6999.           //     $portB1 = $extOrder->getPort();
  7000.           //     $portsB["portB1"] = $portB1;
  7001.           // }
  7002.           // elseif ($extOrder->getOrderNumber() == 2) {
  7003.           //     $portB2 = $extOrder->getPort();
  7004.           //     $portsB["portB2"] = $portB2;
  7005.           // }
  7006.         }
  7007.         LinkController::validateNextExtension($em$link$linkExt$portsB);
  7008.         // LinkController::validateNextExtension($em, $link, $linkExt, $portB1, $portB2);
  7009.       }
  7010.     }
  7011.     $em->flush();
  7012.   }
  7013.   public static function getLinkExceptions()
  7014.   {
  7015.     return array(
  7016.       "F00097",
  7017.       "F00099",
  7018.       "F00164",
  7019.       "F00211",
  7020.       "F00359",
  7021.       "F00360",
  7022.       "F00361",
  7023.       "F00362",
  7024.       "F00363",
  7025.       "F00364",
  7026.       "F00365",
  7027.       "F00366",
  7028.       "F00367",
  7029.       "F00368"
  7030.     );
  7031.   }
  7032.   public function getEquipmentId($eqData$corresExtractedData)
  7033.   {
  7034.     $keyWithSlot implode($eqData);
  7035.     $keyWithoutSlot $eqData["site"] . $eqData["room"] . $eqData["rack"] . $eqData["equipment"];
  7036.     if (array_key_exists($keyWithSlot$corresExtractedData) && ($corresExtractedData[$keyWithSlot]["equipmentId"] || $corresExtractedData[$keyWithSlot]["moduleId"])) {
  7037.       // var_dump($keyWithSlot . " - ". $corresExtractedData[$keyWithSlot]["equipmentId"]);
  7038.       return $corresExtractedData[$keyWithSlot];
  7039.     } elseif (array_key_exists($keyWithoutSlot$corresExtractedData) && ($corresExtractedData[$keyWithoutSlot]["equipmentId"] || $corresExtractedData[$keyWithoutSlot]["moduleId"])) {
  7040.       // var_dump($keyWithoutSlot . " - ". $corresExtractedData[$keyWithoutSlot]["moduleId"]);
  7041.       return $corresExtractedData[$keyWithoutSlot];
  7042.     } elseif ("Cassette.12Fo" == $eqData["equipment"]) {
  7043.       $tempRoom explode(" "$eqData["room"]);
  7044.       $eqName "Idea " $tempRoom[count($tempRoom) - 1] . " " $eqData["rack"];
  7045.       // var_dump($eqName);
  7046.       //To make it work with the slots starts with leading 0
  7047.       $tempSlot $eqData["slot"];
  7048.       // if ($eqData["slot"]{
  7049.       // 0} == "0") {
  7050.       if ($eqData["slot"][0] == "0") {
  7051.         // $tempSlot = $eqData["slot"]{
  7052.         // 1};
  7053.         $tempSlot $eqData["slot"][1];
  7054.       }
  7055.       $moduleName "Cassette " $tempSlot;
  7056.       // var_dump($module);
  7057.       $tempSite $eqData["site"];
  7058.       if (LinkController::startsWith($eqData["site"], "RTL")) {
  7059.         $tempSite "RTL";
  7060.       }
  7061.       $site $this->getDoctrine()->getRepository('App\Entity\Site')->findOneByTitle($tempSite);
  7062.       $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempRoom[count($tempRoom) - 1], "site" => $site]);
  7063.       $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneBy(["title" => $eqData["rack"], "room" => $room]);
  7064.       $equipment $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneBy(["equipmentSpecificName" => $eqName"rack" => $rack]);
  7065.       $module $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneBy(["equipmentSpecificName" => $moduleName"parent" => $equipment]);
  7066.       if ($module) {
  7067.         // var_dump($module->getId());
  7068.         return array(
  7069.           "equipmentName" => $module->getEquipmentSpecificName(),
  7070.           "modulaireId" => null,
  7071.           "moduleId" => $module->getId(),
  7072.           "equipmentId" => null,
  7073.         );
  7074.       } else {
  7075.         $em $this->getDoctrine()->getManager();
  7076.         $eq = new EquipmentSpecific();
  7077.         $eq->setEquipmentSpecificName($moduleName);
  7078.         $eq->setAlias("K7-" $tempSlot);
  7079.         $moduleGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById(3);
  7080.         $eq->setEquipmentGeneric($moduleGeneric);
  7081.         $slot $this->getDoctrine()->getRepository('App\Entity\Slot')->findOneBy(["modulaire" => $equipment"slotNumber" => $tempSlot]);
  7082.         $slot->setModule($eq);
  7083.         $em->persist($slot);
  7084.         $eq->setIsModule(true);
  7085.         $eq->setParent($equipment);
  7086.         //
  7087.         // $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
  7088.         // $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
  7089.         // $eq->setPositionRack($request->request->get('positionRack'));
  7090.         $em->persist($eq);
  7091.         $em->flush();
  7092.         $eq->setRack($rack);
  7093.         // create specific interfaces
  7094.         $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
  7095.         foreach ($interfacesGeneric as $interfaceGeneric) {
  7096.           $interfaceSpecific = new InterfaceSpecific();
  7097.           $interfaceSpecific->setEquipmentSpecific($eq);
  7098.           $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  7099.           $em->persist($interfaceSpecific);
  7100.           $em->flush();
  7101.           $alias null;
  7102.           if ($interfaceGeneric->getAlias()) {
  7103.             $alias json_decode($interfaceGeneric->getAlias(), true);
  7104.           }
  7105.           $portExternes null;
  7106.           $idTemp $interfaceGeneric->getId();
  7107.           // var_dump($_POST["portExterne[$idTemp]"]);
  7108.           if (isset($_POST["portExterne"][$idTemp])) {
  7109.             foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
  7110.               $portExternes[$key] = $value;
  7111.             }
  7112.           }
  7113.           // var_dump($portExternes);
  7114.           // create ports
  7115.           $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  7116.           for ($i 1$i <= $numberOfPorts$i++) {
  7117.             $port = new Port();
  7118.             $port->setInterfaceSpecific($interfaceSpecific);
  7119.             $port->setOrderNo($i);
  7120.             if ($alias && count($alias) > 0) {
  7121.               $port->setAlias($alias[$i]);
  7122.             }
  7123.             if ($portExternes) {
  7124.               if (isset($portExternes[$i]) && $portExternes[$i]) {
  7125.                 $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
  7126.               }
  7127.             }
  7128.             $em->persist($port);
  7129.             $em->flush();
  7130.           }
  7131.         }
  7132.         return array(
  7133.           "equipmentName" => $eq->getEquipmentSpecificName(),
  7134.           "modulaireId" => null,
  7135.           "moduleId" => $eq->getId(),
  7136.           "equipmentId" => null,
  7137.         );
  7138.       }
  7139.     } else {
  7140.       $eqName $eqData["equipment"];
  7141.       $tempSite $eqData["site"];
  7142.       if (LinkController::startsWith($eqData["site"], "RTL")) {
  7143.         $tempSite "RTL";
  7144.       }
  7145.       $site $this->getDoctrine()->getRepository('App\Entity\Site')->findOneByTitle($tempSite);
  7146.       if (null == $site) {
  7147.         return null;
  7148.       }
  7149.       $room null;
  7150.       if ($eqData["room"] == "STU 01") {
  7151.         $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => "STU01""site" => $site]);
  7152.       } else {
  7153.         $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $eqData["room"], "site" => $site]);
  7154.       }
  7155.       if (null == $room) {
  7156.         $tempRoom explode(" "$eqData["room"]);
  7157.         if (count($tempRoom) == 2) {
  7158.           $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempRoom[1], "site" => $site]);
  7159.         } elseif (count($tempRoom) == 3) {
  7160.           $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempRoom[1] . " " $tempRoom[2], "site" => $site]);
  7161.         } else {
  7162.           return null;
  7163.         }
  7164.         if (null == $room) {
  7165.           return null;
  7166.         }
  7167.       }
  7168.       $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneBy(["title" => $eqData["rack"], "room" => $room]);
  7169.       if (null == $rack) {
  7170.         return null;
  7171.       }
  7172.       $equipment $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneBy(["equipmentSpecificName" => $eqName"rack" => $rack]);
  7173.       if ($equipment) {
  7174.         return array(
  7175.           "equipmentName" => $equipment->getEquipmentSpecificName(),
  7176.           "modulaireId" => null,
  7177.           "moduleId" => null,
  7178.           "equipmentId" => $equipment->getId(),
  7179.         );
  7180.       }
  7181.     }
  7182.     return null;
  7183.   }
  7184.   public function getInterfaceSpecific($equipementArray$linkExtensionArray$extremity)
  7185.   {
  7186.     $eqId $equipementArray["equipmentId"] ? $equipementArray["equipmentId"] : $equipementArray["moduleId"];
  7187.     $equipmentSpecific $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($eqId);
  7188.     $interface null;
  7189.     $defaultInterfaceToChoose = ["SFP""SFP LC""SFP SC""SFP SC""SFP X2""QSFP""10G""X2 SC"];
  7190.     if ($equipmentSpecific) {
  7191.       $interfaceSpecificArray $equipmentSpecific->getInterfaceSpecific();
  7192.       $slot $extremity == "A" $linkExtensionArray["slotExtremityA"] : $linkExtensionArray["slotExtremityB"];
  7193.       $eqName $extremity == "A" $linkExtensionArray["equipmentExtremityA"] : $linkExtensionArray["equipmentExtremityB"];
  7194.       if ($equipementArray["equipmentId"]) {
  7195.         foreach ($interfaceSpecificArray as $temp) {
  7196.           if ($temp->getInterfaceGeneric()->getInterfaceNumber() == $slot) {
  7197.             $interface $temp;
  7198.             break;
  7199.           }
  7200.         }
  7201.         if ($interface == null) {
  7202.           if ($eqName == "RACK.48FO") {
  7203.             $interface $interfaceSpecificArray[0];
  7204.           } elseif ($eqName == "SW.BOLERO") {
  7205.             foreach ($interfaceSpecificArray as $temp) {
  7206.               $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7207.               if ($tempInterfaceNo == "2") {
  7208.                 $interface $temp;
  7209.                 break;
  7210.               }
  7211.               // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7212.               //     $interface = $temp;
  7213.               //     break;
  7214.               // }
  7215.             }
  7216.           } else {
  7217.             foreach ($interfaceSpecificArray as $temp) {
  7218.               $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7219.               if (LinkController::startsWith($tempInterfaceNo"SFP")) {
  7220.                 $interface $temp;
  7221.                 break;
  7222.               }
  7223.               // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7224.               //     $interface = $temp;
  7225.               //     break;
  7226.               // }
  7227.             }
  7228.             if ($interface == null) {
  7229.               foreach ($interfaceSpecificArray as $temp) {
  7230.                 $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7231.                 if (LinkController::startsWith($tempInterfaceNo"10G")) {
  7232.                   $interface $temp;
  7233.                   break;
  7234.                 }
  7235.                 // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7236.                 //     $interface = $temp;
  7237.                 //     break;
  7238.                 // }
  7239.               }
  7240.               if ($interface == null) {
  7241.                 foreach ($interfaceSpecificArray as $temp) {
  7242.                   $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7243.                   if (LinkController::startsWith($tempInterfaceNo"QSFP")) {
  7244.                     $interface $temp;
  7245.                     break;
  7246.                   }
  7247.                   // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7248.                   //     $interface = $temp;
  7249.                   //     break;
  7250.                   // }
  7251.                 }
  7252.                 if ($interface == null) {
  7253.                   foreach ($interfaceSpecificArray as $temp) {
  7254.                     $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7255.                     if (LinkController::startsWith($tempInterfaceNo"X2 SC")) {
  7256.                       $interface $temp;
  7257.                       break;
  7258.                     }
  7259.                     // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7260.                     //     $interface = $temp;
  7261.                     //     break;
  7262.                     // }
  7263.                   }
  7264.                 }
  7265.               }
  7266.             }
  7267.           }
  7268.         }
  7269.       } elseif ($equipementArray["moduleId"]) {
  7270.         $slotTemp explode("-"$slot);
  7271.         if (count($slotTemp) > 1) {
  7272.           $slot $slotTemp[count($slotTemp) - 1];
  7273.           foreach ($interfaceSpecificArray as $temp) {
  7274.             if ($temp->getInterfaceGeneric()->getInterfaceNumber() == $slot) {
  7275.               $interface $temp;
  7276.               break;
  7277.             }
  7278.           }
  7279.           if ($interface == null) {
  7280.             foreach ($interfaceSpecificArray as $temp) {
  7281.               $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7282.               if (LinkController::startsWith($tempInterfaceNo"SFP")) {
  7283.                 $interface $temp;
  7284.                 break;
  7285.               }
  7286.               // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7287.               //     $interface = $temp;
  7288.               //     break;
  7289.               // }
  7290.             }
  7291.             if ($interface == null) {
  7292.               foreach ($interfaceSpecificArray as $temp) {
  7293.                 $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7294.                 if (LinkController::startsWith($tempInterfaceNo"10G")) {
  7295.                   $interface $temp;
  7296.                   break;
  7297.                 }
  7298.                 // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7299.                 //     $interface = $temp;
  7300.                 //     break;
  7301.                 // }
  7302.               }
  7303.               if ($interface == null) {
  7304.                 foreach ($interfaceSpecificArray as $temp) {
  7305.                   $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7306.                   if (LinkController::startsWith($tempInterfaceNo"QSFP")) {
  7307.                     $interface $temp;
  7308.                     break;
  7309.                   }
  7310.                   // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7311.                   //     $interface = $temp;
  7312.                   //     break;
  7313.                   // }
  7314.                 }
  7315.                 if ($interface == null) {
  7316.                   foreach ($interfaceSpecificArray as $temp) {
  7317.                     $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7318.                     if (LinkController::startsWith($tempInterfaceNo"X2 SC")) {
  7319.                       $interface $temp;
  7320.                       break;
  7321.                     }
  7322.                     // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7323.                     //     $interface = $temp;
  7324.                     //     break;
  7325.                     // }
  7326.                   }
  7327.                 }
  7328.               }
  7329.             }
  7330.           }
  7331.         } else {
  7332.           if (count($interfaceSpecificArray) == 1) {
  7333.             // var_dump($interfaceSpecificArray{0}->getId());
  7334.             $interface $interfaceSpecificArray[0];
  7335.           } else {
  7336.             foreach ($interfaceSpecificArray as $temp) {
  7337.               $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7338.               if (LinkController::startsWith($tempInterfaceNo"SFP")) {
  7339.                 $interface $temp;
  7340.                 break;
  7341.               }
  7342.             }
  7343.             if ($interface == null) {
  7344.               foreach ($interfaceSpecificArray as $temp) {
  7345.                 $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7346.                 if (LinkController::startsWith($tempInterfaceNo"10G")) {
  7347.                   $interface $temp;
  7348.                   break;
  7349.                 }
  7350.               }
  7351.               if ($interface == null) {
  7352.                 foreach ($interfaceSpecificArray as $temp) {
  7353.                   $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7354.                   if (LinkController::startsWith($tempInterfaceNo"QSFP")) {
  7355.                     $interface $temp;
  7356.                     break;
  7357.                   }
  7358.                 }
  7359.                 if ($interface == null) {
  7360.                   foreach ($interfaceSpecificArray as $temp) {
  7361.                     $tempInterfaceNo $temp->getInterfaceGeneric()->getInterfaceNumber();
  7362.                     if (LinkController::startsWith($tempInterfaceNo"X2 SC")) {
  7363.                       $interface $temp;
  7364.                       break;
  7365.                     }
  7366.                   }
  7367.                 }
  7368.               }
  7369.             }
  7370.             // foreach ($interfaceSpecificArray as $temp) {
  7371.             //     $tempInterfaceNo = $temp->getInterfaceGeneric()->getInterfaceNumber();
  7372.             //     if (LinkController::startsWith($tempInterfaceNo, "SFP")) {
  7373.             //         $interface = $temp;
  7374.             //         break;
  7375.             //     }
  7376.             //     elseif(LinkController::startsWith($tempInterfaceNo, "10G")) {
  7377.             //         $interface = $temp;
  7378.             //         break;
  7379.             //     }
  7380.             //     elseif(LinkController::startsWith($tempInterfaceNo, "QSFP")) {
  7381.             //         $interface = $temp;
  7382.             //         break;
  7383.             //     }
  7384.             //     elseif(LinkController::startsWith($tempInterfaceNo, "X2 SC")) {
  7385.             //         $interface = $temp;
  7386.             //         break;
  7387.             //     }
  7388.             //     // if(in_array($temp->getInterfaceGeneric()->getInterfaceNumber(),$defaultInterfaceToChoose)){
  7389.             //     //     $interface = $temp;
  7390.             //     //     break;
  7391.             //     // }
  7392.             // }
  7393.           }
  7394.         }
  7395.       }
  7396.     }
  7397.     // $this->get('logger')->error("5294 : ".$interface->getId());
  7398.     return $interface;
  7399.   }
  7400.   public function getInterfaceSpecificV2($equipementArray$ports)
  7401.   {
  7402.     // if ($equipementArray["moduleId"]) {
  7403.     $eqId $equipementArray["moduleId"] ? $equipementArray["moduleId"] : $equipementArray["equipmentId"];
  7404.     $equipmentSpecific $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($eqId);
  7405.     $interface null;
  7406.     // $defaultInterfaceToChoose = ["QSFP", "10G", "40G", "X2 SC"];
  7407.     if ($equipmentSpecific) {
  7408.       $interfaceSpecificArray $equipmentSpecific->getInterfaceSpecific();
  7409.       // $slot = $extremity == "A" ? $equipementArray["slotExtremityA"] : $equipementArray["slotExtremityB"];
  7410.       $portsTemp explode("/"$ports);
  7411.       if (count($portsTemp) == 1) {
  7412.         foreach ($interfaceSpecificArray as $temp) {
  7413.           // if(LinkController::startsWith($tempInterfaceNo, "SFP") || in_array($temp->getInterfaceGeneric()->getInterfaceNumber(), $defaultInterfaceToChoose)){
  7414.           foreach ($temp->getPort() as $value) {
  7415.             if ($value->getOrderNo() == $ports || $value->getAlias() == $ports) {
  7416.               // print_r($ports);
  7417.               // print_r($value->getOrderNo());
  7418.               // print_r($value->getAlias());
  7419.               return $temp;
  7420.             }
  7421.           }
  7422.           // }
  7423.         }
  7424.         if (count($interfaceSpecificArray) == && $ports 48) {
  7425.           foreach ($interfaceSpecificArray as $temp) {
  7426.             if ($temp->getInterfaceGeneric()->getNumberOfPorts() != 48) {
  7427.               return $temp;
  7428.             }
  7429.           }
  7430.         }
  7431.       }
  7432.     }
  7433.     // }
  7434.     return null;
  7435.   }
  7436.   public function getPortsCSV($interfaceSpecific$orderNoArray)
  7437.   {
  7438.     // var_dump($interfaceSpecific->getId());
  7439.     $portsArray = array();
  7440.     foreach ($orderNoArray as $orderNo) {
  7441.       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"orderNo" => $orderNo]);
  7442.       if ($port == null) {
  7443.         $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"alias" => $orderNo]);
  7444.       }
  7445.       if ($port == null) {
  7446.         $port $this->getDoctrine()->getRepository("App:Port")->createQueryBuilder('p')
  7447.           ->where('p.interfaceSpecific = :if')
  7448.           ->andWhere('p.orderNo LIKE :no')
  7449.           ->setParameter('if'$interfaceSpecific)
  7450.           ->setParameter('no''%' $orderNo)
  7451.           ->getQuery()
  7452.           ->getOneOrNullResult();
  7453.       }
  7454.       if ($port == null) {
  7455.         switch ($orderNo) {
  7456.           case '49':
  7457.             $orderNo "G1";
  7458.             break;
  7459.           case '50':
  7460.             $orderNo "G2";
  7461.             break;
  7462.           case '51':
  7463.             $orderNo "G3";
  7464.             break;
  7465.           case '52':
  7466.             $orderNo "G4";
  7467.             break;
  7468.           default:
  7469.             // code...
  7470.             break;
  7471.         }
  7472.         $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"alias" => $orderNo]);
  7473.       }
  7474.       $portsArray[] = $port;
  7475.     }
  7476.     return $portsArray;
  7477.   }
  7478.   public function getPortsCSV2($interfaceSpecific$orderNoArray)
  7479.   {
  7480.     // var_dump($interfaceSpecific->getId());
  7481.     $portsArray = array();
  7482.     foreach ($orderNoArray as $orderNo) {
  7483.       $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"orderNo" => $orderNo]);
  7484.       if ($port == null) {
  7485.         $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"alias" => $orderNo]);
  7486.       }
  7487.       if ($port == null) {
  7488.         $port $this->getDoctrine()->getRepository("App:Port")->createQueryBuilder('p')
  7489.           ->where('p.interfaceSpecific = :if')
  7490.           ->andWhere('p.orderNo LIKE :no')
  7491.           ->setParameter('if'$interfaceSpecific)
  7492.           ->setParameter('no''%' $orderNo)
  7493.           ->getQuery()
  7494.           ->getOneOrNullResult();
  7495.         if ($port == null) {
  7496.           $orderNo $orderNo 48;
  7497.           $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"orderNo" => $orderNo]);
  7498.           if ($port == null) {
  7499.             $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneBy(["interfaceSpecific" => $interfaceSpecific"alias" => $orderNo]);
  7500.           }
  7501.           if ($port == null) {
  7502.             $port $this->getDoctrine()->getRepository("App:Port")->createQueryBuilder('p')
  7503.               ->where('p.interfaceSpecific = :if')
  7504.               ->andWhere('p.orderNo LIKE :no')
  7505.               ->setParameter('if'$interfaceSpecific)
  7506.               ->setParameter('no''%' $orderNo)
  7507.               ->getQuery()
  7508.               ->getOneOrNullResult();
  7509.           }
  7510.         }
  7511.       }
  7512.       $portsArray[] = $port;
  7513.     }
  7514.     return $portsArray;
  7515.   }
  7516.   public function createFakeEquipment($tempArray$equipmentsArray$typeLinkId$typeConnectorId$typeInterconnxionId$typeEquipmentId)
  7517.   {
  7518.     $eqName $tempArray["equipment"];
  7519.     $tempSite $tempArray["site"];
  7520.     if (LinkController::startsWith($tempArray["site"], "RTL")) {
  7521.       $tempSite "RTL";
  7522.     }
  7523.     $site $this->getDoctrine()->getRepository('App\Entity\Site')->findOneByTitle($tempSite);
  7524.     if (null == $site) {
  7525.       return false;
  7526.     }
  7527.     $this->get('logger')->error("5586 : " $site->getId());
  7528.     //
  7529.     // if (!$site) {
  7530.     //     return false;
  7531.     // }
  7532.     $room null;
  7533.     if ($tempArray["room"] == "STU 01") {
  7534.       $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => "STU01""site" => $site]);
  7535.     } else {
  7536.       $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempArray["room"], "site" => $site]);
  7537.     }
  7538.     if (null == $room) {
  7539.       $tempRoom explode(" "$tempArray["room"]);
  7540.       if (count($tempRoom) == 2) {
  7541.         $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempRoom[1], "site" => $site]);
  7542.       } elseif (count($tempRoom) == 3) {
  7543.         $room $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["title" => $tempRoom[1] . " " $tempRoom[2], "site" => $site]);
  7544.       } else {
  7545.         return false;
  7546.       }
  7547.       if (null == $room) {
  7548.         return false;
  7549.       }
  7550.     }
  7551.     $this->get('logger')->error("5604 : " $room->getId());
  7552.     // if (!$room) {
  7553.     //     return false;
  7554.     // }
  7555.     $em $this->getDoctrine()->getManager();
  7556.     $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneBy(["title" => $tempArray["rack"], "room" => $room]);
  7557.     if (null == $rack) {
  7558.       $rack = new Rack();
  7559.       $rack->setRoom($room);
  7560.       $rack->setTitle($tempArray["rack"]);
  7561.       $rack->setNumberOfUnits(80);
  7562.       $em->persist($rack);
  7563.       $em->flush();
  7564.     }
  7565.     $this->get('logger')->error("5613 : " $rack->getId());
  7566.     // $eq = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById(["equipmentSpecificName"=>$eqName, "rack"=>$rack]);
  7567.     // if ($eq){
  7568.     //     return array("equipmentName" =>$eq->getEquipmentSpecificName(),
  7569.     //                                                     "modulaireId" =>null,
  7570.     //                                                     "moduleId" =>null,
  7571.     //                                                     "equipmentId" =>$eq->getId(),
  7572.     //                                                     );
  7573.     // }
  7574.     // $slotsArrayTemp = array_unique($equipmentsArray[$eqName]);
  7575.     // foreach ($slotsArrayTemp as $key => $value) {
  7576.     //     $slotsArray[$key] = $value;
  7577.     // }
  7578.     $slotsArray $equipmentsArray[$eqName];
  7579.     $eqGenericId $this->createFakeEquipmentGeneric($eqName$slotsArray$typeLinkId$typeConnectorId$typeInterconnxionId$typeEquipmentId);
  7580.     $this->get('logger')->error("5567 : " $eqGenericId);
  7581.     $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($eqGenericId);
  7582.     $eq = new EquipmentSpecific();
  7583.     $eq->setEquipmentSpecificName($eqName);
  7584.     $eq->setAlias($eqName);
  7585.     $eq->setEquipmentGeneric($eqGeneric);
  7586.     $eq->setRack($rack);
  7587.     $rackFaceId 1;
  7588.     $rackPosition $this->findEmptyRackPosition($rackFaceId$rack->getId(), $eqGeneric->getId());
  7589.     $this->get('logger')->error("5618 : " $rackPosition);
  7590.     if ($rackPosition 1) {
  7591.       $rackFaceId 2;
  7592.       $rackPosition $this->findEmptyRackPosition($rackFaceId$rack->getId(), $eqGeneric->getId());
  7593.     }
  7594.     if ($rackPosition 1) {
  7595.       return false;
  7596.     }
  7597.     $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($rackFaceId));
  7598.     $eq->setPositionRack($rackPosition);
  7599.     $em->persist($eq);
  7600.     $em->flush();
  7601.     // create specific interfaces
  7602.     $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($eqGeneric);
  7603.     foreach ($interfacesGeneric as $interfaceGeneric) {
  7604.       $interfaceSpecific = new InterfaceSpecific();
  7605.       $interfaceSpecific->setEquipmentSpecific($eq);
  7606.       $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  7607.       $em->persist($interfaceSpecific);
  7608.       $em->flush();
  7609.       $alias null;
  7610.       if ($interfaceGeneric->getAlias()) {
  7611.         $alias json_decode($interfaceGeneric->getAlias(), true);
  7612.       }
  7613.       // create ports
  7614.       $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  7615.       for ($i 1$i <= $numberOfPorts$i++) {
  7616.         $port = new Port();
  7617.         $port->setInterfaceSpecific($interfaceSpecific);
  7618.         $port->setOrderNo($i);
  7619.         if ($alias && count($alias) > 0) {
  7620.           $port->setAlias($alias[$i]);
  7621.         }
  7622.         $em->persist($port);
  7623.         $em->flush();
  7624.       }
  7625.     }
  7626.     return array(
  7627.       "equipmentName" => $eq->getEquipmentSpecificName(),
  7628.       "modulaireId" => null,
  7629.       "moduleId" => null,
  7630.       "equipmentId" => $eq->getId(),
  7631.     );
  7632.   }
  7633.   public function createFakeEquipmentGeneric($eqName$slotsArray$typeLinkId$typeConnectorId$typeInterconnxionId$typeEquipmentId)
  7634.   {
  7635.     $eq $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneByTitle($eqName " Generic");
  7636.     if ($eq) {
  7637.       $this->get('logger')->error("5744 : " $eq->getId());
  7638.       return $eq->getId();
  7639.     }
  7640.     $em $this->getDoctrine()->getManager();
  7641.     $eq = new EquipmentGeneric();
  7642.     $eq->setTitle($eqName " Generic");
  7643.     $eq->setNumberOfUnits(1);
  7644.     $eq->setNumberOfInterfaces(count($slotsArray));
  7645.     $eq->setType($this->getDoctrine()->getRepository('App\Entity\TypeEquipment')->findOneById($typeEquipmentId));
  7646.     $em->persist($eq);
  7647.     $em->flush();
  7648.     // $this->get('logger')->info(count($slotsArray));
  7649.     // store interfaces
  7650.     $this->get('logger')->error("5685 : " count($slotsArray));
  7651.     $inter_num $eq->getNumberOfInterfaces();
  7652.     $this->get('logger')->error("5687 : " $inter_num);
  7653.     foreach ($slotsArray as $key => $value) {
  7654.       $this->get('logger')->error($key);
  7655.       $if = new InterfaceGeneric();
  7656.       $if->setEquipmentGeneric($eq);
  7657.       $if->setInterfaceNumber($key);
  7658.       $if->setNumberOfPorts($value);
  7659.       $if->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneById($typeLinkId));
  7660.       $if->setTypeConnector($this->getDoctrine()->getRepository('App\Entity\TypeConnector')->findOneById($typeConnectorId));
  7661.       $if->setTypeInterconnection($this->getDoctrine()->getRepository('App\Entity\TypeInterconnection')->findOneById($typeInterconnxionId));
  7662.       $alias = [];
  7663.       $nPorts = [];
  7664.       for ($j 1$j <= $value$j++) {
  7665.         $alias[$j] = "";
  7666.         $nPorts[] = $j;
  7667.       }
  7668.       $nPorts json_encode($nPorts);
  7669.       $nPorts = (string)$nPorts;
  7670.       $if->setNPorts($nPorts);
  7671.       $alias json_encode($alias);
  7672.       $alias = (string)$alias;
  7673.       $if->setAlias($alias);
  7674.       // }
  7675.       // var_dump($if);
  7676.       //
  7677.       $em->persist($if);
  7678.       $em->flush();
  7679.     }
  7680.     // for ($i = 0; $i < $inter_num; $i++){
  7681.     //
  7682.     //     $this->get('logger')->error($i);
  7683.     //     $if = new InterfaceGeneric();
  7684.     //     $if->setEquipmentGeneric($eq);
  7685.     //     $if->setInterfaceNumber($slotsArray[$i]);
  7686.     //     $if->setNumberOfPorts($slotsArray[$i]);
  7687.     //     $if->setTypeLink($this->getDoctrine()->getRepository('App\Entity\TypeLink')->findOneById($typeLinkId));
  7688.     //     $if->setTypeConnector($this->getDoctrine()->getRepository('App\Entity\TypeConnector')->findOneById($typeConnectorId));
  7689.     //     $if->setTypeInterconnection($this->getDoctrine()->getRepository('App\Entity\TypeInterconnection')->findOneById($typeInterconnxionId));
  7690.     //
  7691.     //       $alias = [];
  7692.     //       $nPorts = [];
  7693.     //
  7694.     //       for ($j = 1; $j<=$nbPorts; $j++){
  7695.     //           $alias[$j] = "";
  7696.     //           $nPorts[] = $j;
  7697.     //       }
  7698.     //       $nPorts = json_encode($nPorts);
  7699.     //       $nPorts = (string)$nPorts;
  7700.     //
  7701.     //       $if->setNPorts($nPorts);
  7702.     //
  7703.     //       $alias = json_encode($alias);
  7704.     //       $alias = (string)$alias;
  7705.     //
  7706.     //       $if->setAlias($alias);
  7707.     //     // }
  7708.     //     // var_dump($if);
  7709.     //     //
  7710.     //     $em->persist($if);
  7711.     //     $em->flush();
  7712.     //
  7713.     // }
  7714.     return $eq->getId();
  7715.   }
  7716.   public function findEmptyRackPosition($rackFaceId$rackId$eqGeneric)
  7717.   {
  7718.     $rack $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($rackId);
  7719.     $rack_capacity $rack->getNumberOfUnits();
  7720.     // start positions in rack
  7721.     $front_positions = [];
  7722.     $rear_positions = [];
  7723.     for ($i 1$i <= $rack_capacity$i++) {
  7724.       $front_positions[] = $i;
  7725.       $rear_positions[] = $i;
  7726.     }
  7727.     // remove occupied positions
  7728.     $eqSpecificInRack $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["rack" => $rack->getId(), "isModule" => false]);
  7729.     foreach ($eqSpecificInRack as $eq) {
  7730.       $eqSpecificPosition $eq->getPositionRack();
  7731.       $eqSpecificHeight $eq->getEquipmentGeneric()->getNumberOfUnits();
  7732.       $eqSpecificRackFace $eq->getRackFace()->getId();
  7733.       for ($j $eqSpecificPosition$j $eqSpecificPosition $eqSpecificHeight$j++) {
  7734.         if ($eqSpecificRackFace == 1) {
  7735.           if (($key array_search($j$front_positions)) !== false) {
  7736.             unset($front_positions[$key]);
  7737.           }
  7738.         } else if ($eqSpecificRackFace == 2) {
  7739.           if (($key array_search($j$front_positions)) !== false) {
  7740.             unset($rear_positions[$key]);
  7741.           }
  7742.         } else {
  7743.           if (($key array_search($j$front_positions)) !== false) {
  7744.             unset($front_positions[$key]);
  7745.             unset($rear_positions[$key]);
  7746.           }
  7747.         }
  7748.       }
  7749.     }
  7750.     // get number of units of generic equipment
  7751.     $equipmentGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($eqGeneric);
  7752.     $numberOfUnits $equipmentGeneric->getNumberOfUnits();
  7753.     $available_positions = [];
  7754.     if ($rackFaceId == 1) {
  7755.       foreach ($front_positions as $key => $value) {
  7756.         $available true;
  7757.         for ($k $value$k $value $numberOfUnits$k++) {
  7758.           if (!in_array($k$front_positions)) {
  7759.             $available false;
  7760.           }
  7761.         }
  7762.         if ($available) {
  7763.           if (!in_array($value$available_positions)) {
  7764.             $available_positions[] = $value;
  7765.           }
  7766.         }
  7767.       }
  7768.     } else if ($rackFaceId == 2) {
  7769.       foreach ($rear_positions as $key => $value) {
  7770.         $available true;
  7771.         for ($k $value$k $value $numberOfUnits$k++) {
  7772.           if (!in_array($k$rear_positions)) {
  7773.             $available false;
  7774.           }
  7775.         }
  7776.         if ($available) {
  7777.           if (!in_array($value$available_positions)) {
  7778.             $available_positions[] = $value;
  7779.           }
  7780.         }
  7781.       }
  7782.     } else {
  7783.       foreach ($front_positions as $key => $value) {
  7784.         $available true;
  7785.         for ($k $value$k $value $numberOfUnits$k++) {
  7786.           if (!in_array($k$front_positions) || !in_array($k$rear_positions)) {
  7787.             $available false;
  7788.           }
  7789.         }
  7790.         if ($available) {
  7791.           if (!in_array($value$available_positions)) {
  7792.             $available_positions[] = $value;
  7793.           }
  7794.         }
  7795.       }
  7796.     }
  7797.     // RETURN ARRAY
  7798.     return count($available_positions) > $available_positions[0] : false;
  7799.   }
  7800.   public function getPorts($trunk$ports$linkType)
  7801.   {
  7802.     //get $tcfs
  7803.     // var_dump($ports);
  7804.     $portsB = [];
  7805.     $tcfsForExts = [];
  7806.     $tcfExtsFromB = array();
  7807.     $duplex false;
  7808.     //MODIFIED ON 06/03/2020
  7809.     if (($linkType->getTitle() == "Duplex" && count($ports) == 1) || ($linkType->getTitle() != "Simplex" && count($ports) == 1)) {
  7810.       $duplex true;
  7811.     }
  7812.     // var_dump($duplex);
  7813.     foreach ($ports as $port) {
  7814.       $tcfFromA null;
  7815.       $tcfFromB null;
  7816.       $tcfExtFromB null;
  7817.       if ($duplex) {
  7818.         $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portA' => $port]);
  7819.         // var_dump($tcfFromA->getId());
  7820.         $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findBy(['portB' => $port]);
  7821.         // var_dump($tcfFromB->getId());
  7822.         $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findBy(['portB' => $port]);
  7823.         foreach ($tcfFromA as $temp) {
  7824.           $portB $temp->getPortB();
  7825.           $portsB[] = $portB;
  7826.           $tcfsForExts[] = $temp;
  7827.         }
  7828.         foreach ($tcfFromB as $temp) {
  7829.           $portB $temp->getPortB();
  7830.           $portsB[] = $portB;
  7831.           $tcfsForExts[] = $temp;
  7832.         }
  7833.         foreach ($tcfExtFromB as $temp) {
  7834.           $tcfExtsFromB[] = $temp;
  7835.           $reverseTrunk true;
  7836.         }
  7837.         // var_dump($tcfsForExts);
  7838.         // var_dump($tcfExtsFromB);
  7839.       } else {
  7840.         $tcfFromA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
  7841.         // var_dump($tcfFromA->getId());
  7842.         $tcfFromB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
  7843.         // var_dump($tcfFromB->getId());
  7844.         $tcfExtFromB $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
  7845.         if ($tcfFromA) {
  7846.           $portB $tcfFromA->getPortB();
  7847.           $portsB[] = $portB;
  7848.           $tcfsForExts[] = $tcfFromA;
  7849.           // var_dump($portB->getId());
  7850.         }
  7851.         if ($tcfFromB) {
  7852.           $portB $tcfFromB->getPortB();
  7853.           $portsB[] = $portB;
  7854.           $tcfsForExts[] = $tcfFromB;
  7855.           // var_dump($portB->getId());
  7856.         }
  7857.         //to treat the reverse case
  7858.         if ($tcfExtFromB) {
  7859.           // var_dump($tcfExtFromB);
  7860.           $tcfExtsFromB[] = $tcfExtFromB;
  7861.           $reverseTrunk true;
  7862.         }
  7863.         // var_dump($tcfsForExts);
  7864.         // var_dump($tcfExtsFromB);
  7865.       }
  7866.     }
  7867.     if (count($tcfsForExts) > 0) {
  7868.       foreach ($tcfsForExts as $tempTcf) {
  7869.         $portsB[] = $tempTcf->getPortB();
  7870.       }
  7871.       for ($i 1$i <= count($tcfsForExts[0]->getExtensions()); $i++) {
  7872.         foreach ($tcfsForExts as $tempTcf) {
  7873.           // get the extensions of sequence $i
  7874.           $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tempTcf"sequenceNo" => $i]);
  7875.           // var_dump($tempExt);
  7876.           if ($tempExt) {
  7877.             $portsB[] = $tempExt->getPortB();
  7878.           }
  7879.         }
  7880.       }
  7881.     }
  7882.     foreach ($tcfExtsFromB as $value) {
  7883.       $tcf $value->getTrunkCableFiber();
  7884.       $portsB[] = $tcf->getPortB();
  7885.       for ($i 1$i <= count($tcf->getExtensions()); $i++) {
  7886.         // get the extensions of sequence $i
  7887.         $tempExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['trunkCableFiber' => $tcf"sequenceNo" => $i]);
  7888.         // var_dump($tempExt);
  7889.         if ($tempExt) {
  7890.           $portsB[] = $tempExt->getPortB();
  7891.         }
  7892.       }
  7893.     }
  7894.     // foreach ($tcfExtsFromB as $tempTcf) {
  7895.     //   $portsB[] = $tempTcf->getPortB();
  7896.     //
  7897.     // }
  7898.     // var_dump($portsB);
  7899.     return $portsB;
  7900.   }
  7901.   public static function validateLastExtension($em$link$extension$portsAArray)
  7902.   {
  7903.     $lastExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() - 1]);
  7904.     $lastExtB $lastExtension->getExtremityB();
  7905.     $lastPorts = [];
  7906.     $lastPortsTemp $lastExtB->getExtensionOrder();
  7907.     foreach ($lastPortsTemp as $value) {
  7908.       $lastPorts[] = $value->getPort();
  7909.     }
  7910.     // $lastPorts = $lastExtB->getPorts();
  7911.     // var_dump($lastPorts);
  7912.     $lastInterfaceSpecific $lastPorts[0]->getInterfaceSpecific();
  7913.     $lastInterfaceGeneric $lastInterfaceSpecific->getInterfaceGeneric();
  7914.     $lastEquipment $lastInterfaceSpecific->getEquipmentSpecific() ? $lastInterfaceSpecific->getEquipmentSpecific() : $lastInterfaceSpecific->getEquipmentSpecificMpo();
  7915.     $currentInterfaceSpecific $portsAArray["portA1"]->getInterfaceSpecific();
  7916.     // $currentInterfaceSpecific = $portA1->getInterfaceSpecific();
  7917.     $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific() ? $currentInterfaceSpecific->getEquipmentSpecific() : $currentInterfaceSpecific->getEquipmentSpecificMpo();
  7918.     //check if it's same as current modified link ext
  7919.     if ($currentEquipment->getId() != $lastEquipment->getId()) {
  7920.       //if false, set the link and las link extension as INVALID
  7921.       $lastExtension->setIsValid(false);
  7922.       if ($lastExtension->getError()) {
  7923.         $lastExtension->setError($lastExtension->getError() . "," "EquipmentB");
  7924.       } else {
  7925.         $lastExtension->setError("EquipmentB");
  7926.       }
  7927.       $em->persist($lastExtension);
  7928.     } else {
  7929.       // var_dump('hi');
  7930.       $errMsg $lastExtension->getError();
  7931.       $errMsg str_replace("EquipmentB"""$errMsg);
  7932.       $lastExtension->setError($errMsg);
  7933.       if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  7934.         $lastExtension->setIsValid(false);
  7935.       } else {
  7936.         $lastExtension->setIsValid(true);
  7937.         $lastExtension->setError(null);
  7938.       }
  7939.       $em->persist($lastExtension);
  7940.       //else get the last extension's extremity B's interface
  7941.       //check if it's 1:1
  7942.       if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  7943.         // if true, check ports are the same
  7944.         //if true, DO NOTHING
  7945.         //else set the link and las link extension as INVALID
  7946.         foreach ($lastPorts as $lastPort) {
  7947.           // var_dump($lastPort);
  7948.           $extensionOrder $em->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $lastPort"extremity" => $lastExtB]);
  7949.           for ($i 1$i <= 12$i++) {
  7950.             if ($extensionOrder->getOrderNumber() == $i) {
  7951.               if ($lastPort->getId() != $portsAArray["portA" $i]->getId()) {
  7952.                 $lastExtension->setIsValid(false);
  7953.                 if ($lastExtension->getError()) {
  7954.                   $lastExtension->setError($lastExtension->getError() . "," "PortB");
  7955.                 } else {
  7956.                   $lastExtension->setError("PortB");
  7957.                 }
  7958.                 $em->persist($lastExtension);
  7959.               } else {
  7960.                 $errMsg str_replace("PortB"""$errMsg);
  7961.                 $lastExtension->setError($errMsg);
  7962.                 if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  7963.                   $lastExtension->setIsValid(false);
  7964.                 } else {
  7965.                   $lastExtension->setIsValid(true);
  7966.                   $lastExtension->setError(null);
  7967.                 }
  7968.                 $em->persist($lastExtension);
  7969.               }
  7970.             }
  7971.           }
  7972.           // if ($extensionOrder->getOrderNumber() == 1) {
  7973.           //   if ($lastPort->getId() != $portsAArray["portA1"]->getId()) {
  7974.           //     $lastExtension->setIsValid(false);
  7975.           //     if ($lastExtension->getError()) {
  7976.           //       $lastExtension->setError($lastExtension->getError() . "," . "PortB");
  7977.           //     }
  7978.           //     else {
  7979.           //       $lastExtension->setError("PortB");
  7980.           //     }
  7981.           //     $em->persist($lastExtension);
  7982.           //   }
  7983.           //   else {
  7984.           //     $errMsg = str_replace("PortB", "", $errMsg);
  7985.           //     $lastExtension->setError($errMsg);
  7986.           //     if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
  7987.           //          $lastExtension->setIsValid(false);
  7988.           //      }
  7989.           //      else {
  7990.           //        $lastExtension->setIsValid(true);
  7991.           //        $lastExtension->setError(null);
  7992.           //      }
  7993.           //     $em->persist($lastExtension);
  7994.           //   }
  7995.           // }
  7996.           // elseif ($extensionOrder->getOrderNumber() == 2) {
  7997.           //   if ($lastPort->getId() != $portsAArray["portA2"]->getId()) {
  7998.           //     $lastExtension->setIsValid(false);
  7999.           //     if ($lastExtension->getError()) {
  8000.           //       $lastExtension->setError($lastExtension->getError() . "," . "PortB");
  8001.           //     }
  8002.           //     else {
  8003.           //       $lastExtension->setError("PortB");
  8004.           //     }
  8005.           //     $em->persist($lastExtension);
  8006.           //   }
  8007.           //   else {
  8008.           //     $errMsg = str_replace("PortB", "", $errMsg);
  8009.           //     $lastExtension->setError($errMsg);
  8010.           //     if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
  8011.           //          $lastExtension->setIsValid(false);
  8012.           //      }
  8013.           //      else {
  8014.           //        $lastExtension->setIsValid(true);
  8015.           //        $lastExtension->setError(null);
  8016.           //      }
  8017.           //     $em->persist($lastExtension);
  8018.           //   }
  8019.           // }
  8020.         }
  8021.       }
  8022.     }
  8023.   }
  8024.   public static function validateLastExtensionV0($em$link$extension$portA1$portA2)
  8025.   {
  8026.     $lastExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() - 1]);
  8027.     $lastExtB $lastExtension->getExtremityB();
  8028.     $lastPorts = [];
  8029.     $lastPortsTemp $lastExtB->getExtensionOrder();
  8030.     foreach ($lastPortsTemp as $value) {
  8031.       $lastPorts[] = $value->getPort();
  8032.     }
  8033.     // $lastPorts = $lastExtB->getPorts();
  8034.     // var_dump($lastPorts);
  8035.     $lastInterfaceSpecific $lastPorts[0]->getInterfaceSpecific();
  8036.     $lastInterfaceGeneric $lastInterfaceSpecific->getInterfaceGeneric();
  8037.     $lastEquipment $lastInterfaceSpecific->getEquipmentSpecific() ? $lastInterfaceSpecific->getEquipmentSpecific() : $lastInterfaceSpecific->getEquipmentSpecificMpo();
  8038.     $currentInterfaceSpecific $portA1->getInterfaceSpecific();
  8039.     $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific() ? $currentInterfaceSpecific->getEquipmentSpecific() : $currentInterfaceSpecific->getEquipmentSpecificMpo();
  8040.     //check if it's same as current modified link ext
  8041.     if ($currentEquipment->getId() != $lastEquipment->getId()) {
  8042.       //if false, set the link and las link extension as INVALID
  8043.       $lastExtension->setIsValid(false);
  8044.       if ($lastExtension->getError()) {
  8045.         $lastExtension->setError($lastExtension->getError() . "," "EquipmentB");
  8046.       } else {
  8047.         $lastExtension->setError("EquipmentB");
  8048.       }
  8049.       $em->persist($lastExtension);
  8050.     } else {
  8051.       // var_dump('hi');
  8052.       $errMsg $lastExtension->getError();
  8053.       $errMsg str_replace("EquipmentB"""$errMsg);
  8054.       $lastExtension->setError($errMsg);
  8055.       if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  8056.         $lastExtension->setIsValid(false);
  8057.       } else {
  8058.         $lastExtension->setIsValid(true);
  8059.         $lastExtension->setError(null);
  8060.       }
  8061.       $em->persist($lastExtension);
  8062.       //else get the last extension's extremity B's interface
  8063.       //check if it's 1:1
  8064.       if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  8065.         // if true, check ports are the same
  8066.         //if true, DO NOTHING
  8067.         //else set the link and las link extension as INVALID
  8068.         foreach ($lastPorts as $lastPort) {
  8069.           // var_dump($lastPort);
  8070.           $extensionOrder $em->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $lastPort"extremity" => $lastExtB]);
  8071.           if ($extensionOrder->getOrderNumber() == 1) {
  8072.             if ($lastPort->getId() != $portA1->getId()) {
  8073.               $lastExtension->setIsValid(false);
  8074.               if ($lastExtension->getError()) {
  8075.                 $lastExtension->setError($lastExtension->getError() . "," "PortB");
  8076.               } else {
  8077.                 $lastExtension->setError("PortB");
  8078.               }
  8079.               $em->persist($lastExtension);
  8080.             } else {
  8081.               $errMsg str_replace("PortB"""$errMsg);
  8082.               $lastExtension->setError($errMsg);
  8083.               if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  8084.                 $lastExtension->setIsValid(false);
  8085.               } else {
  8086.                 $lastExtension->setIsValid(true);
  8087.                 $lastExtension->setError(null);
  8088.               }
  8089.               $em->persist($lastExtension);
  8090.             }
  8091.           } elseif ($extensionOrder->getOrderNumber() == 2) {
  8092.             if ($lastPort->getId() != $portA2->getId()) {
  8093.               $lastExtension->setIsValid(false);
  8094.               if ($lastExtension->getError()) {
  8095.                 $lastExtension->setError($lastExtension->getError() . "," "PortB");
  8096.               } else {
  8097.                 $lastExtension->setError("PortB");
  8098.               }
  8099.               $em->persist($lastExtension);
  8100.             } else {
  8101.               $errMsg str_replace("PortB"""$errMsg);
  8102.               $lastExtension->setError($errMsg);
  8103.               if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  8104.                 $lastExtension->setIsValid(false);
  8105.               } else {
  8106.                 $lastExtension->setIsValid(true);
  8107.                 $lastExtension->setError(null);
  8108.               }
  8109.               $em->persist($lastExtension);
  8110.             }
  8111.           }
  8112.         }
  8113.       }
  8114.     }
  8115.   }
  8116.   public static function validateNextExtension($em$link$extension$portsB)
  8117.   {
  8118.     $nextExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() + 1]);
  8119.     $nextExtA $nextExtension->getExtremityA();
  8120.     $nextPorts = [];
  8121.     $nextPortsTemp $nextExtA->getExtensionOrder();
  8122.     foreach ($nextPortsTemp as $value) {
  8123.       $nextPorts[] = $value->getPort();
  8124.     }
  8125.     // $nextPorts = $nextExtA->getPorts();
  8126.     $nextInterfaceSpecific $nextPorts[0]->getInterfaceSpecific();
  8127.     $nextInterfaceGeneric $nextInterfaceSpecific->getInterfaceGeneric();
  8128.     $nextEquipment $nextInterfaceSpecific->getEquipmentSpecific() ? $nextInterfaceSpecific->getEquipmentSpecific() : $nextInterfaceSpecific->getEquipmentSpecificMpo();
  8129.     $currentInterfaceSpecific $portsB["portB1"]->getInterfaceSpecific();
  8130.     $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific() ? $currentInterfaceSpecific->getEquipmentSpecific() : $currentInterfaceSpecific->getEquipmentSpecificMpo();
  8131.     //check if it's same as current modified link ext
  8132.     if ($currentEquipment != null && $nextEquipment != null && $currentEquipment->getId() != $nextEquipment->getId()) {
  8133.       //if false, set the link and las link extension as INVALID
  8134.       $nextExtension->setIsValid(false);
  8135.       if ($nextExtension->getError()) {
  8136.         $nextExtension->setError($nextExtension->getError() . "," "EquipmentA");
  8137.       } else {
  8138.         $nextExtension->setError("EquipmentA");
  8139.       }
  8140.       $em->persist($nextExtension);
  8141.     } else {
  8142.       $errMsg $nextExtension->getError();
  8143.       $errMsg str_replace("EquipmentA"""$errMsg);
  8144.       $nextExtension->setError($errMsg);
  8145.       if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  8146.         $nextExtension->setIsValid(false);
  8147.       } else {
  8148.         $nextExtension->setIsValid(true);
  8149.         $nextExtension->setError(null);
  8150.       }
  8151.       $em->persist($nextExtension);
  8152.       //else get the next extension's extremity B's interface
  8153.       //check if it's 1:1
  8154.       if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  8155.         // if true, check ports are the same
  8156.         //if true, DO NOTHING
  8157.         //else set the link and las link extension as INVALID
  8158.         foreach ($nextPorts as $nextPort) {
  8159.           $extensionOrder $em->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $nextPort"extremity" => $nextExtA]);
  8160.           for ($i 1$i <= 12$i++) {
  8161.             if ($extensionOrder->getOrderNumber() == $i) {
  8162.               if ($nextPort->getId() != $portsB["portB" $i]->getId()) {
  8163.                 $nextExtension->setIsValid(false);
  8164.                 if ($nextExtension->getError()) {
  8165.                   $nextExtension->setError($nextExtension->getError() . "," "PortA");
  8166.                 } else {
  8167.                   $nextExtension->setError("PortA");
  8168.                 }
  8169.                 $em->persist($nextExtension);
  8170.               } else {
  8171.                 $errMsg str_replace("PortA"""$errMsg);
  8172.                 $nextExtension->setError($errMsg);
  8173.                 if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  8174.                   $nextExtension->setIsValid(false);
  8175.                 } else {
  8176.                   $nextExtension->setIsValid(true);
  8177.                   $nextExtension->setError(null);
  8178.                 }
  8179.                 $em->persist($nextExtension);
  8180.               }
  8181.             }
  8182.           }
  8183.           // if ($extensionOrder->getOrderNumber() == $i) {
  8184.           //   if ($nextPort->getId() != $portsB["portB".$i]->getId()) {
  8185.           //     $nextExtension->setIsValid(false);
  8186.           //     if ($nextExtension->getError()) {
  8187.           //       $nextExtension->setError($nextExtension->getError() . "," . "PortA");
  8188.           //     }
  8189.           //     else {
  8190.           //       $nextExtension->setError("PortA");
  8191.           //     }
  8192.           //     $em->persist($nextExtension);
  8193.           //   }
  8194.           //   else {
  8195.           //     $errMsg = str_replace("PortA", "", $errMsg);
  8196.           //     $nextExtension->setError($errMsg);
  8197.           //     if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
  8198.           //          $nextExtension->setIsValid(false);
  8199.           //      }
  8200.           //      else {
  8201.           //        $nextExtension->setIsValid(true);
  8202.           //        $nextExtension->setError(null);
  8203.           //      }
  8204.           //     $em->persist($nextExtension);
  8205.           //   }
  8206.           // }
  8207.           // elseif ($extensionOrder->getOrderNumber() == 2) {
  8208.           //   if ($nextPort->getId() != $portB2->getId()) {
  8209.           //     $nextExtension->setIsValid(false);
  8210.           //     if ($nextExtension->getError()) {
  8211.           //       $nextExtension->setError($nextExtension->getError() . "," . "PortA");
  8212.           //     }
  8213.           //     else {
  8214.           //       $nextExtension->setError("PortA");
  8215.           //     }
  8216.           //     $em->persist($nextExtension);
  8217.           //   }
  8218.           //   else {
  8219.           //     $errMsg = str_replace("PortA", "", $errMsg);
  8220.           //     $nextExtension->setError($errMsg);
  8221.           //     if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
  8222.           //          $nextExtension->setIsValid(false);
  8223.           //      }
  8224.           //      else {
  8225.           //        $nextExtension->setIsValid(true);
  8226.           //        $nextExtension->setError(null);
  8227.           //      }
  8228.           //     $em->persist($nextExtension);
  8229.           //   }
  8230.           // }
  8231.         }
  8232.       }
  8233.     }
  8234.   }
  8235.   public static function validateNextExtensionV0($em$link$extension$portB1$portB2)
  8236.   {
  8237.     $nextExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link" => $link"sequenceNo" => $extension->getSequenceNo() + 1]);
  8238.     $nextExtA $nextExtension->getExtremityA();
  8239.     $nextPorts = [];
  8240.     $nextPortsTemp $nextExtA->getExtensionOrder();
  8241.     foreach ($nextPortsTemp as $value) {
  8242.       $nextPorts[] = $value->getPort();
  8243.     }
  8244.     // $nextPorts = $nextExtA->getPorts();
  8245.     $nextInterfaceSpecific $nextPorts[0]->getInterfaceSpecific();
  8246.     $nextInterfaceGeneric $nextInterfaceSpecific->getInterfaceGeneric();
  8247.     $nextEquipment $nextInterfaceSpecific->getEquipmentSpecific() ? $nextInterfaceSpecific->getEquipmentSpecific() : $nextInterfaceSpecific->getEquipmentSpecificMpo();
  8248.     $currentInterfaceSpecific $portB1->getInterfaceSpecific();
  8249.     $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific() ? $currentInterfaceSpecific->getEquipmentSpecific() : $currentInterfaceSpecific->getEquipmentSpecificMpo();
  8250.     //check if it's same as current modified link ext
  8251.     if ($currentEquipment->getId() != $nextEquipment->getId()) {
  8252.       //if false, set the link and las link extension as INVALID
  8253.       $nextExtension->setIsValid(false);
  8254.       if ($nextExtension->getError()) {
  8255.         $nextExtension->setError($nextExtension->getError() . "," "EquipmentA");
  8256.       } else {
  8257.         $nextExtension->setError("EquipmentA");
  8258.       }
  8259.       $em->persist($nextExtension);
  8260.     } else {
  8261.       $errMsg $nextExtension->getError();
  8262.       $errMsg str_replace("EquipmentA"""$errMsg);
  8263.       $nextExtension->setError($errMsg);
  8264.       if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  8265.         $nextExtension->setIsValid(false);
  8266.       } else {
  8267.         $nextExtension->setIsValid(true);
  8268.         $nextExtension->setError(null);
  8269.       }
  8270.       $em->persist($nextExtension);
  8271.       //else get the next extension's extremity B's interface
  8272.       //check if it's 1:1
  8273.       if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  8274.         // if true, check ports are the same
  8275.         //if true, DO NOTHING
  8276.         //else set the link and las link extension as INVALID
  8277.         foreach ($nextPorts as $nextPort) {
  8278.           $extensionOrder $em->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port" => $nextPort"extremity" => $nextExtA]);
  8279.           if ($extensionOrder->getOrderNumber() == 1) {
  8280.             if ($nextPort->getId() != $portB1->getId()) {
  8281.               $nextExtension->setIsValid(false);
  8282.               if ($nextExtension->getError()) {
  8283.                 $nextExtension->setError($nextExtension->getError() . "," "PortA");
  8284.               } else {
  8285.                 $nextExtension->setError("PortA");
  8286.               }
  8287.               $em->persist($nextExtension);
  8288.             } else {
  8289.               $errMsg str_replace("PortA"""$errMsg);
  8290.               $nextExtension->setError($errMsg);
  8291.               if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  8292.                 $nextExtension->setIsValid(false);
  8293.               } else {
  8294.                 $nextExtension->setIsValid(true);
  8295.                 $nextExtension->setError(null);
  8296.               }
  8297.               $em->persist($nextExtension);
  8298.             }
  8299.           } elseif ($extensionOrder->getOrderNumber() == 2) {
  8300.             if ($nextPort->getId() != $portB2->getId()) {
  8301.               $nextExtension->setIsValid(false);
  8302.               if ($nextExtension->getError()) {
  8303.                 $nextExtension->setError($nextExtension->getError() . "," "PortA");
  8304.               } else {
  8305.                 $nextExtension->setError("PortA");
  8306.               }
  8307.               $em->persist($nextExtension);
  8308.             } else {
  8309.               $errMsg str_replace("PortA"""$errMsg);
  8310.               $nextExtension->setError($errMsg);
  8311.               if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  8312.                 $nextExtension->setIsValid(false);
  8313.               } else {
  8314.                 $nextExtension->setIsValid(true);
  8315.                 $nextExtension->setError(null);
  8316.               }
  8317.               $em->persist($nextExtension);
  8318.             }
  8319.           }
  8320.         }
  8321.       }
  8322.     }
  8323.   }
  8324.   public function isInTrunk($port)
  8325.   {
  8326.     $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portA" => $port]);
  8327.     $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portB" => $port]);
  8328.     $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  8329.     if ($tcfsA || $tcfsB || $usedExt) {
  8330.       return true;
  8331.     } else {
  8332.       return false;
  8333.     }
  8334.   }
  8335.   public function getTrunkByPortId($port)
  8336.   {
  8337.     $tcfsA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portA" => $port]);
  8338.     if ($tcfsA) {
  8339.       return $tcfsA->getTrunk();
  8340.     }
  8341.     $tcfsB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(["portB" => $port]);
  8342.     if ($tcfsB) {
  8343.       return $tcfsB->getTrunk();
  8344.     }
  8345.     $usedExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  8346.     if ($usedExt) {
  8347.       return $usedExt->getTrunk();
  8348.     }
  8349.     return null;
  8350.   }
  8351. }