src/Controller/TrunkController.php line 3625

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use App\Entity\LinkExtension;
  4. use App\Entity\LinkValidation;
  5. use App\Entity\Trunk;
  6. use App\Entity\TrunkCableFiber;
  7. use App\Entity\TrunkExtension;
  8. use App\Entity\Port;
  9. use App\Entity\ExtensionOrder;
  10. use App\Entity\EquipmentSpecific;
  11. use App\Entity\InterfaceSpecific;
  12. use App\EventListener\LinkTrunkEventListener;
  13. use Symfony\Component\Routing\Annotation\Route;
  14. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  15. use Symfony\Component\HttpFoundation\Request;
  16. use Symfony\Component\HttpFoundation\Response;
  17. use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
  18. use Pagerfanta\Adapter\ArrayAdapter;
  19. use Pagerfanta\Pagerfanta;
  20. use Symfony\Component\Cache\Adapter\FilesystemAdapter;
  21. // use Pagerfanta\Adapter\DoctrineORMAdapter;
  22. use Psr\Log\LoggerInterface;
  23. use Symfony\Contracts\Translation\TranslatorInterface;
  24. use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
  25. class TrunkController  extends AbstractController
  26. {
  27.    /**
  28.     * @Route("/trunk/create/step1", name="trunk_create_form_step1")
  29.     */
  30.    public function createAction(Request $requestTranslatorInterface $translator)
  31.   {
  32.        //get the cable type
  33.        $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  34.        //get a new trunk id
  35.        $trunkID $this->getDoctrine()->getRepository('App\Entity\Trunk')->getNewId();
  36.        //send everything needed to create a form to create a trunk
  37.        return $this->render('trunk/create_step1.html.twig', [
  38.            'action' => 'insert',
  39.            'page_title' => $translator->trans('Create Trunk - Step 1'),
  40.            'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  41.            'typeCable' => $typeCable,
  42.            'trunkID' => $trunkID
  43.        ]);
  44.    }
  45.    /**
  46.     * @IsGranted("ROLE_CRUD")
  47.     * @Route("/trunk/create/step2", name="trunk_create_process_step1")
  48.     * Process trunk creation form
  49.     */
  50.    public function processTrunkAction(Request $requestTranslatorInterface $translator)
  51.   {
  52.        //get the user
  53.        $user $this->get('security.token_storage')->getToken()->getUser();
  54.        //get the entity manager
  55.        $em $this->getDoctrine()->getManager();
  56.        // create a new trunk by processing the data from the form
  57.        $trunk = new Trunk();
  58.        $trunk->setTrunkID($request->request->get('trunkID'));
  59.        $trunk->setOperatorID($request->request->get('operatorID'));
  60.        $trunk->setTypeCable($this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable')));
  61.        $trunk->setCapacity($request->request->get('capacity'));
  62.        $trunk->setTypeCreation($request->request->get('typeCreation'));
  63.        $trunk->setCreatedBy($user);
  64.        $trunk->setUpdatedBy($user);
  65.        //store the trunk to the database
  66.        $em->persist($trunk);
  67.        $em->flush();
  68.        //check if the trunk already exists or to be reserved
  69.        if ($request->request->get('action') == 'reserve'){
  70.            //redirect to trunk list page
  71.            return $this->redirectToRoute('trunk_list');
  72.        }
  73.        //get all the sites, generic equipments, racks and rack faces
  74.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  75.        $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  76.        $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  77.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  78.        $trunkCapacity $trunk->getCapacity();
  79.        $typeCreation $trunk->getTypeCreation();
  80.        switch ($typeCreation){ // $typeCreation = 1=>equipment to equipment, 2=>interface to interface or 3=>port to port
  81.            case 1:
  82.            //send everything needed to create a form to add more data to trunk
  83.                return $this->render('trunk/create_step2_equipment.html.twig', [
  84.                    'action' => 'insert',
  85.                    'page_title' => $translator->trans('Create Trunk - Step 2'),
  86.                    'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  87.                    'trunk' => $trunk,
  88.                    'sites' => $sites,
  89.                    'rackFaces' => $rackFaces,
  90.                    'trunkCapacity' => $trunkCapacity
  91.                ]);
  92.            break;
  93.            case 2:
  94.            //send everything needed to create a form to add more data to trunk
  95.               return $this->render('trunk/create_step2_interface.html.twig', [
  96.                    'action' => 'insert',
  97.                    'page_title' => $translator->trans('Create Trunk - Step 2'),
  98.                   'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  99.                    'trunk' => $trunk,
  100.                    'sites' => $sites,
  101.                    'rackFaces' => $rackFaces,
  102.                    'trunkCapacity' => $trunkCapacity
  103.                ]);
  104.            break;
  105.            case 3:
  106.            //send everything needed to create a form to add more data to trunk
  107.                return $this->render('trunk/create_step2_port.html.twig', [
  108.                    'action' => 'insert',
  109.                    'page_title' => $translator->trans('Create Trunk - Step 2'),
  110.                    'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
  111.                    'trunk' => $trunk,
  112.                    'sites' => $sites,
  113.                    'eqGeneric' => $eqGeneric,
  114.                    'racks' => $racks,
  115.                    'rackFaces' => $rackFaces,
  116.                    'trunkCapacity' => $trunkCapacity
  117.                ]);
  118.            break;
  119.        }
  120.    }
  121.    /**
  122.     * @IsGranted("ROLE_CRUD")
  123.     * @Route("/trunk/create/process/fibers", name="trunk_create_process_step2")
  124.     * Process trunk creation form step 2 (add/update data to the trunk)
  125.     */
  126.    public function processFibersAction(Request $requestLoggerInterface $loggerTranslatorInterface $translator)
  127.   {
  128.       $logger $logger;
  129.        //get the user
  130.        $user $this->get('security.token_storage')->getToken()->getUser();
  131.        //get the entity manager
  132.        $em $this->getDoctrine()->getManager();
  133.        //get the trunk by id
  134.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  135.        //get the trunk capacity : it may be modified
  136.        $trunkCapacity $request->request->get('capacity');
  137.        //store the trunk to the database
  138.        $trunk->setCapacity($trunkCapacity);
  139.        $trunk->setUpdatedBy($user);
  140.        $em->persist($trunk);
  141.        $em->flush();
  142.        //get the cables and update the trunk capacity
  143.        $trunkCableFiber $trunk->getCableFiber();
  144.        foreach ($trunkCableFiber as $item) {
  145.            $trunkCapacity -= 1;
  146.        }
  147.        $typeCreation $request->request->get('type_creation');
  148.        // PORT TO PORT
  149.        if ($typeCreation == 3){
  150.          $intA = array();
  151.          $intB = array();
  152.          for ($i 1$i <= $trunkCapacity$i++){
  153.              if ($_POST['pointA_'.$i] != && $_POST['pointB_'.$i] != 0){
  154.                //MODIFIED
  155.                $portA $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointA_'.$i]);
  156.                $portB $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$i]);
  157.                $intA[] = $portA->getInterfaceSpecific()->getId();
  158.                $intB[] = $portB->getInterfaceSpecific()->getId();
  159.              }
  160.          }
  161.          $intA array_unique($intA);
  162.          $intB array_unique($intB);
  163.          $tempArray array_intersect($intA$intB);
  164.          if (count($tempArray) > 0) {
  165.            $this->addFlash(
  166.                'error',
  167.                'Opération Ã©chouée : Trunk en boucle (interface A == interface B)'
  168.            );
  169.            // return $this->redirectToRoute('trunk_list');
  170.            return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  171.          }
  172.            // store port points
  173.            //create the cables and store them to the database
  174.            for ($i 1$i <= $trunkCapacity$i++){
  175.                // $tcf = new TrunkCableFiber();
  176.                //
  177.                // $tcf->setTrunk($trunk);
  178.                // //check if point A and B are selected
  179.                if ($_POST['pointA_'.$i] != && $_POST['pointB_'.$i] != 0){
  180.                  //MODIFIED
  181.                  $portA $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointA_'.$i]);
  182.                  $portB $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$i]);
  183.                  $typeLnk null;
  184.                  if ($portA->getPortExterne()) {
  185.                    $typeLnk $portA->getPortExterne()->getTypeLink()->getTitle();
  186.                  }
  187.                  else {
  188.                    $typeLnk $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
  189.                  }
  190.                  if ($typeLnk == "Duplex") {
  191.                    for ($j=0$j 2$j++) {
  192.                       $tcf = new TrunkCableFiber();
  193.                       $tcf->setTrunk($trunk);
  194.                       $tcf->setPortA($portA);
  195.                       $tcf->setPortB($portB);
  196.                       $em->persist($tcf);
  197.                       $em->flush();
  198.                    }
  199.                  }
  200.                  else {
  201.                     $tcf = new TrunkCableFiber();
  202.                     $tcf->setTrunk($trunk);
  203.                     $tcf->setPortA($portA);
  204.                     $tcf->setPortB($portB);
  205.                     $em->persist($tcf);
  206.                     $em->flush();
  207.                  }
  208.                }
  209.            }
  210.        // I-I || E-E
  211.        } else if ($typeCreation == || $typeCreation == 1) {
  212.             $eqA null;
  213.             $eqB null;
  214.            // get the type of equipment A : 1 => generic or 2 => specific
  215.            $equipmentTypeA $request->request->get('equipmentTypeA');
  216.            //if generic, process the form to create a new sepcific equipment
  217.            if ($equipmentTypeA == 1){
  218.                $eqA = new EquipmentSpecific();
  219.                //get the generic parent equipment
  220.                $equipmentGenericA $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointA'));
  221.                $eqA->setEquipmentGeneric($equipmentGenericA);
  222.                $eqA->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointA')));
  223.                $eqA->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointA')));
  224.                $eqA->setPositionRack($request->request->get('positionRackPointA'));
  225.                $eqA->setEquipmentSpecificName($request->request->get('equipmentSpecificNameA'));
  226.                $eqA->setAlias($request->request->get('aliasA'));
  227.                $eqA->setOwner($request->request->get('ownerA'));
  228.                $em->persist($eqA);
  229.                $em->flush();
  230.                // create specific interfaces
  231.                $totalPortsA 0;
  232.                $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericA);
  233.                foreach ($interfacesGeneric as $interfaceGeneric) {
  234.                    if ($interfaceGeneric->getTypeLink() && $interfaceGeneric->getTypeLink()->getTitle() == "Port Externe") {
  235.                      $this->addFlash(
  236.                          'error',
  237.                          'Impossible de créer trunk: Ã©quipement générique a des interfaces PORT EXTERNE'
  238.                      );
  239.                      // return $this->redirectToRoute('trunk_list');
  240.                      return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  241.                    }
  242.                    $interfaceSpecific = new InterfaceSpecific();
  243.                    $interfaceSpecific->setEquipmentSpecific($eqA);
  244.                    $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  245.                    $alias json_decode($interfaceGeneric->getAlias(), true);
  246.                    $em->persist($interfaceSpecific);
  247.                    $em->flush();
  248.                    // create ports
  249.                    $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  250.                    $typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
  251.                    if ($typeLinkTitle == "Duplex") {
  252.                      $numberOfPorts 2*$numberOfPorts;
  253.                    }
  254.                    $totalPortsA += $numberOfPorts;
  255.                    for ($i 1$i <= $numberOfPorts$i++) {
  256.                        $port = new Port();
  257.                        $port->setInterfaceSpecific($interfaceSpecific);
  258.                        $port->setOrderNo($i);
  259.                        if ($alias) {
  260.                          $port->setAlias($alias[$i]);
  261.                        }
  262.                        $em->persist($port);
  263.                        $em->flush();
  264.                    }
  265.                }
  266.                //if specific equipment
  267.            } else {
  268.                // get the equipment
  269.                $eqA $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointA'));
  270.            }
  271.            // equipment B
  272.            // get the type of equipment B : 1 => generic or 2 => specific
  273.            $equipmentTypeB $request->request->get('equipmentTypeB');
  274.            //if generic, process the form to create a new sepcific equipment
  275.            if ($equipmentTypeB == 1) {
  276.                $eqB = new EquipmentSpecific();
  277.                $equipmentGenericB $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointB'));
  278.                $eqB->setEquipmentGeneric($equipmentGenericB);
  279.                $eqB->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointB')));
  280.                $eqB->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointB')));
  281.                $eqB->setPositionRack($request->request->get('positionRackPointB'));
  282.                $eqB->setEquipmentSpecificName($request->request->get('equipmentSpecificNameB'));
  283.                $eqB->setAlias($request->request->get('aliasB'));
  284.                $eqB->setOwner($request->request->get('ownerB'));
  285.                $em->persist($eqB);
  286.                $em->flush();
  287.                // create specific interfaces
  288.                $totalPortsB 0;
  289.                $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericB);
  290.                foreach ($interfacesGeneric as $interfaceGeneric) {
  291.                    if ($interfaceGeneric->getTypeLink() && $interfaceGeneric->getTypeLink()->getTitle() == "Port Externe") {
  292.                      $this->addFlash(
  293.                          'error',
  294.                          'Impossible de créer trunk: Ã©quipement générique a des interfaces PORT EXTERNE'
  295.                      );
  296.                      // return $this->redirectToRoute('trunk_list');
  297.                      return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  298.                    }
  299.                    $interfaceSpecific = new InterfaceSpecific();
  300.                    $interfaceSpecific->setEquipmentSpecific($eqB);
  301.                    $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  302.                    $alias json_decode($interfaceGeneric->getAlias(), true);
  303.                    $em->persist($interfaceSpecific);
  304.                    $em->flush();
  305.                    // create ports
  306.                    $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  307.                    $typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
  308.                    if ($typeLinkTitle == "Duplex") {
  309.                      $numberOfPorts 2*$numberOfPorts;
  310.                    }
  311.                    $totalPortsB += $numberOfPorts;
  312.                    for ($i 1$i <= $numberOfPorts$i++) {
  313.                        $port = new Port();
  314.                        $port->setInterfaceSpecific($interfaceSpecific);
  315.                        $port->setOrderNo($i);
  316.                        if ($alias) {
  317.                          $port->setAlias($alias[$i]);
  318.                        }
  319.                        $em->persist($port);
  320.                        $em->flush();
  321.                    }
  322.                }
  323.                //if specific equipment
  324.            } else {
  325.                //get the equipment
  326.                $eqB $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointB'));
  327.            }
  328.            // INTERFACE TO INTERFACE
  329.            if ($typeCreation == 2) {
  330.                // FIBERS A
  331.                //MODIFIED on 07 fevrier 2019
  332.                $countTcfA 0;
  333.                $countTcfB 0;
  334.                $interfacesA $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqA);
  335.                foreach ($interfacesA as $interface) {
  336.                  //ADDED by Soupra
  337.                  $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  338.                    if ($equipmentTypeA == 1) {
  339.                        $interface_id $interface->getInterfaceGeneric()->getId(); // get generic interfaces
  340.                    } else {
  341.                        $interface_id $interface->getId(); // get specific interfaces
  342.                    }
  343.                    //check if interface is selected
  344.                    if (isset($_POST['interfaceA_' $interface_id])) {
  345.                        if ($typeLinkTitle == "Port Externe") {
  346.                          $this->addFlash(
  347.                              'error',
  348.                              'Impossible de créer trunk: Ã©quipement générique a des interfaces PORT EXTERNE'
  349.                          );
  350.                          // return $this->redirectToRoute('trunk_list');
  351.                          return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  352.                        }
  353.                        $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  354.                        $logger->info(count($ports));
  355.                        foreach ($ports as $port) {
  356.                          //ADDED by Soupra
  357.                          $usedA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  358.                          $logger->info(count($usedA));
  359.                          if($usedA == null){
  360.                              if ($typeLinkTitle == "Duplex") {
  361.                                for ($i=0$i 2$i++) {
  362.                                  $tcf = new TrunkCableFiber();
  363.                                  $tcf->setTrunk($trunk);
  364.                                  $tcf->setPortA($port);
  365.                                  $em->persist($tcf);
  366.                                  $em->flush();
  367.                                  $countTcfA++;
  368.                                }
  369.                              }
  370.                              else {
  371.                                $tcf = new TrunkCableFiber();
  372.                                $tcf->setTrunk($trunk);
  373.                                $tcf->setPortA($port);
  374.                                $em->persist($tcf);
  375.                                $em->flush();
  376.                                $countTcfA++;
  377.                              }
  378.                          }
  379.                          if($trunkCapacity <= $countTcfA){
  380.                              break;
  381.                          }
  382.                        }
  383.                    }
  384.                    if($trunkCapacity <= $countTcfA){
  385.                        break;
  386.                    }
  387.                }
  388.                // FIBERS B
  389.                $interfacesB $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
  390.                foreach ($interfacesB as $interface) {
  391.                  //ADDED by Soupra
  392.                  $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  393.                    if ($equipmentTypeB == 1) {
  394.                        $interface_id $interface->getInterfaceGeneric()->getId(); // get generic interfaces
  395.                    } else {
  396.                        $interface_id $interface->getId(); // get specific interfaces
  397.                    }
  398.                    //check if interface is selected
  399.                    if (isset($_POST['interfaceB_' $interface_id])) {
  400.                        if ($typeLinkTitle == "Port Externe") {
  401.                          $this->addFlash(
  402.                              'error',
  403.                              'Impossible de créer trunk: Ã©quipement générique a des interfaces PORT EXTERNE'
  404.                          );
  405.                          // return $this->redirectToRoute('trunk_list');
  406.                          return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  407.                        }
  408.                        $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  409.                        foreach ($ports as $port) {
  410.                            //get the cable which corresponds to the portA
  411.                            //ADDED by Soupra
  412.                            $usedB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  413.                            $logger->info(count($usedA));
  414.                            if($usedB == null){
  415.                                if ($typeLinkTitle == "Duplex") {
  416.                                  for ($i=0$i 2$i++) {
  417.                                    $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
  418.                                    if ($tcf instanceof TrunkCableFiber) {
  419.                                        $tcf->setPortB($port);
  420.                                        $em->persist($tcf);
  421.                                        $em->flush();
  422.                                        $countTcfB++;
  423.                                    }
  424.                                  }
  425.                                }
  426.                                else {
  427.                                  $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
  428.                                  if ($tcf instanceof TrunkCableFiber) {
  429.                                    $tcf->setPortB($port);
  430.                                    $em->persist($tcf);
  431.                                    $em->flush();
  432.                                    $countTcfB++;
  433.                                  }
  434.                                }
  435.                            }
  436.                            if($trunkCapacity <= $countTcfB){
  437.                                break;
  438.                            }
  439.                        }
  440.                        }
  441.                        if($trunkCapacity <= $countTcfB){
  442.                            break;
  443.                        }
  444.                    }
  445.                }
  446.            // EQUIPMENT TO EQUIPMENT
  447.             else {
  448.                // max number of connections to make
  449.                $cf_max_number min($totalPortsA$totalPortsB$trunkCapacity);
  450.                // FIBERS A
  451.                $counter 1;
  452.                $interfacesA $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqA);
  453.                foreach ($interfacesA as $interface) {
  454.                     //ADDED by Soupra begin
  455.                     $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();//end
  456.                    $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  457.                    foreach ($ports as $port) {
  458.                        if ($counter <= $cf_max_number) {
  459.                          //ADDED by Soupra begin
  460.                          if ($typeLinkTitle == "Duplex") {
  461.                            for ($i=0$i 2$i++) {
  462.                              $tcf = new TrunkCableFiber();
  463.                              $tcf->setTrunk($trunk);
  464.                              $tcf->setPortA($port);
  465.                              $em->persist($tcf);
  466.                              $em->flush();
  467.                              $counter++;
  468.                            }
  469.                          }
  470.                          else {
  471.                            $tcf = new TrunkCableFiber();
  472.                            $tcf->setTrunk($trunk);
  473.                            $tcf->setPortA($port);
  474.                            $em->persist($tcf);
  475.                            $em->flush();
  476.                            $counter++;
  477.                          } //end
  478.                          // $tcf = new TrunkCableFiber();
  479.                          // $tcf->setTrunk($trunk);
  480.                          // $tcf->setPortA($port);
  481.                          //
  482.                          // $em->persist($tcf);
  483.                          // $em->flush();
  484.                          //
  485.                          // $counter++;
  486.                        }
  487.                    }
  488.                }
  489.                // FIBERS B
  490.                $counter 1;
  491.                $interfacesB $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
  492.                foreach ($interfacesB as $interface) {
  493.                     //ADDED by Soupra
  494.                     $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  495.                    $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  496.                    foreach ($ports as $port) {
  497.                        if ($counter <= $cf_max_number) {
  498.                          //ADDED by Soupra begin
  499.                          if ($typeLinkTitle == "Duplex") {
  500.                            for ($i=0$i 2$i++) {
  501.                              $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
  502.                              if ($tcf instanceof TrunkCableFiber) {
  503.                                  $tcf->setPortB($port);
  504.                                  $em->persist($tcf);
  505.                                  $em->flush();
  506.                                  $counter ++;
  507.                              }
  508.                            }
  509.                          }
  510.                          else {
  511.                            $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
  512.                            if ($tcf instanceof TrunkCableFiber) {
  513.                                $tcf->setPortB($port);
  514.                                $em->persist($tcf);
  515.                                $em->flush();
  516.                                $counter ++;
  517.                            }
  518.                          } //end
  519.                            // $tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
  520.                            // $tcf->setPortB($port);
  521.                            //
  522.                            // $em->persist($tcf);
  523.                            // $em->flush();
  524.                            //
  525.                            // $counter ++;
  526.                        }
  527.                    }
  528.                }
  529.        }
  530. }
  531.         // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  532.         // $cache = new FilesystemAdapter();
  533.         // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  534.         // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  535.        // AFTER ACTION - REDIRECT
  536.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  537.    }
  538.    /**
  539.     * @IsGranted("ROLE_CRUD")
  540.     * @Route("/trunk/edit/fiber/{id}", name="trunk_edit_fiber")
  541.     *
  542.     */
  543.    public function editFiberAction($idTranslatorInterface $translator)
  544.   {
  545.        $em $this->getDoctrine()->getManager();
  546.        $trunkCableFiber $em->getRepository(TrunkCableFiber::class)->find($id);
  547.        $trunk $trunkCableFiber->getTrunk();
  548.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  549.        $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  550.        $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  551.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  552.        return $this->render('trunk/edit_fiber.html.twig', [
  553.            'action' => 'insert',
  554.            'page_title' => $translator->trans('Edit Cable / Fiber'),
  555.            'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  556.            'tcf' => $trunkCableFiber,
  557.            'sites' => $sites,
  558.            'eqGeneric' => $eqGeneric,
  559.            'racks' => $racks,
  560.            'rackFaces' => $rackFaces,
  561.            'trunk' => $trunk
  562.        ]);
  563.    }
  564.    /**
  565.     * @IsGranted("ROLE_CRUD")
  566.     * @Route("/trunk/edit/process/fiber", name="trunk_edit_process_fiber")
  567.     */
  568.    public function editProcessFiberAction(Request $requestTranslatorInterface $translator)
  569.   {
  570.        $user $this->get('security.token_storage')->getToken()->getUser();
  571.        $em $this->getDoctrine()->getManager();
  572.        $trunkCableFiber $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneById($request->request->get('fiber_id'));
  573.        $trunk $trunkCableFiber->getTrunk();
  574.        //get the affected ports and store them in a array
  575.        // $portsAffected = [];
  576.        //MODIFIED BY Soupra;
  577.        // $portsAffected[] = $trunkCableFiber->getPortB()
  578.        // $portsAffected[] = $trunkCableFiber->getPortA();
  579.        // $portsAffected[] = $trunkCableFiber->getPortB();
  580.        //get new ports and store them in the database
  581.        $portA $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
  582.        $portB $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
  583.        //check for loop
  584.        if ($portA->getInterfaceSpecific()->getId() == $portB->getInterfaceSpecific()->getId()) {
  585.          $this->addFlash(
  586.              'error',
  587.              'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
  588.          );
  589.          return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
  590.        }
  591.        $tempInts = array();
  592.        foreach ($trunkCableFiber->getExtensions() as $value) {
  593.          $tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
  594.        }
  595.        if (in_array($portA->getInterfaceSpecific()->getId(), $tempInts) || in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
  596.          $this->addFlash(
  597.              'error',
  598.              'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
  599.          );
  600.          return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
  601.        }
  602.        $matchedPortB $trunkCableFiber->getPortB();
  603.        $matchedPortA $trunkCableFiber->getPortA();
  604.        $trunkCableFiber->setPortA($portA);
  605.        $trunkCableFiber->setPortB($portB);
  606.        //get the link extension if any matches
  607.        $extMatch null;
  608.        $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPortB);
  609.        if ($extId) {
  610.          $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  611.        }
  612.        // $extMatch = $matchedPortB->getLinkExtension();
  613.        if ($extMatch) {
  614.          // $orderNoExt = $matchedPortB->getOrderNoExtension();
  615.          $matchedPortB->setLink(null);
  616.          $matchedPortB->setLinkExtension(null);
  617.          // $matchedPortB->setOrderNoExtension(1);
  618.          $em->persist($matchedPortB);
  619.          $linkMatch $extMatch->getLink();
  620.          $extrmityB $extMatch->getExtremityB();
  621.          $extBPorts $extrmityB->getExtensionOrder();
  622.          $tempIds = array();
  623.          foreach ($extBPorts as $value) {
  624.            $tempIds[] = $value->getPort()->getId();
  625.          }
  626.          if (in_array($matchedPortB->getId(), $tempIds)) {
  627.            // if (count($matchedPortB->getExtensionOrder()) <= 1) {
  628.            //   $matchedPortB->setLink(null);
  629.            // }
  630.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortB"extremity"=>$extrmityB]);
  631.            $orderNoExt $extensinOrder->getOrderNumber();
  632.            $em->remove($extensinOrder);
  633.            // $extrmityB->removePort($matchedPort);
  634.            $extensinOrder = new ExtensionOrder();
  635.            $extensinOrder->setOrderNumber($orderNoExt);
  636.            $extensinOrder->setPort($portB);
  637.            $extensinOrder->setExtremity($extrmityB);
  638.            $portB->addExtensionOrder($extensinOrder);
  639.            $extrmityB->addExtensionOrder($extensinOrder);
  640.            $em->persist($extensinOrder);
  641.            // $extrmityB->removePort($matchedPortB);
  642.            // $extrmityB->addPort($portB);
  643.            // $portB->setOrderNoExtension($orderNoExt);
  644.            // $portB->addExtremity($extrmityB);
  645.            $portB->setLink($linkMatch);
  646.            $portB->setLinkExtension($extMatch);
  647.            $em->persist($portB);
  648.            $em->persist($extrmityB);
  649.            //check if it's last link extension
  650.            //if it's last, DO NOTHING
  651.            if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  652.              // // var_dump("entering ...");
  653.              // //else get the last extension's extremity B's equipment
  654.              // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  655.              // $nextExtA = $nextExtension->getExtremityA();
  656.              // $nextPorts = array();
  657.              // foreach ($nextExtA->getExtensionOrder() as $value) {
  658.              //   $nextPorts[] = $value->getPort();
  659.              // }
  660.              // // $nextPorts = $nextExtA->getPorts();
  661.              // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  662.              // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  663.              // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  664.              //
  665.              // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  666.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  667.              //
  668.              // //check if it's same as current modified link ext
  669.              // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  670.              //   // var_dump("entering not equals equipments...");
  671.              //
  672.              //   //if false, set the link and las link extension as INVALID
  673.              //   $nextExtension->setIsValid(false);
  674.              //   $em->persist($nextExtension);
  675.              // }
  676.              // else {
  677.              //   // var_dump("entering checking ports...");
  678.              //
  679.              //     $nextExtension->setIsValid(true);
  680.              //     $em->persist($nextExtension);
  681.              //   //else get the next extension's extremity B's interface
  682.              //   //check if it's 1:1
  683.              //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  684.              //     // var_dump("entering checking 1 to 1...");
  685.              //
  686.              //     // if true, check ports are the same
  687.              //     //if true, DO NOTHING
  688.              //     //else set the link and las link extension as INVALID
  689.              //     foreach ($nextPorts as $nextPort) {
  690.              //       if ($nextPort->getId() != $portB->getId()) {
  691.              //         $nextExtension->setIsValid(false);
  692.              //         $em->persist($nextExtension);
  693.              //       }
  694.              //       else {
  695.              //         $nextExtension->setIsValid(true);
  696.              //         $em->persist($nextExtension);
  697.              //       }
  698.              //     }
  699.              //   }
  700.              // }
  701.              TrunkController::validateNextExtension($em$linkMatch$extMatch$portB);
  702.            }
  703.          }
  704.          $extrmityA $extMatch->getExtremityA();
  705.          $extAPorts $extrmityA->getExtensionOrder();
  706.          $tempIds = array();
  707.          foreach ($extAPorts as $value) {
  708.            $tempIds[] = $value->getPort()->getId();
  709.          }
  710.          if (in_array($matchedPortB->getId(), $tempIds)) {
  711.            // if (count($matchedPortB->getExtensionOrder()) <= 1) {
  712.            //   $matchedPortB->setLink(null);
  713.            // }
  714.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortB"extremity"=>$extrmityA]);
  715.            $orderNoExt $extensinOrder->getOrderNumber();
  716.            $em->remove($extensinOrder);
  717.            // $extrmityA->removePort($matchedPort);
  718.            $extensinOrder = new ExtensionOrder();
  719.            $extensinOrder->setOrderNumber($orderNoExt);
  720.            $extensinOrder->setPort($portB);
  721.            $extensinOrder->setExtremity($extrmityA);
  722.            $portB->addExtensionOrder($extensinOrder);
  723.            $extrmityA->addExtensionOrder($extensinOrder);
  724.            $em->persist($extensinOrder);
  725.            // $extrmityA->removePort($matchedPortB);
  726.            // $extrmityA->addPort($portB);
  727.            // $portB->setOrderNoExtension($orderNoExt);
  728.            // $portB->addExtremity($extrmityA);
  729.            $portB->setLink($linkMatch);
  730.            $portB->setLinkExtension($extMatch);
  731.            $em->persist($portB);
  732.            $em->persist($extrmityA);
  733.            if ($extMatch->getSequenceNo() > 1) {
  734.              // //else get the last extension's extremity B's equipment
  735.              // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  736.              //
  737.              // $lastExtB = $lastExtension->getExtremityB();
  738.              // $lastPorts = array();
  739.              // foreach ($lastExtB->getExtensionOrder() as $value) {
  740.              //   $lastPorts[] = $value->getPort();
  741.              // }
  742.              // // $lastPorts = $lastExtB->getPorts();
  743.              // // var_dump($lastPorts);
  744.              // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  745.              // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  746.              // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  747.              //
  748.              // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  749.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  750.              //
  751.              // //check if it's same as current modified link ext
  752.              // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  753.              //   //if false, set the link and las link extension as INVALID
  754.              //   $lastExtension->setIsValid(false);
  755.              //   $em->persist($lastExtension);
  756.              // }
  757.              // else {
  758.              //   // var_dump('hi');
  759.              //   $lastExtension->setIsValid(true);
  760.              //   $em->persist($lastExtension);
  761.              //   //else get the last extension's extremity B's interface
  762.              //   //check if it's 1:1
  763.              //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  764.              //     // if true, check ports are the same
  765.              //     //if true, DO NOTHING
  766.              //     //else set the link and las link extension as INVALID
  767.              //     foreach ($lastPorts as $lastPort) {
  768.              //       // var_dump($lastPort);
  769.              //       if ($lastPort->getId() != $portB->getId()) {
  770.              //         $lastExtension->setIsValid(false);
  771.              //         $em->persist($lastExtension);
  772.              //       }
  773.              //       else {
  774.              //         $lastExtension->setIsValid(true);
  775.              //         $em->persist($lastExtension);
  776.              //       }
  777.              //     }
  778.              //   }
  779.              // }
  780.              TrunkController::validateLastExtension($em$linkMatch$extMatch$portB);
  781.            }
  782.          }
  783.        }
  784.        //Port A
  785.        //get the link extension if any matches
  786.        $extMatch null;
  787.        $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPortA);
  788.        if ($extId) {
  789.          $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  790.        }
  791.        // $extMatch = $matchedPortA->getLinkExtension();
  792.        if ($extMatch) {
  793.          // $orderNoExt = $matchedPortA->getOrderNoExtension();
  794.          $matchedPortA->setLink(null);
  795.          $matchedPortA->setLinkExtension(null);
  796.          // $matchedPortA->setOrderNoExtension(1);
  797.          $em->persist($matchedPortA);
  798.          $linkMatch $extMatch->getLink();
  799.          $extrmityB $extMatch->getExtremityB();
  800.          $extBPorts $extrmityB->getExtensionOrder();
  801.          $tempIds = array();
  802.          foreach ($extBPorts as $value) {
  803.            $tempIds[] = $value->getPort()->getId();
  804.          }
  805.          if (in_array($matchedPortA->getId(), $tempIds)) {
  806.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortA"extremity"=>$extrmityB]);
  807.            $orderNoExt $extensinOrder->getOrderNumber();
  808.            $em->remove($extensinOrder);
  809.            // $extrmityB->removePort($matchedPort);
  810.            $extensinOrder = new ExtensionOrder();
  811.            $extensinOrder->setOrderNumber($orderNoExt);
  812.            $extensinOrder->setPort($portA);
  813.            $extensinOrder->setExtremity($extrmityB);
  814.            $portA->addExtensionOrder($extensinOrder);
  815.            $extrmityB->addExtensionOrder($extensinOrder);
  816.            $em->persist($extensinOrder);
  817.            // $extrmityB->removePort($matchedPortA);
  818.            // $extrmityB->addPort($portA);
  819.            // $portA->setOrderNoExtension($orderNoExt);
  820.            // $portA->addExtremity($extrmityB);
  821.            $portA->setLink($linkMatch);
  822.            $portA->setLinkExtension($extMatch);
  823.            $em->persist($portA);
  824.            $em->persist($extrmityB);
  825.            //check if it's last link extension
  826.            //if it's last, DO NOTHING
  827.            if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  828.              // // var_dump("entering ...");
  829.              // //else get the last extension's extremity B's equipment
  830.              // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  831.              // $nextExtA = $nextExtension->getExtremityA();
  832.              //
  833.              // $nextPorts = array();
  834.              // foreach ($nextExtA->getExtensionOrder() as $value) {
  835.              //   $nextPorts[] = $value->getPort();
  836.              // }
  837.              //
  838.              // // $nextPorts = $nextExtA->getPorts();
  839.              // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  840.              // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  841.              // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  842.              //
  843.              // $currentInterfaceSpecific = $portA->getInterfaceSpecific();
  844.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  845.              //
  846.              // //check if it's same as current modified link ext
  847.              // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  848.              //   // var_dump("entering not equals equipments...");
  849.              //
  850.              //   //if false, set the link and las link extension as INVALID
  851.              //   $nextExtension->setIsValid(false);
  852.              //   $em->persist($nextExtension);
  853.              // }
  854.              // else {
  855.              //   // var_dump("entering checking ports...");
  856.              //
  857.              //     $nextExtension->setIsValid(true);
  858.              //     $em->persist($nextExtension);
  859.              //   //else get the next extension's extremity B's interface
  860.              //   //check if it's 1:1
  861.              //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  862.              //     // var_dump("entering checking 1 to 1...");
  863.              //
  864.              //     // if true, check ports are the same
  865.              //     //if true, DO NOTHING
  866.              //     //else set the link and las link extension as INVALID
  867.              //     foreach ($nextPorts as $nextPort) {
  868.              //       if ($nextPort->getId() != $portA->getId()) {
  869.              //         $nextExtension->setIsValid(false);
  870.              //         $em->persist($nextExtension);
  871.              //       }
  872.              //       else {
  873.              //         $nextExtension->setIsValid(true);
  874.              //         $em->persist($nextExtension);
  875.              //       }
  876.              //     }
  877.              //   }
  878.              // }
  879.              TrunkController::validateNextExtension($em$linkMatch$extMatch$portA);
  880.            }
  881.          }
  882.          $extrmityA $extMatch->getExtremityA();
  883.          $extAPorts $extrmityA->getExtensionOrder();
  884.          $tempIds = array();
  885.          foreach ($extAPorts as $value) {
  886.            $tempIds[] = $value->getPort()->getId();
  887.          }
  888.          if (in_array($matchedPortA->getId(), $tempIds)) {
  889.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortA"extremity"=>$extrmityA]);
  890.            $orderNoExt $extensinOrder->getOrderNumber();
  891.            $em->remove($extensinOrder);
  892.            // $extrmityA->removePort($matchedPort);
  893.            $extensinOrder = new ExtensionOrder();
  894.            $extensinOrder->setOrderNumber($orderNoExt);
  895.            $extensinOrder->setPort($portA);
  896.            $extensinOrder->setExtremity($extrmityA);
  897.            $portA->addExtensionOrder($extensinOrder);
  898.            $extrmityA->addExtensionOrder($extensinOrder);
  899.            $em->persist($extensinOrder);
  900.            // $extrmityA->removePort($matchedPortA);
  901.            // $extrmityA->addPort($portA);
  902.            // $portA->setOrderNoExtension($orderNoExt);
  903.            // $portA->addExtremity($extrmityA);
  904.            $portA->setLink($linkMatch);
  905.            $portA->setLinkExtension($extMatch);
  906.            $em->persist($portA);
  907.            $em->persist($extrmityA);
  908.            if ($extMatch->getSequenceNo() > 1) {
  909.              // //else get the last extension's extremity B's equipment
  910.              // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  911.              //
  912.              // $lastExtB = $lastExtension->getExtremityB();
  913.              // $lastPorts = array();
  914.              // foreach ($lastExtB->getExtensionOrder() as $value) {
  915.              //   $lastPorts[] = $value->getPort();
  916.              // }
  917.              // // $lastPorts = $lastExtB->getPorts();
  918.              // // var_dump($lastPorts);
  919.              // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  920.              // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  921.              // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  922.              //
  923.              // $currentInterfaceSpecific = $portA->getInterfaceSpecific();
  924.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  925.              //
  926.              // //check if it's same as current modified link ext
  927.              // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  928.              //   //if false, set the link and las link extension as INVALID
  929.              //   $lastExtension->setIsValid(false);
  930.              //   $em->persist($lastExtension);
  931.              // }
  932.              // else {
  933.              //   // var_dump('hi');
  934.              //   $lastExtension->setIsValid(true);
  935.              //   $em->persist($lastExtension);
  936.              //   //else get the last extension's extremity B's interface
  937.              //   //check if it's 1:1
  938.              //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  939.              //     // if true, check ports are the same
  940.              //     //if true, DO NOTHING
  941.              //     //else set the link and las link extension as INVALID
  942.              //     foreach ($lastPorts as $lastPort) {
  943.              //       // var_dump($lastPort);
  944.              //       if ($lastPort->getId() != $portA->getId()) {
  945.              //         $lastExtension->setIsValid(false);
  946.              //         $em->persist($lastExtension);
  947.              //       }
  948.              //       else {
  949.              //         $lastExtension->setIsValid(true);
  950.              //         $em->persist($lastExtension);
  951.              //       }
  952.              //     }
  953.              //   }
  954.              // }
  955.              TrunkController::validateLastExtension($em$linkMatch$extMatch$portA);
  956.            }
  957.          }
  958.        }
  959.        $em->persist($trunkCableFiber);
  960.        $em->flush();
  961.        $trunk->setUpdatedBy($user);
  962.        $em->persist($trunk);
  963.        $em->flush();
  964.        // check links for validation
  965.        // foreach($portsAffected as $port){
  966.        //   $linkExtsB = null;
  967.        //   $extremities = array();
  968.        //   foreach ($port->getExtensionOrder() as $value) {
  969.        //     $extremities[] = $value->getExtremity();
  970.        //   }
  971.        //   $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
  972.        //   if (count($extremities) > 1) {
  973.        //     $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
  974.        //   }
  975.        //     // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $port]);
  976.        //     // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $port]);
  977.        //
  978.        //     if ($linkExtsA){
  979.        //
  980.        //         foreach ($linkExtsA as $linkExt){
  981.        //
  982.        //             $link = $linkExt->getLink();
  983.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  984.        //
  985.        //             if (!$linkValidation){
  986.        //
  987.        //                 $linkValidation = new LinkValidation();
  988.        //                 $linkValidation->setLink($link);
  989.        //                 $linkValidation->setTrunk($trunk);
  990.        //                 $linkValidation->setPort($port);
  991.        //
  992.        //                 $em->persist($linkValidation);
  993.        //                 $em->flush();
  994.        //
  995.        //             }
  996.        //         }
  997.        //     }
  998.        //
  999.        //     if ($linkExtsB){
  1000.        //
  1001.        //         foreach ($linkExtsB as $linkExt){
  1002.        //
  1003.        //             $link = $linkExt->getLink();
  1004.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  1005.        //
  1006.        //             if (!$linkValidation){
  1007.        //
  1008.        //                 $linkValidation = new LinkValidation();
  1009.        //                 $linkValidation->setLink($link);
  1010.        //                 $linkValidation->setTrunk($trunk);
  1011.        //                 $linkValidation->setPort($port);
  1012.        //
  1013.        //                 $em->persist($linkValidation);
  1014.        //                 $em->flush();
  1015.        //
  1016.        //             }
  1017.        //         }
  1018.        //     }
  1019.        //
  1020.        // }
  1021.        // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  1022.        // $cache = new FilesystemAdapter();
  1023.        // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  1024.        // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  1025.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  1026.    }
  1027.    /**
  1028.     * @IsGranted("ROLE_CRUD")
  1029.     * @Route("/trunk/edit/{id}/{typeCreation}", name="trunk_edit")
  1030.     * trunk creation step 2 page
  1031.     */
  1032.    public function editTrunkAction($id$typeCreationTranslatorInterface $translator)
  1033.   {
  1034.        $em $this->getDoctrine()->getManager();
  1035.        $trunk $em->getRepository(Trunk::class)->find($id);
  1036.        $trunkCapacity $trunk->getCapacity();
  1037.        $trunkCableFiber $trunk->getCableFiber();
  1038.        foreach ($trunkCableFiber as $item) {
  1039.            $trunkCapacity -= 1;
  1040.        }
  1041.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  1042.        $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  1043.        $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  1044.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1045.        switch ($typeCreation){
  1046.            case 1:
  1047.                return $this->render('trunk/create_step2_equipment.html.twig', [
  1048.                    'action' => 'edit',
  1049.                    'page_title' => $translator->trans('Edit Trunk'),
  1050.                    'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1051.                    'trunk' => $trunk,
  1052.                    'sites' => $sites,
  1053.                    'rackFaces' => $rackFaces,
  1054.                    'trunkCapacity' => $trunkCapacity
  1055.                ]);
  1056.                break;
  1057.            case 2:
  1058.                return $this->render('trunk/create_step2_interface.html.twig', [
  1059.                    'action' => 'edit',
  1060.                    'page_title' => $translator->trans('Edit Trunk'),
  1061.                    'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1062.                    'trunk' => $trunk,
  1063.                    'sites' => $sites,
  1064.                    'rackFaces' => $rackFaces,
  1065.                    'trunkCapacity' => $trunkCapacity
  1066.                ]);
  1067.                break;
  1068.            case 3:
  1069.                return $this->render('trunk/create_step2_port.html.twig', [
  1070.                    'action' => 'edit',
  1071.                    'page_title' => $translator->trans('Edit Trunk'),
  1072.                    'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1073.                    'trunk' => $trunk,
  1074.                    'sites' => $sites,
  1075.                    'eqGeneric' => $eqGeneric,
  1076.                    'racks' => $racks,
  1077.                    'rackFaces' => $rackFaces,
  1078.                    'trunkCapacity' => $trunkCapacity
  1079.                ]);
  1080.                break;
  1081.        }
  1082.    }
  1083.    /**
  1084.     * @IsGranted("ROLE_CRUD")
  1085.     * @Route("/trunk/delete/fibers", name="trunk_delete_fibers")
  1086.     * process the delete action of a trunk
  1087.     */
  1088.    public function deleteFibersAction(Request $requestTranslatorInterface $translator)
  1089.   {
  1090.        $user $this->get('security.token_storage')->getToken()->getUser();
  1091.        $em $this->getDoctrine()->getManager();
  1092.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  1093.        $trunkCableFiber $trunk->getCableFiber();
  1094.        $portsAffected = [];
  1095.        $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  1096.        $portsAll = array();
  1097.        foreach ($portsAllTemp as $tempArray) {
  1098.          foreach ($tempArray as $key => $value) {
  1099.            $portsAll[] = $value;
  1100.          }
  1101.        }
  1102.        $error = [];
  1103.        foreach ($trunkCableFiber as $item){
  1104.            $id $item->getId();
  1105.            if (isset($_POST['tcf_'.$id])){
  1106.                $portsAffected[] = $item->getPortA();
  1107.                $portsAffected[] = $item->getPortB();
  1108.                if (in_array($item->getPortA()->getId(), $portsAll) || in_array($item->getPortB()->getId(), $portsAll)) {
  1109.                  $error = array('error' => 'usage');
  1110.                }
  1111.                else {
  1112.                  $error = array('error' => null);
  1113.                  $em->remove($item);
  1114.                  $em->flush();
  1115.                }
  1116.            }
  1117.        }
  1118.        if ($error['error']) {
  1119.          $this->addFlash(
  1120.              'error',
  1121.              'usage'
  1122.          );
  1123.        }
  1124.        $trunk->setUpdatedBy($user);
  1125.        $em->persist($trunk);
  1126.        $em->flush();
  1127.        // check links for validation
  1128.        // foreach($portsAffected as $port){
  1129.        //   $linkExtsB = null;
  1130.        //   $extremities = array();
  1131.        //   foreach ($port->getExtensionOrder() as $value) {
  1132.        //     $extremities[] = $value->getExtremity();
  1133.        //   }
  1134.        //   $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
  1135.        //   if (count($extremities) > 1) {
  1136.        //     $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
  1137.        //   }
  1138.        //     // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $port]);
  1139.        //     // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $port]);
  1140.        //
  1141.        //     if ($linkExtsA){
  1142.        //
  1143.        //         foreach ($linkExtsA as $linkExt){
  1144.        //
  1145.        //             $link = $linkExt->getLink();
  1146.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  1147.        //
  1148.        //             if (!$linkValidation){
  1149.        //
  1150.        //                 $linkValidation = new LinkValidation();
  1151.        //                 $linkValidation->setLink($link);
  1152.        //                 $linkValidation->setTrunk($trunk);
  1153.        //                 $linkValidation->setPort($port);
  1154.        //
  1155.        //                 $em->persist($linkValidation);
  1156.        //                 $em->flush();
  1157.        //
  1158.        //             }
  1159.        //         }
  1160.        //     }
  1161.        //
  1162.        //     if ($linkExtsB){
  1163.        //
  1164.        //         foreach ($linkExtsB as $linkExt){
  1165.        //
  1166.        //             $link = $linkExt->getLink();
  1167.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  1168.        //
  1169.        //             if (!$linkValidation){
  1170.        //
  1171.        //                 $linkValidation = new LinkValidation();
  1172.        //                 $linkValidation->setLink($link);
  1173.        //                 $linkValidation->setTrunk($trunk);
  1174.        //                 $linkValidation->setPort($port);
  1175.        //
  1176.        //                 $em->persist($linkValidation);
  1177.        //                 $em->flush();
  1178.        //
  1179.        //             }
  1180.        //         }
  1181.        //     }
  1182.        //
  1183.        // }
  1184.        // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  1185.        // $cache = new FilesystemAdapter();
  1186.        // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  1187.        // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  1188.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  1189.    }
  1190.    /**
  1191.     * @IsGranted("ROLE_CRUD")
  1192.     * @Route("/trunk/extend/fibers", name="trunk_extend_fibers")
  1193.     * creates a page which gives an user a function to extend the selected cables of a trunk
  1194.     */
  1195.    public function extendFibersAction(Request $requestTranslatorInterface $translator)
  1196.   {
  1197.        $em $this->getDoctrine()->getManager();
  1198.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  1199.        $trunkCableFiber $trunk->getCableFiber();
  1200.        $tcfs = [];
  1201.        foreach ($trunkCableFiber as $item){
  1202.            $id $item->getId();
  1203.            //check if the cable is selected
  1204.            if (isset($_POST['tcf_'.$id])){
  1205.                $tcfs[] = $item;
  1206.            }
  1207.        }
  1208.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  1209.        $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  1210.        $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  1211.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1212.        $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  1213.        return $this->render('trunk/extend_fibers.html.twig', [
  1214.            'action' => 'insert',
  1215.            'page_title' => $translator->trans('Extend Cable / Fiber'),
  1216.            'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Extend Cable / Fiber'),
  1217.            'sites' => $sites,
  1218.            'eqGeneric' => $eqGeneric,
  1219.            'racks' => $racks,
  1220.            'rackFaces' => $rackFaces,
  1221.            'typeCable' => $typeCable,
  1222.            'trunk' => $trunk,
  1223.            'tcfs' => $tcfs
  1224.        ]);
  1225.    }
  1226.    /**
  1227.     * @IsGranted("ROLE_CRUD")
  1228.     * @Route("/trunk/fibers/orerator", name="trunk_add_fibers_operator")
  1229.     * Add operator ID to fibers
  1230.     */
  1231.    public function addFibersOperator(Request $requestTranslatorInterface $translator)
  1232.   {
  1233.        $em $this->getDoctrine()->getManager();
  1234.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  1235.        $operatorID $request->request->get('operator_id_to_add');
  1236.        $trunkCableFiber $trunk->getCableFiber();
  1237.        foreach ($trunkCableFiber as $item){
  1238.            $id $item->getId();
  1239.            //check if the cable is selected
  1240.            if (isset($_POST['tcf_'.$id])){
  1241.                $item->setOperatorID($operatorID);
  1242.                $em->persist($item);
  1243.                $em->flush();
  1244.            }
  1245.            foreach ($item->getExtensions() as $ext) {
  1246.                $extId $ext->getId();
  1247.                //check if the cable is selected
  1248.                if (isset($_POST['extension_'.$extId])){
  1249.                    $ext->setOperatorID($operatorID);
  1250.                    $em->persist($ext);
  1251.                    $em->flush();
  1252.                }
  1253.            }
  1254.        }
  1255.        return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
  1256.    }
  1257.    /**
  1258.     * @IsGranted("ROLE_CRUD")
  1259.     * @Route("/trunk/extend/interfaces/{id}", name="trunk_extend_interfaces")
  1260.     * creates a page which gives an user a function to extend the interfaces of a trunk
  1261.     */
  1262.    public function extendInterfacesAction(Request $request$idTranslatorInterface $translator)
  1263.   {
  1264.      //get the user
  1265.      $user $this->get('security.token_storage')->getToken()->getUser();
  1266.      //get the entity manager
  1267.      $em $this->getDoctrine()->getManager();
  1268.      $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->find($id);
  1269.      //get all the sites, generic equipments, racks and rack faces
  1270.      $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  1271.      $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  1272.      $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  1273.      $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1274.      $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  1275.      $portBArray = [];
  1276.      //get all the interfaces associated with the trunk
  1277.      $tcfs $trunk->getCableFiber();
  1278.      $interfaces = array();
  1279.      $interfacesTemp = array();
  1280.      $portB null;
  1281.      foreach ($tcfs as $tcf) {
  1282.        $lenTemp count($tcf->getExtensions());
  1283.        if ($lenTemp 0) {
  1284.          $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$lenTemp]);
  1285.          $portB $trunkExtTemp->getPortB();
  1286.          $portBArray[] = $portB->getId();
  1287.        }
  1288.        else {
  1289.          $portB $tcf->getPortB();
  1290.          $portBArray[] = $portB->getId();
  1291.        }
  1292.        $interfacesTemp[] = $portB->getInterfaceSpecific()->getId();
  1293.      }
  1294.      $interfacesTemp array_unique($interfacesTemp);
  1295.      foreach ($interfacesTemp as $interface) {
  1296.        $temp $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interface);
  1297.        $ports $temp->getPort();
  1298.        $nbPortsFree 0;
  1299.        foreach ($ports as $port){
  1300.              if (in_array($port->getId(), $portBArray)){
  1301.                  $nbPortsFree++;
  1302.                  // $used = 1;
  1303.              }
  1304.        }
  1305.        $temp->nbPorts $temp->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex" $nbPortsFree*$nbPortsFree;
  1306.        $eqName null;
  1307.        if ($temp->getEquipmentSpecific()->getParent()) {
  1308.          $eqName $temp->getEquipmentSpecific()->getParent()->getEquipmentSpecificName() . " â•‘ " $temp->getEquipmentSpecific()->getEquipmentSpecificName();
  1309.        }
  1310.        else {
  1311.          $eqName $temp->getEquipmentSpecific()->getEquipmentSpecificName();
  1312.        }
  1313.        if (isset($interfaces[$eqName])) {
  1314.          $interfaces[$eqName][] = $temp;
  1315.        }
  1316.        else {
  1317.          $interfaces[$eqName] = array();
  1318.          $interfaces[$eqName][] = $temp;
  1319.        }
  1320.      }
  1321.      return $this->render('trunk/extend_interfaces.html.twig', [
  1322.           'action' => 'insert',
  1323.           'page_title' => $translator->trans('Etendre Interfaces'),
  1324.           'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Etendre Interfaces'),
  1325.           'trunk' => $trunk,
  1326.           'sites' => $sites,
  1327.           'rackFaces' => $rackFaces,
  1328.           'interfaces'=>$interfaces,
  1329.           'typeCable' => $typeCable
  1330.       ]);
  1331.    }
  1332.    /**
  1333.     * @IsGranted("ROLE_CRUD")
  1334.     * @Route("/trunk/extension/edit/{id}", name="trunk_edit_extension")
  1335.     * page to edit the selected trunk extension
  1336.     */
  1337.    public function editExtensionAction($idTranslatorInterface $translator)
  1338.   {
  1339.        $em $this->getDoctrine()->getManager();
  1340.        $trunkExtension $em->getRepository(TrunkExtension::class)->find($id);
  1341.        $trunkCableFiber $trunkExtension->getTrunkCableFiber();
  1342.        $trunk $trunkCableFiber->getTrunk();
  1343.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
  1344.        $eqGeneric $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
  1345.        $racks $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
  1346.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  1347.        return $this->render('trunk/edit_extension.html.twig', [
  1348.            'action' => 'insert',
  1349.            'page_title' => $translator->trans('Edit Extension'),
  1350.            'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
  1351.            'tcf' => $trunkCableFiber,
  1352.            'extension' => $trunkExtension,
  1353.            'sites' => $sites,
  1354.            'eqGeneric' => $eqGeneric,
  1355.            'racks' => $racks,
  1356.            'rackFaces' => $rackFaces,
  1357.            'trunk' => $trunk
  1358.        ]);
  1359.    }
  1360.    /**
  1361.     * @IsGranted("ROLE_CRUD")
  1362.     * @Route("/trunk/extension/process", name="trunk_edit_process_extension")
  1363.     * process the trunk extexsion edition form
  1364.     */
  1365.    public function editExtensionProcess(Request $requestTranslatorInterface $translator)
  1366.   {
  1367.        $em $this->getDoctrine()->getManager();
  1368.        $extension_id $request->request->get('extension_id');
  1369.        $trunkExtension $em->getRepository(TrunkExtension::class)->find($extension_id);
  1370.        $tcf $trunkExtension->getTrunkCableFiber();
  1371.        $trunk $tcf->getTrunk();
  1372.        $portBext $trunkExtension->getPortB();
  1373.        $currentOperatorID $trunkExtension->getOperatorID();
  1374.        $trunkExtension->setOperatorID($request->request->get('operatorID'));
  1375.        $portB $em->getRepository(Port::class)->find($request->request->get('pointB'));
  1376.        //check for loop
  1377.        $tempInts = array();
  1378.        $tempInts[] = $tcf->getPortA()->getInterfaceSpecific()->getId();
  1379.        $tempInts[] = $tcf->getPortB()->getInterfaceSpecific()->getId();
  1380.        foreach ($tcf->getExtensions() as $value) {
  1381.          if ($value->getId() != $trunkExtension->getId()) {
  1382.            $tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
  1383.          }
  1384.        }
  1385.        if (in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
  1386.          $this->addFlash(
  1387.              'error',
  1388.              'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
  1389.          );
  1390.          return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
  1391.        }
  1392.        $matchedPort $trunkExtension->getPortB();
  1393.        $trunkExtension->setPortB($portB);
  1394.        //get the link extension if any matches
  1395.        $extMatch null;
  1396.        $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  1397.        // var_dump($extId);
  1398.        if ($extId) {
  1399.          $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  1400.        }
  1401.        // $extMatch = $matchedPort->getLinkExtension();
  1402.        if ($extMatch) {
  1403.          $matchedPort->setLink(null);
  1404.          $matchedPort->setLinkExtension(null);
  1405.          // $matchedPort->setOrderNoExtension(1);
  1406.          $em->persist($matchedPort);
  1407.          $linkMatch $extMatch->getLink();
  1408.          $extrmityB $extMatch->getExtremityB();
  1409.          $extBPorts $extrmityB->getExtensionOrder();
  1410.          $tempIds = array();
  1411.          foreach ($extBPorts as $value) {
  1412.            $tempIds[] = $value->getPort()->getId();
  1413.          }
  1414.          if (in_array($matchedPort->getId(), $tempIds)) {
  1415.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  1416.            $orderNoExt $extensinOrder->getOrderNumber();
  1417.            $em->remove($extensinOrder);
  1418.            // $extrmityB->removePort($matchedPort);
  1419.            // $extrmityB->addPort($portB);
  1420.            // $portB->setOrderNoExtension($orderNoExt);
  1421.            // $portB->addExtremity($extrmityB);
  1422.            $extensinOrder = new ExtensionOrder();
  1423.            $extensinOrder->setOrderNumber($orderNoExt);
  1424.            $extensinOrder->setPort($portB);
  1425.            $extensinOrder->setExtremity($extrmityB);
  1426.            $portB->addExtensionOrder($extensinOrder);
  1427.            $extrmityB->addExtensionOrder($extensinOrder);
  1428.            $em->persist($extensinOrder);
  1429.            $portB->setLink($linkMatch);
  1430.            $portB->setLinkExtension($extMatch);
  1431.            $em->persist($portB);
  1432.            $em->persist($extrmityB);
  1433.            //check if it's last link extension
  1434.            //if it's last, DO NOTHING
  1435.            if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  1436.              // // var_dump("entering ...");
  1437.              // //else get the last extension's extremity B's equipment
  1438.              // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  1439.              // $nextExtA = $nextExtension->getExtremityA();
  1440.              //
  1441.              // $nextPorts = array();
  1442.              // foreach ($nextExtA->getExtensionOrder() as $value) {
  1443.              //   $nextPorts[] = $value->getPort();
  1444.              // }
  1445.              //
  1446.              // // $nextPorts = $nextExtA->getPorts();
  1447.              // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  1448.              // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  1449.              // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  1450.              //
  1451.              // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  1452.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  1453.              //
  1454.              // //check if it's same as current modified link ext
  1455.              // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  1456.              //   // var_dump("entering not equals equipments...");
  1457.              //
  1458.              //   //if false, set the link and las link extension as INVALID
  1459.              //   $nextExtension->setIsValid(false);
  1460.              //   $em->persist($nextExtension);
  1461.              // }
  1462.              // else {
  1463.              //   // var_dump("entering checking ports...");
  1464.              //
  1465.              //     $nextExtension->setIsValid(true);
  1466.              //     $em->persist($nextExtension);
  1467.              //   //else get the next extension's extremity B's interface
  1468.              //   //check if it's 1:1
  1469.              //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  1470.              //     // var_dump("entering checking 1 to 1...");
  1471.              //
  1472.              //     // if true, check ports are the same
  1473.              //     //if true, DO NOTHING
  1474.              //     //else set the link and las link extension as INVALID
  1475.              //     foreach ($nextPorts as $nextPort) {
  1476.              //       if ($nextPort->getId() != $portB->getId()) {
  1477.              //         $nextExtension->setIsValid(false);
  1478.              //         $em->persist($nextExtension);
  1479.              //       }
  1480.              //       else {
  1481.              //         $nextExtension->setIsValid(true);
  1482.              //         $em->persist($nextExtension);
  1483.              //       }
  1484.              //     }
  1485.              //   }
  1486.              // }
  1487.              TrunkController::validateNextExtension($em$linkMatch$extMatch$portB);
  1488.            }
  1489.          }
  1490.          $extrmityA $extMatch->getExtremityA();
  1491.          $extAPorts $extrmityA->getExtensionOrder();
  1492.          $tempIds = array();
  1493.          foreach ($extAPorts as $value) {
  1494.            $tempIds[] = $value->getPort()->getId();
  1495.          }
  1496.          if (in_array($matchedPort->getId(), $tempIds)) {
  1497.            $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  1498.            $orderNoExt $extensinOrder->getOrderNumber();
  1499.            $em->remove($extensinOrder);
  1500.            // $extrmityA->removePort($matchedPort);
  1501.            $extensinOrder = new ExtensionOrder();
  1502.            $extensinOrder->setOrderNumber($orderNoExt);
  1503.            $extensinOrder->setPort($portB);
  1504.            $extensinOrder->setExtremity($extrmityA);
  1505.            $portB->addExtensionOrder($extensinOrder);
  1506.            $extrmityA->addExtensionOrder($extensinOrder);
  1507.            $em->persist($extensinOrder);
  1508.            // $extrmityA->addPort($portB);
  1509.            // $portB->setOrderNoExtension($orderNoExt);
  1510.            // $portB->addExtremity($extrmityA);
  1511.            $portB->setLink($linkMatch);
  1512.            $portB->setLinkExtension($extMatch);
  1513.            $em->persist($portB);
  1514.            $em->persist($extrmityA);
  1515.            if ($extMatch->getSequenceNo() > 1) {
  1516.              // //else get the last extension's extremity B's equipment
  1517.              // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  1518.              //
  1519.              // $lastExtB = $lastExtension->getExtremityB();
  1520.              //
  1521.              // $lastPorts = array();
  1522.              // foreach ($lastExtB->getExtensionOrder() as $value) {
  1523.              //   $lastPorts[] = $value->getPort();
  1524.              // }
  1525.              //
  1526.              // // $lastPorts = $lastExtB->getPorts();
  1527.              // // var_dump($lastPorts);
  1528.              // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  1529.              // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  1530.              // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  1531.              //
  1532.              // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  1533.              // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  1534.              //
  1535.              // //check if it's same as current modified link ext
  1536.              // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  1537.              //   //if false, set the link and las link extension as INVALID
  1538.              //   $lastExtension->setIsValid(false);
  1539.              //   $em->persist($lastExtension);
  1540.              // }
  1541.              // else {
  1542.              //   // var_dump('hi');
  1543.              //   $lastExtension->setIsValid(true);
  1544.              //   $em->persist($lastExtension);
  1545.              //   //else get the last extension's extremity B's interface
  1546.              //   //check if it's 1:1
  1547.              //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  1548.              //     // if true, check ports are the same
  1549.              //     //if true, DO NOTHING
  1550.              //     //else set the link and las link extension as INVALID
  1551.              //     foreach ($lastPorts as $lastPort) {
  1552.              //       // var_dump($lastPort);
  1553.              //       if ($lastPort->getId() != $portB->getId()) {
  1554.              //         $lastExtension->setIsValid(false);
  1555.              //         $em->persist($lastExtension);
  1556.              //       }
  1557.              //       else {
  1558.              //         $lastExtension->setIsValid(true);
  1559.              //         $em->persist($lastExtension);
  1560.              //       }
  1561.              //     }
  1562.              //   }
  1563.              // }
  1564.              TrunkController::validateLastExtension($em$linkMatch$extMatch$portB);
  1565.            }
  1566.          }
  1567.        }
  1568.        $em->persist($trunkExtension);
  1569.        $em->flush();
  1570.        // set operator id for all in sequence
  1571.        // MODIFIED on 13 mars 2019 begin
  1572.        // $trunkExtensionsInSequence = $em->getRepository(TrunkExtension::class)->findBy(['operatorID' => $currentOperatorID]);
  1573.        // foreach ($trunkExtensionsInSequence as $item){
  1574.        //     $item->setOperatorID($request->request->get('operatorID'));
  1575.        //     $em->persist($item);
  1576.        //     $em->flush();
  1577.        // }
  1578.        // MODIFIED on 13 mars 2019 end
  1579.        // check links for validation
  1580.        // $trunk = $trunkExtension->getTrunkCableFiber()->getTrunk();
  1581.        //
  1582.        // $linkExtsB = null;
  1583.        // $extremities = array();
  1584.        //
  1585.        // foreach ($portBext->getExtensionOrder() as $value) {
  1586.        //   $extremities[] = $value->getExtremity();
  1587.        // }
  1588.        // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
  1589.        // if (count($extremities) > 1) {
  1590.        //   $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
  1591.        // }
  1592.        // // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $portBext]);
  1593.        // // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $portBext]);
  1594.        // if ($linkExtsA){
  1595.        //
  1596.        //     foreach ($linkExtsA as $linkExt){
  1597.        //
  1598.        //         $link = $linkExt->getLink();
  1599.        //         $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $portB]);
  1600.        //
  1601.        //         if (!$linkValidation){
  1602.        //
  1603.        //             $linkValidation = new LinkValidation();
  1604.        //             $linkValidation->setLink($link);
  1605.        //             $linkValidation->setTrunk($trunk);
  1606.        //             $linkValidation->setPort($portB);
  1607.        //
  1608.        //             $em->persist($linkValidation);
  1609.        //             $em->flush();
  1610.        //
  1611.        //         }
  1612.        //     }
  1613.        // }
  1614.        //
  1615.        // if ($linkExtsB){
  1616.        //
  1617.        //     foreach ($linkExtsB as $linkExt){
  1618.        //
  1619.        //         $link = $linkExt->getLink();
  1620.        //         $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $portB]);
  1621.        //
  1622.        //         if (!$linkValidation){
  1623.        //
  1624.        //             $linkValidation = new LinkValidation();
  1625.        //             $linkValidation->setLink($link);
  1626.        //             $linkValidation->setTrunk($trunk);
  1627.        //             $linkValidation->setPort($portB);
  1628.        //
  1629.        //             $em->persist($linkValidation);
  1630.        //             $em->flush();
  1631.        //
  1632.        //         }
  1633.        //     }
  1634.        // }
  1635.        // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  1636.        // $cache = new FilesystemAdapter();
  1637.        // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  1638.        // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  1639.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  1640.    }
  1641.    /**
  1642.     * @IsGranted("ROLE_CRUD")
  1643.     * @Route("/trunk/extend", name="trunk_create_process_extend")
  1644.     * process the trunk extension form
  1645.     */
  1646.    public function processExtensionsAction(Request $requestTranslatorInterface $translator)
  1647.   {
  1648.        $user $this->get('security.token_storage')->getToken()->getUser();
  1649.        $em $this->getDoctrine()->getManager();
  1650.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  1651.        // from form
  1652.        $noFibers $request->request->get('noFibers');
  1653.        $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  1654.        $operatorId $request->request->get('operatorID');
  1655.        $tcfs = [];
  1656.        // $portsAffected = [];
  1657.        foreach ($_POST['tcf'] as $tcf_id){
  1658.            $tcf $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneById($tcf_id);
  1659.            // $portsAffected[] = $tcf->getPortA();
  1660.            // $portsAffected[] = $tcf->getPortB();
  1661.            $tcfs[] = $tcf;
  1662.        }
  1663.        $redirect false;
  1664.        $counter 0;
  1665.        $duplexPort false;
  1666.        for ($i=0$i<$noFibers$i++){
  1667.            $j $i+1;
  1668.            $tcf $tcfs[$i];
  1669.            $sequence_no $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
  1670.            $portB $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$j]);
  1671.            //check for the loop
  1672.            $tempInts = array();
  1673.            $tempInts[] = $tcf->getPortA()->getInterfaceSpecific()->getId();
  1674.            $tempInts[] = $tcf->getPortB()->getInterfaceSpecific()->getId();
  1675.            foreach ($tcf->getExtensions() as $value) {
  1676.              $tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
  1677.            }
  1678.            if (in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
  1679.              $redirect true;
  1680.            }
  1681.            if ($redirect) {
  1682.              break;
  1683.            }
  1684.            else {
  1685.              // $portsAffected[] = $portB;
  1686.              $typeCable $tcf->getTrunk()->getTypeCable();
  1687.              $ext = new TrunkExtension();
  1688.              $ext->setTrunkCableFiber($tcf);
  1689.              $ext->setTypeCable($typeCable);
  1690.              $ext->setOperatorID($operatorId);
  1691.              $ext->setPortB($portB);
  1692.              $ext->setSequenceNo($sequence_no);
  1693.              $em->persist($ext);
  1694.              $em->flush();
  1695.              //get the link extension if any matches
  1696.              $extMatch null;
  1697.              $matchedPort null;
  1698.              // var_dump($sequence_no);
  1699.              if ($sequence_no == 1) {
  1700.                $matchedPort $tcf->getPortB();
  1701.              }
  1702.              else {
  1703.                $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$sequence_no-1]);
  1704.                $matchedPort $lastTrunkExt->getPortB();
  1705.              }
  1706.              // var_dump($matchedPort);
  1707.              if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
  1708.                $duplexPort true;
  1709.                $counter++;
  1710.              }
  1711.              else {
  1712.                $duplexPort false;
  1713.                $counter 2;
  1714.              }
  1715.              $extMatch null;
  1716.              $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  1717.              if ($extId) {
  1718.                $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  1719.              }
  1720.              // var_dump($extId);
  1721.              // $extMatch = $matchedPort->getLinkExtension();
  1722.              if ($extMatch) {
  1723.                // var_dump($extMatch->getId());
  1724.                // $orderNoExt = $matchedPort->getOrderNoExtension();
  1725.                if ($counter == 2) {
  1726.                  $matchedPort->setLink(null);
  1727.                  $matchedPort->setLinkExtension(null);
  1728.                  // $matchedPort->setOrderNoExtension(1);
  1729.                  $em->persist($matchedPort);
  1730.                  // $counter = 0;
  1731.                }
  1732.                $linkMatch $extMatch->getLink();
  1733.                $extrmityB $extMatch->getExtremityB();
  1734.                $extBPorts $extrmityB->getExtensionOrder();
  1735.                $tempIds = array();
  1736.                foreach ($extBPorts as $value) {
  1737.                  $tempIds[] = $value->getPort()->getId();
  1738.                }
  1739.                // var_dump($tempIds);
  1740.                if (in_array($matchedPort->getId(), $tempIds)) {
  1741.                  $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  1742.                  $orderNoExt $extensinOrder->getOrderNumber();
  1743.                  if ($counter == && $duplexPort) {
  1744.                    // var_dump($duplexPort);
  1745.                    $orderNoExt 2;
  1746.                    $em->remove($extensinOrder);
  1747.                    $duplexPort false;
  1748.                    $counter 0;
  1749.                  }
  1750.                  elseif ($counter == 2) {
  1751.                    $em->remove($extensinOrder);
  1752.                    $counter 0;
  1753.                  }
  1754.                  // $extrmityB->removePort($matchedPort);
  1755.                  $extensinOrder = new ExtensionOrder();
  1756.                  $extensinOrder->setOrderNumber($orderNoExt);
  1757.                  $extensinOrder->setPort($portB);
  1758.                  $extensinOrder->setExtremity($extrmityB);
  1759.                  $portB->addExtensionOrder($extensinOrder);
  1760.                  $extrmityB->addExtensionOrder($extensinOrder);
  1761.                  $em->persist($extensinOrder);
  1762.                  // $extrmityB->addPort($portB);
  1763.                  // $portB->setOrderNoExtension($orderNoExt);
  1764.                  // $portB->addExtremity($extrmityB);
  1765.                  $portB->setLink($linkMatch);
  1766.                  $portB->setLinkExtension($extMatch);
  1767.                  $em->persist($portB);
  1768.                  $em->persist($extrmityB);
  1769.                  //check if it's last link extension
  1770.                  //if it's last, DO NOTHING
  1771.                  // var_dump('hi');
  1772.                  // var_dump($extMatch->getSequenceNo());
  1773.                  // var_dump(count($linkMatch->getLinkExtension()));
  1774.                  if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  1775.                    // // var_dump("entering ...");
  1776.                    // //else get the last extension's extremity B's equipment
  1777.                    // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  1778.                    // $nextExtA = $nextExtension->getExtremityA();
  1779.                    //
  1780.                    // $nextPorts = array();
  1781.                    // foreach ($nextExtA->getExtensionOrder() as $value) {
  1782.                    //   $nextPorts[] = $value->getPort();
  1783.                    // }
  1784.                    //
  1785.                    // // $nextPorts = $nextExtA->getPorts();
  1786.                    // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  1787.                    // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  1788.                    // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  1789.                    //
  1790.                    // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  1791.                    // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  1792.                    //
  1793.                    // //check if it's same as current modified link ext
  1794.                    // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  1795.                    //   // var_dump("entering not equals equipments...");
  1796.                    //
  1797.                    //   //if false, set the link and las link extension as INVALID
  1798.                    //   $nextExtension->setIsValid(false);
  1799.                    //   $em->persist($nextExtension);
  1800.                    // }
  1801.                    // else {
  1802.                    //   // var_dump("entering checking ports...");
  1803.                    //   $errMsg = $nextExtension->getError();
  1804.                    //   $errMsg = str_replace("EquipmentA", "", $errMsg);
  1805.                    //   $nextExtension->setError($errMsg);
  1806.                    //   if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
  1807.                    //        $nextExtension->setIsValid(false);
  1808.                    //    }
  1809.                    //    else {
  1810.                    //      $nextExtension->setIsValid(true);
  1811.                    //    }
  1812.                    //
  1813.                    //     $em->persist($nextExtension);
  1814.                    //   //else get the next extension's extremity B's interface
  1815.                    //   //check if it's 1:1
  1816.                    //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  1817.                    //     // var_dump("entering checking 1 to 1...");
  1818.                    //
  1819.                    //     // if true, check ports are the same
  1820.                    //     //if true, DO NOTHING
  1821.                    //     //else set the link and las link extension as INVALID
  1822.                    //     foreach ($nextPorts as $nextPort) {
  1823.                    //       if ($nextPort->getId() != $portB->getId()) {
  1824.                    //         $nextExtension->setIsValid(false);
  1825.                    //         if ($nextExtension->getError()) {
  1826.                    //           $nextExtension->setError($nextExtension->getError() . "," . "PortA");
  1827.                    //         }
  1828.                    //         else {
  1829.                    //           $nextExtension->setError("PortA");
  1830.                    //         }
  1831.                    //         $em->persist($nextExtension);
  1832.                    //       }
  1833.                    //       else {
  1834.                    //         $nextExtension->setIsValid(true);
  1835.                    //         $errMsg = str_replace("PortA", "", $errMsg);
  1836.                    //         $nextExtension->setError($errMsg);
  1837.                    //         $em->persist($nextExtension);
  1838.                    //       }
  1839.                    //     }
  1840.                    //   }
  1841.                    // }
  1842.                    TrunkController::validateNextExtension($em$linkMatch$extMatch$portB);
  1843.                  }
  1844.                }
  1845.                $extrmityA $extMatch->getExtremityA();
  1846.                $extAPorts $extrmityA->getExtensionOrder();
  1847.                $tempIds = array();
  1848.                foreach ($extAPorts as $value) {
  1849.                  $tempIds[] = $value->getPort()->getId();
  1850.                }
  1851.                if (in_array($matchedPort->getId(), $tempIds)) {
  1852.                  $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  1853.                  $orderNoExt $extensinOrder->getOrderNumber();
  1854.                  if ($counter == && $duplexPort) {
  1855.                    // var_dump($duplexPort);
  1856.                    $orderNoExt 2;
  1857.                    $em->remove($extensinOrder);
  1858.                    $duplexPort false;
  1859.                    $counter 0;
  1860.                  }
  1861.                  elseif ($counter == 2) {
  1862.                    $em->remove($extensinOrder);
  1863.                    $counter 0;
  1864.                  }
  1865.                  // $extrmityA->removePort($matchedPort);
  1866.                  $extensinOrder = new ExtensionOrder();
  1867.                  $extensinOrder->setOrderNumber($orderNoExt);
  1868.                  $extensinOrder->setPort($portB);
  1869.                  $extensinOrder->setExtremity($extrmityA);
  1870.                  $portB->addExtensionOrder($extensinOrder);
  1871.                  $extrmityA->addExtensionOrder($extensinOrder);
  1872.                  $em->persist($extensinOrder);
  1873.                  // $extrmityA->removePort($matchedPort);
  1874.                  // $extrmityA->addPort($portB);
  1875.                  // $portB->setOrderNoExtension($orderNoExt);
  1876.                  // $portB->addExtremity($extrmityA);
  1877.                  $portB->setLink($linkMatch);
  1878.                  $portB->setLinkExtension($extMatch);
  1879.                  $em->persist($portB);
  1880.                  $em->persist($extrmityA);
  1881.                  if ($extMatch->getSequenceNo() > 1) {
  1882.                    // //else get the last extension's extremity B's equipment
  1883.                    // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  1884.                    // $lastExtB = $lastExtension->getExtremityB();
  1885.                    //
  1886.                    // $lastPorts = array();
  1887.                    // foreach ($lastExtB->getExtensionOrder() as $value) {
  1888.                    //   $lastPorts[] = $value->getPort();
  1889.                    // }
  1890.                    //
  1891.                    // // $lastPorts = $lastExtB->getPorts();
  1892.                    // // var_dump($lastPorts);
  1893.                    // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  1894.                    // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  1895.                    // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  1896.                    //
  1897.                    // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  1898.                    // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  1899.                    //
  1900.                    // //check if it's same as current modified link ext
  1901.                    // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  1902.                    //   //if false, set the link and las link extension as INVALID
  1903.                    //   $lastExtension->setIsValid(false);
  1904.                    //   $em->persist($lastExtension);
  1905.                    // }
  1906.                    // else {
  1907.                    //   // var_dump('hi');
  1908.                    //   $errMsg = $lastExtension->getError();
  1909.                    //   $errMsg = str_replace("EquipmentB", "", $errMsg);
  1910.                    //   $lastExtension->setError($errMsg);
  1911.                    //   if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
  1912.                    //        $lastExtension->setIsValid(false);
  1913.                    //    }
  1914.                    //    else {
  1915.                    //      $lastExtension->setIsValid(true);
  1916.                    //      $lastExtension->setError(null);
  1917.                    //    }
  1918.                    //   $em->persist($lastExtension);
  1919.                    //   //else get the last extension's extremity B's interface
  1920.                    //   //check if it's 1:1
  1921.                    //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  1922.                    //     // if true, check ports are the same
  1923.                    //     //if true, DO NOTHING
  1924.                    //     //else set the link and las link extension as INVALID
  1925.                    //     foreach ($lastPorts as $lastPort) {
  1926.                    //       // var_dump($lastPort);
  1927.                    //       if ($lastPort->getId() != $portB->getId()) {
  1928.                    //         $lastExtension->setIsValid(false);
  1929.                    //         $em->persist($lastExtension);
  1930.                    //       }
  1931.                    //       else {
  1932.                    //         $lastExtension->setIsValid(true);
  1933.                    //         $em->persist($lastExtension);
  1934.                    //       }
  1935.                    //     }
  1936.                    //   }
  1937.                    // }
  1938.                    TrunkController::validateLastExtension($em$linkMatch$extMatch$portB);
  1939.                  }
  1940.                }
  1941.              }
  1942.            }
  1943.        }
  1944.        if ($redirect) {
  1945.          $this->addFlash(
  1946.              'error',
  1947.              'Trunk en boucle : Veuillez vérifier les ports choisis, SVP'
  1948.          );
  1949.          return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
  1950.        }
  1951.        else {
  1952.          $trunk->setUpdatedBy($user);
  1953.          $em->persist($trunk);
  1954.          $em->flush();
  1955.        }
  1956.        //
  1957.        // check links for validation
  1958.        // foreach($portsAffected as $port){
  1959.        //    $linkExtsB = null;
  1960.        //    $extremities = array();
  1961.        //    foreach ($port->getExtensionOrder() as $value) {
  1962.        //      $extremities[] = $value->getExtremity();
  1963.        //    }
  1964.        //    $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
  1965.        //    if (count($extremities) > 1) {
  1966.        //      $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
  1967.        //    }
  1968.        //
  1969.        //
  1970.        //     if ($linkExtsA){
  1971.        //
  1972.        //         foreach ($linkExtsA as $linkExt){
  1973.        //
  1974.        //             $link = $linkExt->getLink();
  1975.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  1976.        //
  1977.        //             if (!$linkValidation){
  1978.        //
  1979.        //                 $linkValidation = new LinkValidation();
  1980.        //                 $linkValidation->setLink($link);
  1981.        //                 $linkValidation->setTrunk($trunk);
  1982.        //                 $linkValidation->setPort($port);
  1983.        //
  1984.        //                 $em->persist($linkValidation);
  1985.        //                 $em->flush();
  1986.        //
  1987.        //             }
  1988.        //         }
  1989.        //     }
  1990.        //
  1991.        //     if ($linkExtsB){
  1992.        //
  1993.        //         foreach ($linkExtsB as $linkExt){
  1994.        //
  1995.        //             $link = $linkExt->getLink();
  1996.        //             $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
  1997.        //
  1998.        //             if (!$linkValidation){
  1999.        //
  2000.        //                 $linkValidation = new LinkValidation();
  2001.        //                 $linkValidation->setLink($link);
  2002.        //                 $linkValidation->setTrunk($trunk);
  2003.        //                 $linkValidation->setPort($port);
  2004.        //
  2005.        //                 $em->persist($linkValidation);
  2006.        //                 $em->flush();
  2007.        //
  2008.        //             }
  2009.        //         }
  2010.        //     }
  2011.        //
  2012.        // }
  2013.        // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  2014.        // $cache = new FilesystemAdapter();
  2015.        // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  2016.        // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  2017.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  2018.    }
  2019. /**
  2020.  * @IsGranted("ROLE_CRUD")
  2021.  * @Route("/trunk/extend/interfaces", name="trunk_extend_interface_process")
  2022.  * process the trunk extension interface form
  2023.  */
  2024. public function processExtensionsInterfaceAction(Request $requestLoggerInterface $logger)
  2025. {
  2026.   // $logger = $this->get('logger');
  2027.   //get the user
  2028.   $user $this->get('security.token_storage')->getToken()->getUser();
  2029.   //get the entity manager
  2030.   $em $this->getDoctrine()->getManager();
  2031.   //get the trunk by id
  2032.   $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  2033.   $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
  2034.   $operatorId $request->request->get('operatorID');
  2035.   //get all the interfaces associated with the trunk
  2036.   $tcfs $trunk->getCableFiber();
  2037.   $interfaces = array();
  2038.   $interfacesTemp = array();
  2039.   $portB null;
  2040.   foreach ($tcfs as $tcf) {
  2041.     $lenTemp count($tcf->getExtensions());
  2042.     if ($lenTemp 0) {
  2043.       $trunkExtTemp $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$lenTemp]);
  2044.       $portB $trunkExtTemp->getPortB();
  2045.     }
  2046.     else {
  2047.       $portB $tcf->getPortB();
  2048.     }
  2049.     $interfacesTemp[] = $portB->getInterfaceSpecific()->getId();
  2050.   }
  2051.   $interfacesTemp array_unique($interfacesTemp);
  2052.   foreach ($interfacesTemp as $interface) {
  2053.     $interfaces[] = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interface);
  2054.   }
  2055.   $typeCreation $request->request->get('type_creation');
  2056.   if ($typeCreation == 2) {
  2057.        $eqB null;
  2058.       // equipment B
  2059.       // get the type of equipment B : 1 => generic or 2 => specific
  2060.       $equipmentTypeB $request->request->get('equipmentTypeB');
  2061.       //if generic, process the form to create a new sepcific equipment
  2062.       if ($equipmentTypeB == 1) {
  2063.         $eqB = new EquipmentSpecific();
  2064.         $equipmentGenericB $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointB'));
  2065.         $eqB->setEquipmentGeneric($equipmentGenericB);
  2066.         $eqB->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointB')));
  2067.         $eqB->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointB')));
  2068.         $eqB->setPositionRack($request->request->get('positionRackPointB'));
  2069.         $eqB->setEquipmentSpecificName($request->request->get('equipmentSpecificNameB'));
  2070.         $eqB->setAlias($request->request->get('aliasB'));
  2071.         $eqB->setOwner($request->request->get('ownerB'));
  2072.         $em->persist($eqB);
  2073.         $em->flush();
  2074.         // create specific interfaces
  2075.         $totalPortsB 0;
  2076.         $interfacesGeneric $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericB);
  2077.         foreach ($interfacesGeneric as $interfaceGeneric) {
  2078.           $interfaceSpecific = new InterfaceSpecific();
  2079.           $interfaceSpecific->setEquipmentSpecific($eqB);
  2080.           $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
  2081.           $alias json_decode($interfaceGeneric->getAlias(), true);
  2082.           $em->persist($interfaceSpecific);
  2083.           $em->flush();
  2084.           // create ports
  2085.           $numberOfPorts $interfaceGeneric->getNumberOfPorts();
  2086.           $typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
  2087.           if ($typeLinkTitle == "Duplex") {
  2088.             $numberOfPorts 2*$numberOfPorts;
  2089.           }
  2090.           $totalPortsB += $numberOfPorts;
  2091.           for ($i 1$i <= $numberOfPorts$i++) {
  2092.             $port = new Port();
  2093.             $port->setInterfaceSpecific($interfaceSpecific);
  2094.             $port->setOrderNo($i);
  2095.             if ($alias) {
  2096.               $port->setAlias($alias[$i]);
  2097.             }
  2098.             $em->persist($port);
  2099.             $em->flush();
  2100.           }
  2101.         }
  2102.         //if specific equipment
  2103.       } else {
  2104.         //get the equipment
  2105.         $eqB $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointB'));
  2106.       }
  2107.       // INTERFACE TO INTERFACE
  2108.       if ($typeCreation == 2) {
  2109.         // FIBERS A
  2110.         $tcfFound = [];
  2111.         //get all the interfaces associated with the trunk
  2112.         $tcfs $trunk->getCableFiber();
  2113.         foreach ($interfaces as $interface) {
  2114.           $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  2115.           $logger->info($typeLinkTitle);
  2116.           $interface_id $interface->getId(); // get specific interfaces
  2117.           //check if interface is selected
  2118.           if (isset($_POST['interfaceA_' $interface_id])) {
  2119.             $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  2120.             foreach ($ports as $port) {
  2121.               $tExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findByPortB($port);
  2122.               if (count($tExt) > 0) {
  2123.                 foreach ($tExt as $value) {
  2124.                   $tcfFound[] = $value->getTrunkCableFiber();
  2125.                 }
  2126.               }
  2127.               else {
  2128.                 $k 0;
  2129.                 foreach ($tcfs as $tcf) {
  2130.                   if ($tcf->getPortB() == $port) {
  2131.                     $logger->info($tcf->getId());
  2132.                     $tcfFound[] = $tcf;
  2133.                     $k++;
  2134.                   }
  2135.                   if ($typeLinkTitle == "Duplex" && $k == 2) {
  2136.                     $k 0;
  2137.                     break;
  2138.                   }
  2139.                   elseif ($typeLinkTitle == "Simplex" && $k == 1) {
  2140.                     $k 0;
  2141.                     break;
  2142.                   }
  2143.                 }
  2144.               }
  2145.             }
  2146.           }
  2147.         }
  2148.         // FIBERS B
  2149.         $countTcf 0;
  2150.         if ($eqB->isModulaire()) {
  2151.             $modules $eqB->getModules();
  2152.             $chassisModule $eqB->getChassisModule();
  2153.             if ($chassisModule) {
  2154.                 $modules->add($chassisModule);
  2155.             }
  2156.           foreach ($modules as $module) {
  2157.             $interfacesB $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($module);
  2158.             foreach ($interfacesB as $interface) {
  2159.               //ADDED by Soupra
  2160.               $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  2161.               if ($equipmentTypeB == 1) {
  2162.                 $interface_id $interface->getInterfaceGeneric()->getId(); // get generic interfaces
  2163.               } else {
  2164.                 $interface_id $interface->getId(); // get specific interfaces
  2165.               }
  2166.               //check if interface is selected
  2167.               if (isset($_POST['interfaceB_' $interface_id])) {
  2168.                 $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  2169.                 foreach ($ports as $port) {
  2170.                   //get the cable which corresponds to the portA
  2171.                   //ADDED by Soupra
  2172.                   $usedTmpA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  2173.                   $usedTmpB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2174.                   $usedTmpExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2175.                   if($usedTmpA == null && $usedTmpB == null && $usedTmpExt == null){
  2176.                       if ($typeLinkTitle == "Duplex") {
  2177.                         for ($i=0$i 2$i++) {
  2178.                           $tcf $tcfFound[$countTcf++];
  2179.                           $ext = new TrunkExtension();
  2180.                           $sequence_no $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
  2181.                           $ext->setTrunkCableFiber($tcf);
  2182.                           $ext->setTypeCable($typeCable);
  2183.                           $ext->setOperatorID($operatorId);
  2184.                           $ext->setPortB($port);
  2185.                           $ext->setSequenceNo($sequence_no);
  2186.                           $em->persist($ext);
  2187.                           //check for continuity
  2188.                           //get the link extension if any matches
  2189.                           $extMatch null;
  2190.                           $matchedPort null;
  2191.                           // var_dump($sequence_no);
  2192.                           if ($sequence_no == 1) {
  2193.                             $matchedPort $tcf->getPortB();
  2194.                           }
  2195.                           else {
  2196.                             $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$sequence_no-1]);
  2197.                             $matchedPort $lastTrunkExt->getPortB();
  2198.                           }
  2199.                           // var_dump($matchedPort);
  2200.                           if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
  2201.                             $duplexPort true;
  2202.                             $counter++;
  2203.                           }
  2204.                           else {
  2205.                             $duplexPort false;
  2206.                             $counter 2;
  2207.                           }
  2208.                           $extMatch null;
  2209.                           $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  2210.                           if ($extId) {
  2211.                             $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  2212.                           }
  2213.                           // $extMatch = $matchedPort->getLinkExtension();
  2214.                           if ($extMatch) {
  2215.                             // var_dump($extMatch->getId());
  2216.                             // $orderNoExt = $matchedPort->getOrderNoExtension();
  2217.                             if ($counter == 2) {
  2218.                               $matchedPort->setLink(null);
  2219.                               $matchedPort->setLinkExtension(null);
  2220.                               // $matchedPort->setOrderNoExtension(1);
  2221.                               $em->persist($matchedPort);
  2222.                               // $counter = 0;
  2223.                             }
  2224.                             $linkMatch $extMatch->getLink();
  2225.                             $extrmityB $extMatch->getExtremityB();
  2226.                             $extBPorts $extrmityB->getExtensionOrder();
  2227.                             $tempIds = array();
  2228.                             foreach ($extBPorts as $value) {
  2229.                               $tempIds[] = $value->getPort()->getId();
  2230.                             }
  2231.                             // var_dump($tempIds);
  2232.                             if (in_array($matchedPort->getId(), $tempIds)) {
  2233.                               $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  2234.                               $orderNoExt $extensinOrder->getOrderNumber();
  2235.                               if ($counter == && $duplexPort) {
  2236.                                 var_dump($duplexPort);
  2237.                                 $orderNoExt 2;
  2238.                                 $em->remove($extensinOrder);
  2239.                                 $duplexPort false;
  2240.                                 $counter 0;
  2241.                               }
  2242.                               elseif ($counter == 2) {
  2243.                                 $em->remove($extensinOrder);
  2244.                                 $counter 0;
  2245.                               }
  2246.                               // $extrmityB->removePort($matchedPort);
  2247.                               $extensinOrder = new ExtensionOrder();
  2248.                               $extensinOrder->setOrderNumber($orderNoExt);
  2249.                               $extensinOrder->setPort($port);
  2250.                               $extensinOrder->setExtremity($extrmityB);
  2251.                               $port->addExtensionOrder($extensinOrder);
  2252.                               $extrmityB->addExtensionOrder($extensinOrder);
  2253.                               $em->persist($extensinOrder);
  2254.                               // $extrmityB->addPort($port);
  2255.                               // $port->setOrderNoExtension($orderNoExt);
  2256.                               // $port->addExtremity($extrmityB);
  2257.                               $port->setLink($linkMatch);
  2258.                               $port->setLinkExtension($extMatch);
  2259.                               $em->persist($port);
  2260.                               $em->persist($extrmityB);
  2261.                               //check if it's last link extension
  2262.                               //if it's last, DO NOTHING
  2263.                               // var_dump('hi');
  2264.                               // var_dump($extMatch->getSequenceNo());
  2265.                               // var_dump(count($linkMatch->getLinkExtension()));
  2266.                               if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  2267.                                 // // var_dump("entering ...");
  2268.                                 // //else get the last extension's extremity B's equipment
  2269.                                 // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  2270.                                 // $nextExtA = $nextExtension->getExtremityA();
  2271.                                 //
  2272.                                 // $nextPorts = array();
  2273.                                 // foreach ($nextExtA->getExtensionOrder() as $value) {
  2274.                                 //   $nextPorts[] = $value->getPort();
  2275.                                 // }
  2276.                                 //
  2277.                                 // // $nextPorts = $nextExtA->getPorts();
  2278.                                 // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  2279.                                 // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  2280.                                 // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  2281.                                 //
  2282.                                 // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2283.                                 // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2284.                                 //
  2285.                                 // //check if it's same as current modified link ext
  2286.                                 // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  2287.                                 //   // var_dump("entering not equals equipments...");
  2288.                                 //
  2289.                                 //   //if false, set the link and las link extension as INVALID
  2290.                                 //   $nextExtension->setIsValid(false);
  2291.                                 //   $em->persist($nextExtension);
  2292.                                 // }
  2293.                                 // else {
  2294.                                 //   // var_dump("entering checking ports...");
  2295.                                 //
  2296.                                 //     $nextExtension->setIsValid(true);
  2297.                                 //     $em->persist($nextExtension);
  2298.                                 //   //else get the next extension's extremity B's interface
  2299.                                 //   //check if it's 1:1
  2300.                                 //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2301.                                 //     // var_dump("entering checking 1 to 1...");
  2302.                                 //
  2303.                                 //     // if true, check ports are the same
  2304.                                 //     //if true, DO NOTHING
  2305.                                 //     //else set the link and las link extension as INVALID
  2306.                                 //     foreach ($nextPorts as $nextPort) {
  2307.                                 //       if ($nextPort->getId() != $port->getId()) {
  2308.                                 //         $nextExtension->setIsValid(false);
  2309.                                 //         $em->persist($nextExtension);
  2310.                                 //       }
  2311.                                 //       else {
  2312.                                 //         $nextExtension->setIsValid(true);
  2313.                                 //         $em->persist($nextExtension);
  2314.                                 //       }
  2315.                                 //     }
  2316.                                 //   }
  2317.                                 // }
  2318.                               TrunkController::validateNextExtension($em$linkMatch$extMatch$port);
  2319.                               }
  2320.                             }
  2321.                             $extrmityA $extMatch->getExtremityA();
  2322.                             $extAPorts $extrmityA->getExtensionOrder();
  2323.                             $tempIds = array();
  2324.                             foreach ($extAPorts as $value) {
  2325.                               $tempIds[] = $value->getPort()->getId();
  2326.                             }
  2327.                             if (in_array($matchedPort->getId(), $tempIds)) {
  2328.                               $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  2329.                               $orderNoExt $extensinOrder->getOrderNumber();
  2330.                               $em->remove($extensinOrder);
  2331.                               // $extrmityA->removePort($matchedPort);
  2332.                               $extensinOrder = new ExtensionOrder();
  2333.                               $extensinOrder->setOrderNumber($orderNoExt);
  2334.                               $extensinOrder->setPort($port);
  2335.                               $extensinOrder->setExtremity($extrmityA);
  2336.                               $port->addExtensionOrder($extensinOrder);
  2337.                               $extrmityA->addExtensionOrder($extensinOrder);
  2338.                               $em->persist($extensinOrder);
  2339.                               // $extrmityA->removePort($matchedPort);
  2340.                               // $extrmityA->addPort($port);
  2341.                               // $port->setOrderNoExtension($orderNoExt);
  2342.                               // $port->addExtremity($extrmityA);
  2343.                               $port->setLink($linkMatch);
  2344.                               $port->setLinkExtension($extMatch);
  2345.                               $em->persist($port);
  2346.                               $em->persist($extrmityA);
  2347.                               if ($extMatch->getSequenceNo() > 1) {
  2348.                                 // //else get the last extension's extremity B's equipment
  2349.                                 // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  2350.                                 // $lastExtB = $lastExtension->getExtremityB();
  2351.                                 //
  2352.                                 // $lastPorts = array();
  2353.                                 // foreach ($lastExtB->getExtensionOrder() as $value) {
  2354.                                 //   $lastPorts[] = $value->getPort();
  2355.                                 // }
  2356.                                 //
  2357.                                 // // $lastPorts = $lastExtB->getPorts();
  2358.                                 // // var_dump($lastPorts);
  2359.                                 // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  2360.                                 // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  2361.                                 // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  2362.                                 //
  2363.                                 // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2364.                                 // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2365.                                 //
  2366.                                 // //check if it's same as current modified link ext
  2367.                                 // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  2368.                                 //   //if false, set the link and las link extension as INVALID
  2369.                                 //   $lastExtension->setIsValid(false);
  2370.                                 //   $em->persist($lastExtension);
  2371.                                 // }
  2372.                                 // else {
  2373.                                 //   // var_dump('hi');
  2374.                                 //   $lastExtension->setIsValid(true);
  2375.                                 //   $em->persist($lastExtension);
  2376.                                 //   //else get the last extension's extremity B's interface
  2377.                                 //   //check if it's 1:1
  2378.                                 //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2379.                                 //     // if true, check ports are the same
  2380.                                 //     //if true, DO NOTHING
  2381.                                 //     //else set the link and las link extension as INVALID
  2382.                                 //     foreach ($lastPorts as $lastPort) {
  2383.                                 //       // var_dump($lastPort);
  2384.                                 //       if ($lastPort->getId() != $port->getId()) {
  2385.                                 //         $lastExtension->setIsValid(false);
  2386.                                 //         $em->persist($lastExtension);
  2387.                                 //       }
  2388.                                 //       else {
  2389.                                 //         $lastExtension->setIsValid(true);
  2390.                                 //         $em->persist($lastExtension);
  2391.                                 //       }
  2392.                                 //     }
  2393.                                 //   }
  2394.                                 // }
  2395.                                 TrunkController::validateLastExtension($em$linkMatch$extMatch$port);
  2396.                               }
  2397.                             }
  2398.                           }//end of check for continuity
  2399.                         }
  2400.                       }
  2401.                       else {
  2402.                         $tcf $tcfFound[$countTcf++];
  2403.                         $ext = new TrunkExtension();
  2404.                         $sequence_no $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
  2405.                         $ext->setTrunkCableFiber($tcf);
  2406.                         $ext->setTypeCable($typeCable);
  2407.                         $ext->setOperatorID($operatorId);
  2408.                         $ext->setPortB($port);
  2409.                         $ext->setSequenceNo($sequence_no);
  2410.                         $em->persist($ext);
  2411.                         //check for continuity
  2412.                         //get the link extension if any matches
  2413.                         $extMatch null;
  2414.                         $matchedPort null;
  2415.                         // var_dump($sequence_no);
  2416.                         if ($sequence_no == 1) {
  2417.                           $matchedPort $tcf->getPortB();
  2418.                         }
  2419.                         else {
  2420.                           $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$sequence_no-1]);
  2421.                           $matchedPort $lastTrunkExt->getPortB();
  2422.                         }
  2423.                         // var_dump($matchedPort);
  2424.                         if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
  2425.                           $duplexPort true;
  2426.                           $counter++;
  2427.                         }
  2428.                         else {
  2429.                           $duplexPort false;
  2430.                           $counter 2;
  2431.                         }
  2432.                         $extMatch null;
  2433.                         $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  2434.                         if ($extId) {
  2435.                           $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  2436.                         }
  2437.                         // $extMatch = $matchedPort->getLinkExtension();
  2438.                         if ($extMatch) {
  2439.                           // var_dump($extMatch->getId());
  2440.                           // $orderNoExt = $matchedPort->getOrderNoExtension();
  2441.                           if ($counter == 2) {
  2442.                             $matchedPort->setLink(null);
  2443.                             $matchedPort->setLinkExtension(null);
  2444.                             // $matchedPort->setOrderNoExtension(1);
  2445.                             $em->persist($matchedPort);
  2446.                             // $counter = 0;
  2447.                           }
  2448.                           $linkMatch $extMatch->getLink();
  2449.                           $extrmityB $extMatch->getExtremityB();
  2450.                           $extBPorts $extrmityB->getExtensionOrder();
  2451.                           $tempIds = array();
  2452.                           foreach ($extBPorts as $value) {
  2453.                             $tempIds[] = $value->getPort()->getId();
  2454.                           }
  2455.                           // var_dump($tempIds);
  2456.                           if (in_array($matchedPort->getId(), $tempIds)) {
  2457.                             $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  2458.                             $orderNoExt $extensinOrder->getOrderNumber();
  2459.                             if ($counter == && $duplexPort) {
  2460.                               var_dump($duplexPort);
  2461.                               $orderNoExt 2;
  2462.                               $em->remove($extensinOrder);
  2463.                               $duplexPort false;
  2464.                               $counter 0;
  2465.                             }
  2466.                             elseif ($counter == 2) {
  2467.                               $em->remove($extensinOrder);
  2468.                               $counter 0;
  2469.                             }
  2470.                             // $extrmityB->removePort($matchedPort);
  2471.                             $extensinOrder = new ExtensionOrder();
  2472.                             $extensinOrder->setOrderNumber($orderNoExt);
  2473.                             $extensinOrder->setPort($port);
  2474.                             $extensinOrder->setExtremity($extrmityB);
  2475.                             $port->addExtensionOrder($extensinOrder);
  2476.                             $extrmityB->addExtensionOrder($extensinOrder);
  2477.                             $em->persist($extensinOrder);
  2478.                             // $extrmityB->addPort($port);
  2479.                             // $port->setOrderNoExtension($orderNoExt);
  2480.                             // $port->addExtremity($extrmityB);
  2481.                             $port->setLink($linkMatch);
  2482.                             $port->setLinkExtension($extMatch);
  2483.                             $em->persist($port);
  2484.                             $em->persist($extrmityB);
  2485.                             //check if it's last link extension
  2486.                             //if it's last, DO NOTHING
  2487.                             // var_dump('hi');
  2488.                             // var_dump($extMatch->getSequenceNo());
  2489.                             // var_dump(count($linkMatch->getLinkExtension()));
  2490.                             if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  2491.                               // // var_dump("entering ...");
  2492.                               // //else get the last extension's extremity B's equipment
  2493.                               // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  2494.                               // $nextExtA = $nextExtension->getExtremityA();
  2495.                               //
  2496.                               // $nextPorts = array();
  2497.                               // foreach ($nextExtA->getExtensionOrder() as $value) {
  2498.                               //   $nextPorts[] = $value->getPort();
  2499.                               // }
  2500.                               //
  2501.                               // // $nextPorts = $nextExtA->getPorts();
  2502.                               // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  2503.                               // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  2504.                               // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  2505.                               //
  2506.                               // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2507.                               // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2508.                               //
  2509.                               // //check if it's same as current modified link ext
  2510.                               // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  2511.                               //   // var_dump("entering not equals equipments...");
  2512.                               //
  2513.                               //   //if false, set the link and las link extension as INVALID
  2514.                               //   $nextExtension->setIsValid(false);
  2515.                               //   $em->persist($nextExtension);
  2516.                               // }
  2517.                               // else {
  2518.                               //   // var_dump("entering checking ports...");
  2519.                               //
  2520.                               //     $nextExtension->setIsValid(true);
  2521.                               //     $em->persist($nextExtension);
  2522.                               //   //else get the next extension's extremity B's interface
  2523.                               //   //check if it's 1:1
  2524.                               //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2525.                               //     // var_dump("entering checking 1 to 1...");
  2526.                               //
  2527.                               //     // if true, check ports are the same
  2528.                               //     //if true, DO NOTHING
  2529.                               //     //else set the link and las link extension as INVALID
  2530.                               //     foreach ($nextPorts as $nextPort) {
  2531.                               //       if ($nextPort->getId() != $port->getId()) {
  2532.                               //         $nextExtension->setIsValid(false);
  2533.                               //         $em->persist($nextExtension);
  2534.                               //       }
  2535.                               //       else {
  2536.                               //         $nextExtension->setIsValid(true);
  2537.                               //         $em->persist($nextExtension);
  2538.                               //       }
  2539.                               //     }
  2540.                               //   }
  2541.                               // }
  2542.                               TrunkController::validateNextExtension($em$linkMatch$extMatch$port);
  2543.                             }
  2544.                           }
  2545.                           $extrmityA $extMatch->getExtremityA();
  2546.                           $extAPorts $extrmityA->getExtensionOrder();
  2547.                           $tempIds = array();
  2548.                           foreach ($extAPorts as $value) {
  2549.                             $tempIds[] = $value->getPort()->getId();
  2550.                           }
  2551.                           if (in_array($matchedPort->getId(), $tempIds)) {
  2552.                             $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  2553.                             $orderNoExt $extensinOrder->getOrderNumber();
  2554.                             $em->remove($extensinOrder);
  2555.                             // $extrmityA->removePort($matchedPort);
  2556.                             $extensinOrder = new ExtensionOrder();
  2557.                             $extensinOrder->setOrderNumber($orderNoExt);
  2558.                             $extensinOrder->setPort($port);
  2559.                             $extensinOrder->setExtremity($extrmityA);
  2560.                             $port->addExtensionOrder($extensinOrder);
  2561.                             $extrmityA->addExtensionOrder($extensinOrder);
  2562.                             $em->persist($extensinOrder);
  2563.                             // $extrmityA->removePort($matchedPort);
  2564.                             // $extrmityA->addPort($port);
  2565.                             // $port->setOrderNoExtension($orderNoExt);
  2566.                             // $port->addExtremity($extrmityA);
  2567.                             $port->setLink($linkMatch);
  2568.                             $port->setLinkExtension($extMatch);
  2569.                             $em->persist($port);
  2570.                             $em->persist($extrmityA);
  2571.                             if ($extMatch->getSequenceNo() > 1) {
  2572.                               // //else get the last extension's extremity B's equipment
  2573.                               // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  2574.                               // $lastExtB = $lastExtension->getExtremityB();
  2575.                               //
  2576.                               // $lastPorts = array();
  2577.                               // foreach ($lastExtB->getExtensionOrder() as $value) {
  2578.                               //   $lastPorts[] = $value->getPort();
  2579.                               // }
  2580.                               //
  2581.                               // // $lastPorts = $lastExtB->getPorts();
  2582.                               // // var_dump($lastPorts);
  2583.                               // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  2584.                               // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  2585.                               // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  2586.                               //
  2587.                               // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2588.                               // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2589.                               //
  2590.                               // //check if it's same as current modified link ext
  2591.                               // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  2592.                               //   //if false, set the link and las link extension as INVALID
  2593.                               //   $lastExtension->setIsValid(false);
  2594.                               //   $em->persist($lastExtension);
  2595.                               // }
  2596.                               // else {
  2597.                               //   // var_dump('hi');
  2598.                               //   $lastExtension->setIsValid(true);
  2599.                               //   $em->persist($lastExtension);
  2600.                               //   //else get the last extension's extremity B's interface
  2601.                               //   //check if it's 1:1
  2602.                               //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2603.                               //     // if true, check ports are the same
  2604.                               //     //if true, DO NOTHING
  2605.                               //     //else set the link and las link extension as INVALID
  2606.                               //     foreach ($lastPorts as $lastPort) {
  2607.                               //       // var_dump($lastPort);
  2608.                               //       if ($lastPort->getId() != $port->getId()) {
  2609.                               //         $lastExtension->setIsValid(false);
  2610.                               //         $em->persist($lastExtension);
  2611.                               //       }
  2612.                               //       else {
  2613.                               //         $lastExtension->setIsValid(true);
  2614.                               //         $em->persist($lastExtension);
  2615.                               //       }
  2616.                               //     }
  2617.                               //   }
  2618.                               // }
  2619.                               TrunkController::validateLastExtension($em$linkMatch$extMatch$port);
  2620.                             }
  2621.                           }
  2622.                         }//end of check for continuity
  2623.                       }
  2624.                 }
  2625.             }
  2626.               }
  2627.             }
  2628.           }
  2629.         }
  2630.         else {
  2631.           $interfacesB $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
  2632.           foreach ($interfacesB as $interface) {
  2633.             //ADDED by Soupra
  2634.             $typeLinkTitle $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
  2635.             if ($equipmentTypeB == 1) {
  2636.               $interface_id $interface->getInterfaceGeneric()->getId(); // get generic interfaces
  2637.             } else {
  2638.               $interface_id $interface->getId(); // get specific interfaces
  2639.             }
  2640.             //check if interface is selected
  2641.             if (isset($_POST['interfaceB_' $interface_id])) {
  2642.               $ports $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
  2643.               foreach ($ports as $port) {
  2644.                 //get the cable which corresponds to the portA
  2645.                 $usedTmpA $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
  2646.                 $usedTmpB $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  2647.                 $usedTmpExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  2648.                 if($usedTmpA == null && $usedTmpB == null && $usedTmpExt == null){
  2649.                     if ($typeLinkTitle == "Duplex") {
  2650.                       for ($i=0$i 2$i++) {
  2651.                         $tcf $tcfFound[$countTcf++];
  2652.                         $ext = new TrunkExtension();
  2653.                         $sequence_no $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
  2654.                         $ext->setTrunkCableFiber($tcf);
  2655.                         $ext->setTypeCable($typeCable);
  2656.                         $ext->setOperatorID($operatorId);
  2657.                         $ext->setPortB($port);
  2658.                         $ext->setSequenceNo($sequence_no);
  2659.                         $em->persist($ext);
  2660.                         //check for continuity
  2661.                         //get the link extension if any matches
  2662.                         $extMatch null;
  2663.                         $matchedPort null;
  2664.                         // var_dump($sequence_no);
  2665.                         if ($sequence_no == 1) {
  2666.                           $matchedPort $tcf->getPortB();
  2667.                         }
  2668.                         else {
  2669.                           $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$sequence_no-1]);
  2670.                           $matchedPort $lastTrunkExt->getPortB();
  2671.                         }
  2672.                         // var_dump($matchedPort);
  2673.                         if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
  2674.                           $duplexPort true;
  2675.                           $counter++;
  2676.                         }
  2677.                         else {
  2678.                           $duplexPort false;
  2679.                           $counter 2;
  2680.                         }
  2681.                         $extMatch null;
  2682.                         $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  2683.                         if ($extId) {
  2684.                           $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  2685.                         }
  2686.                         // $extMatch = $matchedPort->getLinkExtension();
  2687.                         if ($extMatch) {
  2688.                           // var_dump($extMatch->getId());
  2689.                           // $orderNoExt = $matchedPort->getOrderNoExtension();
  2690.                           if ($counter == 2) {
  2691.                             $matchedPort->setLink(null);
  2692.                             $matchedPort->setLinkExtension(null);
  2693.                             // $matchedPort->setOrderNoExtension(1);
  2694.                             $em->persist($matchedPort);
  2695.                             // $counter = 0;
  2696.                           }
  2697.                           $linkMatch $extMatch->getLink();
  2698.                           $extrmityB $extMatch->getExtremityB();
  2699.                           $extBPorts $extrmityB->getExtensionOrder();
  2700.                           $tempIds = array();
  2701.                           foreach ($extBPorts as $value) {
  2702.                             $tempIds[] = $value->getPort()->getId();
  2703.                           }
  2704.                           // var_dump($tempIds);
  2705.                           if (in_array($matchedPort->getId(), $tempIds)) {
  2706.                             $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  2707.                             $orderNoExt $extensinOrder->getOrderNumber();
  2708.                             if ($counter == && $duplexPort) {
  2709.                               var_dump($duplexPort);
  2710.                               $orderNoExt 2;
  2711.                               $em->remove($extensinOrder);
  2712.                               $duplexPort false;
  2713.                               $counter 0;
  2714.                             }
  2715.                             elseif ($counter == 2) {
  2716.                               $em->remove($extensinOrder);
  2717.                               $counter 0;
  2718.                             }
  2719.                             // $extrmityB->removePort($matchedPort);
  2720.                             $extensinOrder = new ExtensionOrder();
  2721.                             $extensinOrder->setOrderNumber($orderNoExt);
  2722.                             $extensinOrder->setPort($port);
  2723.                             $extensinOrder->setExtremity($extrmityB);
  2724.                             $port->addExtensionOrder($extensinOrder);
  2725.                             $extrmityB->addExtensionOrder($extensinOrder);
  2726.                             $em->persist($extensinOrder);
  2727.                             // $extrmityB->addPort($port);
  2728.                             // $port->setOrderNoExtension($orderNoExt);
  2729.                             // $port->addExtremity($extrmityB);
  2730.                             $port->setLink($linkMatch);
  2731.                             $port->setLinkExtension($extMatch);
  2732.                             $em->persist($port);
  2733.                             $em->persist($extrmityB);
  2734.                             //check if it's last link extension
  2735.                             //if it's last, DO NOTHING
  2736.                             // var_dump('hi');
  2737.                             // var_dump($extMatch->getSequenceNo());
  2738.                             // var_dump(count($linkMatch->getLinkExtension()));
  2739.                             if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  2740.                               // // var_dump("entering ...");
  2741.                               // //else get the last extension's extremity B's equipment
  2742.                               // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  2743.                               // $nextExtA = $nextExtension->getExtremityA();
  2744.                               //
  2745.                               // $nextPorts = array();
  2746.                               // foreach ($nextExtA->getExtensionOrder() as $value) {
  2747.                               //   $nextPorts[] = $value->getPort();
  2748.                               // }
  2749.                               //
  2750.                               // // $nextPorts = $nextExtA->getPorts();
  2751.                               // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  2752.                               // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  2753.                               // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  2754.                               //
  2755.                               // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2756.                               // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2757.                               //
  2758.                               // //check if it's same as current modified link ext
  2759.                               // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  2760.                               //   // var_dump("entering not equals equipments...");
  2761.                               //
  2762.                               //   //if false, set the link and las link extension as INVALID
  2763.                               //   $nextExtension->setIsValid(false);
  2764.                               //   $em->persist($nextExtension);
  2765.                               // }
  2766.                               // else {
  2767.                               //   // var_dump("entering checking ports...");
  2768.                               //
  2769.                               //     $nextExtension->setIsValid(true);
  2770.                               //     $em->persist($nextExtension);
  2771.                               //   //else get the next extension's extremity B's interface
  2772.                               //   //check if it's 1:1
  2773.                               //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2774.                               //     // var_dump("entering checking 1 to 1...");
  2775.                               //
  2776.                               //     // if true, check ports are the same
  2777.                               //     //if true, DO NOTHING
  2778.                               //     //else set the link and las link extension as INVALID
  2779.                               //     foreach ($nextPorts as $nextPort) {
  2780.                               //       if ($nextPort->getId() != $port->getId()) {
  2781.                               //         $nextExtension->setIsValid(false);
  2782.                               //         $em->persist($nextExtension);
  2783.                               //       }
  2784.                               //       else {
  2785.                               //         $nextExtension->setIsValid(true);
  2786.                               //         $em->persist($nextExtension);
  2787.                               //       }
  2788.                               //     }
  2789.                               //   }
  2790.                               // }
  2791.                               TrunkController::validateNextExtension($em$linkMatch$extMatch$port);
  2792.                             }
  2793.                           }
  2794.                           $extrmityA $extMatch->getExtremityA();
  2795.                           $extAPorts $extrmityA->getExtensionOrder();
  2796.                           $tempIds = array();
  2797.                           foreach ($extAPorts as $value) {
  2798.                             $tempIds[] = $value->getPort()->getId();
  2799.                           }
  2800.                           if (in_array($matchedPort->getId(), $tempIds)) {
  2801.                             $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  2802.                             $orderNoExt $extensinOrder->getOrderNumber();
  2803.                             $em->remove($extensinOrder);
  2804.                             // $extrmityA->removePort($matchedPort);
  2805.                             $extensinOrder = new ExtensionOrder();
  2806.                             $extensinOrder->setOrderNumber($orderNoExt);
  2807.                             $extensinOrder->setPort($port);
  2808.                             $extensinOrder->setExtremity($extrmityA);
  2809.                             $port->addExtensionOrder($extensinOrder);
  2810.                             $extrmityA->addExtensionOrder($extensinOrder);
  2811.                             $em->persist($extensinOrder);
  2812.                             // $extrmityA->removePort($matchedPort);
  2813.                             // $extrmityA->addPort($port);
  2814.                             // $port->setOrderNoExtension($orderNoExt);
  2815.                             // $port->addExtremity($extrmityA);
  2816.                             $port->setLink($linkMatch);
  2817.                             $port->setLinkExtension($extMatch);
  2818.                             $em->persist($port);
  2819.                             $em->persist($extrmityA);
  2820.                             if ($extMatch->getSequenceNo() > 1) {
  2821.                               // //else get the last extension's extremity B's equipment
  2822.                               // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  2823.                               // $lastExtB = $lastExtension->getExtremityB();
  2824.                               //
  2825.                               // $lastPorts = array();
  2826.                               // foreach ($lastExtB->getExtensionOrder() as $value) {
  2827.                               //   $lastPorts[] = $value->getPort();
  2828.                               // }
  2829.                               //
  2830.                               // // $lastPorts = $lastExtB->getPorts();
  2831.                               // // var_dump($lastPorts);
  2832.                               // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  2833.                               // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  2834.                               // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  2835.                               //
  2836.                               // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2837.                               // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2838.                               //
  2839.                               // //check if it's same as current modified link ext
  2840.                               // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  2841.                               //   //if false, set the link and las link extension as INVALID
  2842.                               //   $lastExtension->setIsValid(false);
  2843.                               //   $em->persist($lastExtension);
  2844.                               // }
  2845.                               // else {
  2846.                               //   // var_dump('hi');
  2847.                               //   $lastExtension->setIsValid(true);
  2848.                               //   $em->persist($lastExtension);
  2849.                               //   //else get the last extension's extremity B's interface
  2850.                               //   //check if it's 1:1
  2851.                               //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2852.                               //     // if true, check ports are the same
  2853.                               //     //if true, DO NOTHING
  2854.                               //     //else set the link and las link extension as INVALID
  2855.                               //     foreach ($lastPorts as $lastPort) {
  2856.                               //       // var_dump($lastPort);
  2857.                               //       if ($lastPort->getId() != $port->getId()) {
  2858.                               //         $lastExtension->setIsValid(false);
  2859.                               //         $em->persist($lastExtension);
  2860.                               //       }
  2861.                               //       else {
  2862.                               //         $lastExtension->setIsValid(true);
  2863.                               //         $em->persist($lastExtension);
  2864.                               //       }
  2865.                               //     }
  2866.                               //   }
  2867.                               // }
  2868.                               TrunkController::validateLastExtension($em$linkMatch$extMatch$port);
  2869.                             }
  2870.                           }
  2871.                         }//end of check for continuity
  2872.                       }
  2873.                     }
  2874.                     else {
  2875.                       $tcf $tcfFound[$countTcf++];
  2876.                       $ext = new TrunkExtension();
  2877.                       $sequence_no $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
  2878.                       $ext->setTrunkCableFiber($tcf);
  2879.                       $ext->setTypeCable($typeCable);
  2880.                       $ext->setOperatorID($operatorId);
  2881.                       $ext->setPortB($port);
  2882.                       $ext->setSequenceNo($sequence_no);
  2883.                       $em->persist($ext);
  2884.                       //check for continuity
  2885.                       //get the link extension if any matches
  2886.                       $extMatch null;
  2887.                       $matchedPort null;
  2888.                       // var_dump($sequence_no);
  2889.                       if ($sequence_no == 1) {
  2890.                         $matchedPort $tcf->getPortB();
  2891.                       }
  2892.                       else {
  2893.                         $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf"sequenceNo"=>$sequence_no-1]);
  2894.                         $matchedPort $lastTrunkExt->getPortB();
  2895.                       }
  2896.                       // var_dump($matchedPort);
  2897.                       if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
  2898.                         $duplexPort true;
  2899.                         $counter++;
  2900.                       }
  2901.                       else {
  2902.                         $duplexPort false;
  2903.                         $counter 2;
  2904.                       }
  2905.                       $extMatch null;
  2906.                       $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  2907.                       if ($extId) {
  2908.                         $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  2909.                       }
  2910.                       // $extMatch = $matchedPort->getLinkExtension();
  2911.                       if ($extMatch) {
  2912.                         // var_dump($extMatch->getId());
  2913.                         // $orderNoExt = $matchedPort->getOrderNoExtension();
  2914.                         if ($counter == 2) {
  2915.                           $matchedPort->setLink(null);
  2916.                           $matchedPort->setLinkExtension(null);
  2917.                           // $matchedPort->setOrderNoExtension(1);
  2918.                           $em->persist($matchedPort);
  2919.                           // $counter = 0;
  2920.                         }
  2921.                         $linkMatch $extMatch->getLink();
  2922.                         $extrmityB $extMatch->getExtremityB();
  2923.                         $extBPorts $extrmityB->getExtensionOrder();
  2924.                         $tempIds = array();
  2925.                         foreach ($extBPorts as $value) {
  2926.                           $tempIds[] = $value->getPort()->getId();
  2927.                         }
  2928.                         // var_dump($tempIds);
  2929.                         if (in_array($matchedPort->getId(), $tempIds)) {
  2930.                           $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  2931.                           $orderNoExt $extensinOrder->getOrderNumber();
  2932.                           if ($counter == && $duplexPort) {
  2933.                             var_dump($duplexPort);
  2934.                             $orderNoExt 2;
  2935.                             $em->remove($extensinOrder);
  2936.                             $duplexPort false;
  2937.                             $counter 0;
  2938.                           }
  2939.                           elseif ($counter == 2) {
  2940.                             $em->remove($extensinOrder);
  2941.                             $counter 0;
  2942.                           }
  2943.                           // $extrmityB->removePort($matchedPort);
  2944.                           $extensinOrder = new ExtensionOrder();
  2945.                           $extensinOrder->setOrderNumber($orderNoExt);
  2946.                           $extensinOrder->setPort($port);
  2947.                           $extensinOrder->setExtremity($extrmityB);
  2948.                           $port->addExtensionOrder($extensinOrder);
  2949.                           $extrmityB->addExtensionOrder($extensinOrder);
  2950.                           $em->persist($extensinOrder);
  2951.                           // $extrmityB->addPort($port);
  2952.                           // $port->setOrderNoExtension($orderNoExt);
  2953.                           // $port->addExtremity($extrmityB);
  2954.                           $port->setLink($linkMatch);
  2955.                           $port->setLinkExtension($extMatch);
  2956.                           $em->persist($port);
  2957.                           $em->persist($extrmityB);
  2958.                           //check if it's last link extension
  2959.                           //if it's last, DO NOTHING
  2960.                           // var_dump('hi');
  2961.                           // var_dump($extMatch->getSequenceNo());
  2962.                           // var_dump(count($linkMatch->getLinkExtension()));
  2963.                           if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  2964.                             // // var_dump("entering ...");
  2965.                             // //else get the last extension's extremity B's equipment
  2966.                             // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  2967.                             // $nextExtA = $nextExtension->getExtremityA();
  2968.                             //
  2969.                             // $nextPorts = array();
  2970.                             // foreach ($nextExtA->getExtensionOrder() as $value) {
  2971.                             //   $nextPorts[] = $value->getPort();
  2972.                             // }
  2973.                             //
  2974.                             // // $nextPorts = $nextExtA->getPorts();
  2975.                             // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  2976.                             // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  2977.                             // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  2978.                             //
  2979.                             // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  2980.                             // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  2981.                             //
  2982.                             // //check if it's same as current modified link ext
  2983.                             // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  2984.                             //   // var_dump("entering not equals equipments...");
  2985.                             //
  2986.                             //   //if false, set the link and las link extension as INVALID
  2987.                             //   $nextExtension->setIsValid(false);
  2988.                             //   $em->persist($nextExtension);
  2989.                             // }
  2990.                             // else {
  2991.                             //   // var_dump("entering checking ports...");
  2992.                             //
  2993.                             //     $nextExtension->setIsValid(true);
  2994.                             //     $em->persist($nextExtension);
  2995.                             //   //else get the next extension's extremity B's interface
  2996.                             //   //check if it's 1:1
  2997.                             //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  2998.                             //     // var_dump("entering checking 1 to 1...");
  2999.                             //
  3000.                             //     // if true, check ports are the same
  3001.                             //     //if true, DO NOTHING
  3002.                             //     //else set the link and las link extension as INVALID
  3003.                             //     foreach ($nextPorts as $nextPort) {
  3004.                             //       if ($nextPort->getId() != $port->getId()) {
  3005.                             //         $nextExtension->setIsValid(false);
  3006.                             //         $em->persist($nextExtension);
  3007.                             //       }
  3008.                             //       else {
  3009.                             //         $nextExtension->setIsValid(true);
  3010.                             //         $em->persist($nextExtension);
  3011.                             //       }
  3012.                             //     }
  3013.                             //   }
  3014.                             // }
  3015.                             TrunkController::validateNextExtension($em$linkMatch$extMatch$port);
  3016.                           }
  3017.                         }
  3018.                         $extrmityA $extMatch->getExtremityA();
  3019.                         $extAPorts $extrmityA->getExtensionOrder();
  3020.                         $tempIds = array();
  3021.                         foreach ($extAPorts as $value) {
  3022.                           $tempIds[] = $value->getPort()->getId();
  3023.                         }
  3024.                         if (in_array($matchedPort->getId(), $tempIds)) {
  3025.                           $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  3026.                           $orderNoExt $extensinOrder->getOrderNumber();
  3027.                           $em->remove($extensinOrder);
  3028.                           // $extrmityA->removePort($matchedPort);
  3029.                           $extensinOrder = new ExtensionOrder();
  3030.                           $extensinOrder->setOrderNumber($orderNoExt);
  3031.                           $extensinOrder->setPort($port);
  3032.                           $extensinOrder->setExtremity($extrmityA);
  3033.                           $port->addExtensionOrder($extensinOrder);
  3034.                           $extrmityA->addExtensionOrder($extensinOrder);
  3035.                           $em->persist($extensinOrder);
  3036.                           // $extrmityA->removePort($matchedPort);
  3037.                           // $extrmityA->addPort($port);
  3038.                           // $port->setOrderNoExtension($orderNoExt);
  3039.                           // $port->addExtremity($extrmityA);
  3040.                           $port->setLink($linkMatch);
  3041.                           $port->setLinkExtension($extMatch);
  3042.                           $em->persist($port);
  3043.                           $em->persist($extrmityA);
  3044.                           if ($extMatch->getSequenceNo() > 1) {
  3045.                             // //else get the last extension's extremity B's equipment
  3046.                             // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  3047.                             // $lastExtB = $lastExtension->getExtremityB();
  3048.                             //
  3049.                             // $lastPorts = array();
  3050.                             // foreach ($lastExtB->getExtensionOrder() as $value) {
  3051.                             //   $lastPorts[] = $value->getPort();
  3052.                             // }
  3053.                             //
  3054.                             // // $lastPorts = $lastExtB->getPorts();
  3055.                             // // var_dump($lastPorts);
  3056.                             // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  3057.                             // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  3058.                             // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  3059.                             //
  3060.                             // $currentInterfaceSpecific = $port->getInterfaceSpecific();
  3061.                             // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  3062.                             //
  3063.                             // //check if it's same as current modified link ext
  3064.                             // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  3065.                             //   //if false, set the link and las link extension as INVALID
  3066.                             //   $lastExtension->setIsValid(false);
  3067.                             //   $em->persist($lastExtension);
  3068.                             // }
  3069.                             // else {
  3070.                             //   // var_dump('hi');
  3071.                             //   $lastExtension->setIsValid(true);
  3072.                             //   $em->persist($lastExtension);
  3073.                             //   //else get the last extension's extremity B's interface
  3074.                             //   //check if it's 1:1
  3075.                             //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  3076.                             //     // if true, check ports are the same
  3077.                             //     //if true, DO NOTHING
  3078.                             //     //else set the link and las link extension as INVALID
  3079.                             //     foreach ($lastPorts as $lastPort) {
  3080.                             //       // var_dump($lastPort);
  3081.                             //       if ($lastPort->getId() != $port->getId()) {
  3082.                             //         $lastExtension->setIsValid(false);
  3083.                             //         $em->persist($lastExtension);
  3084.                             //       }
  3085.                             //       else {
  3086.                             //         $lastExtension->setIsValid(true);
  3087.                             //         $em->persist($lastExtension);
  3088.                             //       }
  3089.                             //     }
  3090.                             //   }
  3091.                             // }
  3092.                             TrunkController::validateLastExtension($em$linkMatch$extMatch$port);
  3093.                           }
  3094.                         }
  3095.                       }//end of check for continuity
  3096.                     }
  3097.             }
  3098.         }
  3099.               }
  3100.             }
  3101.           }
  3102.         }
  3103.       }
  3104.       $em->flush();
  3105.       // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  3106.       // $cache = new FilesystemAdapter();
  3107.       // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  3108.       // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  3109.     return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  3110. }
  3111.    /**
  3112.     * @Route("/trunk/list", name="trunk_list")
  3113.     * trunk list page ???
  3114.     */
  3115.    public function listAction(Request $requestLoggerInterface $loggerTranslatorInterface $translator)
  3116.   {
  3117.        // $cache = new FilesystemAdapter();
  3118.        // $trunkList = $cache->getItem('pagerfanta.list.trunk');
  3119.        // $trunkList->expiresAfter(1);
  3120.        $trunks null;
  3121.        // if (!$trunkList->isHit()) {
  3122.          //get all the trunks
  3123.          $trunks $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
  3124.          foreach ($trunks as $trunk){
  3125.            $usedPorts 0;
  3126.            $operators = [];
  3127.            $operators[] = $trunk->getOperatorID();
  3128.            $tcfs $trunk->getCableFiber();
  3129.            if ( !($tcfs->isEmpty()) ) {
  3130.              //get the first equipment ???
  3131.              $firstTcf $tcfs[0];
  3132.              $eqA $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  3133.              $trunk->eqA $eqA;
  3134.              //MODIFIED on 28 janvier 2019
  3135.              $portB $firstTcf->getPortB();
  3136.              if($portB){
  3137.                  $eqB $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  3138.              }
  3139.              else{
  3140.                  $eqB null;
  3141.              }
  3142.              foreach ($tcfs as $tcf) {
  3143.                  if (!in_array($tcf->getOperatorID(), $operators)){
  3144.                      if ($tcf->getOperatorID()) {
  3145.                          $operators[] =  $tcf->getOperatorID();
  3146.                      }
  3147.                  }
  3148.                $extensions $tcf->getExtensions();
  3149.                if ($extensions) {
  3150.                  foreach ($extensions as $extension) {
  3151.                      //MODIFIED on 28 janvier 2019
  3152.                      $portBtemp $extension->getPortB();
  3153.                      if($portBtemp){
  3154.                          $eqB $portBtemp->getInterfaceSpecific()->getEquipmentSpecific();
  3155.                      }
  3156.                    if (!in_array($extension->getOperatorID(), $operators)){
  3157.                        if ($extension->getOperatorID()) {
  3158.                            $operators[] = $extension->getOperatorID();
  3159.                        }
  3160.                    }
  3161.                  }
  3162.                }
  3163.                $portA $tcf->getPortA();
  3164.                $typeLnk $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
  3165.                if (count($portA->getExtensionOrder()) > 0){
  3166.                  $usedPorts++;
  3167.                }
  3168.                // $linkExtA =  $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portA' => $portA]);
  3169.                // $linkExtB =  $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portB' => $portA]);
  3170.                // //ADDED by Soupra
  3171.                // if (!$linkExtA && !$linkExtB){
  3172.                //   $freePorts++;
  3173.                //
  3174.                // }
  3175.              }
  3176.              //get the last equipment ???
  3177.              $trunk->eqB $eqB;
  3178.            }
  3179.            $trunk->operators $operators;
  3180.            $trunk->freePorts $trunk->getCapacity() - $usedPorts;
  3181.          }
  3182.        //   $cache->save($trunkList->set($trunks));
  3183.        // }
  3184.        // else {
  3185.        //   $trunks = $trunkList->get();
  3186.        //   // var_dump($links);
  3187.        // }
  3188.        // $adapter = new ArrayAdapter($trunks);
  3189.        // $pagerfanta = new Pagerfanta($adapter);
  3190.        $pageLength $request->query->get("pageLength"$this->getParameter("trunk.maxPerPage"));
  3191.        // if ($pageLength == "Tout") {
  3192.        //   $pagerfanta->setMaxPerPage(count($trunks)); // 10 by default
  3193.        // }
  3194.        // else {
  3195.        //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  3196.        // }
  3197.        // // $this->container->setParameter("link.maxPerPage", $pageLength);
  3198.        // $page = $request->query->get("page", 1);
  3199.        // $pagerfanta->setCurrentPage($page);
  3200.        $logger->info(count($trunks));
  3201.        // $logger->info(count($pagerfanta->getCurrentPageResults()));
  3202.        return $this->render('trunk/list.html.twig', [
  3203.            'action' => 'list',
  3204.            'page_title' => $translator->trans('Trunks'),
  3205.            'list' => $trunks,
  3206.            // 'my_pager' => $pagerfanta,
  3207.            'pageLength' => $pageLength,
  3208.        ]);
  3209.    }
  3210.    /**
  3211.     * @Route("/trunk/usage/all", name="trunk_usage_all")
  3212.     */
  3213.    public function overviewListFullAction(Request $requestTranslatorInterface $translator)
  3214.   {
  3215.        $list = [];
  3216.        $maxPorts 0;
  3217.        //get all the ports used by Links
  3218.        $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  3219.        $portsAll = array();
  3220.        foreach ($portsAllTemp as $tempArray) {
  3221.          foreach ($tempArray as $key => $value) {
  3222.            $portsAll[] = $value;
  3223.          }
  3224.        }
  3225.        // $cache = new FilesystemAdapter();
  3226.        // $trunkList = $cache->getItem('pagerfanta.list.overview.trunk"');
  3227.        // $maxPortsFromCache = $cache->getItem('pagerfanta.list.overview.maxPorts"');
  3228.        //
  3229.        // if (!$trunkList->isHit()) {
  3230.          $trunks $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
  3231.          foreach ($trunks as $trunk){
  3232.            $eqBArray = array();
  3233.            // $eqBArray = [];
  3234.            $tcfs $trunk->getCableFiber();
  3235.            if ( !($tcfs->isEmpty()) ) {
  3236.              foreach ($tcfs as $firstTcf) {
  3237.              $eqA $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  3238.              //check if eqA is modulaire
  3239.              // if ($eqATemp->isModule()) {
  3240.              //   foreach ($eqATemp->getParent()->getModules() as $value) {
  3241.              //     $eqAArray[] = $value;
  3242.              //   }
  3243.              // }
  3244.              // else {
  3245.              //   $eqAArray[] = $eqATemp;
  3246.              // }
  3247.              $eqB null;
  3248.              if (count($firstTcf->getExtensions()) > 0) {
  3249.                $trunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
  3250.                $eqB $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  3251.              }
  3252.              else {
  3253.                $eqB $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  3254.              }
  3255.              //check if eqB is modulaire
  3256.              // if ($eqBTemp->isModule()) {
  3257.              //   foreach ($eqBTemp->getParent()->getModules() as $value) {
  3258.              //     $eqBArray[] = $value;
  3259.              //   }
  3260.              // }
  3261.              // else {
  3262.              //   $eqBArray[] = $eqBTemp;
  3263.              // }
  3264.              // var_dump($eqA->getId());
  3265.              if (!in_array($eqA->getId(), $eqBArray)) {
  3266.                $trunk->eqA $eqA;
  3267.                $res $this->createEquipment($trunk$eqA$portsAll$maxPorts);
  3268.                $list[] = $res["eq"];
  3269.                $maxPorts $res["maxPorts"];
  3270.                $eqBArray[] = $eqA->getId();
  3271.              }
  3272.              // $rackTitle = $eqA->getRack()->getTitle();
  3273.              //
  3274.              //     $eq['trunkID'] = $trunk->getTrunkID();
  3275.              //     $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  3276.              //     $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  3277.              //     $eq['rack'] = $rackTitle;
  3278.              //     $eq['equipment'] = $eqA->getEquipmentSpecificName();
  3279.              //     $eq['interfaces'] = [];
  3280.              //
  3281.              //     $interfaces = $eqA->getInterfaceSpecific();
  3282.              //     foreach ($interfaces as $interface) {
  3283.              //         // var_dump($interface->getId());
  3284.              //         $totalPorts = 0;
  3285.              //         $totalPortsUsed = 0;
  3286.              //         $totalPortsInInterface = 0;
  3287.              //
  3288.              //         $ports = $interface->getPort();
  3289.              //
  3290.              //         $portList = [];
  3291.              //
  3292.              //         $isInterfaceInTrunk = 0;
  3293.              //
  3294.              //         foreach ($ports as $port) {
  3295.              //           // var_dump($port->getId());
  3296.              //
  3297.              //             $isPortInTrunk = 0;
  3298.              //
  3299.              //             $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3300.              //             $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3301.              //             $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  3302.              //             // var_dump($usedInTrunkPointA);
  3303.              //             // var_dump($usedInTrunkPointB);
  3304.              //             // var_dump($usedInTrunkExtension);
  3305.              //
  3306.              //             if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  3307.              //                 $isInterfaceInTrunk = 1;
  3308.              //                 $isPortInTrunk = 1;
  3309.              //                 $totalPorts++;
  3310.              //             }
  3311.              //
  3312.              //             $port->nPort = 0;
  3313.              //             $port->used = 0;
  3314.              //
  3315.              //             $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  3316.              //             if ($nPorts){
  3317.              //                 $nPorts = json_decode($nPorts);
  3318.              //                 if (in_array($port->getOrderNo(), $nPorts)){
  3319.              //                     $port->nPort = 1;
  3320.              //                 }
  3321.              //             }
  3322.              //
  3323.              //             // $used = 0;
  3324.              //             // $usedLinkID = '';
  3325.              //             // $usedLink_id = '';
  3326.              //
  3327.              //             if (in_array($port->getId(), $portsAll)) {
  3328.              //             // $usedALink = null;
  3329.              //             // $usedBLink = null;
  3330.              //             // $tempExts = $port->getExtensionOrder();
  3331.              //             // foreach ( $tempExts as $value) {
  3332.              //             //   $extremityB = $value->getExtremity();
  3333.              //             //   if ($usedALink && $usedBLink) {
  3334.              //             //     break;
  3335.              //             //   }
  3336.              //             //   if(!$usedALink) {
  3337.              //             //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3338.              //             //   }
  3339.              //             //   if (!$usedBLink) {
  3340.              //             //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3341.              //             //   }
  3342.              //             // }
  3343.              //             // $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3344.              //             // $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3345.              //             //
  3346.              //             // if ($usedALink) {
  3347.              //             //   $used = 1;
  3348.              //             //   $usedLinkID = $usedALink->getLink()->getLinkID();
  3349.              //             //   $usedLink_id = $usedALink->getLink()->getId();
  3350.              //             // }
  3351.              //             // if ($usedBLink) {
  3352.              //             //   $used = 1;
  3353.              //             //   $usedLinkID = $usedBLink->getLink()->getLinkID();
  3354.              //             //   $usedLink_id = $usedBLink->getLink()->getId();
  3355.              //             // }
  3356.              //             //
  3357.              //             // if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  3358.              //             //
  3359.              //             // }
  3360.              //             // else if($trunkExtension) {
  3361.              //             //   // var_dump("Got it");
  3362.              //             //   $used = 1;
  3363.              //             //   $usedLinkID = $port->getLink()->getLinkID();
  3364.              //             //   $usedLink_id = $port->getLink()->getId();
  3365.              //             // }
  3366.              //             // if ($tcfB && $usedBLink) {
  3367.              //             //
  3368.              //             // }
  3369.              //             // else if($tcfB){
  3370.              //             //   $used = 1;
  3371.              //             //   $usedLinkID = $port->getLink()->getLinkID();
  3372.              //             //   $usedLink_id = $port->getLink()->getId();
  3373.              //             //
  3374.              //             // }
  3375.              //
  3376.              //             // $port->used = $used;
  3377.              //             $port->used = 1;
  3378.              //             $port->usedLinkID = $port->getLink()->getLinkID();
  3379.              //             $port->usedLink_id = $port->getLink()->getId();
  3380.              //           }
  3381.              //             // $usedALink = null;
  3382.              //             // $usedBLink = null;
  3383.              //             // $tempExts = $port->getExtremities();
  3384.              //             // foreach ( $tempExts as $extremityB) {
  3385.              //             //   if ($usedALink && $usedBLink) {
  3386.              //             //     break;
  3387.              //             //   }
  3388.              //             //   if(!$usedALink) {
  3389.              //             //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3390.              //             //   }
  3391.              //             //   if (!$usedBLink) {
  3392.              //             //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3393.              //             //   }
  3394.              //             // }
  3395.              //             // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3396.              //             // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3397.              //             // if ($usedALink) {
  3398.              //             //     $used = 1;
  3399.              //             //     $usedLinkID = $usedALink->getLink()->getLinkID();
  3400.              //             //     $usedLink_id = $usedALink->getLink()->getId();
  3401.              //             // }
  3402.              //             //
  3403.              //             // if ($usedBLink) {
  3404.              //             //     $used = 1;
  3405.              //             //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  3406.              //             //     $usedLink_id = $usedBLink->getLink()->getId();
  3407.              //             // }
  3408.              //             // // var_dump($used);
  3409.              //             //
  3410.              //             // $port->used = $used;
  3411.              //             // $port->usedLinkID = $usedLinkID;
  3412.              //             // $port->usedLink_id = $usedLink_id;
  3413.              //
  3414.              //             $p['used'] = $used;
  3415.              //             $p['usedLinkID'] = $usedLinkID;
  3416.              //             $p['usedLink_id'] = $usedLink_id;
  3417.              //             $p['nPort'] = $port->nPort;
  3418.              //             $p['inTrunk'] = $isPortInTrunk;
  3419.              //
  3420.              //
  3421.              //             if ($port->nPort == 1 && $port->used == 1){
  3422.              //
  3423.              //                 $p['id'] = $port->getId();
  3424.              //
  3425.              //             }
  3426.              //
  3427.              //
  3428.              //             $totalPortsInInterface++;
  3429.              //
  3430.              //             if ($used == 1) {
  3431.              //                 $totalPortsUsed++;
  3432.              //             }
  3433.              //
  3434.              //             $portList[] = $p;
  3435.              //
  3436.              //         }
  3437.              //
  3438.              //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  3439.              //         $int['totalPorts'] = $totalPorts;
  3440.              //         $int['totalPortsUsed'] = $totalPortsUsed;
  3441.              //         $int['ports'] = $portList;
  3442.              //
  3443.              //         if ($isInterfaceInTrunk == 1){
  3444.              //
  3445.              //             $eq['interfaces'][] = $int;
  3446.              //
  3447.              //             if ($totalPortsInInterface > $maxPorts){
  3448.              //                 $maxPorts = $totalPortsInInterface;
  3449.              //             }
  3450.              //
  3451.              //         }
  3452.              //
  3453.              //     }
  3454.              // $list[] = $eq;
  3455.              if (!in_array($eqB->getId(), $eqBArray)) {
  3456.                  $trunk->eqB $eqB;
  3457.                  $res $this->createEquipment($trunk$eqB$portsAll$maxPorts);
  3458.                  $list[] = $res["eq"];
  3459.                  $maxPorts $res["maxPorts"];
  3460.                  $eqBArray[] = $eqB->getId();
  3461.                }
  3462.              // if (in_array()$eqB != $eqA) {
  3463.              //   //eqB
  3464.              //
  3465.              //   $trunk->eqB = $eqB;
  3466.              //   // var_dump($eqA->getId());
  3467.              //
  3468.              //   $rackTitle = $eqB->getRack()->getTitle();
  3469.              //
  3470.              //       $eq['trunkID'] = $trunk->getTrunkID();
  3471.              //       $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  3472.              //       $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  3473.              //       $eq['rack'] = $rackTitle;
  3474.              //       $eq['equipment'] = $eqB->getEquipmentSpecificName();
  3475.              //       $eq['interfaces'] = [];
  3476.              //
  3477.              //       $interfaces = $eqB->getInterfaceSpecific();
  3478.              //       foreach ($interfaces as $interface) {
  3479.              //           // var_dump($interface->getId());
  3480.              //           $totalPorts = 0;
  3481.              //           $totalPortsUsed = 0;
  3482.              //           $totalPortsInInterface = 0;
  3483.              //
  3484.              //           $ports = $interface->getPort();
  3485.              //
  3486.              //           $portList = [];
  3487.              //
  3488.              //           $isInterfaceInTrunk = 0;
  3489.              //
  3490.              //           foreach ($ports as $port) {
  3491.              //             // var_dump($port->getId());
  3492.              //
  3493.              //               $isPortInTrunk = 0;
  3494.              //
  3495.              //               $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3496.              //               $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3497.              //               $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  3498.              //               // var_dump($usedInTrunkPointA);
  3499.              //               // var_dump($usedInTrunkPointB);
  3500.              //               // var_dump($usedInTrunkExtension);
  3501.              //
  3502.              //               if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  3503.              //                   $isInterfaceInTrunk = 1;
  3504.              //                   $isPortInTrunk = 1;
  3505.              //                   $totalPorts++;
  3506.              //               }
  3507.              //
  3508.              //               $port->nPort = 0;
  3509.              //               $port->used = 0;
  3510.              //
  3511.              //               $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  3512.              //               if ($nPorts){
  3513.              //                   $nPorts = json_decode($nPorts);
  3514.              //                   if (in_array($port->getOrderNo(), $nPorts)){
  3515.              //                       $port->nPort = 1;
  3516.              //                   }
  3517.              //               }
  3518.              //
  3519.              //               $used = 0;
  3520.              //               $usedLinkID = '';
  3521.              //               $usedLink_id = '';
  3522.              //
  3523.              //               if (in_array($port->getId(), $portsAll)) {
  3524.              //               // $usedALink = null;
  3525.              //               // $usedBLink = null;
  3526.              //               // $tempExts = $port->getExtensionOrder();
  3527.              //               // foreach ( $tempExts as $value) {
  3528.              //               //   $extremityB = $value->getExtremity();
  3529.              //               //   if ($usedALink && $usedBLink) {
  3530.              //               //     break;
  3531.              //               //   }
  3532.              //               //   if(!$usedALink) {
  3533.              //               //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3534.              //               //   }
  3535.              //               //   if (!$usedBLink) {
  3536.              //               //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3537.              //               //   }
  3538.              //               // }
  3539.              //               // $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3540.              //               // $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3541.              //               //
  3542.              //               // if ($usedALink) {
  3543.              //               //   $used = 1;
  3544.              //               //   $usedLinkID = $usedALink->getLink()->getLinkID();
  3545.              //               //   $usedLink_id = $usedALink->getLink()->getId();
  3546.              //               // }
  3547.              //               // if ($usedBLink) {
  3548.              //               //   $used = 1;
  3549.              //               //   $usedLinkID = $usedBLink->getLink()->getLinkID();
  3550.              //               //   $usedLink_id = $usedBLink->getLink()->getId();
  3551.              //               // }
  3552.              //               //
  3553.              //               // if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  3554.              //               //
  3555.              //               // }
  3556.              //               // else if($trunkExtension) {
  3557.              //               //   // var_dump("Got it");
  3558.              //               //   $used = 1;
  3559.              //               //   $usedLinkID = $port->getLink()->getLinkID();
  3560.              //               //   $usedLink_id = $port->getLink()->getId();
  3561.              //               // }
  3562.              //               // if ($tcfB && $usedBLink) {
  3563.              //               //
  3564.              //               // }
  3565.              //               // else if($tcfB){
  3566.              //               //   $used = 1;
  3567.              //               //   $usedLinkID = $port->getLink()->getLinkID();
  3568.              //               //   $usedLink_id = $port->getLink()->getId();
  3569.              //               //
  3570.              //               // }
  3571.              //
  3572.              //               $port->used = 1;
  3573.              //               $port->usedLinkID = $port->getLink()->getLinkID();
  3574.              //               $port->usedLink_id = $port->getLink()->getId();
  3575.              //             }
  3576.              //               // $usedALink = null;
  3577.              //               // $usedBLink = null;
  3578.              //               // $tempExts = $port->getExtremities();
  3579.              //               // foreach ( $tempExts as $extremityB) {
  3580.              //               //   if ($usedALink && $usedBLink) {
  3581.              //               //     break;
  3582.              //               //   }
  3583.              //               //   if(!$usedALink) {
  3584.              //               //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3585.              //               //   }
  3586.              //               //   if (!$usedBLink) {
  3587.              //               //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3588.              //               //   }
  3589.              //               // }
  3590.              //               // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3591.              //               // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3592.              //               // if ($usedALink) {
  3593.              //               //     $used = 1;
  3594.              //               //     $usedLinkID = $usedALink->getLink()->getLinkID();
  3595.              //               //     $usedLink_id = $usedALink->getLink()->getId();
  3596.              //               // }
  3597.              //               //
  3598.              //               // if ($usedBLink) {
  3599.              //               //     $used = 1;
  3600.              //               //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  3601.              //               //     $usedLink_id = $usedBLink->getLink()->getId();
  3602.              //               // }
  3603.              //               // // var_dump($used);
  3604.              //               //
  3605.              //               // $port->used = $used;
  3606.              //               // $port->usedLinkID = $usedLinkID;
  3607.              //               // $port->usedLink_id = $usedLink_id;
  3608.              //
  3609.              //               $p['used'] = $used;
  3610.              //               $p['usedLinkID'] = $usedLinkID;
  3611.              //               $p['usedLink_id'] = $usedLink_id;
  3612.              //               $p['nPort'] = $port->nPort;
  3613.              //               $p['inTrunk'] = $isPortInTrunk;
  3614.              //
  3615.              //
  3616.              //               if ($port->nPort == 1 && $port->used == 1){
  3617.              //
  3618.              //                   $p['id'] = $port->getId();
  3619.              //
  3620.              //               }
  3621.              //
  3622.              //
  3623.              //               $totalPortsInInterface++;
  3624.              //
  3625.              //               if ($used == 1) {
  3626.              //                   $totalPortsUsed++;
  3627.              //               }
  3628.              //
  3629.              //               $portList[] = $p;
  3630.              //
  3631.              //           }
  3632.              //
  3633.              //           $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  3634.              //           $int['totalPorts'] = $totalPorts;
  3635.              //           $int['totalPortsUsed'] = $totalPortsUsed;
  3636.              //           $int['ports'] = $portList;
  3637.              //
  3638.              //           if ($isInterfaceInTrunk == 1){
  3639.              //
  3640.              //               $eq['interfaces'][] = $int;
  3641.              //
  3642.              //               if ($totalPortsInInterface > $maxPorts){
  3643.              //                   $maxPorts = $totalPortsInInterface;
  3644.              //               }
  3645.              //
  3646.              //           }
  3647.              //
  3648.              //       }
  3649.              //
  3650.              //   $list[] = $eq;
  3651.              // }
  3652.              //version long avec tous les Ã©quipements intermédiaire
  3653.              // foreach ($tcfs as $firstTcf) {
  3654.              //   // $firstTcf = $tcfs[0];
  3655.              //   $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  3656.              //   if (!in_array($eqA->getId(), $eqBArray)) {
  3657.              //     $eqBArray[] = $eqA->getId();
  3658.              //     $trunk->eqA = $eqA;
  3659.              //     // var_dump($eqA->getId());
  3660.              //
  3661.              //     $rackTitle = $eqA->getRack()->getTitle();
  3662.              //
  3663.              //         $eq['trunkID'] = $trunk->getTrunkID();
  3664.              //         $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  3665.              //         $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  3666.              //         $eq['rack'] = $rackTitle;
  3667.              //         $eq['equipment'] = $eqA->getEquipmentSpecificName();
  3668.              //         $eq['interfaces'] = [];
  3669.              //
  3670.              //         $interfaces = $eqA->getInterfaceSpecific();
  3671.              //         foreach ($interfaces as $interface) {
  3672.              //             // var_dump($interface->getId());
  3673.              //             $totalPorts = 0;
  3674.              //             $totalPortsUsed = 0;
  3675.              //             $totalPortsInInterface = 0;
  3676.              //
  3677.              //             $ports = $interface->getPort();
  3678.              //
  3679.              //             $portList = [];
  3680.              //
  3681.              //             $isInterfaceInTrunk = 0;
  3682.              //
  3683.              //             foreach ($ports as $port) {
  3684.              //               // var_dump($port->getId());
  3685.              //
  3686.              //                 $isPortInTrunk = 0;
  3687.              //
  3688.              //                 $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3689.              //                 $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3690.              //                 $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  3691.              //                 // var_dump($usedInTrunkPointA);
  3692.              //                 // var_dump($usedInTrunkPointB);
  3693.              //                 // var_dump($usedInTrunkExtension);
  3694.              //
  3695.              //                 if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  3696.              //                     $isInterfaceInTrunk = 1;
  3697.              //                     $isPortInTrunk = 1;
  3698.              //                     $totalPorts++;
  3699.              //                 }
  3700.              //
  3701.              //                 $port->nPort = 0;
  3702.              //                 $port->used = 0;
  3703.              //
  3704.              //                 $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  3705.              //                 if ($nPorts){
  3706.              //                     $nPorts = json_decode($nPorts);
  3707.              //                     if (in_array($port->getOrderNo(), $nPorts)){
  3708.              //                         $port->nPort = 1;
  3709.              //                     }
  3710.              //                 }
  3711.              //
  3712.              //                 $used = 0;
  3713.              //                 $usedLinkID = '';
  3714.              //                 $usedLink_id = '';
  3715.              //
  3716.              //                 if (in_array($port->getId(), $portsAll)) {
  3717.              //                 $usedALink = null;
  3718.              //                 $usedBLink = null;
  3719.              //                 $tempExts = $port->getExtensionOrder();
  3720.              //                 foreach ( $tempExts as $value) {
  3721.              //                   $extremityB = $value->getExtremity();
  3722.              //                   if ($usedALink && $usedBLink) {
  3723.              //                     break;
  3724.              //                   }
  3725.              //                   if(!$usedALink) {
  3726.              //                      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3727.              //                   }
  3728.              //                   if (!$usedBLink) {
  3729.              //                     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3730.              //                   }
  3731.              //                 }
  3732.              //                 $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3733.              //                 $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3734.              //
  3735.              //                 if ($usedALink) {
  3736.              //                   $used = 1;
  3737.              //                   $usedLinkID = $usedALink->getLink()->getLinkID();
  3738.              //                   $usedLink_id = $usedALink->getLink()->getId();
  3739.              //                 }
  3740.              //                 if ($usedBLink) {
  3741.              //                   $used = 1;
  3742.              //                   $usedLinkID = $usedBLink->getLink()->getLinkID();
  3743.              //                   $usedLink_id = $usedBLink->getLink()->getId();
  3744.              //                 }
  3745.              //
  3746.              //                 if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  3747.              //
  3748.              //                 }
  3749.              //                 else if($trunkExtension) {
  3750.              //                   // var_dump("Got it");
  3751.              //                   $used = 1;
  3752.              //                   $usedLinkID = $port->getLink()->getLinkID();
  3753.              //                   $usedLink_id = $port->getLink()->getId();
  3754.              //                 }
  3755.              //                 if ($tcfB && $usedBLink) {
  3756.              //
  3757.              //                 }
  3758.              //                 else if($tcfB){
  3759.              //                   $used = 1;
  3760.              //                   $usedLinkID = $port->getLink()->getLinkID();
  3761.              //                   $usedLink_id = $port->getLink()->getId();
  3762.              //
  3763.              //                 }
  3764.              //
  3765.              //                 $port->used = $used;
  3766.              //                 $port->usedLinkID = $usedLinkID;
  3767.              //                 $port->usedLink_id = $usedLink_id;
  3768.              //               }
  3769.              //                 // $usedALink = null;
  3770.              //                 // $usedBLink = null;
  3771.              //                 // $tempExts = $port->getExtremities();
  3772.              //                 // foreach ( $tempExts as $extremityB) {
  3773.              //                 //   if ($usedALink && $usedBLink) {
  3774.              //                 //     break;
  3775.              //                 //   }
  3776.              //                 //   if(!$usedALink) {
  3777.              //                 //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3778.              //                 //   }
  3779.              //                 //   if (!$usedBLink) {
  3780.              //                 //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3781.              //                 //   }
  3782.              //                 // }
  3783.              //                 // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3784.              //                 // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3785.              //                 // if ($usedALink) {
  3786.              //                 //     $used = 1;
  3787.              //                 //     $usedLinkID = $usedALink->getLink()->getLinkID();
  3788.              //                 //     $usedLink_id = $usedALink->getLink()->getId();
  3789.              //                 // }
  3790.              //                 //
  3791.              //                 // if ($usedBLink) {
  3792.              //                 //     $used = 1;
  3793.              //                 //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  3794.              //                 //     $usedLink_id = $usedBLink->getLink()->getId();
  3795.              //                 // }
  3796.              //                 // // var_dump($used);
  3797.              //                 //
  3798.              //                 // $port->used = $used;
  3799.              //                 // $port->usedLinkID = $usedLinkID;
  3800.              //                 // $port->usedLink_id = $usedLink_id;
  3801.              //
  3802.              //                 $p['used'] = $used;
  3803.              //                 $p['usedLinkID'] = $usedLinkID;
  3804.              //                 $p['usedLink_id'] = $usedLink_id;
  3805.              //                 $p['nPort'] = $port->nPort;
  3806.              //                 $p['inTrunk'] = $isPortInTrunk;
  3807.              //
  3808.              //
  3809.              //                 if ($port->nPort == 1 && $port->used == 1){
  3810.              //
  3811.              //                     $p['id'] = $port->getId();
  3812.              //
  3813.              //                 }
  3814.              //
  3815.              //
  3816.              //                 $totalPortsInInterface++;
  3817.              //
  3818.              //                 if ($used == 1) {
  3819.              //                     $totalPortsUsed++;
  3820.              //                 }
  3821.              //
  3822.              //                 $portList[] = $p;
  3823.              //
  3824.              //             }
  3825.              //
  3826.              //             $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  3827.              //             $int['totalPorts'] = $totalPorts;
  3828.              //             $int['totalPortsUsed'] = $totalPortsUsed;
  3829.              //             $int['ports'] = $portList;
  3830.              //
  3831.              //             if ($isInterfaceInTrunk == 1){
  3832.              //
  3833.              //                 $eq['interfaces'][] = $int;
  3834.              //
  3835.              //                 if ($totalPortsInInterface > $maxPorts){
  3836.              //                     $maxPorts = $totalPortsInInterface;
  3837.              //                 }
  3838.              //
  3839.              //             }
  3840.              //
  3841.              //         }
  3842.              //
  3843.              //     $list[] = $eq;
  3844.              //   }
  3845.              //
  3846.              //
  3847.              //   $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  3848.              //   if (!in_array($eqB->getId(), $eqBArray)) {
  3849.              //       $eqBArray[] = $eqB->getId();
  3850.              //       $trunk->eqB = $eqB;
  3851.              //
  3852.              //       $rackTitle = $eqB->getRack()->getTitle();
  3853.              //
  3854.              //       $eq['trunkID'] = $trunk->getTrunkID();
  3855.              //       $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  3856.              //       $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  3857.              //       $eq['rack'] = $rackTitle;
  3858.              //       $eq['equipment'] = $eqB->getEquipmentSpecificName();
  3859.              //       $eq['interfaces'] = [];
  3860.              //
  3861.              //       $interfaces = $eqB->getInterfaceSpecific();
  3862.              //       foreach ($interfaces as $interface){
  3863.              //
  3864.              //         $totalPorts = 0;
  3865.              //         $totalPortsUsed = 0;
  3866.              //         $totalPortsInInterface = 0;
  3867.              //
  3868.              //         $ports = $interface->getPort();
  3869.              //
  3870.              //         $portList = [];
  3871.              //
  3872.              //         $isInterfaceInTrunk = 0;
  3873.              //
  3874.              //         foreach ($ports as $port){
  3875.              //
  3876.              //           $isPortInTrunk = 0;
  3877.              //
  3878.              //           $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3879.              //           $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3880.              //           $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  3881.              //
  3882.              //           if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  3883.              //             $isInterfaceInTrunk = 1;
  3884.              //             $isPortInTrunk = 1;
  3885.              //             $totalPorts++;
  3886.              //           }
  3887.              //
  3888.              //
  3889.              //           $port->nPort = 0;
  3890.              //           $port->used = 0;
  3891.              //
  3892.              //           $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  3893.              //           if ($nPorts){
  3894.              //             $nPorts = json_decode($nPorts);
  3895.              //             if (in_array($port->getOrderNo(), $nPorts)){
  3896.              //               $port->nPort = 1;
  3897.              //             }
  3898.              //           }
  3899.              //
  3900.              //           $used = 0;
  3901.              //           $usedLinkID = '';
  3902.              //           $usedLink_id = '';
  3903.              //           if (in_array($port->getId(), $portsAll)) {
  3904.              //             $usedALink = null;
  3905.              //             $usedBLink = null;
  3906.              //             $tempExts = $port->getExtensionOrder();
  3907.              //             foreach ( $tempExts as $value) {
  3908.              //               $extremityB = $value->getExtremity();
  3909.              //               if ($usedALink && $usedBLink) {
  3910.              //                 break;
  3911.              //               }
  3912.              //               if(!$usedALink) {
  3913.              //                 $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3914.              //               }
  3915.              //               if (!$usedBLink) {
  3916.              //                 $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3917.              //               }
  3918.              //             }
  3919.              //             $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  3920.              //             $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  3921.              //
  3922.              //             if ($usedALink) {
  3923.              //               $used = 1;
  3924.              //               $usedLinkID = $usedALink->getLink()->getLinkID();
  3925.              //               $usedLink_id = $usedALink->getLink()->getId();
  3926.              //             }
  3927.              //             if ($usedBLink) {
  3928.              //               $used = 1;
  3929.              //               $usedLinkID = $usedBLink->getLink()->getLinkID();
  3930.              //               $usedLink_id = $usedBLink->getLink()->getId();
  3931.              //             }
  3932.              //
  3933.              //             if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  3934.              //
  3935.              //             }
  3936.              //             else if($trunkExtension) {
  3937.              //               // var_dump("Got it");
  3938.              //               $used = 1;
  3939.              //               $usedLinkID = $port->getLink()->getLinkID();
  3940.              //               $usedLink_id = $port->getLink()->getId();
  3941.              //             }
  3942.              //             if ($tcfB && $usedBLink) {
  3943.              //
  3944.              //             }
  3945.              //             else if($tcfB){
  3946.              //               $used = 1;
  3947.              //               $usedLinkID = $port->getLink()->getLinkID();
  3948.              //               $usedLink_id = $port->getLink()->getId();
  3949.              //
  3950.              //             }
  3951.              //
  3952.              //             $port->used = $used;
  3953.              //             $port->usedLinkID = $usedLinkID;
  3954.              //             $port->usedLink_id = $usedLink_id;
  3955.              //           }
  3956.              //           // $usedALink = null;
  3957.              //           // $usedBLink = null;
  3958.              //           // $tempExts = $port->getExtremities();
  3959.              //           // foreach ( $tempExts as $extremityB) {
  3960.              //           //   if ($usedALink && $usedBLink) {
  3961.              //           //     break;
  3962.              //           //   }
  3963.              //           //   if(!$usedALink) {
  3964.              //           //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  3965.              //           //   }
  3966.              //           //   if (!$usedBLink) {
  3967.              //           //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  3968.              //           //   }
  3969.              //           // }
  3970.              //           //
  3971.              //           // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  3972.              //           // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  3973.              //           //
  3974.              //           // if ($usedALink){
  3975.              //           //     $used = 1;
  3976.              //           //     $usedLinkID = $usedALink->getLink()->getLinkID();
  3977.              //           //     $usedLink_id = $usedALink->getLink()->getId();
  3978.              //           // }
  3979.              //           //
  3980.              //           // if ($usedBLink){
  3981.              //           //     $used = 1;
  3982.              //           //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  3983.              //           //     $usedLink_id = $usedBLink->getLink()->getId();
  3984.              //           // }
  3985.              //
  3986.              //           $port->used = $used;
  3987.              //           $port->usedLinkID = $usedLinkID;
  3988.              //           $port->usedLink_id = $usedLink_id;
  3989.              //
  3990.              //           $p['used'] = $used;
  3991.              //           $p['usedLinkID'] = $usedLinkID;
  3992.              //           $p['usedLink_id'] = $usedLink_id;
  3993.              //           $p['nPort'] = $port->nPort;
  3994.              //           $p['inTrunk'] = $isPortInTrunk;
  3995.              //
  3996.              //
  3997.              //           if ($port->nPort == 1 && $port->used == 1){
  3998.              //
  3999.              //             $p['id'] = $port->getId();
  4000.              //
  4001.              //           }
  4002.              //
  4003.              //           $totalPortsInInterface ++;
  4004.              //
  4005.              //           if ($used == 1){
  4006.              //             $totalPortsUsed ++;
  4007.              //           }
  4008.              //
  4009.              //           $portList[] = $p;
  4010.              //
  4011.              //         }
  4012.              //
  4013.              //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4014.              //         $int['totalPorts'] = $totalPorts;
  4015.              //         $int['totalPortsUsed'] = $totalPortsUsed;
  4016.              //         $int['ports'] = $portList;
  4017.              //
  4018.              //         if ($isInterfaceInTrunk == 1){
  4019.              //
  4020.              //           $eq['interfaces'][] = $int;
  4021.              //
  4022.              //           if ($totalPortsInInterface > $maxPorts){
  4023.              //             $maxPorts = $totalPortsInInterface;
  4024.              //           }
  4025.              //
  4026.              //         }
  4027.              //
  4028.              //
  4029.              //       }
  4030.              //
  4031.              //       $list[] = $eq;
  4032.              //       $extensions = $firstTcf->getExtensions();
  4033.              //         foreach ($extensions as $extension) {
  4034.              //           $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  4035.              //
  4036.              //           if (!in_array($eqB->getId(), $eqBArray)) {
  4037.              //             $eqBArray[] = $eqB->getId();
  4038.              //             $trunk->eqB = $eqB;
  4039.              //
  4040.              //             $rackTitle = $eqB->getRack()->getTitle();
  4041.              //
  4042.              //             $eq['trunkID'] = $trunk->getTrunkID();
  4043.              //             $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  4044.              //             $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  4045.              //             $eq['rack'] = $rackTitle;
  4046.              //             $eq['equipment'] = $eqB->getEquipmentSpecificName();
  4047.              //             $eq['interfaces'] = [];
  4048.              //
  4049.              //             $interfaces = $eqB->getInterfaceSpecific();
  4050.              //             foreach ($interfaces as $interface){
  4051.              //
  4052.              //               $totalPorts = 0;
  4053.              //               $totalPortsUsed = 0;
  4054.              //               $totalPortsInInterface = 0;
  4055.              //
  4056.              //               $ports = $interface->getPort();
  4057.              //
  4058.              //               $portList = [];
  4059.              //
  4060.              //               $isInterfaceInTrunk = 0;
  4061.              //
  4062.              //               foreach ($ports as $port){
  4063.              //
  4064.              //                 $isPortInTrunk = 0;
  4065.              //
  4066.              //                 $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4067.              //                 $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4068.              //                 $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  4069.              //
  4070.              //                 if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  4071.              //                   $isInterfaceInTrunk = 1;
  4072.              //                   $isPortInTrunk = 1;
  4073.              //                   $totalPorts++;
  4074.              //                 }
  4075.              //
  4076.              //
  4077.              //                 $port->nPort = 0;
  4078.              //                 $port->used = 0;
  4079.              //
  4080.              //                 $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4081.              //                 if ($nPorts){
  4082.              //                   $nPorts = json_decode($nPorts);
  4083.              //                   if (in_array($port->getOrderNo(), $nPorts)){
  4084.              //                     $port->nPort = 1;
  4085.              //                   }
  4086.              //                 }
  4087.              //
  4088.              //                 $used = 0;
  4089.              //                 $usedLinkID = '';
  4090.              //                 $usedLink_id = '';
  4091.              //                 if (in_array($port->getId(), $portsAll)) {
  4092.              //                   $usedALink = null;
  4093.              //                   $usedBLink = null;
  4094.              //                   $tempExts = $port->getExtensionOrder();
  4095.              //                   foreach ( $tempExts as $value) {
  4096.              //                     $extrmityB = $value->getExtremity();
  4097.              //                     if ($usedALink && $usedBLink) {
  4098.              //                       break;
  4099.              //                     }
  4100.              //                     if(!$usedALink) {
  4101.              //                       $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4102.              //                     }
  4103.              //                     if (!$usedBLink) {
  4104.              //                       $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4105.              //                     }
  4106.              //                   }
  4107.              //                   $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  4108.              //                   $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  4109.              //
  4110.              //                   if ($usedALink) {
  4111.              //                     $used = 1;
  4112.              //                     $usedLinkID = $usedALink->getLink()->getLinkID();
  4113.              //                     $usedLink_id = $usedALink->getLink()->getId();
  4114.              //                   }
  4115.              //                   if ($usedBLink) {
  4116.              //                     $used = 1;
  4117.              //                     $usedLinkID = $usedBLink->getLink()->getLinkID();
  4118.              //                     $usedLink_id = $usedBLink->getLink()->getId();
  4119.              //                   }
  4120.              //
  4121.              //                   if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  4122.              //
  4123.              //                   }
  4124.              //                   else if($trunkExtension) {
  4125.              //                     // var_dump("Got it");
  4126.              //                     $used = 1;
  4127.              //                     $usedLinkID = $port->getLink()->getLinkID();
  4128.              //                     $usedLink_id = $port->getLink()->getId();
  4129.              //                   }
  4130.              //                   if ($tcfB && $usedBLink) {
  4131.              //
  4132.              //                   }
  4133.              //                   else if($tcfB){
  4134.              //                     $used = 1;
  4135.              //                     $usedLinkID = $port->getLink()->getLinkID();
  4136.              //                     $usedLink_id = $port->getLink()->getId();
  4137.              //
  4138.              //                   }
  4139.              //
  4140.              //                   $port->used = $used;
  4141.              //                   $port->usedLinkID = $usedLinkID;
  4142.              //                   $port->usedLink_id = $usedLink_id;
  4143.              //                 }
  4144.              //                 // $usedALink = null;
  4145.              //                 // $usedBLink = null;
  4146.              //                 // $tempExts = $port->getExtremities();
  4147.              //                 // foreach ( $tempExts as $extremityB) {
  4148.              //                 //   if ($usedALink && $usedBLink) {
  4149.              //                 //     break;
  4150.              //                 //   }
  4151.              //                 //   if(!$usedALink) {
  4152.              //                 //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4153.              //                 //   }
  4154.              //                 //   if (!$usedBLink) {
  4155.              //                 //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4156.              //                 //   }
  4157.              //                 // }
  4158.              //                 //
  4159.              //                 // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4160.              //                 // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4161.              //                 //
  4162.              //                 // if ($usedALink){
  4163.              //                 //     $used = 1;
  4164.              //                 //     $usedLinkID = $usedALink->getLink()->getLinkID();
  4165.              //                 //     $usedLink_id = $usedALink->getLink()->getId();
  4166.              //                 // }
  4167.              //                 //
  4168.              //                 // if ($usedBLink){
  4169.              //                 //     $used = 1;
  4170.              //                 //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  4171.              //                 //     $usedLink_id = $usedBLink->getLink()->getId();
  4172.              //                 // }
  4173.              //
  4174.              //                 $port->used = $used;
  4175.              //                 $port->usedLinkID = $usedLinkID;
  4176.              //                 $port->usedLink_id = $usedLink_id;
  4177.              //
  4178.              //                 $p['used'] = $used;
  4179.              //                 $p['usedLinkID'] = $usedLinkID;
  4180.              //                 $p['usedLink_id'] = $usedLink_id;
  4181.              //                 $p['nPort'] = $port->nPort;
  4182.              //                 $p['inTrunk'] = $isPortInTrunk;
  4183.              //
  4184.              //
  4185.              //                 if ($port->nPort == 1 && $port->used == 1){
  4186.              //
  4187.              //                   $p['id'] = $port->getId();
  4188.              //
  4189.              //                 }
  4190.              //
  4191.              //                 $totalPortsInInterface ++;
  4192.              //
  4193.              //                 if ($used == 1){
  4194.              //                   $totalPortsUsed ++;
  4195.              //                 }
  4196.              //
  4197.              //                 $portList[] = $p;
  4198.              //
  4199.              //               }
  4200.              //
  4201.              //               $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4202.              //               $int['totalPorts'] = $totalPorts;
  4203.              //               $int['totalPortsUsed'] = $totalPortsUsed;
  4204.              //               $int['ports'] = $portList;
  4205.              //
  4206.              //               if ($isInterfaceInTrunk == 1){
  4207.              //
  4208.              //                 $eq['interfaces'][] = $int;
  4209.              //
  4210.              //                 if ($totalPortsInInterface > $maxPorts){
  4211.              //                   $maxPorts = $totalPortsInInterface;
  4212.              //                 }
  4213.              //
  4214.              //               }
  4215.              //
  4216.              //
  4217.              //             }
  4218.              //
  4219.              //             $list[] = $eq;
  4220.              //           }
  4221.              //         }
  4222.              //   }
  4223.              //   // var_dump($firstTcf);
  4224.              //   // var_dump($firstTcf->getPortB()->getId());
  4225.              //   // var_dump($eqB->getId());
  4226.              //
  4227.              //     // foreach ($tcfs as $tcf) {
  4228.              //     //
  4229.              //     // }
  4230.              //
  4231.              //       // $trunk->eqB = $eqB;
  4232.              //       //
  4233.              //       // $rackTitle = $eqB->getRack()->getTitle();
  4234.              //       //
  4235.              //       // $eq['trunkID'] = $trunk->getTrunkID();
  4236.              //       // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  4237.              //       // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  4238.              //       // $eq['rack'] = $rackTitle;
  4239.              //       // $eq['equipment'] = $eqB->getEquipmentSpecificName();
  4240.              //       // $eq['interfaces'] = [];
  4241.              //       //
  4242.              //       // $interfaces = $eqB->getInterfaceSpecific();
  4243.              //       // foreach ($interfaces as $interface){
  4244.              //       //      // var_dump($interface->getId());
  4245.              //       //     $totalPorts = 0;
  4246.              //       //     $totalPortsUsed = 0;
  4247.              //       //     $totalPortsInInterface = 0;
  4248.              //       //
  4249.              //       //     $ports = $interface->getPort();
  4250.              //       //
  4251.              //       //     $portList = [];
  4252.              //       //
  4253.              //       //     $isInterfaceInTrunk = 0;
  4254.              //       //
  4255.              //       //     foreach ($ports as $port){
  4256.              //       //        // var_dump($port->getId());
  4257.              //       //         $isPortInTrunk = 0;
  4258.              //       //
  4259.              //       //         $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4260.              //       //         $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4261.              //       //         $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  4262.              //       //
  4263.              //       //         if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  4264.              //       //             $isInterfaceInTrunk = 1;
  4265.              //       //             $isPortInTrunk = 1;
  4266.              //       //             $totalPorts++;
  4267.              //       //         }
  4268.              //       //
  4269.              //       //
  4270.              //       //         $port->nPort = 0;
  4271.              //       //
  4272.              //       //         $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4273.              //       //         if ($nPorts){
  4274.              //       //             $nPorts = json_decode($nPorts);
  4275.              //       //             if (in_array($port->getOrderNo(), $nPorts)){
  4276.              //       //                 $port->nPort = 1;
  4277.              //       //             }
  4278.              //       //         }
  4279.              //       //
  4280.              //       //         $used = 0;
  4281.              //       //         $usedLinkID = '';
  4282.              //       //         $usedLink_id = '';
  4283.              //       //         $usedALink = null;
  4284.              //       //         $usedBLink = null;
  4285.              //       //         $tempExts = $port->getExtremities();
  4286.              //       //         foreach ( $tempExts as $extremityB) {
  4287.              //       //           if ($usedALink && $usedBLink) {
  4288.              //       //             break;
  4289.              //       //           }
  4290.              //       //           if(!$usedALink) {
  4291.              //       //              $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4292.              //       //           }
  4293.              //       //           if (!$usedBLink) {
  4294.              //       //             $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4295.              //       //           }
  4296.              //       //         }
  4297.              //       //
  4298.              //       //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4299.              //       //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4300.              //       //
  4301.              //       //         if ($usedALink){
  4302.              //       //             $used = 1;
  4303.              //       //             $usedLinkID = $usedALink->getLink()->getLinkID();
  4304.              //       //             $usedLink_id = $usedALink->getLink()->getId();
  4305.              //       //         }
  4306.              //       //
  4307.              //       //         if ($usedBLink){
  4308.              //       //             $used = 1;
  4309.              //       //             $usedLinkID = $usedBLink->getLink()->getLinkID();
  4310.              //       //             $usedLink_id = $usedBLink->getLink()->getId();
  4311.              //       //         }
  4312.              //       //
  4313.              //       //         $port->used = $used;
  4314.              //       //         $port->usedLinkID = $usedLinkID;
  4315.              //       //         $port->usedLink_id = $usedLink_id;
  4316.              //       //         // var_dump($used);
  4317.              //       //         $p['used'] = $used;
  4318.              //       //         $p['usedLinkID'] = $usedLinkID;
  4319.              //       //         $p['usedLink_id'] = $usedLink_id;
  4320.              //       //         $p['nPort'] = $port->nPort;
  4321.              //       //         $p['inTrunk'] = $isPortInTrunk;
  4322.              //       //
  4323.              //       //
  4324.              //       //         if ($port->nPort == 1 && $port->used == 1){
  4325.              //       //
  4326.              //       //             $p['id'] = $port->getId();
  4327.              //       //
  4328.              //       //         }
  4329.              //       //
  4330.              //       //         $totalPortsInInterface++;
  4331.              //       //
  4332.              //       //         if ($used == 1){
  4333.              //       //             $totalPortsUsed ++;
  4334.              //       //         }
  4335.              //       //
  4336.              //       //         $portList[] = $p;
  4337.              //       //
  4338.              //       //     }
  4339.              //       //
  4340.              //       //     $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4341.              //       //     $int['totalPorts'] = $totalPorts;
  4342.              //       //     $int['totalPortsUsed'] = $totalPortsUsed;
  4343.              //       //     $int['ports'] = $portList;
  4344.              //       //
  4345.              //       //     if ($isInterfaceInTrunk == 1){
  4346.              //       //
  4347.              //       //         $eq['interfaces'][] = $int;
  4348.              //       //
  4349.              //       //         if ($totalPortsInInterface > $maxPorts){
  4350.              //       //             $maxPorts = $totalPortsInInterface;
  4351.              //       //         }
  4352.              //       //
  4353.              //       //     }
  4354.              //       //
  4355.              //       //
  4356.              //       // }
  4357.              //       //
  4358.              //       // $list[] = $eq;
  4359.              //
  4360.              //   }
  4361.            }
  4362.          }
  4363.         }
  4364.        //   $cache->save($trunkList->set($list));
  4365.        //   $cache->save($maxPortsFromCache->set($maxPorts));
  4366.        // }
  4367.        // else {
  4368.        //   $list = $trunkList->get();
  4369.        //   $maxPorts = $maxPortsFromCache->get();
  4370.        //   // var_dump($links);
  4371.        // }
  4372.        // $adapter = new ArrayAdapter($list);
  4373.        // $pagerfanta = new Pagerfanta($adapter);
  4374.        $pageLength $request->query->get("pageLength"$this->getParameter("trunk.details.maxPerPage"));
  4375.        // if ($pageLength == "Tout") {
  4376.        //   $pagerfanta->setMaxPerPage(count($list)); // 10 by default
  4377.        // }
  4378.        // else {
  4379.        //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  4380.        // }
  4381.        // // $this->container->setParameter("link.maxPerPage", $pageLength);
  4382.        // $page = $request->query->get("page", 1);
  4383.        // $pagerfanta->setCurrentPage($page);
  4384.        return $this->render('overview/trunk_usage_full.html.twig', [
  4385.            'action' => 'list',
  4386.            'page_title' => $translator->trans('Trunk Usage'),
  4387.            'list' => $list,
  4388.            'maxPorts' => $maxPorts,
  4389.            // 'my_pager' => $pagerfanta,
  4390.            'pageLength' => $pageLength,
  4391.        ]);
  4392.    }
  4393.    /**
  4394.     * @Route("/trunk/usage/all/extended", name="trunk_usage_all_extended")
  4395.     */
  4396.    public function overviewListFullExtendedAction(TranslatorInterface $translator)
  4397.   {
  4398.        $list = [];
  4399.        $trunks $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
  4400.        $maxPorts 0;
  4401.        //get all the ports used by Links
  4402.        $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  4403.        $portsAll = array();
  4404.        foreach ($portsAllTemp as $tempArray) {
  4405.          foreach ($tempArray as $key => $value) {
  4406.            $portsAll[] = $value;
  4407.          }
  4408.        }
  4409.        foreach ($trunks as $trunk){
  4410.             $eqBArray = [];
  4411.             $tcfs $trunk->getCableFiber();
  4412.            if ( !($tcfs->isEmpty()) ) {
  4413.                // $firstTcf = $tcfs[0];
  4414.                // $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  4415.                // $eqB = null;
  4416.                //
  4417.                // if (count($firstTcf->getExtensions()) > 0) {
  4418.                //   $trunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
  4419.                //   $eqB = $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  4420.                // }
  4421.                // else {
  4422.                //   $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  4423.                // }
  4424.                // $trunk->eqA = $eqA;
  4425.                // // var_dump($eqA->getId());
  4426.                //
  4427.                // $rackTitle = $eqA->getRack()->getTitle();
  4428.                //
  4429.                //     $eq['trunkID'] = $trunk->getTrunkID();
  4430.                //     $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  4431.                //     $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  4432.                //     $eq['rack'] = $rackTitle;
  4433.                //     $eq['equipment'] = $eqA->getEquipmentSpecificName();
  4434.                //     $eq['interfaces'] = [];
  4435.                //
  4436.                //     $interfaces = $eqA->getInterfaceSpecific();
  4437.                //     foreach ($interfaces as $interface) {
  4438.                //         // var_dump($interface->getId());
  4439.                //         $totalPorts = 0;
  4440.                //         $totalPortsUsed = 0;
  4441.                //         $totalPortsInInterface = 0;
  4442.                //
  4443.                //         $ports = $interface->getPort();
  4444.                //
  4445.                //         $portList = [];
  4446.                //
  4447.                //         $isInterfaceInTrunk = 0;
  4448.                //
  4449.                //         foreach ($ports as $port) {
  4450.                //           // var_dump($port->getId());
  4451.                //
  4452.                //             $isPortInTrunk = 0;
  4453.                //
  4454.                //             $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4455.                //             $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4456.                //             $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  4457.                //             // var_dump($usedInTrunkPointA);
  4458.                //             // var_dump($usedInTrunkPointB);
  4459.                //             // var_dump($usedInTrunkExtension);
  4460.                //
  4461.                //             if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  4462.                //                 $isInterfaceInTrunk = 1;
  4463.                //                 $isPortInTrunk = 1;
  4464.                //                 $totalPorts++;
  4465.                //             }
  4466.                //
  4467.                //             $port->nPort = 0;
  4468.                //             $port->used = 0;
  4469.                //
  4470.                //             $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4471.                //             if ($nPorts){
  4472.                //                 $nPorts = json_decode($nPorts);
  4473.                //                 if (in_array($port->getOrderNo(), $nPorts)){
  4474.                //                     $port->nPort = 1;
  4475.                //                 }
  4476.                //             }
  4477.                //
  4478.                //             $used = 0;
  4479.                //             $usedLinkID = '';
  4480.                //             $usedLink_id = '';
  4481.                //
  4482.                //             if (in_array($port->getId(), $portsAll)) {
  4483.                //             $usedALink = null;
  4484.                //             $usedBLink = null;
  4485.                //             $tempExts = $port->getExtensionOrder();
  4486.                //             foreach ( $tempExts as $value) {
  4487.                //               $extremityB = $value->getExtremity();
  4488.                //               if ($usedALink && $usedBLink) {
  4489.                //                 break;
  4490.                //               }
  4491.                //               if(!$usedALink) {
  4492.                //                  $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4493.                //               }
  4494.                //               if (!$usedBLink) {
  4495.                //                 $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4496.                //               }
  4497.                //             }
  4498.                //             $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  4499.                //             $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  4500.                //
  4501.                //             if ($usedALink) {
  4502.                //               $used = 1;
  4503.                //               $usedLinkID = $usedALink->getLink()->getLinkID();
  4504.                //               $usedLink_id = $usedALink->getLink()->getId();
  4505.                //             }
  4506.                //             if ($usedBLink) {
  4507.                //               $used = 1;
  4508.                //               $usedLinkID = $usedBLink->getLink()->getLinkID();
  4509.                //               $usedLink_id = $usedBLink->getLink()->getId();
  4510.                //             }
  4511.                //
  4512.                //             if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  4513.                //
  4514.                //             }
  4515.                //             else if($trunkExtension) {
  4516.                //               // var_dump("Got it");
  4517.                //               $used = 1;
  4518.                //               $usedLinkID = $port->getLink()->getLinkID();
  4519.                //               $usedLink_id = $port->getLink()->getId();
  4520.                //             }
  4521.                //             if ($tcfB && $usedBLink) {
  4522.                //
  4523.                //             }
  4524.                //             else if($tcfB){
  4525.                //               $used = 1;
  4526.                //               $usedLinkID = $port->getLink()->getLinkID();
  4527.                //               $usedLink_id = $port->getLink()->getId();
  4528.                //
  4529.                //             }
  4530.                //
  4531.                //             $port->used = $used;
  4532.                //             $port->usedLinkID = $usedLinkID;
  4533.                //             $port->usedLink_id = $usedLink_id;
  4534.                //           }
  4535.                //             // $usedALink = null;
  4536.                //             // $usedBLink = null;
  4537.                //             // $tempExts = $port->getExtremities();
  4538.                //             // foreach ( $tempExts as $extremityB) {
  4539.                //             //   if ($usedALink && $usedBLink) {
  4540.                //             //     break;
  4541.                //             //   }
  4542.                //             //   if(!$usedALink) {
  4543.                //             //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4544.                //             //   }
  4545.                //             //   if (!$usedBLink) {
  4546.                //             //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4547.                //             //   }
  4548.                //             // }
  4549.                //             // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4550.                //             // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4551.                //             // if ($usedALink) {
  4552.                //             //     $used = 1;
  4553.                //             //     $usedLinkID = $usedALink->getLink()->getLinkID();
  4554.                //             //     $usedLink_id = $usedALink->getLink()->getId();
  4555.                //             // }
  4556.                //             //
  4557.                //             // if ($usedBLink) {
  4558.                //             //     $used = 1;
  4559.                //             //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  4560.                //             //     $usedLink_id = $usedBLink->getLink()->getId();
  4561.                //             // }
  4562.                //             // // var_dump($used);
  4563.                //             //
  4564.                //             // $port->used = $used;
  4565.                //             // $port->usedLinkID = $usedLinkID;
  4566.                //             // $port->usedLink_id = $usedLink_id;
  4567.                //
  4568.                //             $p['used'] = $used;
  4569.                //             $p['usedLinkID'] = $usedLinkID;
  4570.                //             $p['usedLink_id'] = $usedLink_id;
  4571.                //             $p['nPort'] = $port->nPort;
  4572.                //             $p['inTrunk'] = $isPortInTrunk;
  4573.                //
  4574.                //
  4575.                //             if ($port->nPort == 1 && $port->used == 1){
  4576.                //
  4577.                //                 $p['id'] = $port->getId();
  4578.                //
  4579.                //             }
  4580.                //
  4581.                //
  4582.                //             $totalPortsInInterface++;
  4583.                //
  4584.                //             if ($used == 1) {
  4585.                //                 $totalPortsUsed++;
  4586.                //             }
  4587.                //
  4588.                //             $portList[] = $p;
  4589.                //
  4590.                //         }
  4591.                //
  4592.                //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4593.                //         $int['totalPorts'] = $totalPorts;
  4594.                //         $int['totalPortsUsed'] = $totalPortsUsed;
  4595.                //         $int['ports'] = $portList;
  4596.                //
  4597.                //         if ($isInterfaceInTrunk == 1){
  4598.                //
  4599.                //             $eq['interfaces'][] = $int;
  4600.                //
  4601.                //             if ($totalPortsInInterface > $maxPorts){
  4602.                //                 $maxPorts = $totalPortsInInterface;
  4603.                //             }
  4604.                //
  4605.                //         }
  4606.                //
  4607.                //     }
  4608.                //
  4609.                // $list[] = $eq;
  4610.                // if ($eqB != $eqA) {
  4611.                //   //eqB
  4612.                //   $trunk->eqB = $eqB;
  4613.                //   // var_dump($eqA->getId());
  4614.                //
  4615.                //   $rackTitle = $eqB->getRack()->getTitle();
  4616.                //
  4617.                //       $eq['trunkID'] = $trunk->getTrunkID();
  4618.                //       $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  4619.                //       $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  4620.                //       $eq['rack'] = $rackTitle;
  4621.                //       $eq['equipment'] = $eqB->getEquipmentSpecificName();
  4622.                //       $eq['interfaces'] = [];
  4623.                //
  4624.                //       $interfaces = $eqB->getInterfaceSpecific();
  4625.                //       foreach ($interfaces as $interface) {
  4626.                //           // var_dump($interface->getId());
  4627.                //           $totalPorts = 0;
  4628.                //           $totalPortsUsed = 0;
  4629.                //           $totalPortsInInterface = 0;
  4630.                //
  4631.                //           $ports = $interface->getPort();
  4632.                //
  4633.                //           $portList = [];
  4634.                //
  4635.                //           $isInterfaceInTrunk = 0;
  4636.                //
  4637.                //           foreach ($ports as $port) {
  4638.                //             // var_dump($port->getId());
  4639.                //
  4640.                //               $isPortInTrunk = 0;
  4641.                //
  4642.                //               $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4643.                //               $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4644.                //               $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  4645.                //               // var_dump($usedInTrunkPointA);
  4646.                //               // var_dump($usedInTrunkPointB);
  4647.                //               // var_dump($usedInTrunkExtension);
  4648.                //
  4649.                //               if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  4650.                //                   $isInterfaceInTrunk = 1;
  4651.                //                   $isPortInTrunk = 1;
  4652.                //                   $totalPorts++;
  4653.                //               }
  4654.                //
  4655.                //               $port->nPort = 0;
  4656.                //               $port->used = 0;
  4657.                //
  4658.                //               $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4659.                //               if ($nPorts){
  4660.                //                   $nPorts = json_decode($nPorts);
  4661.                //                   if (in_array($port->getOrderNo(), $nPorts)){
  4662.                //                       $port->nPort = 1;
  4663.                //                   }
  4664.                //               }
  4665.                //
  4666.                //               $used = 0;
  4667.                //               $usedLinkID = '';
  4668.                //               $usedLink_id = '';
  4669.                //
  4670.                //               if (in_array($port->getId(), $portsAll)) {
  4671.                //               $usedALink = null;
  4672.                //               $usedBLink = null;
  4673.                //               $tempExts = $port->getExtensionOrder();
  4674.                //               foreach ( $tempExts as $value) {
  4675.                //                 $extremityB = $value->getExtremity();
  4676.                //                 if ($usedALink && $usedBLink) {
  4677.                //                   break;
  4678.                //                 }
  4679.                //                 if(!$usedALink) {
  4680.                //                    $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4681.                //                 }
  4682.                //                 if (!$usedBLink) {
  4683.                //                   $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4684.                //                 }
  4685.                //               }
  4686.                //               $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  4687.                //               $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  4688.                //
  4689.                //               if ($usedALink) {
  4690.                //                 $used = 1;
  4691.                //                 $usedLinkID = $usedALink->getLink()->getLinkID();
  4692.                //                 $usedLink_id = $usedALink->getLink()->getId();
  4693.                //               }
  4694.                //               if ($usedBLink) {
  4695.                //                 $used = 1;
  4696.                //                 $usedLinkID = $usedBLink->getLink()->getLinkID();
  4697.                //                 $usedLink_id = $usedBLink->getLink()->getId();
  4698.                //               }
  4699.                //
  4700.                //               if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  4701.                //
  4702.                //               }
  4703.                //               else if($trunkExtension) {
  4704.                //                 // var_dump("Got it");
  4705.                //                 $used = 1;
  4706.                //                 $usedLinkID = $port->getLink()->getLinkID();
  4707.                //                 $usedLink_id = $port->getLink()->getId();
  4708.                //               }
  4709.                //               if ($tcfB && $usedBLink) {
  4710.                //
  4711.                //               }
  4712.                //               else if($tcfB){
  4713.                //                 $used = 1;
  4714.                //                 $usedLinkID = $port->getLink()->getLinkID();
  4715.                //                 $usedLink_id = $port->getLink()->getId();
  4716.                //
  4717.                //               }
  4718.                //
  4719.                //               $port->used = $used;
  4720.                //               $port->usedLinkID = $usedLinkID;
  4721.                //               $port->usedLink_id = $usedLink_id;
  4722.                //             }
  4723.                //               // $usedALink = null;
  4724.                //               // $usedBLink = null;
  4725.                //               // $tempExts = $port->getExtremities();
  4726.                //               // foreach ( $tempExts as $extremityB) {
  4727.                //               //   if ($usedALink && $usedBLink) {
  4728.                //               //     break;
  4729.                //               //   }
  4730.                //               //   if(!$usedALink) {
  4731.                //               //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4732.                //               //   }
  4733.                //               //   if (!$usedBLink) {
  4734.                //               //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4735.                //               //   }
  4736.                //               // }
  4737.                //               // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4738.                //               // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4739.                //               // if ($usedALink) {
  4740.                //               //     $used = 1;
  4741.                //               //     $usedLinkID = $usedALink->getLink()->getLinkID();
  4742.                //               //     $usedLink_id = $usedALink->getLink()->getId();
  4743.                //               // }
  4744.                //               //
  4745.                //               // if ($usedBLink) {
  4746.                //               //     $used = 1;
  4747.                //               //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  4748.                //               //     $usedLink_id = $usedBLink->getLink()->getId();
  4749.                //               // }
  4750.                //               // // var_dump($used);
  4751.                //               //
  4752.                //               // $port->used = $used;
  4753.                //               // $port->usedLinkID = $usedLinkID;
  4754.                //               // $port->usedLink_id = $usedLink_id;
  4755.                //
  4756.                //               $p['used'] = $used;
  4757.                //               $p['usedLinkID'] = $usedLinkID;
  4758.                //               $p['usedLink_id'] = $usedLink_id;
  4759.                //               $p['nPort'] = $port->nPort;
  4760.                //               $p['inTrunk'] = $isPortInTrunk;
  4761.                //
  4762.                //
  4763.                //               if ($port->nPort == 1 && $port->used == 1){
  4764.                //
  4765.                //                   $p['id'] = $port->getId();
  4766.                //
  4767.                //               }
  4768.                //
  4769.                //
  4770.                //               $totalPortsInInterface++;
  4771.                //
  4772.                //               if ($used == 1) {
  4773.                //                   $totalPortsUsed++;
  4774.                //               }
  4775.                //
  4776.                //               $portList[] = $p;
  4777.                //
  4778.                //           }
  4779.                //
  4780.                //           $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4781.                //           $int['totalPorts'] = $totalPorts;
  4782.                //           $int['totalPortsUsed'] = $totalPortsUsed;
  4783.                //           $int['ports'] = $portList;
  4784.                //
  4785.                //           if ($isInterfaceInTrunk == 1){
  4786.                //
  4787.                //               $eq['interfaces'][] = $int;
  4788.                //
  4789.                //               if ($totalPortsInInterface > $maxPorts){
  4790.                //                   $maxPorts = $totalPortsInInterface;
  4791.                //               }
  4792.                //
  4793.                //           }
  4794.                //
  4795.                //       }
  4796.                //
  4797.                //   $list[] = $eq;
  4798.                // }
  4799.                 //version long avec tous les Ã©quipements intermédiaire
  4800.                 foreach ($tcfs as $firstTcf) {
  4801.                   // $firstTcf = $tcfs[0];
  4802.                   $eqA $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  4803.                   if (!in_array($eqA->getId(), $eqBArray)) {
  4804.                     $eqBArray[] = $eqA->getId();
  4805.                     $res $this->createEquipment($trunk$eqA$portsAll$maxPorts);
  4806.                     $list[] = $res["eq"];
  4807.                     $maxPorts $res["maxPorts"];
  4808.                     // $trunk->eqA = $eqA;
  4809.                     // // var_dump($eqA->getId());
  4810.                     //
  4811.                     // $rackTitle = $eqA->getRack()->getTitle();
  4812.                     //
  4813.                     //     $eq['trunkID'] = $trunk->getTrunkID();
  4814.                     //     $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  4815.                     //     $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  4816.                     //     $eq['rack'] = $rackTitle;
  4817.                     //     $eq['equipment'] = $eqA->getEquipmentSpecificName();
  4818.                     //     $eq['interfaces'] = [];
  4819.                     //
  4820.                     //     $interfaces = $eqA->getInterfaceSpecific();
  4821.                     //     foreach ($interfaces as $interface) {
  4822.                     //         // var_dump($interface->getId());
  4823.                     //         $totalPorts = 0;
  4824.                     //         $totalPortsUsed = 0;
  4825.                     //         $totalPortsInInterface = 0;
  4826.                     //
  4827.                     //         $ports = $interface->getPort();
  4828.                     //
  4829.                     //         $portList = [];
  4830.                     //
  4831.                     //         $isInterfaceInTrunk = 0;
  4832.                     //
  4833.                     //         foreach ($ports as $port) {
  4834.                     //           // var_dump($port->getId());
  4835.                     //
  4836.                     //             $isPortInTrunk = 0;
  4837.                     //
  4838.                     //             $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4839.                     //             $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4840.                     //             $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  4841.                     //             // var_dump($usedInTrunkPointA);
  4842.                     //             // var_dump($usedInTrunkPointB);
  4843.                     //             // var_dump($usedInTrunkExtension);
  4844.                     //
  4845.                     //             if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  4846.                     //                 $isInterfaceInTrunk = 1;
  4847.                     //                 $isPortInTrunk = 1;
  4848.                     //                 $totalPorts++;
  4849.                     //             }
  4850.                     //
  4851.                     //             $port->nPort = 0;
  4852.                     //             $port->used = 0;
  4853.                     //
  4854.                     //             $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  4855.                     //             if ($nPorts){
  4856.                     //                 $nPorts = json_decode($nPorts);
  4857.                     //                 if (in_array($port->getOrderNo(), $nPorts)){
  4858.                     //                     $port->nPort = 1;
  4859.                     //                 }
  4860.                     //             }
  4861.                     //
  4862.                     //             $used = 0;
  4863.                     //             $usedLinkID = '';
  4864.                     //             $usedLink_id = '';
  4865.                     //
  4866.                     //             if (in_array($port->getId(), $portsAll)) {
  4867.                     //             $usedALink = null;
  4868.                     //             $usedBLink = null;
  4869.                     //             $tempExts = $port->getExtensionOrder();
  4870.                     //             foreach ( $tempExts as $value) {
  4871.                     //               $extremityB = $value->getExtremity();
  4872.                     //               if ($usedALink && $usedBLink) {
  4873.                     //                 break;
  4874.                     //               }
  4875.                     //               if(!$usedALink) {
  4876.                     //                  $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4877.                     //               }
  4878.                     //               if (!$usedBLink) {
  4879.                     //                 $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4880.                     //               }
  4881.                     //             }
  4882.                     //             $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  4883.                     //             $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  4884.                     //
  4885.                     //             if ($usedALink) {
  4886.                     //               $used = 1;
  4887.                     //               $usedLinkID = $usedALink->getLink()->getLinkID();
  4888.                     //               $usedLink_id = $usedALink->getLink()->getId();
  4889.                     //             }
  4890.                     //             if ($usedBLink) {
  4891.                     //               $used = 1;
  4892.                     //               $usedLinkID = $usedBLink->getLink()->getLinkID();
  4893.                     //               $usedLink_id = $usedBLink->getLink()->getId();
  4894.                     //             }
  4895.                     //
  4896.                     //             if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  4897.                     //
  4898.                     //             }
  4899.                     //             else if($trunkExtension) {
  4900.                     //               // var_dump("Got it");
  4901.                     //               $used = 1;
  4902.                     //               $usedLinkID = $port->getLink()->getLinkID();
  4903.                     //               $usedLink_id = $port->getLink()->getId();
  4904.                     //             }
  4905.                     //             if ($tcfB && $usedBLink) {
  4906.                     //
  4907.                     //             }
  4908.                     //             else if($tcfB){
  4909.                     //               $used = 1;
  4910.                     //               $usedLinkID = $port->getLink()->getLinkID();
  4911.                     //               $usedLink_id = $port->getLink()->getId();
  4912.                     //
  4913.                     //             }
  4914.                     //
  4915.                     //             $port->used = $used;
  4916.                     //             $port->usedLinkID = $usedLinkID;
  4917.                     //             $port->usedLink_id = $usedLink_id;
  4918.                     //           }
  4919.                     //             // $usedALink = null;
  4920.                     //             // $usedBLink = null;
  4921.                     //             // $tempExts = $port->getExtremities();
  4922.                     //             // foreach ( $tempExts as $extremityB) {
  4923.                     //             //   if ($usedALink && $usedBLink) {
  4924.                     //             //     break;
  4925.                     //             //   }
  4926.                     //             //   if(!$usedALink) {
  4927.                     //             //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  4928.                     //             //   }
  4929.                     //             //   if (!$usedBLink) {
  4930.                     //             //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  4931.                     //             //   }
  4932.                     //             // }
  4933.                     //             // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  4934.                     //             // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  4935.                     //             // if ($usedALink) {
  4936.                     //             //     $used = 1;
  4937.                     //             //     $usedLinkID = $usedALink->getLink()->getLinkID();
  4938.                     //             //     $usedLink_id = $usedALink->getLink()->getId();
  4939.                     //             // }
  4940.                     //             //
  4941.                     //             // if ($usedBLink) {
  4942.                     //             //     $used = 1;
  4943.                     //             //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  4944.                     //             //     $usedLink_id = $usedBLink->getLink()->getId();
  4945.                     //             // }
  4946.                     //             // // var_dump($used);
  4947.                     //             //
  4948.                     //             // $port->used = $used;
  4949.                     //             // $port->usedLinkID = $usedLinkID;
  4950.                     //             // $port->usedLink_id = $usedLink_id;
  4951.                     //
  4952.                     //             $p['used'] = $used;
  4953.                     //             $p['usedLinkID'] = $usedLinkID;
  4954.                     //             $p['usedLink_id'] = $usedLink_id;
  4955.                     //             $p['nPort'] = $port->nPort;
  4956.                     //             $p['inTrunk'] = $isPortInTrunk;
  4957.                     //
  4958.                     //
  4959.                     //             if ($port->nPort == 1 && $port->used == 1){
  4960.                     //
  4961.                     //                 $p['id'] = $port->getId();
  4962.                     //
  4963.                     //             }
  4964.                     //
  4965.                     //
  4966.                     //             $totalPortsInInterface++;
  4967.                     //
  4968.                     //             if ($used == 1) {
  4969.                     //                 $totalPortsUsed++;
  4970.                     //             }
  4971.                     //
  4972.                     //             $portList[] = $p;
  4973.                     //
  4974.                     //         }
  4975.                     //
  4976.                     //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  4977.                     //         $int['totalPorts'] = $totalPorts;
  4978.                     //         $int['totalPortsUsed'] = $totalPortsUsed;
  4979.                     //         $int['ports'] = $portList;
  4980.                     //
  4981.                     //         if ($isInterfaceInTrunk == 1){
  4982.                     //
  4983.                     //             $eq['interfaces'][] = $int;
  4984.                     //
  4985.                     //             if ($totalPortsInInterface > $maxPorts){
  4986.                     //                 $maxPorts = $totalPortsInInterface;
  4987.                     //             }
  4988.                     //
  4989.                     //         }
  4990.                     //
  4991.                     //     }
  4992.                     //
  4993.                     // $list[] = $eq;
  4994.                   }
  4995.                   $eqB $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  4996.                   if (!in_array($eqB->getId(), $eqBArray)) {
  4997.                       $eqBArray[] = $eqB->getId();
  4998.                       $res $this->createEquipment($trunk$eqB$portsAll$maxPorts);
  4999.                       $list[] = $res["eq"];
  5000.                       $maxPorts $res["maxPorts"];
  5001.                       // $trunk->eqB = $eqB;
  5002.                       //
  5003.                       // $rackTitle = $eqB->getRack()->getTitle();
  5004.                       //
  5005.                       // $eq['trunkID'] = $trunk->getTrunkID();
  5006.                       // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  5007.                       // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  5008.                       // $eq['rack'] = $rackTitle;
  5009.                       // $eq['equipment'] = $eqB->getEquipmentSpecificName();
  5010.                       // $eq['interfaces'] = [];
  5011.                       //
  5012.                       // $interfaces = $eqB->getInterfaceSpecific();
  5013.                       // foreach ($interfaces as $interface){
  5014.                       //
  5015.                       //   $totalPorts = 0;
  5016.                       //   $totalPortsUsed = 0;
  5017.                       //   $totalPortsInInterface = 0;
  5018.                       //
  5019.                       //   $ports = $interface->getPort();
  5020.                       //
  5021.                       //   $portList = [];
  5022.                       //
  5023.                       //   $isInterfaceInTrunk = 0;
  5024.                       //
  5025.                       //   foreach ($ports as $port){
  5026.                       //
  5027.                       //     $isPortInTrunk = 0;
  5028.                       //
  5029.                       //     $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5030.                       //     $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5031.                       //     $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  5032.                       //
  5033.                       //     if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  5034.                       //       $isInterfaceInTrunk = 1;
  5035.                       //       $isPortInTrunk = 1;
  5036.                       //       $totalPorts++;
  5037.                       //     }
  5038.                       //
  5039.                       //
  5040.                       //     $port->nPort = 0;
  5041.                       //     $port->used = 0;
  5042.                       //
  5043.                       //     $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  5044.                       //     if ($nPorts){
  5045.                       //       $nPorts = json_decode($nPorts);
  5046.                       //       if (in_array($port->getOrderNo(), $nPorts)){
  5047.                       //         $port->nPort = 1;
  5048.                       //       }
  5049.                       //     }
  5050.                       //
  5051.                       //     $used = 0;
  5052.                       //     $usedLinkID = '';
  5053.                       //     $usedLink_id = '';
  5054.                       //     if (in_array($port->getId(), $portsAll)) {
  5055.                       //       $usedALink = null;
  5056.                       //       $usedBLink = null;
  5057.                       //       $tempExts = $port->getExtensionOrder();
  5058.                       //       foreach ( $tempExts as $value) {
  5059.                       //         $extremityB = $value->getExtremity();
  5060.                       //         if ($usedALink && $usedBLink) {
  5061.                       //           break;
  5062.                       //         }
  5063.                       //         if(!$usedALink) {
  5064.                       //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5065.                       //         }
  5066.                       //         if (!$usedBLink) {
  5067.                       //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5068.                       //         }
  5069.                       //       }
  5070.                       //       $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  5071.                       //       $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  5072.                       //
  5073.                       //       if ($usedALink) {
  5074.                       //         $used = 1;
  5075.                       //         $usedLinkID = $usedALink->getLink()->getLinkID();
  5076.                       //         $usedLink_id = $usedALink->getLink()->getId();
  5077.                       //       }
  5078.                       //       if ($usedBLink) {
  5079.                       //         $used = 1;
  5080.                       //         $usedLinkID = $usedBLink->getLink()->getLinkID();
  5081.                       //         $usedLink_id = $usedBLink->getLink()->getId();
  5082.                       //       }
  5083.                       //
  5084.                       //       if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  5085.                       //
  5086.                       //       }
  5087.                       //       else if($trunkExtension) {
  5088.                       //         // var_dump("Got it");
  5089.                       //         $used = 1;
  5090.                       //         $usedLinkID = $port->getLink()->getLinkID();
  5091.                       //         $usedLink_id = $port->getLink()->getId();
  5092.                       //       }
  5093.                       //       if ($tcfB && $usedBLink) {
  5094.                       //
  5095.                       //       }
  5096.                       //       else if($tcfB){
  5097.                       //         $used = 1;
  5098.                       //         $usedLinkID = $port->getLink()->getLinkID();
  5099.                       //         $usedLink_id = $port->getLink()->getId();
  5100.                       //
  5101.                       //       }
  5102.                       //
  5103.                       //       $port->used = $used;
  5104.                       //       $port->usedLinkID = $usedLinkID;
  5105.                       //       $port->usedLink_id = $usedLink_id;
  5106.                       //     }
  5107.                       //     // $usedALink = null;
  5108.                       //     // $usedBLink = null;
  5109.                       //     // $tempExts = $port->getExtremities();
  5110.                       //     // foreach ( $tempExts as $extremityB) {
  5111.                       //     //   if ($usedALink && $usedBLink) {
  5112.                       //     //     break;
  5113.                       //     //   }
  5114.                       //     //   if(!$usedALink) {
  5115.                       //     //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5116.                       //     //   }
  5117.                       //     //   if (!$usedBLink) {
  5118.                       //     //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5119.                       //     //   }
  5120.                       //     // }
  5121.                       //     //
  5122.                       //     // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5123.                       //     // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5124.                       //     //
  5125.                       //     // if ($usedALink){
  5126.                       //     //     $used = 1;
  5127.                       //     //     $usedLinkID = $usedALink->getLink()->getLinkID();
  5128.                       //     //     $usedLink_id = $usedALink->getLink()->getId();
  5129.                       //     // }
  5130.                       //     //
  5131.                       //     // if ($usedBLink){
  5132.                       //     //     $used = 1;
  5133.                       //     //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  5134.                       //     //     $usedLink_id = $usedBLink->getLink()->getId();
  5135.                       //     // }
  5136.                       //
  5137.                       //     $port->used = $used;
  5138.                       //     $port->usedLinkID = $usedLinkID;
  5139.                       //     $port->usedLink_id = $usedLink_id;
  5140.                       //
  5141.                       //     $p['used'] = $used;
  5142.                       //     $p['usedLinkID'] = $usedLinkID;
  5143.                       //     $p['usedLink_id'] = $usedLink_id;
  5144.                       //     $p['nPort'] = $port->nPort;
  5145.                       //     $p['inTrunk'] = $isPortInTrunk;
  5146.                       //
  5147.                       //
  5148.                       //     if ($port->nPort == 1 && $port->used == 1){
  5149.                       //
  5150.                       //       $p['id'] = $port->getId();
  5151.                       //
  5152.                       //     }
  5153.                       //
  5154.                       //     $totalPortsInInterface ++;
  5155.                       //
  5156.                       //     if ($used == 1){
  5157.                       //       $totalPortsUsed ++;
  5158.                       //     }
  5159.                       //
  5160.                       //     $portList[] = $p;
  5161.                       //
  5162.                       //   }
  5163.                       //
  5164.                       //   $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  5165.                       //   $int['totalPorts'] = $totalPorts;
  5166.                       //   $int['totalPortsUsed'] = $totalPortsUsed;
  5167.                       //   $int['ports'] = $portList;
  5168.                       //
  5169.                       //   if ($isInterfaceInTrunk == 1){
  5170.                       //
  5171.                       //     $eq['interfaces'][] = $int;
  5172.                       //
  5173.                       //     if ($totalPortsInInterface > $maxPorts){
  5174.                       //       $maxPorts = $totalPortsInInterface;
  5175.                       //     }
  5176.                       //
  5177.                       //   }
  5178.                       //
  5179.                       //
  5180.                       // }
  5181.                       //
  5182.                       // $list[] = $eq;
  5183.                       $extensions $firstTcf->getExtensions();
  5184.                         foreach ($extensions as $extension) {
  5185.                           $eqB $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5186.                           if (!in_array($eqB->getId(), $eqBArray)) {
  5187.                             $eqBArray[] = $eqB->getId();
  5188.                             $res $this->createEquipment($trunk$eqB$portsAll$maxPorts);
  5189.                             $list[] = $res["eq"];
  5190.                             $maxPorts $res["maxPorts"];
  5191.                             // $trunk->eqB = $eqB;
  5192.                             //
  5193.                             // $rackTitle = $eqB->getRack()->getTitle();
  5194.                             //
  5195.                             // $eq['trunkID'] = $trunk->getTrunkID();
  5196.                             // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  5197.                             // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  5198.                             // $eq['rack'] = $rackTitle;
  5199.                             // $eq['equipment'] = $eqB->getEquipmentSpecificName();
  5200.                             // $eq['interfaces'] = [];
  5201.                             //
  5202.                             // $interfaces = $eqB->getInterfaceSpecific();
  5203.                             // foreach ($interfaces as $interface){
  5204.                             //
  5205.                             //   $totalPorts = 0;
  5206.                             //   $totalPortsUsed = 0;
  5207.                             //   $totalPortsInInterface = 0;
  5208.                             //
  5209.                             //   $ports = $interface->getPort();
  5210.                             //
  5211.                             //   $portList = [];
  5212.                             //
  5213.                             //   $isInterfaceInTrunk = 0;
  5214.                             //
  5215.                             //   foreach ($ports as $port){
  5216.                             //
  5217.                             //     $isPortInTrunk = 0;
  5218.                             //
  5219.                             //     $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5220.                             //     $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5221.                             //     $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  5222.                             //
  5223.                             //     if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  5224.                             //       $isInterfaceInTrunk = 1;
  5225.                             //       $isPortInTrunk = 1;
  5226.                             //       $totalPorts++;
  5227.                             //     }
  5228.                             //
  5229.                             //
  5230.                             //     $port->nPort = 0;
  5231.                             //     $port->used = 0;
  5232.                             //
  5233.                             //     $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  5234.                             //     if ($nPorts){
  5235.                             //       $nPorts = json_decode($nPorts);
  5236.                             //       if (in_array($port->getOrderNo(), $nPorts)){
  5237.                             //         $port->nPort = 1;
  5238.                             //       }
  5239.                             //     }
  5240.                             //
  5241.                             //     $used = 0;
  5242.                             //     $usedLinkID = '';
  5243.                             //     $usedLink_id = '';
  5244.                             //     if (in_array($port->getId(), $portsAll)) {
  5245.                             //       $usedALink = null;
  5246.                             //       $usedBLink = null;
  5247.                             //       $tempExts = $port->getExtensionOrder();
  5248.                             //       foreach ( $tempExts as $value) {
  5249.                             //         $extrmityB = $value->getExtremity();
  5250.                             //         if ($usedALink && $usedBLink) {
  5251.                             //           break;
  5252.                             //         }
  5253.                             //         if(!$usedALink) {
  5254.                             //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5255.                             //         }
  5256.                             //         if (!$usedBLink) {
  5257.                             //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5258.                             //         }
  5259.                             //       }
  5260.                             //       $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  5261.                             //       $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  5262.                             //
  5263.                             //       if ($usedALink) {
  5264.                             //         $used = 1;
  5265.                             //         $usedLinkID = $usedALink->getLink()->getLinkID();
  5266.                             //         $usedLink_id = $usedALink->getLink()->getId();
  5267.                             //       }
  5268.                             //       if ($usedBLink) {
  5269.                             //         $used = 1;
  5270.                             //         $usedLinkID = $usedBLink->getLink()->getLinkID();
  5271.                             //         $usedLink_id = $usedBLink->getLink()->getId();
  5272.                             //       }
  5273.                             //
  5274.                             //       if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  5275.                             //
  5276.                             //       }
  5277.                             //       else if($trunkExtension) {
  5278.                             //         // var_dump("Got it");
  5279.                             //         $used = 1;
  5280.                             //         $usedLinkID = $port->getLink()->getLinkID();
  5281.                             //         $usedLink_id = $port->getLink()->getId();
  5282.                             //       }
  5283.                             //       if ($tcfB && $usedBLink) {
  5284.                             //
  5285.                             //       }
  5286.                             //       else if($tcfB){
  5287.                             //         $used = 1;
  5288.                             //         $usedLinkID = $port->getLink()->getLinkID();
  5289.                             //         $usedLink_id = $port->getLink()->getId();
  5290.                             //
  5291.                             //       }
  5292.                             //
  5293.                             //       $port->used = $used;
  5294.                             //       $port->usedLinkID = $usedLinkID;
  5295.                             //       $port->usedLink_id = $usedLink_id;
  5296.                             //     }
  5297.                             //     // $usedALink = null;
  5298.                             //     // $usedBLink = null;
  5299.                             //     // $tempExts = $port->getExtremities();
  5300.                             //     // foreach ( $tempExts as $extremityB) {
  5301.                             //     //   if ($usedALink && $usedBLink) {
  5302.                             //     //     break;
  5303.                             //     //   }
  5304.                             //     //   if(!$usedALink) {
  5305.                             //     //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5306.                             //     //   }
  5307.                             //     //   if (!$usedBLink) {
  5308.                             //     //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5309.                             //     //   }
  5310.                             //     // }
  5311.                             //     //
  5312.                             //     // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5313.                             //     // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5314.                             //     //
  5315.                             //     // if ($usedALink){
  5316.                             //     //     $used = 1;
  5317.                             //     //     $usedLinkID = $usedALink->getLink()->getLinkID();
  5318.                             //     //     $usedLink_id = $usedALink->getLink()->getId();
  5319.                             //     // }
  5320.                             //     //
  5321.                             //     // if ($usedBLink){
  5322.                             //     //     $used = 1;
  5323.                             //     //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  5324.                             //     //     $usedLink_id = $usedBLink->getLink()->getId();
  5325.                             //     // }
  5326.                             //
  5327.                             //     $port->used = $used;
  5328.                             //     $port->usedLinkID = $usedLinkID;
  5329.                             //     $port->usedLink_id = $usedLink_id;
  5330.                             //
  5331.                             //     $p['used'] = $used;
  5332.                             //     $p['usedLinkID'] = $usedLinkID;
  5333.                             //     $p['usedLink_id'] = $usedLink_id;
  5334.                             //     $p['nPort'] = $port->nPort;
  5335.                             //     $p['inTrunk'] = $isPortInTrunk;
  5336.                             //
  5337.                             //
  5338.                             //     if ($port->nPort == 1 && $port->used == 1){
  5339.                             //
  5340.                             //       $p['id'] = $port->getId();
  5341.                             //
  5342.                             //     }
  5343.                             //
  5344.                             //     $totalPortsInInterface ++;
  5345.                             //
  5346.                             //     if ($used == 1){
  5347.                             //       $totalPortsUsed ++;
  5348.                             //     }
  5349.                             //
  5350.                             //     $portList[] = $p;
  5351.                             //
  5352.                             //   }
  5353.                             //
  5354.                             //   $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  5355.                             //   $int['totalPorts'] = $totalPorts;
  5356.                             //   $int['totalPortsUsed'] = $totalPortsUsed;
  5357.                             //   $int['ports'] = $portList;
  5358.                             //
  5359.                             //   if ($isInterfaceInTrunk == 1){
  5360.                             //
  5361.                             //     $eq['interfaces'][] = $int;
  5362.                             //
  5363.                             //     if ($totalPortsInInterface > $maxPorts){
  5364.                             //       $maxPorts = $totalPortsInInterface;
  5365.                             //     }
  5366.                             //
  5367.                             //   }
  5368.                             //
  5369.                             //
  5370.                             // }
  5371.                             //
  5372.                             // $list[] = $eq;
  5373.                           }
  5374.                         }
  5375.                   }
  5376.                   // var_dump($firstTcf);
  5377.                   // var_dump($firstTcf->getPortB()->getId());
  5378.                   // var_dump($eqB->getId());
  5379.                     // foreach ($tcfs as $tcf) {
  5380.                     //
  5381.                     // }
  5382.                       // $trunk->eqB = $eqB;
  5383.                       //
  5384.                       // $rackTitle = $eqB->getRack()->getTitle();
  5385.                       //
  5386.                       // $eq['trunkID'] = $trunk->getTrunkID();
  5387.                       // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  5388.                       // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  5389.                       // $eq['rack'] = $rackTitle;
  5390.                       // $eq['equipment'] = $eqB->getEquipmentSpecificName();
  5391.                       // $eq['interfaces'] = [];
  5392.                       //
  5393.                       // $interfaces = $eqB->getInterfaceSpecific();
  5394.                       // foreach ($interfaces as $interface){
  5395.                       //      // var_dump($interface->getId());
  5396.                       //     $totalPorts = 0;
  5397.                       //     $totalPortsUsed = 0;
  5398.                       //     $totalPortsInInterface = 0;
  5399.                       //
  5400.                       //     $ports = $interface->getPort();
  5401.                       //
  5402.                       //     $portList = [];
  5403.                       //
  5404.                       //     $isInterfaceInTrunk = 0;
  5405.                       //
  5406.                       //     foreach ($ports as $port){
  5407.                       //        // var_dump($port->getId());
  5408.                       //         $isPortInTrunk = 0;
  5409.                       //
  5410.                       //         $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5411.                       //         $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5412.                       //         $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  5413.                       //
  5414.                       //         if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  5415.                       //             $isInterfaceInTrunk = 1;
  5416.                       //             $isPortInTrunk = 1;
  5417.                       //             $totalPorts++;
  5418.                       //         }
  5419.                       //
  5420.                       //
  5421.                       //         $port->nPort = 0;
  5422.                       //
  5423.                       //         $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  5424.                       //         if ($nPorts){
  5425.                       //             $nPorts = json_decode($nPorts);
  5426.                       //             if (in_array($port->getOrderNo(), $nPorts)){
  5427.                       //                 $port->nPort = 1;
  5428.                       //             }
  5429.                       //         }
  5430.                       //
  5431.                       //         $used = 0;
  5432.                       //         $usedLinkID = '';
  5433.                       //         $usedLink_id = '';
  5434.                       //         $usedALink = null;
  5435.                       //         $usedBLink = null;
  5436.                       //         $tempExts = $port->getExtremities();
  5437.                       //         foreach ( $tempExts as $extremityB) {
  5438.                       //           if ($usedALink && $usedBLink) {
  5439.                       //             break;
  5440.                       //           }
  5441.                       //           if(!$usedALink) {
  5442.                       //              $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5443.                       //           }
  5444.                       //           if (!$usedBLink) {
  5445.                       //             $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5446.                       //           }
  5447.                       //         }
  5448.                       //
  5449.                       //         // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5450.                       //         // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5451.                       //
  5452.                       //         if ($usedALink){
  5453.                       //             $used = 1;
  5454.                       //             $usedLinkID = $usedALink->getLink()->getLinkID();
  5455.                       //             $usedLink_id = $usedALink->getLink()->getId();
  5456.                       //         }
  5457.                       //
  5458.                       //         if ($usedBLink){
  5459.                       //             $used = 1;
  5460.                       //             $usedLinkID = $usedBLink->getLink()->getLinkID();
  5461.                       //             $usedLink_id = $usedBLink->getLink()->getId();
  5462.                       //         }
  5463.                       //
  5464.                       //         $port->used = $used;
  5465.                       //         $port->usedLinkID = $usedLinkID;
  5466.                       //         $port->usedLink_id = $usedLink_id;
  5467.                       //         // var_dump($used);
  5468.                       //         $p['used'] = $used;
  5469.                       //         $p['usedLinkID'] = $usedLinkID;
  5470.                       //         $p['usedLink_id'] = $usedLink_id;
  5471.                       //         $p['nPort'] = $port->nPort;
  5472.                       //         $p['inTrunk'] = $isPortInTrunk;
  5473.                       //
  5474.                       //
  5475.                       //         if ($port->nPort == 1 && $port->used == 1){
  5476.                       //
  5477.                       //             $p['id'] = $port->getId();
  5478.                       //
  5479.                       //         }
  5480.                       //
  5481.                       //         $totalPortsInInterface++;
  5482.                       //
  5483.                       //         if ($used == 1){
  5484.                       //             $totalPortsUsed ++;
  5485.                       //         }
  5486.                       //
  5487.                       //         $portList[] = $p;
  5488.                       //
  5489.                       //     }
  5490.                       //
  5491.                       //     $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  5492.                       //     $int['totalPorts'] = $totalPorts;
  5493.                       //     $int['totalPortsUsed'] = $totalPortsUsed;
  5494.                       //     $int['ports'] = $portList;
  5495.                       //
  5496.                       //     if ($isInterfaceInTrunk == 1){
  5497.                       //
  5498.                       //         $eq['interfaces'][] = $int;
  5499.                       //
  5500.                       //         if ($totalPortsInInterface > $maxPorts){
  5501.                       //             $maxPorts = $totalPortsInInterface;
  5502.                       //         }
  5503.                       //
  5504.                       //     }
  5505.                       //
  5506.                       //
  5507.                       // }
  5508.                       //
  5509.                       // $list[] = $eq;
  5510.                   }
  5511.                 }
  5512.        }
  5513.        return $this->render('overview/trunk_usage_full_extended.html.twig', [
  5514.            'action' => 'list',
  5515.            'page_title' => $translator->trans('Trunk Usage'),
  5516.            'list' => $list,
  5517.            'maxPorts' => $maxPorts
  5518.        ]);
  5519.    }
  5520.    /**
  5521.     * @Route("/trunk/nPort/links", name="trunk_usage_nPort")
  5522.     */
  5523.    public function nPortLinksAction()
  5524.    {
  5525.        $port $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['id']);
  5526.        $extremities = array();
  5527.        foreach ($port->getExtensionOrder() as $value) {
  5528.          $extremities[] = $value->getExtremity();
  5529.        }
  5530.        // $extremities = $port->getExtremities();
  5531.        $usedALinks = array();
  5532.        $usedBLinks = array();
  5533.        foreach ($extremities as $extremity) {
  5534.          $usedALinks[] = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremity);
  5535.          $usedBLinks[] = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremity);
  5536.        }
  5537.        $links = [];
  5538.        foreach ($usedALinks as $usedALink){
  5539.          if ($usedALink) {
  5540.            $links[] = $usedALink->getLink()->getId();
  5541.            // $links[] = array('link_id' => $usedALink->getLink()->getId(), 'linkID' => $usedALink->getLink()->getLinkID());
  5542.          }
  5543.        }
  5544.        foreach ($usedBLinks as $usedBLink){
  5545.          if ($usedBLink) {
  5546.            $links[] = $usedBLink->getLink()->getId();
  5547.            // $links[] = array('link_id' => $usedBLink->getLink()->getId(), 'linkID' => $usedBLink->getLink()->getLinkID());
  5548.          }
  5549.        }
  5550.        $temp array_unique($links);
  5551.        $res = [];
  5552.        foreach ($temp as $value) {
  5553.          $link $this->getDoctrine()->getRepository('App\Entity\Link')->find($value);
  5554.          $res[] = array('link_id' => $link->getId(), 'linkID' => $link->getLinkID());
  5555.        }
  5556.        return $this->json($res);
  5557.    }
  5558.    /**
  5559.     * @Route("/trunk/overview/list", name="trunk_overview_list")
  5560.     */
  5561.    public function overviewListAction(Request $requestLoggerInterface $loggerTranslatorInterface $translator)
  5562.   {
  5563.       //  $logger = $this->get('logger');
  5564.        // $cache = new FilesystemAdapter();
  5565.        // $trunkList = $cache->getItem('pagerfanta.list.trunk"');
  5566.        // $trunkList->expiresAfter(1);
  5567.        $trunks null;
  5568.        // if (!$trunkList->isHit()) {
  5569.        $trunks $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
  5570.        foreach ($trunks as $trunk){
  5571.            $logger->info("trunk");
  5572.             $logger->info($trunk->getId());
  5573.            $freePorts 0;
  5574.            $operators = [];
  5575.            $operators[] = $trunk->getOperatorID();
  5576.            $tcfs $trunk->getCableFiber();
  5577.            if ( !($tcfs->isEmpty()) ) {
  5578.                $firstTcf $tcfs[0];
  5579.                $eqA $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  5580.                $trunk->eqA $eqA;
  5581.                 $logger->info($firstTcf->getId());
  5582.                $eqB $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5583.                foreach ($tcfs as $tcf) {
  5584.                    $extensions $tcf->getExtensions();
  5585.                    if ($extensions) {
  5586.                        foreach ($extensions as $extension) {
  5587.                            $eqB $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5588.                            if (!in_array($extension->getOperatorID(), $operators)){
  5589.                                $operators[] = $extension->getOperatorID();
  5590.                            }
  5591.                        }
  5592.                    }
  5593.                    $portA $tcf->getPortA();
  5594.                    if (count($portA->getExtensionOrder()) == 0){
  5595.                        $freePorts++;
  5596.                    }
  5597.                    // $linkExtA =  $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portA' => $portA]);
  5598.                    // $linkExtB =  $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portB' => $portA]);
  5599.                    //
  5600.                    // if (!$linkExtA && !$linkExtB){
  5601.                    //     $freePorts++;
  5602.                    // }
  5603.                }
  5604.                $trunk->eqB $eqB;
  5605.            }
  5606.            $trunk->operators $operators;
  5607.            $trunk->freePorts $freePorts;
  5608.        }
  5609.      //   $cache->save($trunkList->set($trunks));
  5610.      // }
  5611.      // else {
  5612.      //   $trunks = $trunkList->get();
  5613.      //   // var_dump($links);
  5614.      // }
  5615.      // $adapter = new ArrayAdapter($trunks);
  5616.      // $pagerfanta = new Pagerfanta($adapter);
  5617.      $pageLength $request->query->get("pageLength"$this->getParameter("trunk.maxPerPage"));
  5618.      // if ($pageLength == "Tout") {
  5619.      //   $pagerfanta->setMaxPerPage(count($trunks)); // 10 by default
  5620.      // }
  5621.      // else {
  5622.      //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  5623.      // }
  5624.      // // $this->container->setParameter("link.maxPerPage", $pageLength);
  5625.      // $page = $request->query->get("page", 1);
  5626.      // $pagerfanta->setCurrentPage($page);
  5627.        return $this->render('overview/trunk_list.html.twig', [
  5628.            'action' => 'list',
  5629.            'page_title' => $translator->trans('Trunk Overview'),
  5630.            'list' => $trunks,
  5631.            // 'my_pager' => $pagerfanta,
  5632.            'pageLength' => $pageLength,
  5633.        ]);
  5634.    }
  5635.    /**
  5636.     * @Route("/trunk/view/{id}", name="trunk_view")
  5637.     */
  5638.    public function viewAction(Request $request$idTranslatorInterface $translator)
  5639.   {
  5640.        $em $this->getDoctrine()->getManager();
  5641.        $trunk $em->getRepository(Trunk::class)->find($id);
  5642.        $typeCable $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
  5643.        $sites $this->getDoctrine()->getRepository('App\Entity\Site')->findAll();
  5644.        $rackFaces $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
  5645.        // $tcfs = $trunk->getCableFiber();
  5646.        //
  5647.        // foreach ($tcfs as $tcf){
  5648.        //
  5649.        //     $ext = $tcf->getExtensions();
  5650.        //
  5651.        // }
  5652.        $linkValidationList '';
  5653.        // $queryBuilder = $em->createQueryBuilder()
  5654.        // ->select('tcf')
  5655.        // ->from('App\Entity\TrunkCableFiber', 'tcf')
  5656.        // ->where("tcf.trunk = :trunk")
  5657.        // ->setParameter("trunk", $trunk);
  5658.        // $adapter = new DoctrineORMAdapter($queryBuilder);
  5659.        // $pagerfanta = new Pagerfanta($adapter);
  5660.        $pageLength $request->query->get("pageLength"$this->getParameter("trunk.details.maxPerPage"));
  5661.        // if ($pageLength == "Tout") {
  5662.        //   $qb = $em->createQueryBuilder()
  5663.        //   ->select('COUNT(tcf.id)')
  5664.        //   ->from('App\Entity\TrunkCableFiber', 'tcf')
  5665.        //   ->where("tcf.trunk = :trunk")
  5666.        //   ->setParameter("trunk", $trunk);
  5667.        //
  5668.        //   $count = $qb->getQuery()->getSingleScalarResult();
  5669.        //   $pagerfanta->setMaxPerPage($count); // 10 by default
  5670.        // }
  5671.        // else {
  5672.        //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  5673.        // }
  5674.        // $page = $request->query->get("page", 1);
  5675.        // $pagerfanta->setCurrentPage($page);
  5676.        //
  5677.        // $linkValidations = $em->getRepository(LinkValidation::class)->findBy(['trunk' => $trunk]);
  5678.        // if ($linkValidations){
  5679.        //
  5680.        //     $linkValidationList = [];
  5681.        //
  5682.        //     foreach ($linkValidations as $linkValidation){
  5683.        //
  5684.        //         $linkValidationList[] = array('link_id' => $linkValidation->getLink()->getId(), 'linkID' =>  $linkValidation->getLink()->getLinkID());
  5685.        //
  5686.        //     }
  5687.        //
  5688.        // }
  5689.        return $this->render('trunk/list_details.html.twig', [
  5690.            'action' => 'list',
  5691.            'page_title' => $translator->trans('Trunk').' '.$trunk->getTrunkID(),
  5692.            'trunk' => $trunk,
  5693.            'typeCable' => $typeCable,
  5694.            'sites' => $sites,
  5695.            'rackFaces' => $rackFaces,
  5696.            'linkValidationList' => $linkValidationList,
  5697.            // 'my_pager' => $pagerfanta,
  5698.            'pageLength' => $pageLength,
  5699.        ]);
  5700.    }
  5701.    /**
  5702.     * @Route("/trunk/usage/item/{id}", name="trunk_usage")
  5703.     */
  5704.    public function usageAction($idTranslatorInterface $translator)
  5705.   {
  5706.        $em $this->getDoctrine()->getManager();
  5707.        $trunk $em->getRepository(Trunk::class)->find($id);
  5708.        $maxPorts 0;
  5709.        $list = [];
  5710.        $eqBArray = [];
  5711.        $tcfs $trunk->getCableFiber();
  5712.        if ( !($tcfs->isEmpty()) ) {
  5713.            //get all the ports used by Links
  5714.            $portsAllTemp $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
  5715.            $portsAll = array();
  5716.            foreach ($portsAllTemp as $tempArray) {
  5717.              foreach ($tempArray as $key => $value) {
  5718.                $portsAll[] = $value;
  5719.              }
  5720.            }
  5721.            foreach ($tcfs as $firstTcf) {
  5722.              $eqA $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  5723.              //check if eqA is modulaire
  5724.              // if ($eqATemp->isModule()) {
  5725.              //   foreach ($eqATemp->getParent()->getModules() as $value) {
  5726.              //     $eqAArray[] = $value;
  5727.              //   }
  5728.              // }
  5729.              // else {
  5730.              //   $eqAArray[] = $eqATemp;
  5731.              // }
  5732.              $eqB null;
  5733.              if (count($firstTcf->getExtensions()) > 0) {
  5734.                $trunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
  5735.                $eqB $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5736.              }
  5737.              else {
  5738.                $eqB $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5739.              }
  5740.              //check if eqB is modulaire
  5741.              // if ($eqBTemp->isModule()) {
  5742.              //   foreach ($eqBTemp->getParent()->getModules() as $value) {
  5743.              //     $eqBArray[] = $value;
  5744.              //   }
  5745.              // }
  5746.              // else {
  5747.              //   $eqBArray[] = $eqBTemp;
  5748.              // }
  5749.              // var_dump($eqA->getId());
  5750.              if (!in_array($eqA->getId(), $eqBArray)) {
  5751.                $trunk->eqA $eqA;
  5752.                $res $this->createEquipment($trunk$eqA$portsAll$maxPorts);
  5753.                $list[] = $res["eq"];
  5754.                $maxPorts $res["maxPorts"];
  5755.                $eqBArray[] = $eqA->getId();
  5756.                // $trunk->eqA = $eqA;
  5757.                // // var_dump($eqA->getId());
  5758.                //
  5759.                // $rackTitle = $eqA->getRack()->getTitle();
  5760.                //
  5761.                //     $eq['trunkID'] = $trunk->getTrunkID();
  5762.                //     $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  5763.                //     $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  5764.                //     $eq['rack'] = $rackTitle;
  5765.                //     $eq['equipment'] = $eqA->getEquipmentSpecificName();
  5766.                //     $eq['interfaces'] = [];
  5767.                //
  5768.                //     $interfaces = $eqA->getInterfaceSpecific();
  5769.                //     foreach ($interfaces as $interface) {
  5770.                //         // var_dump($interface->getId());
  5771.                //         $totalPorts = 0;
  5772.                //         $totalPortsUsed = 0;
  5773.                //         $totalPortsInInterface = 0;
  5774.                //
  5775.                //         $ports = $interface->getPort();
  5776.                //
  5777.                //         $portList = [];
  5778.                //
  5779.                //         $isInterfaceInTrunk = 0;
  5780.                //
  5781.                //         foreach ($ports as $port) {
  5782.                //           // var_dump($port->getId());
  5783.                //
  5784.                //             $isPortInTrunk = 0;
  5785.                //
  5786.                //             $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5787.                //             $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5788.                //             $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  5789.                //             // var_dump($usedInTrunkPointA);
  5790.                //             // var_dump($usedInTrunkPointB);
  5791.                //             // var_dump($usedInTrunkExtension);
  5792.                //
  5793.                //             if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  5794.                //                 $isInterfaceInTrunk = 1;
  5795.                //                 $isPortInTrunk = 1;
  5796.                //                 $totalPorts++;
  5797.                //             }
  5798.                //
  5799.                //             $port->nPort = 0;
  5800.                //             $port->used = 0;
  5801.                //
  5802.                //             $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  5803.                //             if ($nPorts){
  5804.                //                 $nPorts = json_decode($nPorts);
  5805.                //                 if (in_array($port->getOrderNo(), $nPorts)){
  5806.                //                     $port->nPort = 1;
  5807.                //                 }
  5808.                //             }
  5809.                //
  5810.                //             $used = 0;
  5811.                //             $usedLinkID = '';
  5812.                //             $usedLink_id = '';
  5813.                //
  5814.                //             if (in_array($port->getId(), $portsAll)) {
  5815.                //             $usedALink = null;
  5816.                //             $usedBLink = null;
  5817.                //             $tempExts = $port->getExtensionOrder();
  5818.                //             foreach ( $tempExts as $value) {
  5819.                //               $extremityB = $value->getExtremity();
  5820.                //               if ($usedALink && $usedBLink) {
  5821.                //                 break;
  5822.                //               }
  5823.                //               if(!$usedALink) {
  5824.                //                  $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5825.                //               }
  5826.                //               if (!$usedBLink) {
  5827.                //                 $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5828.                //               }
  5829.                //             }
  5830.                //             $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  5831.                //             $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  5832.                //
  5833.                //             if ($usedALink) {
  5834.                //               $used = 1;
  5835.                //               $usedLinkID = $usedALink->getLink()->getLinkID();
  5836.                //               $usedLink_id = $usedALink->getLink()->getId();
  5837.                //             }
  5838.                //             if ($usedBLink) {
  5839.                //               $used = 1;
  5840.                //               $usedLinkID = $usedBLink->getLink()->getLinkID();
  5841.                //               $usedLink_id = $usedBLink->getLink()->getId();
  5842.                //             }
  5843.                //
  5844.                //             if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  5845.                //
  5846.                //             }
  5847.                //             else if($trunkExtension) {
  5848.                //               // var_dump("Got it");
  5849.                //               $used = 1;
  5850.                //               $usedLinkID = $port->getLink()->getLinkID();
  5851.                //               $usedLink_id = $port->getLink()->getId();
  5852.                //             }
  5853.                //             if ($tcfB && $usedBLink) {
  5854.                //
  5855.                //             }
  5856.                //             else if($tcfB){
  5857.                //               $used = 1;
  5858.                //               $usedLinkID = $port->getLink()->getLinkID();
  5859.                //               $usedLink_id = $port->getLink()->getId();
  5860.                //
  5861.                //             }
  5862.                //
  5863.                //             $port->used = $used;
  5864.                //             $port->usedLinkID = $usedLinkID;
  5865.                //             $port->usedLink_id = $usedLink_id;
  5866.                //           }
  5867.                //             // $usedALink = null;
  5868.                //             // $usedBLink = null;
  5869.                //             // $tempExts = $port->getExtremities();
  5870.                //             // foreach ( $tempExts as $extremityB) {
  5871.                //             //   if ($usedALink && $usedBLink) {
  5872.                //             //     break;
  5873.                //             //   }
  5874.                //             //   if(!$usedALink) {
  5875.                //             //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  5876.                //             //   }
  5877.                //             //   if (!$usedBLink) {
  5878.                //             //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  5879.                //             //   }
  5880.                //             // }
  5881.                //             // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5882.                //             // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5883.                //             // if ($usedALink) {
  5884.                //             //     $used = 1;
  5885.                //             //     $usedLinkID = $usedALink->getLink()->getLinkID();
  5886.                //             //     $usedLink_id = $usedALink->getLink()->getId();
  5887.                //             // }
  5888.                //             //
  5889.                //             // if ($usedBLink) {
  5890.                //             //     $used = 1;
  5891.                //             //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  5892.                //             //     $usedLink_id = $usedBLink->getLink()->getId();
  5893.                //             // }
  5894.                //             // // var_dump($used);
  5895.                //             //
  5896.                //             // $port->used = $used;
  5897.                //             // $port->usedLinkID = $usedLinkID;
  5898.                //             // $port->usedLink_id = $usedLink_id;
  5899.                //
  5900.                //             $p['used'] = $used;
  5901.                //             $p['usedLinkID'] = $usedLinkID;
  5902.                //             $p['usedLink_id'] = $usedLink_id;
  5903.                //             $p['nPort'] = $port->nPort;
  5904.                //             $p['inTrunk'] = $isPortInTrunk;
  5905.                //
  5906.                //
  5907.                //             if ($port->nPort == 1 && $port->used == 1){
  5908.                //
  5909.                //                 $p['id'] = $port->getId();
  5910.                //
  5911.                //             }
  5912.                //
  5913.                //
  5914.                //             $totalPortsInInterface++;
  5915.                //
  5916.                //             if ($used == 1) {
  5917.                //                 $totalPortsUsed++;
  5918.                //             }
  5919.                //
  5920.                //             $portList[] = $p;
  5921.                //
  5922.                //         }
  5923.                //
  5924.                //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  5925.                //         $int['totalPorts'] = $totalPorts;
  5926.                //         $int['totalPortsUsed'] = $totalPortsUsed;
  5927.                //         $int['ports'] = $portList;
  5928.                //
  5929.                //         if ($isInterfaceInTrunk == 1){
  5930.                //
  5931.                //             $eq['interfaces'][] = $int;
  5932.                //
  5933.                //             if ($totalPortsInInterface > $maxPorts){
  5934.                //                 $maxPorts = $totalPortsInInterface;
  5935.                //             }
  5936.                //
  5937.                //         }
  5938.                //
  5939.                //     }
  5940.                //
  5941.                // $list[] = $eq;
  5942.              }
  5943.              // $extCount = count($firstTcf->getExtensions());
  5944.              // if ($extCount > 0) {
  5945.              //   $lastExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$trunkCableFiber, "sequenceNo"=>$extCount]);
  5946.              //   $eqB = $lastExtension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5947.              // }
  5948.              // else {
  5949.              //   $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  5950.              // }
  5951.              if (!in_array($eqB->getId(), $eqBArray)) {
  5952.                  $trunk->eqB $eqB;
  5953.                  $res $this->createEquipment($trunk$eqB$portsAll$maxPorts);
  5954.                  $list[] = $res["eq"];
  5955.                  $maxPorts $res["maxPorts"];
  5956.                  $eqBArray[] = $eqB->getId();
  5957.                  // $eqBArray[] = $eqB->getId();
  5958.                  // $trunk->eqB = $eqB;
  5959.                  //
  5960.                  // $rackTitle = $eqB->getRack()->getTitle();
  5961.                  //
  5962.                  // $eq['trunkID'] = $trunk->getTrunkID();
  5963.                  // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  5964.                  // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  5965.                  // $eq['rack'] = $rackTitle;
  5966.                  // $eq['equipment'] = $eqB->getEquipmentSpecificName();
  5967.                  // $eq['interfaces'] = [];
  5968.                  //
  5969.                  // $interfaces = $eqB->getInterfaceSpecific();
  5970.                  // foreach ($interfaces as $interface){
  5971.                  //
  5972.                  //   $totalPorts = 0;
  5973.                  //   $totalPortsUsed = 0;
  5974.                  //   $totalPortsInInterface = 0;
  5975.                  //
  5976.                  //   $ports = $interface->getPort();
  5977.                  //
  5978.                  //   $portList = [];
  5979.                  //
  5980.                  //   $isInterfaceInTrunk = 0;
  5981.                  //
  5982.                  //   foreach ($ports as $port){
  5983.                  //
  5984.                  //     $isPortInTrunk = 0;
  5985.                  //
  5986.                  //     $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  5987.                  //     $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  5988.                  //     $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  5989.                  //
  5990.                  //     if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  5991.                  //       $isInterfaceInTrunk = 1;
  5992.                  //       $isPortInTrunk = 1;
  5993.                  //       $totalPorts++;
  5994.                  //     }
  5995.                  //
  5996.                  //
  5997.                  //     $port->nPort = 0;
  5998.                  //     $port->used = 0;
  5999.                  //
  6000.                  //     $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  6001.                  //     if ($nPorts){
  6002.                  //       $nPorts = json_decode($nPorts);
  6003.                  //       if (in_array($port->getOrderNo(), $nPorts)){
  6004.                  //         $port->nPort = 1;
  6005.                  //       }
  6006.                  //     }
  6007.                  //
  6008.                  //     $used = 0;
  6009.                  //     $usedLinkID = '';
  6010.                  //     $usedLink_id = '';
  6011.                  //     if (in_array($port->getId(), $portsAll)) {
  6012.                  //       $usedALink = null;
  6013.                  //       $usedBLink = null;
  6014.                  //       $tempExts = $port->getExtensionOrder();
  6015.                  //       foreach ( $tempExts as $value) {
  6016.                  //         $extremityB = $value->getExtremity();
  6017.                  //         if ($usedALink && $usedBLink) {
  6018.                  //           break;
  6019.                  //         }
  6020.                  //         if(!$usedALink) {
  6021.                  //           $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6022.                  //         }
  6023.                  //         if (!$usedBLink) {
  6024.                  //           $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6025.                  //         }
  6026.                  //       }
  6027.                  //       $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  6028.                  //       $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  6029.                  //
  6030.                  //       if ($usedALink) {
  6031.                  //         $used = 1;
  6032.                  //         $usedLinkID = $usedALink->getLink()->getLinkID();
  6033.                  //         $usedLink_id = $usedALink->getLink()->getId();
  6034.                  //       }
  6035.                  //       if ($usedBLink) {
  6036.                  //         $used = 1;
  6037.                  //         $usedLinkID = $usedBLink->getLink()->getLinkID();
  6038.                  //         $usedLink_id = $usedBLink->getLink()->getId();
  6039.                  //       }
  6040.                  //
  6041.                  //       if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  6042.                  //
  6043.                  //       }
  6044.                  //       else if($trunkExtension) {
  6045.                  //         // var_dump("Got it");
  6046.                  //         $used = 1;
  6047.                  //         $usedLinkID = $port->getLink()->getLinkID();
  6048.                  //         $usedLink_id = $port->getLink()->getId();
  6049.                  //       }
  6050.                  //       if ($tcfB && $usedBLink) {
  6051.                  //
  6052.                  //       }
  6053.                  //       else if($tcfB){
  6054.                  //         $used = 1;
  6055.                  //         $usedLinkID = $port->getLink()->getLinkID();
  6056.                  //         $usedLink_id = $port->getLink()->getId();
  6057.                  //
  6058.                  //       }
  6059.                  //
  6060.                  //       $port->used = $used;
  6061.                  //       $port->usedLinkID = $usedLinkID;
  6062.                  //       $port->usedLink_id = $usedLink_id;
  6063.                  //     }
  6064.                  //     // $usedALink = null;
  6065.                  //     // $usedBLink = null;
  6066.                  //     // $tempExts = $port->getExtremities();
  6067.                  //     // foreach ( $tempExts as $extremityB) {
  6068.                  //     //   if ($usedALink && $usedBLink) {
  6069.                  //     //     break;
  6070.                  //     //   }
  6071.                  //     //   if(!$usedALink) {
  6072.                  //     //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6073.                  //     //   }
  6074.                  //     //   if (!$usedBLink) {
  6075.                  //     //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6076.                  //     //   }
  6077.                  //     // }
  6078.                  //     //
  6079.                  //     // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6080.                  //     // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6081.                  //     //
  6082.                  //     // if ($usedALink){
  6083.                  //     //     $used = 1;
  6084.                  //     //     $usedLinkID = $usedALink->getLink()->getLinkID();
  6085.                  //     //     $usedLink_id = $usedALink->getLink()->getId();
  6086.                  //     // }
  6087.                  //     //
  6088.                  //     // if ($usedBLink){
  6089.                  //     //     $used = 1;
  6090.                  //     //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  6091.                  //     //     $usedLink_id = $usedBLink->getLink()->getId();
  6092.                  //     // }
  6093.                  //
  6094.                  //     $port->used = $used;
  6095.                  //     $port->usedLinkID = $usedLinkID;
  6096.                  //     $port->usedLink_id = $usedLink_id;
  6097.                  //
  6098.                  //     $p['used'] = $used;
  6099.                  //     $p['usedLinkID'] = $usedLinkID;
  6100.                  //     $p['usedLink_id'] = $usedLink_id;
  6101.                  //     $p['nPort'] = $port->nPort;
  6102.                  //     $p['inTrunk'] = $isPortInTrunk;
  6103.                  //
  6104.                  //
  6105.                  //     if ($port->nPort == 1 && $port->used == 1){
  6106.                  //
  6107.                  //       $p['id'] = $port->getId();
  6108.                  //
  6109.                  //     }
  6110.                  //
  6111.                  //     $totalPortsInInterface ++;
  6112.                  //
  6113.                  //     if ($used == 1){
  6114.                  //       $totalPortsUsed ++;
  6115.                  //     }
  6116.                  //
  6117.                  //     $portList[] = $p;
  6118.                  //
  6119.                  //   }
  6120.                  //
  6121.                  //   $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  6122.                  //   $int['totalPorts'] = $totalPorts;
  6123.                  //   $int['totalPortsUsed'] = $totalPortsUsed;
  6124.                  //   $int['ports'] = $portList;
  6125.                  //
  6126.                  //   if ($isInterfaceInTrunk == 1){
  6127.                  //
  6128.                  //     $eq['interfaces'][] = $int;
  6129.                  //
  6130.                  //     if ($totalPortsInInterface > $maxPorts){
  6131.                  //       $maxPorts = $totalPortsInInterface;
  6132.                  //     }
  6133.                  //
  6134.                  //   }
  6135.                  //
  6136.                  //
  6137.                  // }
  6138.                  //
  6139.                  // $list[] = $eq;
  6140.                  // $extensions = $firstTcf->getExtensions();
  6141.                  //   foreach ($extensions as $extension) {
  6142.                  //     $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  6143.                  //
  6144.                  //     if (!in_array($eqB->getId(), $eqBArray)) {
  6145.                  //       $eqBArray[] = $eqB->getId();
  6146.                  //       $trunk->eqB = $eqB;
  6147.                  //
  6148.                  //       $rackTitle = $eqB->getRack()->getTitle();
  6149.                  //
  6150.                  //       $eq['trunkID'] = $trunk->getTrunkID();
  6151.                  //       $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  6152.                  //       $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  6153.                  //       $eq['rack'] = $rackTitle;
  6154.                  //       $eq['equipment'] = $eqB->getEquipmentSpecificName();
  6155.                  //       $eq['interfaces'] = [];
  6156.                  //
  6157.                  //       $interfaces = $eqB->getInterfaceSpecific();
  6158.                  //       foreach ($interfaces as $interface){
  6159.                  //
  6160.                  //         $totalPorts = 0;
  6161.                  //         $totalPortsUsed = 0;
  6162.                  //         $totalPortsInInterface = 0;
  6163.                  //
  6164.                  //         $ports = $interface->getPort();
  6165.                  //
  6166.                  //         $portList = [];
  6167.                  //
  6168.                  //         $isInterfaceInTrunk = 0;
  6169.                  //
  6170.                  //         foreach ($ports as $port){
  6171.                  //
  6172.                  //           $isPortInTrunk = 0;
  6173.                  //
  6174.                  //           $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6175.                  //           $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6176.                  //           $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  6177.                  //
  6178.                  //           if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  6179.                  //             $isInterfaceInTrunk = 1;
  6180.                  //             $isPortInTrunk = 1;
  6181.                  //             $totalPorts++;
  6182.                  //           }
  6183.                  //
  6184.                  //
  6185.                  //           $port->nPort = 0;
  6186.                  //           $port->used = 0;
  6187.                  //
  6188.                  //           $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  6189.                  //           if ($nPorts){
  6190.                  //             $nPorts = json_decode($nPorts);
  6191.                  //             if (in_array($port->getOrderNo(), $nPorts)){
  6192.                  //               $port->nPort = 1;
  6193.                  //             }
  6194.                  //           }
  6195.                  //
  6196.                  //           $used = 0;
  6197.                  //           $usedLinkID = '';
  6198.                  //           $usedLink_id = '';
  6199.                  //           if (in_array($port->getId(), $portsAll)) {
  6200.                  //             $usedALink = null;
  6201.                  //             $usedBLink = null;
  6202.                  //             $tempExts = $port->getExtensionOrder();
  6203.                  //             foreach ( $tempExts as $value) {
  6204.                  //               $extrmityB = $value->getExtremity();
  6205.                  //               if ($usedALink && $usedBLink) {
  6206.                  //                 break;
  6207.                  //               }
  6208.                  //               if(!$usedALink) {
  6209.                  //                 $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6210.                  //               }
  6211.                  //               if (!$usedBLink) {
  6212.                  //                 $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6213.                  //               }
  6214.                  //             }
  6215.                  //             $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  6216.                  //             $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  6217.                  //
  6218.                  //             if ($usedALink) {
  6219.                  //               $used = 1;
  6220.                  //               $usedLinkID = $usedALink->getLink()->getLinkID();
  6221.                  //               $usedLink_id = $usedALink->getLink()->getId();
  6222.                  //             }
  6223.                  //             if ($usedBLink) {
  6224.                  //               $used = 1;
  6225.                  //               $usedLinkID = $usedBLink->getLink()->getLinkID();
  6226.                  //               $usedLink_id = $usedBLink->getLink()->getId();
  6227.                  //             }
  6228.                  //
  6229.                  //             if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  6230.                  //
  6231.                  //             }
  6232.                  //             else if($trunkExtension) {
  6233.                  //               // var_dump("Got it");
  6234.                  //               $used = 1;
  6235.                  //               $usedLinkID = $port->getLink()->getLinkID();
  6236.                  //               $usedLink_id = $port->getLink()->getId();
  6237.                  //             }
  6238.                  //             if ($tcfB && $usedBLink) {
  6239.                  //
  6240.                  //             }
  6241.                  //             else if($tcfB){
  6242.                  //               $used = 1;
  6243.                  //               $usedLinkID = $port->getLink()->getLinkID();
  6244.                  //               $usedLink_id = $port->getLink()->getId();
  6245.                  //
  6246.                  //             }
  6247.                  //
  6248.                  //             $port->used = $used;
  6249.                  //             $port->usedLinkID = $usedLinkID;
  6250.                  //             $port->usedLink_id = $usedLink_id;
  6251.                  //           }
  6252.                  //           // $usedALink = null;
  6253.                  //           // $usedBLink = null;
  6254.                  //           // $tempExts = $port->getExtremities();
  6255.                  //           // foreach ( $tempExts as $extremityB) {
  6256.                  //           //   if ($usedALink && $usedBLink) {
  6257.                  //           //     break;
  6258.                  //           //   }
  6259.                  //           //   if(!$usedALink) {
  6260.                  //           //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6261.                  //           //   }
  6262.                  //           //   if (!$usedBLink) {
  6263.                  //           //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6264.                  //           //   }
  6265.                  //           // }
  6266.                  //           //
  6267.                  //           // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6268.                  //           // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6269.                  //           //
  6270.                  //           // if ($usedALink){
  6271.                  //           //     $used = 1;
  6272.                  //           //     $usedLinkID = $usedALink->getLink()->getLinkID();
  6273.                  //           //     $usedLink_id = $usedALink->getLink()->getId();
  6274.                  //           // }
  6275.                  //           //
  6276.                  //           // if ($usedBLink){
  6277.                  //           //     $used = 1;
  6278.                  //           //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  6279.                  //           //     $usedLink_id = $usedBLink->getLink()->getId();
  6280.                  //           // }
  6281.                  //
  6282.                  //           $port->used = $used;
  6283.                  //           $port->usedLinkID = $usedLinkID;
  6284.                  //           $port->usedLink_id = $usedLink_id;
  6285.                  //
  6286.                  //           $p['used'] = $used;
  6287.                  //           $p['usedLinkID'] = $usedLinkID;
  6288.                  //           $p['usedLink_id'] = $usedLink_id;
  6289.                  //           $p['nPort'] = $port->nPort;
  6290.                  //           $p['inTrunk'] = $isPortInTrunk;
  6291.                  //
  6292.                  //
  6293.                  //           if ($port->nPort == 1 && $port->used == 1){
  6294.                  //
  6295.                  //             $p['id'] = $port->getId();
  6296.                  //
  6297.                  //           }
  6298.                  //
  6299.                  //           $totalPortsInInterface ++;
  6300.                  //
  6301.                  //           if ($used == 1){
  6302.                  //             $totalPortsUsed ++;
  6303.                  //           }
  6304.                  //
  6305.                  //           $portList[] = $p;
  6306.                  //
  6307.                  //         }
  6308.                  //
  6309.                  //         $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  6310.                  //         $int['totalPorts'] = $totalPorts;
  6311.                  //         $int['totalPortsUsed'] = $totalPortsUsed;
  6312.                  //         $int['ports'] = $portList;
  6313.                  //
  6314.                  //         if ($isInterfaceInTrunk == 1){
  6315.                  //
  6316.                  //           $eq['interfaces'][] = $int;
  6317.                  //
  6318.                  //           if ($totalPortsInInterface > $maxPorts){
  6319.                  //             $maxPorts = $totalPortsInInterface;
  6320.                  //           }
  6321.                  //
  6322.                  //         }
  6323.                  //
  6324.                  //
  6325.                  //       }
  6326.                  //
  6327.                  //       $list[] = $eq;
  6328.                  //     }
  6329.                  //   }
  6330.              }
  6331.            }
  6332.            // $firstTcf = $tcfs[0];
  6333.           //  $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  6334.           //  $eqBArray[] = $eqA->getId();
  6335.           //
  6336.           //  $trunk->eqA = $eqA;
  6337.           //
  6338.           //  $rackTitle = $eqA->getRack()->getTitle();
  6339.           //
  6340.           //  $eq['trunkID'] = $trunk->getTrunkID();
  6341.           //  $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  6342.           //  $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  6343.           //  $eq['rack'] = $rackTitle;
  6344.           //  $eq['equipment'] = $eqA->getEquipmentSpecificName()/*. ' (' . $eqA->getEquipmentGeneric()->getTitle() . ')'*/;
  6345.           //  $eq['interfaces'] = [];
  6346.           //
  6347.           //  $interfaces = $eqA->getInterfaceSpecific();
  6348.           //  foreach ($interfaces as $interface) {
  6349.           //
  6350.           //      $totalPorts = 0;
  6351.           //      $totalPortsUsed = 0;
  6352.           //      $totalPortsInInterface = 0;
  6353.           //
  6354.           //      $ports = $interface->getPort();
  6355.           //      $portList = [];
  6356.           //
  6357.           //      $isInterfaceInTrunk = 0;
  6358.           //
  6359.           //      foreach ($ports as $port) {
  6360.           //
  6361.           //          $isPortInTrunk = 0;
  6362.           //
  6363.           //          $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6364.           //          $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6365.           //          $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  6366.           //
  6367.           //          if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  6368.           //              $isInterfaceInTrunk = 1;
  6369.           //              $isPortInTrunk = 1;
  6370.           //              $totalPorts++;
  6371.           //          }
  6372.           //
  6373.           //          $port->nPort = 0;
  6374.           //          $port->used = 0;
  6375.           //          $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  6376.           //          if ($nPorts){
  6377.           //              $nPorts = json_decode($nPorts);
  6378.           //              if (in_array($port->getOrderNo(), $nPorts)){
  6379.           //                  $port->nPort = 1;
  6380.           //              }
  6381.           //          }
  6382.           //
  6383.           //          $used = 0;
  6384.           //          $usedLinkID = '';
  6385.           //          $usedLink_id = '';
  6386.           //
  6387.           //          /*$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
  6388.           //          $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);*/
  6389.           //          if (in_array($port->getId(), $portsAll)) {
  6390.           //            $usedALink = null;
  6391.           //            $usedBLink = null;
  6392.           //            $tempExts = $port->getExtensionOrder();
  6393.           //            foreach ( $tempExts as $value) {
  6394.           //              $extremityB = $value->getExtremity();
  6395.           //              if ($usedALink && $usedBLink) {
  6396.           //                break;
  6397.           //              }
  6398.           //              if(!$usedALink) {
  6399.           //                 $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6400.           //              }
  6401.           //              if (!$usedBLink) {
  6402.           //                $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6403.           //              }
  6404.           //            }
  6405.           //            $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  6406.           //            $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  6407.           //
  6408.           //            if ($usedALink) {
  6409.           //              $used = 1;
  6410.           //              $usedLinkID = $usedALink->getLink()->getLinkID();
  6411.           //              $usedLink_id = $usedALink->getLink()->getId();
  6412.           //            }
  6413.           //            if ($usedBLink) {
  6414.           //              $used = 1;
  6415.           //              $usedLinkID = $usedBLink->getLink()->getLinkID();
  6416.           //              $usedLink_id = $usedBLink->getLink()->getId();
  6417.           //            }
  6418.           //
  6419.           //            if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  6420.           //
  6421.           //            }
  6422.           //            else if($trunkExtension) {
  6423.           //              // var_dump("Got it");
  6424.           //              $used = 1;
  6425.           //              $usedLinkID = $port->getLink()->getLinkID();
  6426.           //              $usedLink_id = $port->getLink()->getId();
  6427.           //            }
  6428.           //            if ($tcfB && $usedBLink) {
  6429.           //
  6430.           //            }
  6431.           //            else if($tcfB){
  6432.           //              $used = 1;
  6433.           //              $usedLinkID = $port->getLink()->getLinkID();
  6434.           //              $usedLink_id = $port->getLink()->getId();
  6435.           //
  6436.           //            }
  6437.           //
  6438.           //            $port->used = $used;
  6439.           //            $port->usedLinkID = $usedLinkID;
  6440.           //            $port->usedLink_id = $usedLink_id;
  6441.           //          }
  6442.           //
  6443.           //          // $usedALink = null;
  6444.           //          // $usedBLink = null;
  6445.           //          // $tempExts = $port->getExtremities();
  6446.           //          // foreach ( $tempExts as $extremityB) {
  6447.           //          //   if ($usedALink && $usedBLink) {
  6448.           //          //     break;
  6449.           //          //   }
  6450.           //          //   if(!$usedALink) {
  6451.           //          //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6452.           //          //   }
  6453.           //          //   if (!$usedBLink) {
  6454.           //          //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6455.           //          //   }
  6456.           //          // }
  6457.           //          // //
  6458.           //          // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6459.           //          // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6460.           //          //
  6461.           //          // if ($usedALink) {
  6462.           //          //     $used = 1;
  6463.           //          //     $usedLinkID = $usedALink->getLink()->getLinkID();
  6464.           //          //     $usedLink_id = $usedALink->getLink()->getId();
  6465.           //          // }
  6466.           //          //
  6467.           //          // if ($usedBLink) {
  6468.           //          //     $used = 1;
  6469.           //          //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  6470.           //          //     $usedLink_id = $usedBLink->getLink()->getId();
  6471.           //          // }
  6472.           //          //
  6473.           //          // $port->used = $used;
  6474.           //          // $port->usedLinkID = $usedLinkID;
  6475.           //          // $port->usedLink_id = $usedLink_id;
  6476.           //
  6477.           //          $p['used'] = $used;
  6478.           //          $p['usedLinkID'] = $usedLinkID;
  6479.           //          $p['usedLink_id'] = $usedLink_id;
  6480.           //          $p['nPort'] = $port->nPort;
  6481.           //          $p['inTrunk'] = $isPortInTrunk;
  6482.           //
  6483.           //
  6484.           //          if ($port->nPort == 1 && $port->used == 1){
  6485.           //
  6486.           //              $p['id'] = $port->getId();
  6487.           //
  6488.           //          }
  6489.           //
  6490.           //
  6491.           //          $totalPortsInInterface++;
  6492.           //
  6493.           //          if ($used == 1) {
  6494.           //              $totalPortsUsed++;
  6495.           //          }
  6496.           //
  6497.           //          $portList[] = $p;
  6498.           //
  6499.           //      }
  6500.           //
  6501.           //      $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  6502.           //      $int['totalPorts'] = $totalPorts;
  6503.           //      $int['totalPortsUsed'] = $totalPortsUsed;
  6504.           //      $int['ports'] = $portList;
  6505.           //
  6506.           //      if ($isInterfaceInTrunk == 1){
  6507.           //
  6508.           //          $eq['interfaces'][] = $int;
  6509.           //
  6510.           //          if ($totalPortsInInterface > $maxPorts){
  6511.           //              $maxPorts = $totalPortsInInterface;
  6512.           //          }
  6513.           //
  6514.           //      }
  6515.           //
  6516.           //  }
  6517.           //
  6518.           //
  6519.           // $list[] = $eq;
  6520.           //
  6521.           //  $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  6522.           //  if ($eqB->getId() != $eqA->getId()){
  6523.           //    $eqBArray[] = $eqB->getId();
  6524.           //    $trunk->eqB = $eqB;
  6525.           //
  6526.           //    $rackTitle = $eqB->getRack()->getTitle();
  6527.           //
  6528.           //    $eq['trunkID'] = $trunk->getTrunkID();
  6529.           //    $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  6530.           //    $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  6531.           //    $eq['rack'] = $rackTitle;
  6532.           //    $eq['equipment'] = $eqB->getEquipmentSpecificName();
  6533.           //    $eq['interfaces'] = [];
  6534.           //
  6535.           //    $interfaces = $eqB->getInterfaceSpecific();
  6536.           //    foreach ($interfaces as $interface){
  6537.           //
  6538.           //        $totalPorts = 0;
  6539.           //        $totalPortsUsed = 0;
  6540.           //        $totalPortsInInterface = 0;
  6541.           //
  6542.           //        $ports = $interface->getPort();
  6543.           //
  6544.           //        $portList = [];
  6545.           //
  6546.           //        $isInterfaceInTrunk = 0;
  6547.           //
  6548.           //        foreach ($ports as $port){
  6549.           //
  6550.           //            $isPortInTrunk = 0;
  6551.           //
  6552.           //            $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6553.           //            $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6554.           //            $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  6555.           //
  6556.           //            if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  6557.           //                $isInterfaceInTrunk = 1;
  6558.           //                $isPortInTrunk = 1;
  6559.           //                $totalPorts++;
  6560.           //            }
  6561.           //
  6562.           //
  6563.           //            $port->nPort = 0;
  6564.           //            $port->used = 0;
  6565.           //            $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  6566.           //            if ($nPorts){
  6567.           //                $nPorts = json_decode($nPorts);
  6568.           //                if (in_array($port->getOrderNo(), $nPorts)){
  6569.           //                    $port->nPort = 1;
  6570.           //                }
  6571.           //            }
  6572.           //
  6573.           //            $used = 0;
  6574.           //            $usedLinkID = '';
  6575.           //            $usedLink_id = '';
  6576.           //            if (in_array($port->getId(), $portsAll)) {
  6577.           //              $usedALink = null;
  6578.           //              $usedBLink = null;
  6579.           //              $tempExts = $port->getExtensionOrder();
  6580.           //              foreach ( $tempExts as $value) {
  6581.           //                $extremityB = $value->getExtremity();
  6582.           //                if ($usedALink && $usedBLink) {
  6583.           //                  break;
  6584.           //                }
  6585.           //                if(!$usedALink) {
  6586.           //                   $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6587.           //                }
  6588.           //                if (!$usedBLink) {
  6589.           //                  $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6590.           //                }
  6591.           //              }
  6592.           //              $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  6593.           //              $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  6594.           //
  6595.           //              if ($usedALink) {
  6596.           //                $used = 1;
  6597.           //                $usedLinkID = $usedALink->getLink()->getLinkID();
  6598.           //                $usedLink_id = $usedALink->getLink()->getId();
  6599.           //              }
  6600.           //              if ($usedBLink) {
  6601.           //                $used = 1;
  6602.           //                $usedLinkID = $usedBLink->getLink()->getLinkID();
  6603.           //                $usedLink_id = $usedBLink->getLink()->getId();
  6604.           //              }
  6605.           //
  6606.           //              if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  6607.           //
  6608.           //              }
  6609.           //              else if($trunkExtension) {
  6610.           //                // var_dump("Got it");
  6611.           //                $used = 1;
  6612.           //                $usedLinkID = $port->getLink()->getLinkID();
  6613.           //                $usedLink_id = $port->getLink()->getId();
  6614.           //              }
  6615.           //              if ($tcfB && $usedBLink) {
  6616.           //
  6617.           //              }
  6618.           //              else if($tcfB){
  6619.           //                $used = 1;
  6620.           //                $usedLinkID = $port->getLink()->getLinkID();
  6621.           //                $usedLink_id = $port->getLink()->getId();
  6622.           //
  6623.           //              }
  6624.           //
  6625.           //              $port->used = $used;
  6626.           //              $port->usedLinkID = $usedLinkID;
  6627.           //              $port->usedLink_id = $usedLink_id;
  6628.           //            }
  6629.           //            // $usedALink = null;
  6630.           //            // $usedBLink = null;
  6631.           //            // $tempExts = $port->getExtremities();
  6632.           //            // foreach ( $tempExts as $extremityB) {
  6633.           //            //   if ($usedALink && $usedBLink) {
  6634.           //            //     break;
  6635.           //            //   }
  6636.           //            //   if(!$usedALink) {
  6637.           //            //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6638.           //            //   }
  6639.           //            //   if (!$usedBLink) {
  6640.           //            //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6641.           //            //   }
  6642.           //            // }
  6643.           //            //
  6644.           //            // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6645.           //            // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6646.           //            //
  6647.           //            // if ($usedALink){
  6648.           //            //     $used = 1;
  6649.           //            //     $usedLinkID = $usedALink->getLink()->getLinkID();
  6650.           //            //     $usedLink_id = $usedALink->getLink()->getId();
  6651.           //            // }
  6652.           //            //
  6653.           //            // if ($usedBLink){
  6654.           //            //     $used = 1;
  6655.           //            //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  6656.           //            //     $usedLink_id = $usedBLink->getLink()->getId();
  6657.           //            // }
  6658.           //
  6659.           //            $port->used = $used;
  6660.           //            $port->usedLinkID = $usedLinkID;
  6661.           //            $port->usedLink_id = $usedLink_id;
  6662.           //
  6663.           //            $p['used'] = $used;
  6664.           //            $p['usedLinkID'] = $usedLinkID;
  6665.           //            $p['usedLink_id'] = $usedLink_id;
  6666.           //            $p['nPort'] = $port->nPort;
  6667.           //            $p['inTrunk'] = $isPortInTrunk;
  6668.           //
  6669.           //
  6670.           //            if ($port->nPort == 1 && $port->used == 1){
  6671.           //
  6672.           //                $p['id'] = $port->getId();
  6673.           //
  6674.           //            }
  6675.           //
  6676.           //            $totalPortsInInterface ++;
  6677.           //
  6678.           //            if ($used == 1){
  6679.           //                $totalPortsUsed ++;
  6680.           //            }
  6681.           //
  6682.           //            $portList[] = $p;
  6683.           //
  6684.           //        }
  6685.           //
  6686.           //        $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  6687.           //        $int['totalPorts'] = $totalPorts;
  6688.           //        $int['totalPortsUsed'] = $totalPortsUsed;
  6689.           //        $int['ports'] = $portList;
  6690.           //
  6691.           //        if ($isInterfaceInTrunk == 1){
  6692.           //
  6693.           //            $eq['interfaces'][] = $int;
  6694.           //
  6695.           //            if ($totalPortsInInterface > $maxPorts){
  6696.           //                $maxPorts = $totalPortsInInterface;
  6697.           //            }
  6698.           //
  6699.           //        }
  6700.           //
  6701.           //
  6702.           //    }
  6703.           //
  6704.           //    $list[] = $eq;
  6705.           //      foreach ($tcfs as $tcf) {
  6706.           //          $extensions = $tcf->getExtensions();
  6707.           //          foreach ($extensions as $extension) {
  6708.           //              $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
  6709.           //
  6710.           //              if (!in_array($eqB->getId(), $eqBArray)) {
  6711.           //                $eqBArray[] = $eqB->getId();
  6712.           //                $trunk->eqB = $eqB;
  6713.           //
  6714.           //                $rackTitle = $eqB->getRack()->getTitle();
  6715.           //
  6716.           //                $eq['trunkID'] = $trunk->getTrunkID();
  6717.           //                $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
  6718.           //                $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
  6719.           //                $eq['rack'] = $rackTitle;
  6720.           //                $eq['equipment'] = $eqB->getEquipmentSpecificName();
  6721.           //                $eq['interfaces'] = [];
  6722.           //
  6723.           //                $interfaces = $eqB->getInterfaceSpecific();
  6724.           //                foreach ($interfaces as $interface){
  6725.           //
  6726.           //                    $totalPorts = 0;
  6727.           //                    $totalPortsUsed = 0;
  6728.           //                    $totalPortsInInterface = 0;
  6729.           //
  6730.           //                    $ports = $interface->getPort();
  6731.           //
  6732.           //                    $portList = [];
  6733.           //
  6734.           //                    $isInterfaceInTrunk = 0;
  6735.           //
  6736.           //                    foreach ($ports as $port){
  6737.           //
  6738.           //                        $isPortInTrunk = 0;
  6739.           //
  6740.           //                        $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6741.           //                        $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6742.           //                        $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
  6743.           //
  6744.           //                        if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  6745.           //                            $isInterfaceInTrunk = 1;
  6746.           //                            $isPortInTrunk = 1;
  6747.           //                            $totalPorts++;
  6748.           //                        }
  6749.           //
  6750.           //
  6751.           //                        $port->nPort = 0;
  6752.           //                        $port->used = 0;
  6753.           //                        $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  6754.           //                        if ($nPorts){
  6755.           //                            $nPorts = json_decode($nPorts);
  6756.           //                            if (in_array($port->getOrderNo(), $nPorts)){
  6757.           //                                $port->nPort = 1;
  6758.           //                            }
  6759.           //                        }
  6760.           //
  6761.           //                        $used = 0;
  6762.           //                        $usedLinkID = '';
  6763.           //                        $usedLink_id = '';
  6764.           //                        if (in_array($port->getId(), $portsAll)) {
  6765.           //                          $usedALink = null;
  6766.           //                          $usedBLink = null;
  6767.           //                          $tempExts = $port->getExtensionOrder();
  6768.           //                          foreach ( $tempExts as $value) {
  6769.           //                            $extremityB =$value->getExtremity();
  6770.           //                            if ($usedALink && $usedBLink) {
  6771.           //                              break;
  6772.           //                            }
  6773.           //                            if(!$usedALink) {
  6774.           //                               $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6775.           //                            }
  6776.           //                            if (!$usedBLink) {
  6777.           //                              $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6778.           //                            }
  6779.           //                          }
  6780.           //                          $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  6781.           //                          $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  6782.           //
  6783.           //                          if ($usedALink) {
  6784.           //                            $used = 1;
  6785.           //                            $usedLinkID = $usedALink->getLink()->getLinkID();
  6786.           //                            $usedLink_id = $usedALink->getLink()->getId();
  6787.           //                          }
  6788.           //                          if ($usedBLink) {
  6789.           //                            $used = 1;
  6790.           //                            $usedLinkID = $usedBLink->getLink()->getLinkID();
  6791.           //                            $usedLink_id = $usedBLink->getLink()->getId();
  6792.           //                          }
  6793.           //
  6794.           //                          if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  6795.           //
  6796.           //                          }
  6797.           //                          else if($trunkExtension) {
  6798.           //                            // var_dump("Got it");
  6799.           //                            $used = 1;
  6800.           //                            $usedLinkID = $port->getLink()->getLinkID();
  6801.           //                            $usedLink_id = $port->getLink()->getId();
  6802.           //                          }
  6803.           //                          if ($tcfB && $usedBLink) {
  6804.           //
  6805.           //                          }
  6806.           //                          else if($tcfB){
  6807.           //                            $used = 1;
  6808.           //                            $usedLinkID = $port->getLink()->getLinkID();
  6809.           //                            $usedLink_id = $port->getLink()->getId();
  6810.           //
  6811.           //                          }
  6812.           //
  6813.           //                          $port->used = $used;
  6814.           //                          $port->usedLinkID = $usedLinkID;
  6815.           //                          $port->usedLink_id = $usedLink_id;
  6816.           //                        }
  6817.           //                        // $usedALink = null;
  6818.           //                        // $usedBLink = null;
  6819.           //                        // $tempExts = $port->getExtremities();
  6820.           //                        // foreach ( $tempExts as $extremityB) {
  6821.           //                        //   if ($usedALink && $usedBLink) {
  6822.           //                        //     break;
  6823.           //                        //   }
  6824.           //                        //   if(!$usedALink) {
  6825.           //                        //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  6826.           //                        //   }
  6827.           //                        //   if (!$usedBLink) {
  6828.           //                        //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  6829.           //                        //   }
  6830.           //                        // }
  6831.           //                        //
  6832.           //                        // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  6833.           //                        // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  6834.           //                        //
  6835.           //                        // if ($usedALink){
  6836.           //                        //     $used = 1;
  6837.           //                        //     $usedLinkID = $usedALink->getLink()->getLinkID();
  6838.           //                        //     $usedLink_id = $usedALink->getLink()->getId();
  6839.           //                        // }
  6840.           //                        //
  6841.           //                        // if ($usedBLink){
  6842.           //                        //     $used = 1;
  6843.           //                        //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  6844.           //                        //     $usedLink_id = $usedBLink->getLink()->getId();
  6845.           //                        // }
  6846.           //
  6847.           //                        $port->used = $used;
  6848.           //                        $port->usedLinkID = $usedLinkID;
  6849.           //                        $port->usedLink_id = $usedLink_id;
  6850.           //
  6851.           //                        $p['used'] = $used;
  6852.           //                        $p['usedLinkID'] = $usedLinkID;
  6853.           //                        $p['usedLink_id'] = $usedLink_id;
  6854.           //                        $p['nPort'] = $port->nPort;
  6855.           //                        $p['inTrunk'] = $isPortInTrunk;
  6856.           //
  6857.           //
  6858.           //                        if ($port->nPort == 1 && $port->used == 1){
  6859.           //
  6860.           //                            $p['id'] = $port->getId();
  6861.           //
  6862.           //                        }
  6863.           //
  6864.           //                        $totalPortsInInterface ++;
  6865.           //
  6866.           //                        if ($used == 1){
  6867.           //                            $totalPortsUsed ++;
  6868.           //                        }
  6869.           //
  6870.           //                        $portList[] = $p;
  6871.           //
  6872.           //                    }
  6873.           //
  6874.           //                    $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  6875.           //                    $int['totalPorts'] = $totalPorts;
  6876.           //                    $int['totalPortsUsed'] = $totalPortsUsed;
  6877.           //                    $int['ports'] = $portList;
  6878.           //
  6879.           //                    if ($isInterfaceInTrunk == 1){
  6880.           //
  6881.           //                        $eq['interfaces'][] = $int;
  6882.           //
  6883.           //                        if ($totalPortsInInterface > $maxPorts){
  6884.           //                            $maxPorts = $totalPortsInInterface;
  6885.           //                        }
  6886.           //
  6887.           //                    }
  6888.           //
  6889.           //
  6890.           //                }
  6891.           //
  6892.           //                $list[] = $eq;
  6893.           //              }
  6894.           //          }
  6895.           //      }
  6896.           //      // var_dump($eqA);
  6897.           //      // var_dump($eqB);
  6898.           //      // print_r($eqBArray);
  6899.           //
  6900.           //  } //end
  6901.        }
  6902.        return $this->render('overview/trunk_usage.html.twig', [
  6903.            'action' => 'list',
  6904.            'page_title' => $translator->trans('Trunk Usage'),
  6905.            'trunk' => $trunk,
  6906.            'list' => $list,
  6907.            'maxPorts' => $maxPorts
  6908.        ]);
  6909.    }
  6910.    /**
  6911.     * @Route("/trunk/overview/item/{id}", name="trunk_overview")
  6912.     */
  6913.    public function overviewAction(Request $request$idTranslatorInterface $translator)
  6914.   {
  6915.        $em $this->getDoctrine()->getManager();
  6916.        $trunk $em->getRepository(Trunk::class)->find($id);
  6917.        // $queryBuilder = $em->createQueryBuilder()
  6918.        // ->select('tcf')
  6919.        // ->from('App\Entity\TrunkCableFiber', 'tcf')
  6920.        // ->where("tcf.trunk = :trunk")
  6921.        // ->setParameter("trunk", $trunk);
  6922.        // $adapter = new DoctrineORMAdapter($queryBuilder);
  6923.        // $pagerfanta = new Pagerfanta($adapter);
  6924.        $pageLength $request->query->get("pageLength"$this->getParameter("trunk.details.maxPerPage"));
  6925.        // if ($pageLength == "Tout") {
  6926.        //   $qb = $em->createQueryBuilder()
  6927.        //   ->select('COUNT(tcf.id)')
  6928.        //   ->from('App\Entity\TrunkCableFiber', 'tcf')
  6929.        //   ->where("tcf.trunk = :trunk")
  6930.        //   ->setParameter("trunk", $trunk);
  6931.        //
  6932.        //   $count = $qb->getQuery()->getSingleScalarResult();
  6933.        //   $pagerfanta->setMaxPerPage($count); // 10 by default
  6934.        // }
  6935.        // else {
  6936.        //   $pagerfanta->setMaxPerPage($pageLength); // 10 by default
  6937.        // }
  6938.        // $page = $request->query->get("page", 1);
  6939.        // $pagerfanta->setCurrentPage($page);
  6940.        // $tcfs = $trunk->getCableFiber();
  6941.        //
  6942.        // foreach ($tcfs as $tcf){
  6943.        //
  6944.        //     $ext = $tcf->getExtensions();
  6945.        //
  6946.        // }
  6947.        return $this->render('overview/trunk_view.html.twig', [
  6948.            'page_title' => $translator->trans('Trunk Overview'),
  6949.            'trunk' => $trunk,
  6950.            // 'my_pager' => $pagerfanta,
  6951.            'pageLength' => $pageLength,
  6952.        ]);
  6953.    }
  6954.    /**
  6955.     * @IsGranted("ROLE_CRUD")
  6956.     * @Route("/trunk/process/basic", name="trunk_edit_basic")
  6957.     */
  6958.    public function editBasicAction(Request $requestTranslatorInterface $translator)
  6959.   {
  6960.        $user $this->get('security.token_storage')->getToken()->getUser();
  6961.        $em $this->getDoctrine()->getManager();
  6962.        $trunk $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
  6963.        $trunk->setTrunkID($request->request->get('trunkID'));
  6964.        $trunk->setOperatorID($request->request->get('operatorID'));
  6965.        $trunk->setTypeCable($this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable')));
  6966.        $trunk->setUpdatedBy($user);
  6967.        $usedCapacity 0;
  6968.        $trunkCableFiber $trunk->getCableFiber();
  6969.        foreach ($trunkCableFiber as $item) {
  6970.            $usedCapacity += 1;
  6971.        }
  6972.        $newCapacity $request->request->get('capacity');
  6973.        if ($newCapacity >= $usedCapacity){
  6974.            $trunk->setCapacity($newCapacity);
  6975.        }
  6976.        $em->persist($trunk);
  6977.        $em->flush();
  6978.        // return $this->redirectToRoute('trunk_list');
  6979.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  6980.    }
  6981.    /**
  6982.     * @IsGranted("ROLE_CRUD")
  6983.     * @Route("/trunk/delete/{id}", name="trunk_delete")
  6984.     */
  6985.    public function deleteAction($idTranslatorInterface $translator)
  6986.   {
  6987.        $em $this->getDoctrine()->getManager();
  6988.        $trunk $em->getRepository(Trunk::class)->find($id);
  6989.        $used $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByTrunk($trunk);
  6990.        $error = [];
  6991.        if (!$used){
  6992.            $sql "delete from trunk_cable_fiber where trunk_id = " $id;
  6993.            $conn $em->getConnection();
  6994.            $stmt $conn->prepare($sql);
  6995.            $stmt->execute();
  6996.            // $em->flush();
  6997.            $em->remove($trunk);
  6998.            $em->flush();
  6999.            $error = array('error' => null);
  7000.        } else {
  7001.            $error = array('error' => 'usage');
  7002.        }
  7003.        if ($error['error']) {
  7004.          $this->addFlash(
  7005.              'error',
  7006.              'usage'
  7007.          );
  7008.        }
  7009.        return $this->redirectToRoute('trunk_list');
  7010.    }
  7011.    /**
  7012.     * @IsGranted("ROLE_CRUD")
  7013.     * @Route("/trunk/delete/extension/{id}", name="trunk_delete_extension")
  7014.     */
  7015.    public function deleteExtensionAction($idTranslatorInterface $translator)
  7016.   {
  7017.        $user $this->get('security.token_storage')->getToken()->getUser();
  7018.        $em $this->getDoctrine()->getManager();
  7019.        $trunkExtension $em->getRepository(TrunkExtension::class)->find($id);
  7020.        $trunkCableFiber $trunkExtension->getTrunkCableFiber();
  7021.        $trunkExtensionSequenceNo $trunkExtension->getSequenceNo();
  7022.        $lastTrunkExt $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$trunkCableFiber"sequenceNo"=>$trunkExtensionSequenceNo-1]);
  7023.        $portB null;
  7024.        if ($lastTrunkExt) {
  7025.          $portB $lastTrunkExt->getPortB();
  7026.        }
  7027.        else {
  7028.          $portB $trunkCableFiber->getPortB();
  7029.        }
  7030.        $trunkExts $em->getRepository(TrunkExtension::class)->getAllNextExtensions($trunkCableFiber$trunkExtensionSequenceNo);
  7031.        foreach ($trunkExts as $trunkExt) {
  7032.          $matchedPort $trunkExt->getPortB();
  7033.          //get the link extension if any matches
  7034.          $extMatch null;
  7035.          $extId $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
  7036.          if ($extId) {
  7037.            $extMatch $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
  7038.          }
  7039.          // $extMatch = $matchedPort->getLinkExtension();
  7040.          if ($extMatch) {
  7041.            // $orderNoExt = $matchedPort->getOrderNoExtension();
  7042.            $matchedPort->setLink(null);
  7043.            $matchedPort->setLinkExtension(null);
  7044.            // $matchedPort->setOrderNoExtension(1);
  7045.            $em->persist($matchedPort);
  7046.            $linkMatch $extMatch->getLink();
  7047.            $extrmityB $extMatch->getExtremityB();
  7048.            $extBPorts $extrmityB->getExtensionOrder();
  7049.            $tempIds = array();
  7050.            foreach ($extBPorts as $value) {
  7051.              $tempIds[] = $value->getPort()->getId();
  7052.            }
  7053.            if (in_array($matchedPort->getId(), $tempIds)) {
  7054.              $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityB]);
  7055.              $orderNoExt $extensinOrder->getOrderNumber();
  7056.              $em->remove($extensinOrder);
  7057.              // $extrmityB->removePort($matchedPort);
  7058.              if (!$this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portB"extremity"=>$extrmityB])) {
  7059.                $extensinOrder = new ExtensionOrder();
  7060.                $extensinOrder->setOrderNumber($orderNoExt);
  7061.                $extensinOrder->setPort($portB);
  7062.                $extensinOrder->setExtremity($extrmityB);
  7063.                $portB->addExtensionOrder($extensinOrder);
  7064.                $extrmityB->addExtensionOrder($extensinOrder);
  7065.                $em->persist($extensinOrder);
  7066.                // $extrmityB->removePort($matchedPort);
  7067.                // $extrmityB->addPort($portB);
  7068.                // $portB->setOrderNoExtension($orderNoExt);
  7069.                // $portB->addExtremity($extrmityB);
  7070.                $portB->setLink($linkMatch);
  7071.                $portB->setLinkExtension($extMatch);
  7072.                $em->persist($portB);
  7073.                $em->persist($extrmityB);
  7074.              }
  7075.              //check if it's last link extension
  7076.              //if it's last, DO NOTHING
  7077.              if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
  7078.                // // var_dump("entering ...");
  7079.                // //else get the last extension's extremity B's equipment
  7080.                // $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
  7081.                // $nextExtA = $nextExtension->getExtremityA();
  7082.                // $nextPorts = array();
  7083.                // foreach ($nextExtA->getExtensionOrder() as $value) {
  7084.                //   $nextPorts[] = $value->getPort();
  7085.                // }
  7086.                // // $nextPorts = $nextExtA->getPorts();
  7087.                // $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
  7088.                // $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
  7089.                // $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
  7090.                //
  7091.                // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  7092.                // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  7093.                //
  7094.                // //check if it's same as current modified link ext
  7095.                // if ($currentEquipment->getId() != $nextEquipment->getId()) {
  7096.                //   // var_dump("entering not equals equipments...");
  7097.                //
  7098.                //   //if false, set the link and las link extension as INVALID
  7099.                //   $nextExtension->setIsValid(false);
  7100.                //   $em->persist($nextExtension);
  7101.                // }
  7102.                // else {
  7103.                //   // var_dump("entering checking ports...");
  7104.                //
  7105.                //     $nextExtension->setIsValid(true);
  7106.                //     $em->persist($nextExtension);
  7107.                //   //else get the next extension's extremity B's interface
  7108.                //   //check if it's 1:1
  7109.                //   if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  7110.                //     // var_dump("entering checking 1 to 1...");
  7111.                //
  7112.                //     // if true, check ports are the same
  7113.                //     //if true, DO NOTHING
  7114.                //     //else set the link and las link extension as INVALID
  7115.                //     foreach ($nextPorts as $nextPort) {
  7116.                //       if ($nextPort->getId() != $portB->getId()) {
  7117.                //         $nextExtension->setIsValid(false);
  7118.                //         $em->persist($nextExtension);
  7119.                //       }
  7120.                //       else {
  7121.                //         $nextExtension->setIsValid(true);
  7122.                //         $em->persist($nextExtension);
  7123.                //       }
  7124.                //     }
  7125.                //   }
  7126.                // }
  7127.                TrunkController::validateNextExtension($em$linkMatch$extMatch$portB);
  7128.              }
  7129.            }
  7130.            $extrmityA $extMatch->getExtremityA();
  7131.            $extAPorts $extrmityA->getExtensionOrder();
  7132.            $tempIds = array();
  7133.            foreach ($extAPorts as $value) {
  7134.              $tempIds[] = $value->getPort()->getId();
  7135.            }
  7136.            if (in_array($matchedPort->getId(), $tempIds)) {
  7137.              $extensinOrder $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort"extremity"=>$extrmityA]);
  7138.              $orderNoExt $extensinOrder->getOrderNumber();
  7139.              $em->remove($extensinOrder);
  7140.              // $extrmityA->removePort($matchedPort);
  7141.              $extensinOrder = new ExtensionOrder();
  7142.              $extensinOrder->setOrderNumber($orderNoExt);
  7143.              $extensinOrder->setPort($portB);
  7144.              $extensinOrder->setExtremity($extrmityA);
  7145.              $portB->addExtensionOrder($extensinOrder);
  7146.              $extrmityA->addExtensionOrder($extensinOrder);
  7147.              $em->persist($extensinOrder);
  7148.              // $extrmityA->removePort($matchedPort);
  7149.              // $extrmityA->addPort($portB);
  7150.              // $portB->setOrderNoExtension($orderNoExt);
  7151.              // $portB->addExtremity($extrmityA);
  7152.              $portB->setLink($linkMatch);
  7153.              $portB->setLinkExtension($extMatch);
  7154.              $em->persist($portB);
  7155.              $em->persist($extrmityA);
  7156.              if ($extMatch->getSequenceNo() > 1) {
  7157.                // //else get the last extension's extremity B's equipment
  7158.                // $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
  7159.                //
  7160.                // $lastExtB = $lastExtension->getExtremityB();
  7161.                //
  7162.                // $lastPorts = array();
  7163.                // foreach ($lastExtB->getExtensionOrder() as $value) {
  7164.                //   $lastPorts[] = $value->getPort();
  7165.                // }
  7166.                //
  7167.                // // $lastPorts = $lastExtB->getPorts();
  7168.                // // var_dump($lastPorts);
  7169.                // $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
  7170.                // $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
  7171.                // $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
  7172.                //
  7173.                // $currentInterfaceSpecific = $portB->getInterfaceSpecific();
  7174.                // $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
  7175.                //
  7176.                // //check if it's same as current modified link ext
  7177.                // if ($currentEquipment->getId() != $lastEquipment->getId()) {
  7178.                //   //if false, set the link and las link extension as INVALID
  7179.                //   $lastExtension->setIsValid(false);
  7180.                //   $em->persist($lastExtension);
  7181.                // }
  7182.                // else {
  7183.                //   // var_dump('hi');
  7184.                //   $lastExtension->setIsValid(true);
  7185.                //   $em->persist($lastExtension);
  7186.                //   //else get the last extension's extremity B's interface
  7187.                //   //check if it's 1:1
  7188.                //   if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  7189.                //     // if true, check ports are the same
  7190.                //     //if true, DO NOTHING
  7191.                //     //else set the link and las link extension as INVALID
  7192.                //     foreach ($lastPorts as $lastPort) {
  7193.                //       // var_dump($lastPort);
  7194.                //       if ($lastPort->getId() != $portB->getId()) {
  7195.                //         $lastExtension->setIsValid(false);
  7196.                //         $em->persist($lastExtension);
  7197.                //       }
  7198.                //       else {
  7199.                //         $lastExtension->setIsValid(true);
  7200.                //         $em->persist($lastExtension);
  7201.                //       }
  7202.                //     }
  7203.                //   }
  7204.                // }
  7205.                TrunkController::validateLastExtension($em$linkMatch$extMatch$portB);
  7206.              }
  7207.            }
  7208.          }
  7209.        }
  7210.        // delete action
  7211.        $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->deleteExtension($trunkCableFiber$trunkExtensionSequenceNo);
  7212.        $trunk $trunkCableFiber->getTrunk();
  7213.        $trunk->setUpdatedBy($user);
  7214.        $em->persist($trunk);
  7215.        $em->flush();
  7216.        // $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
  7217.        // $cache = new FilesystemAdapter();
  7218.        // LinkTrunkEventListener::treateTrunkList($trunks, $cache);
  7219.        // LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
  7220.        return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
  7221.    }
  7222.    /**
  7223.     * @Route("/trunk/findTrunkIdDuplicate", name="ajax_find_trunk_id")
  7224.     */
  7225.    public function findTrunkIdDuplicate()
  7226.    {
  7227.        $response $this->getDoctrine()->getRepository('App\Entity\Trunk')->findTrunkIdDuplicate($_POST['trunkID']);
  7228.        return $this->json($response);
  7229.    }
  7230.    /**
  7231.     * @Route("/trunk/findTrunkIdDuplicateOther", name="ajax_find_trunk_id_other")
  7232.     */
  7233.    public function findTrunkIdDuplicateOther()
  7234.    {
  7235.        $response $this->getDoctrine()->getRepository('App\Entity\Trunk')->findTrunkIdDuplicateOther($_POST['trunkID'], $_POST['id']);
  7236.        return $this->json($response);
  7237.    }
  7238.    /**
  7239.     * @Route("/trunk/findOperatorIdExtensionOther", name="ajax_find_operator_id_extension_other")
  7240.     */
  7241.    public function findOperatorIdDuplicateOther()
  7242.    {
  7243.        $trunk_id $_POST['trunk_id'];
  7244.        $operatorId $_POST['operatorId'];
  7245.        $response $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOperatorIdDuplicateOther($trunk_id$operatorId);
  7246.        return $this->json($response);
  7247.    }
  7248.    public function createEquipment($trunk$eqA$portsAll$maxPorts)
  7249.    {
  7250.          $rackTitle $eqA->getRack()->getTitle();
  7251.          $eq['trunkID'] = $trunk->getTrunkID();
  7252.          $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
  7253.          $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
  7254.          $eq['rack'] = $rackTitle;
  7255.          if ($eqA->isModule()) {
  7256.            // $eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName() . " â•‘ " . $eqA->getEquipmentSpecificName();
  7257.            $eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName();
  7258.          }
  7259.          elseif ($eqA->isChassisModule()) {
  7260.            // $eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName() . " â•‘ " . $eqA->getEquipmentSpecificName();
  7261.            $eq['equipment'] = $eqA->getChassisParent()->getEquipmentSpecificName();
  7262.          }
  7263.          else {
  7264.            $eq['equipment'] = $eqA->getEquipmentSpecificName();
  7265.          }
  7266.          $eq['interfaces'] = [];
  7267.          $interfaces $eqA->getInterfaceSpecific();
  7268.          foreach ($interfaces as $interface) {
  7269.              // var_dump($interface->getId());
  7270.              $totalPorts 0;
  7271.              $totalPortsUsed 0;
  7272.              $totalPortsInInterface 0;
  7273.              $ports $interface->getPort();
  7274.              $portList = [];
  7275.              $isInterfaceInTrunk 0;
  7276.              foreach ($ports as $port) {
  7277.                // var_dump($port->getId());
  7278.                  $used 0;
  7279.                  $usedLinkID null;
  7280.                  $usedLink_id null;
  7281.                  $isPortInTrunk 0;
  7282.                  $usedInTrunkPointA =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port'trunk' => $trunk]);
  7283.                  $usedInTrunkPointB =  $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port'trunk' => $trunk]);
  7284.                  $usedInTrunkExtension $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port$trunk);
  7285.                  // var_dump($usedInTrunkPointA);
  7286.                  // var_dump($usedInTrunkPointB);
  7287.                  // var_dump($usedInTrunkExtension);
  7288.                  if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
  7289.                      $isInterfaceInTrunk 1;
  7290.                      $isPortInTrunk 1;
  7291.                      $totalPorts++;
  7292.                  }
  7293.                  $port->nPort 0;
  7294.                  $port->used  0;
  7295.                  $nPorts $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
  7296.                  if ($nPorts){
  7297.                      $nPorts json_decode($nPorts);
  7298.                      if (in_array($port->getOrderNo(), $nPorts)){
  7299.                          $port->nPort 1;
  7300.                      }
  7301.                  }
  7302.                  // $used = 0;
  7303.                  // $usedLinkID = '';
  7304.                  // $usedLink_id = '';
  7305.                  if (in_array($port->getId(), $portsAll)) {
  7306.                  // $usedALink = null;
  7307.                  // $usedBLink = null;
  7308.                  // $tempExts = $port->getExtensionOrder();
  7309.                  // foreach ( $tempExts as $value) {
  7310.                  //   $extremityB = $value->getExtremity();
  7311.                  //   if ($usedALink && $usedBLink) {
  7312.                  //     break;
  7313.                  //   }
  7314.                  //   if(!$usedALink) {
  7315.                  //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  7316.                  //   }
  7317.                  //   if (!$usedBLink) {
  7318.                  //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  7319.                  //   }
  7320.                  // }
  7321.                  // $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
  7322.                  // $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
  7323.                  //
  7324.                  // if ($usedALink) {
  7325.                  //   $used = 1;
  7326.                  //   $usedLinkID = $usedALink->getLink()->getLinkID();
  7327.                  //   $usedLink_id = $usedALink->getLink()->getId();
  7328.                  // }
  7329.                  // if ($usedBLink) {
  7330.                  //   $used = 1;
  7331.                  //   $usedLinkID = $usedBLink->getLink()->getLinkID();
  7332.                  //   $usedLink_id = $usedBLink->getLink()->getId();
  7333.                  // }
  7334.                  //
  7335.                  // if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
  7336.                  //
  7337.                  // }
  7338.                  // else if($trunkExtension) {
  7339.                  //   // var_dump("Got it");
  7340.                  //   $used = 1;
  7341.                  //   $usedLinkID = $port->getLink()->getLinkID();
  7342.                  //   $usedLink_id = $port->getLink()->getId();
  7343.                  // }
  7344.                  // if ($tcfB && $usedBLink) {
  7345.                  //
  7346.                  // }
  7347.                  // else if($tcfB){
  7348.                  //   $used = 1;
  7349.                  //   $usedLinkID = $port->getLink()->getLinkID();
  7350.                  //   $usedLink_id = $port->getLink()->getId();
  7351.                  //
  7352.                  // }
  7353.                  $used 1;
  7354.                  $usedLinkID $port->getLink()->getLinkID();
  7355.                  $usedLink_id $port->getLink()->getId();
  7356.                  // $port->used = $used;
  7357.                  $port->used $used;
  7358.                  $port->usedLinkID $usedLinkID;
  7359.                  $port->usedLink_id $usedLink_id;
  7360.                }
  7361.                  // $usedALink = null;
  7362.                  // $usedBLink = null;
  7363.                  // $tempExts = $port->getExtremities();
  7364.                  // foreach ( $tempExts as $extremityB) {
  7365.                  //   if ($usedALink && $usedBLink) {
  7366.                  //     break;
  7367.                  //   }
  7368.                  //   if(!$usedALink) {
  7369.                  //      $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
  7370.                  //   }
  7371.                  //   if (!$usedBLink) {
  7372.                  //     $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
  7373.                  //   }
  7374.                  // }
  7375.                  // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
  7376.                  // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
  7377.                  // if ($usedALink) {
  7378.                  //     $used = 1;
  7379.                  //     $usedLinkID = $usedALink->getLink()->getLinkID();
  7380.                  //     $usedLink_id = $usedALink->getLink()->getId();
  7381.                  // }
  7382.                  //
  7383.                  // if ($usedBLink) {
  7384.                  //     $used = 1;
  7385.                  //     $usedLinkID = $usedBLink->getLink()->getLinkID();
  7386.                  //     $usedLink_id = $usedBLink->getLink()->getId();
  7387.                  // }
  7388.                  // // var_dump($used);
  7389.                  //
  7390.                  // $port->used = $used;
  7391.                  // $port->usedLinkID = $usedLinkID;
  7392.                  // $port->usedLink_id = $usedLink_id;
  7393.                  $p['used'] = $used;
  7394.                  $p['usedLinkID'] = $usedLinkID;
  7395.                  $p['usedLink_id'] = $usedLink_id;
  7396.                  $p['nPort'] = $port->nPort;
  7397.                  $p['inTrunk'] = $isPortInTrunk;
  7398.                  if ($port->nPort == && $port->used == 1){
  7399.                      $p['id'] = $port->getId();
  7400.                  }
  7401.                  $totalPortsInInterface++;
  7402.                  if ($used == && $isPortInTrunk == 1) {
  7403.                      $totalPortsUsed++;
  7404.                  }
  7405.                  $portList[] = $p;
  7406.              }
  7407.              if ($eqA->isModule() || $eqA->isChassisModule()) {
  7408.                  if (count($interfaces) == 1) {
  7409.                      $int['interfaceNumber'] = $eqA->getEquipmentSpecificName();
  7410.                  }
  7411.                  else {
  7412.                      $int['interfaceNumber'] = $eqA->getEquipmentSpecificName()."-".$interface->getInterfaceGeneric()->getInterfaceNumber();
  7413.                  }
  7414.              }
  7415.              else {
  7416.                $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
  7417.              }
  7418.              $int['totalPorts'] = $totalPorts;
  7419.              $int['totalPortsUsed'] = $totalPortsUsed;
  7420.              $int['ports'] = $portList;
  7421.              if ($isInterfaceInTrunk == 1){
  7422.                  $eq['interfaces'][] = $int;
  7423.                  if ($totalPortsInInterface $maxPorts){
  7424.                      $maxPorts $totalPortsInInterface;
  7425.                  }
  7426.              }
  7427.          }
  7428.          return array("eq"=>$eq"maxPorts"=>$maxPorts);
  7429.    }
  7430.    public static function validateLastExtension($em$link$extension$portA1)
  7431.    {
  7432.      $lastExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link"sequenceNo"=>$extension->getSequenceNo()-1]);
  7433.      $lastExtB $lastExtension->getExtremityB();
  7434.      $lastPorts = [];
  7435.      $lastPortsTemp $lastExtB->getExtensionOrder();
  7436.      foreach ($lastPortsTemp as $value) {
  7437.        $lastPorts[] = $value->getPort();
  7438.      }
  7439.      // $lastPorts = $lastExtB->getPorts();
  7440.      // var_dump($lastPorts);
  7441.      $lastInterfaceSpecific $lastPorts[0]->getInterfaceSpecific();
  7442.      $lastInterfaceGeneric $lastInterfaceSpecific->getInterfaceGeneric();
  7443.      $lastEquipment $lastInterfaceSpecific->getEquipmentSpecific();
  7444.      $currentInterfaceSpecific $portA1->getInterfaceSpecific();
  7445.      $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific();
  7446.      //check if it's same as current modified link ext
  7447.      if ($currentEquipment->getId() != $lastEquipment->getId()) {
  7448.        //if false, set the link and las link extension as INVALID
  7449.        $lastExtension->setIsValid(false);
  7450.        if ($lastExtension->getError()) {
  7451.          $lastExtension->setError($lastExtension->getError() . "," "EquipmentB");
  7452.        }
  7453.        else {
  7454.          $lastExtension->setError("EquipmentB");
  7455.        }
  7456.        $em->persist($lastExtension);
  7457.      }
  7458.      else {
  7459.        // var_dump('hi');
  7460.        $errMsg $lastExtension->getError();
  7461.        $errMsg str_replace("EquipmentB"""$errMsg);
  7462.        $lastExtension->setError($errMsg);
  7463.        if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  7464.             $lastExtension->setIsValid(false);
  7465.         }
  7466.         else {
  7467.           $lastExtension->setIsValid(true);
  7468.           $lastExtension->setError(null);
  7469.         }
  7470.        $em->persist($lastExtension);
  7471.        //else get the last extension's extremity B's interface
  7472.        //check if it's 1:1
  7473.        if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  7474.          // if true, check ports are the same
  7475.          //if true, DO NOTHING
  7476.          //else set the link and las link extension as INVALID
  7477.          foreach ($lastPorts as $lastPort) {
  7478.            if ($lastPort->getId() != $portA1->getId()) {
  7479.              $lastExtension->setIsValid(false);
  7480.              if ($lastExtension->getError()) {
  7481.                $lastExtension->setError($lastExtension->getError() . "," "PortB");
  7482.              }
  7483.              else {
  7484.                $lastExtension->setError("PortB");
  7485.              }
  7486.              $em->persist($lastExtension);
  7487.            }
  7488.            else {
  7489.              $errMsg str_replace("PortB"""$errMsg);
  7490.              $lastExtension->setError($errMsg);
  7491.              if (!$errMsg && (strpos($errMsg'EquipmentA') !== false || strpos($errMsg'PortA') !== false)) {
  7492.                   $lastExtension->setIsValid(false);
  7493.               }
  7494.               else {
  7495.                 $lastExtension->setIsValid(true);
  7496.                 $lastExtension->setError(null);
  7497.               }
  7498.              $em->persist($lastExtension);
  7499.            }
  7500.          }
  7501.        }
  7502.      }
  7503.    }
  7504.    public static function validateNextExtension($em$link$extension$portB1){
  7505.      $nextExtension $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link"sequenceNo"=>$extension->getSequenceNo()+1]);
  7506.      $nextExtA $nextExtension->getExtremityA();
  7507.      $nextPorts = [];
  7508.      $nextPortsTemp $nextExtA->getExtensionOrder();
  7509.      foreach ($nextPortsTemp as $value) {
  7510.        $nextPorts[] = $value->getPort();
  7511.      }
  7512.      // $nextPorts = $nextExtA->getPorts();
  7513.      $nextInterfaceSpecific $nextPorts[0]->getInterfaceSpecific();
  7514.      $nextInterfaceGeneric $nextInterfaceSpecific->getInterfaceGeneric();
  7515.      $nextEquipment $nextInterfaceSpecific->getEquipmentSpecific();
  7516.      $currentInterfaceSpecific $portB1->getInterfaceSpecific();
  7517.      $currentEquipment $currentInterfaceSpecific->getEquipmentSpecific();
  7518.      //check if it's same as current modified link ext
  7519.      if ($currentEquipment->getId() != $nextEquipment->getId()) {
  7520.        //if false, set the link and las link extension as INVALID
  7521.        $nextExtension->setIsValid(false);
  7522.        if ($nextExtension->getError()) {
  7523.          $nextExtension->setError($nextExtension->getError() . "," "EquipmentA");
  7524.        }
  7525.        else {
  7526.          $nextExtension->setError("EquipmentA");
  7527.        }
  7528.        $em->persist($nextExtension);
  7529.      }
  7530.      else {
  7531.        $errMsg $nextExtension->getError();
  7532.        $errMsg str_replace("EquipmentA"""$errMsg);
  7533.        $nextExtension->setError($errMsg);
  7534.        if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  7535.             $nextExtension->setIsValid(false);
  7536.         }
  7537.         else {
  7538.           $nextExtension->setIsValid(true);
  7539.           $nextExtension->setError(null);
  7540.         }
  7541.          $em->persist($nextExtension);
  7542.        //else get the next extension's extremity B's interface
  7543.        //check if it's 1:1
  7544.        if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
  7545.          // if true, check ports are the same
  7546.          //if true, DO NOTHING
  7547.          //else set the link and las link extension as INVALID
  7548.          foreach ($nextPorts as $nextPort) {
  7549.            if ($nextPort->getId() != $portB1->getId()) {
  7550.              $nextExtension->setIsValid(false);
  7551.              if ($nextExtension->getError()) {
  7552.                $nextExtension->setError($nextExtension->getError() . "," "PortA");
  7553.              }
  7554.              else {
  7555.                $nextExtension->setError("PortA");
  7556.              }
  7557.              $em->persist($nextExtension);
  7558.            }
  7559.            else {
  7560.              $errMsg str_replace("PortA"""$errMsg);
  7561.              $nextExtension->setError($errMsg);
  7562.              if (!$errMsg && (strpos($errMsg'EquipmentB') !== false || strpos($errMsg'PortB') !== false)) {
  7563.                   $nextExtension->setIsValid(false);
  7564.               }
  7565.               else {
  7566.                 $nextExtension->setIsValid(true);
  7567.                 $nextExtension->setError(null);
  7568.               }
  7569.              $em->persist($nextExtension);
  7570.            }
  7571.          }
  7572.        }
  7573.      }
  7574.    }
  7575. }