src/Controller/LabelController.php line 24

Open in your IDE?
  1. <?php
  2. namespace App\Controller;
  3. use Symfony\Component\Routing\Annotation\Route;
  4. use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
  5. use Symfony\Component\HttpFoundation\Request;
  6. use Symfony\Component\HttpFoundation\Response;
  7. use Symfony\Contracts\Translation\TranslatorInterface;
  8. use App\Entity\Rack;
  9. use App\Entity\EquipmentSpecific;
  10. use App\Entity\InterfaceSpecific;
  11. use App\Entity\Port;
  12. use App\Entity\Link;
  13. use Psr\Log\LoggerInterface;
  14. class LabelController  extends AbstractController
  15. {
  16.     /**
  17.      * @Route("/label/racks", name="label_form_racks")
  18.      */
  19.     public function rackLabelIndexAction(Request $requestTranslatorInterface $translator)
  20.     {
  21.         $list $this->getDoctrine()->getRepository(Rack::class)->findAll();
  22.         $racks = [];
  23.         foreach ($list as $item){
  24.             $title $item->getTitle();
  25.             if ( strtolower(substr($title01)) == 'f' ){
  26.                 $racks[] = $item;
  27.             }
  28.         }
  29.         return $this->render('label/rack_list.html.twig', [
  30.             'page_title' => $translator->trans('Label - Choose Rack'),
  31.             'path_create' => 'label_create_racks',
  32.             'list' => $racks,
  33.         ]);
  34.     }
  35.     /**
  36.      * @Route("/label/racks/{id}", name="label_create_racks")
  37.      */
  38.     public function rackLabelCreateAction($idTranslatorInterface $translator)
  39.     {
  40.         $em $this->getDoctrine()->getManager();
  41.         $rack $em->getRepository(Rack::class)->find($id);
  42.         $room $rack->getRoom();
  43.         $list = [];
  44.         $linkExtensionsAIDS = []; // prevents duplication on bidirectional
  45.         $eq_in_rack $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findByRack($rack);
  46.         foreach ($eq_in_rack as $eq){
  47.             $interfaces $eq->getInterfaceSpecific();
  48.             foreach ($interfaces as $interface){
  49.                 $ports $interface->getPort();
  50.                 // var_dump(count($ports));
  51.                 foreach ($ports as $port){
  52.                     $extOrder $port->getExtensionOrder();
  53.                     // var_dump(count($extOrder));
  54.                     foreach ($extOrder as $value) {
  55.                       $extremity $value->getExtremity();
  56.                       // var_dump(count($extremity));
  57.                       // $extremity = $linkExt->getExtremityA()->getExtensionOrder();
  58.                       $linkExt $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremity]);
  59.                       // $linkExtensionsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portA' => $port, 'sequenceNo' => 1]);
  60.                       // foreach ($linkExtensionsA as $linkExt){
  61.                       if ($linkExt) {
  62.                         $portB null;
  63.                         $link $linkExt->getLink();
  64.                         $extOrder1 $linkExt->getExtremityB()->getExtensionOrder();
  65.                         foreach ($extOrder1 as $value1) {
  66.                             // $portB = $value1->getPort();
  67.                           if ($value->getOrderNumber() == $value1->getOrderNumber()) {
  68.                              $portB $value1->getPort();
  69.                           }
  70.                         }
  71.                         // $portB = $linkExt->getExtremityB()->getExtensionOrder();
  72.                         if($portB != null){
  73.                             $roomB $portB->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom();
  74.                             $rackBtitle $portB->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  75.                             if($roomB == $room && strtolower(substr($rackBtitle01)) == 'f'){
  76.                                 $rackA_lab $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  77.                                 $eqA_lab $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName();
  78.                                 $intA_lab $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  79.                                 $portA_lab $port->getAlias() ? $port->getAlias() : $port->getOrderNo();
  80.                                 $rackB_lab $portB->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  81.                                 $eqB_lab $portB->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName();
  82.                                 $intB_lab $portB->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  83.                                 $portB_lab $portB->getAlias() ? $portB->getAlias() : $portB->getOrderNo();
  84.                                 $link_lab $link->getLinkID();
  85.                                 $label $rackA_lab.'-'.$intA_lab.'-'.$portA_lab.' / '.$rackB_lab.'-'.$intB_lab.'-'.$portB_lab;
  86.                                 $list[] = [
  87.                                     'rackA' => $rackA_lab,
  88.                                     'eqA' => $eqA_lab,
  89.                                     'intA' => $intA_lab,
  90.                                     'portA' => $portA_lab,
  91.                                     'rackB' => $rackB_lab,
  92.                                     'eqB' => $eqB_lab,
  93.                                     'intB' => $intB_lab,
  94.                                     'portB' => $portB_lab,
  95.                                     'label' => $label,
  96.                                     'link' => $link_lab
  97.                                 ];
  98.                                 $linkExtensionsAIDS[] = $linkExt->getId();
  99.                             }
  100.                         }
  101.                       }
  102.                       // }
  103.                       // $linkExtensionsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portB' => $port, 'sequenceNo' => 1]);
  104.                       $linkExt $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremity]);
  105.                       // foreach ($linkExtensionsB as $linkExt){
  106.                           if ($linkExt) {
  107.                             if (!in_array($linkExt->getId(), $linkExtensionsAIDS)){ // prevents duplication on bidirectional
  108.                                 $portA null;
  109.                                 $link $linkExt->getLink();
  110.                                 $extOrder1 $linkExt->getExtremityA()->getExtensionOrder();
  111.                                 foreach ($extOrder1 as $value1) {
  112.                                     // $portA = $value1->getPort();
  113.                                   if ($value->getOrderNumber() == $value1->getOrderNumber()) {
  114.                                       $portA $value1->getPort();
  115.                                   }
  116.                                 }
  117.                                 // $portA = $linkExt->getPortA();
  118.                                 if($portA != null){
  119.                                     $roomA $portA->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom();
  120.                                     $rackBtitle $portA->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  121.                                     if($roomA == $room && strtolower(substr($rackBtitle01)) == 'f'){
  122.                                         $rackB_lab $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  123.                                         $eqB_lab $port->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName();
  124.                                         $intB_lab $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  125.                                         $portB_lab $port->getAlias() ? $port->getAlias() : $port->getOrderNo();
  126.                                         $rackA_lab $portA->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  127.                                         $eqA_lab $portA->getInterfaceSpecific()->getEquipmentSpecific()->getEquipmentSpecificName();
  128.                                         $intA_lab $portA->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  129.                                         $portA_lab $portA->getAlias() ? $portA->getAlias() : $portA->getOrderNo();
  130.                                         $link_lab $link->getLinkID();
  131.                                         $label $rackA_lab.'-'.$intA_lab.'-'.$portA_lab.' / '.$rackB_lab.'-'.$intB_lab.'-'.$portB_lab;
  132.                                         $list[] = [
  133.                                             'rackA' => $rackA_lab,
  134.                                             'eqA' => $eqA_lab,
  135.                                             'intA' => $intA_lab,
  136.                                             'portA' => $portA_lab,
  137.                                             'rackB' => $rackB_lab,
  138.                                             'eqB' => $eqB_lab,
  139.                                             'intB' => $intB_lab,
  140.                                             'portB' => $portB_lab,
  141.                                             'label' => $label,
  142.                                             'link' => $link_lab
  143.                                         ];
  144.                                     }
  145.                                 }
  146.                             }
  147.                           }
  148.                     }
  149.                     // }
  150.                 }
  151.             }
  152.         }
  153.         //return $this->json($linkExtensionsAIDS);
  154.         return $this->render('label/rack_labels.html.twig', [
  155.             'page_title' => $translator->trans('Rack Labels'),
  156.             'list' => $list,
  157.         ]);
  158.     }
  159.     /**
  160.      * @Route("/label/links", name="label_form_links")
  161.      */
  162.     public function linkLabelIndexAction(Request $requestTranslatorInterface $translator)
  163.     {
  164.         $links $this->getDoctrine()->getRepository('App\Entity\Link')->findAll();
  165.         foreach ($links as $link){
  166.             $extensions $link->getLinkExtension();
  167.             if ( !($extensions->isEmpty()) ) {
  168.                 $firstExt $extensions[0];
  169.                 $eqA $firstExt->getExtremityA()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific()->getEquipmentSpecific();
  170.                 // $eqA = $firstExt->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
  171.                 $link->eqA $eqA;
  172.                 $eqB $firstExt->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific()->getEquipmentSpecific();
  173.                 foreach ($extensions as $extension) {
  174.                     $portB $extension->getExtremityB()->getExtensionOrder()[0]->getPort();
  175.                     if (isset($portB)) {
  176.                         $eqB $extension->getExtremityB()->getExtensionOrder()[0]->getPort()->getInterfaceSpecific()->getEquipmentSpecific();
  177.                     }
  178.                 }
  179.                 $link->eqB $eqB;
  180.             }
  181.         }
  182.         return $this->render('label/link_list.html.twig', [
  183.             'page_title' => $translator->trans('Label - Choose Links'),
  184.             'path_create' => 'label_create_links',
  185.             'list' => $links,
  186.         ]);
  187.     }
  188.     /**
  189.      * @Route("/label/links/create", name="label_create_links")
  190.      */
  191.     public function linkLabelCreateAction(TranslatorInterface $translator)
  192.     {
  193.         $em $this->getDoctrine()->getManager();
  194.         $links $em->getRepository(Link::class)->findAll();
  195.         $list = [];
  196.         foreach ($links as $link){
  197.             if (isset($_POST['link_'.$link->getId()])){
  198.                 $extensions = [];
  199.                 $sequence = [];
  200.                 $e 1;
  201.                 $t 0;
  202.                 $tsn 0;
  203.                 $linkExtensions $link->getLinkExtension();
  204.                 foreach ($linkExtensions as $ext){
  205.                     $portsA = array();
  206.                     $portsB = array();
  207.                     $linkExtensionSequenceNo $ext->getSequenceNo();
  208.                     $linkExtensionTrunk $ext->getTrunk();
  209.                     if (is_null($linkExtensionTrunk)){
  210.                         $e $linkExtensionSequenceNo $t;
  211.                         if ($e 1){
  212.                             $extension['id'] = $link->getLinkID().'_E'.($e-1);
  213.                         } else {
  214.                             $extension['id'] =  $link->getLinkID();
  215.                         }
  216.                     } else {
  217.                         if ($linkExtensionSequenceNo != $tsn){
  218.                             $extension['id'] = $linkExtensionTrunk->getTrunkID();
  219.                             $tsn $linkExtensionSequenceNo;
  220.                             $t++;
  221.                         }
  222.                     }
  223.                     // $fiberNo = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->noFibersInExtension($link, $linkExtensionSequenceNo);
  224.                     // if ($fiberNo > 1){
  225.                         $portsATemp $ext->getExtremityA()->getExtensionOrder();
  226.                         foreach ($portsATemp as $value) {
  227.                           $portsA[] = $value->getPort();
  228.                         }
  229.                         // $portsA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsABySequence($link, $linkExtensionSequenceNo);
  230.                         $portsBTemp $ext->getExtremityB()->getExtensionOrder();
  231.                         foreach ($portsBTemp as $value) {
  232.                           $portsB[] = $value->getPort();
  233.                         }
  234.                         // $portsB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getPortsBBySequence($link, $linkExtensionSequenceNo);
  235.                         $extension['portA'] = '';
  236.                         $extension['portB'] = '';
  237.                         $portsAIDS = [];
  238.                         $portsBIDS = [];
  239.                         // var_dump($portsA);
  240.                         foreach ($portsA as $portID){
  241.                             $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  242.                             $extension['siteA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  243.                             if ($port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias()){
  244.                                 $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias();
  245.                             } else {
  246.                                 $extension['roomA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  247.                             }
  248.                             $extension['rackA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  249.                             $extension['equipmentA'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getAlias();
  250.                             $extension['interfaceA'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  251.                             if (!in_array($portID,$portsAIDS)){
  252.                                 $extension['portA'] .= $port->getAlias() ? $port->getAlias().'/' $port->getOrderNo().'/';
  253.                             }
  254.                             $portsAIDS[] = $portID;
  255.                         }
  256.                         $extension['portA'] = substr($extension['portA'], 0, -1);
  257.                         foreach ($portsB as $portID){
  258.                             $port $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($portID);
  259.                             $extension['siteB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  260.                             if ($port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias()){
  261.                                 $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias();
  262.                             } else {
  263.                                 $extension['roomB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  264.                             }
  265.                             $extension['rackB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  266.                             $extension['equipmentB'] = $port->getInterfaceSpecific()->getEquipmentSpecific()->getAlias();
  267.                             $extension['interfaceB'] = $port->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  268.                             if (!in_array($portID,$portsBIDS)){
  269.                                 $extension['portB'] .= $port->getAlias() ? $port->getAlias().'/' $port->getOrderNo().'/';
  270.                             }
  271.                             $portsBIDS[] = $portID;
  272.                         }
  273.                         $extension['portB'] = substr($extension['portB'], 0, -1);
  274.                     // } else {
  275.                     //
  276.                     //     $extension['siteA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  277.                     //
  278.                     //     if ($ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias()){
  279.                     //         $extension['roomA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias();
  280.                     //     } else {
  281.                     //         $extension['roomA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  282.                     //     }
  283.                     //
  284.                     //     $extension['rackA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  285.                     //     $extension['equipmentA'] = $ext->getPortA()->getInterfaceSpecific()->getEquipmentSpecific()->getAlias();
  286.                     //     $extension['interfaceA'] = $ext->getPortA()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  287.                     //     $extension['portA'] = $ext->getPortA()->getOrderNo();
  288.                     //
  289.                     //     $extension['siteB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getSite()->getTitle();
  290.                     //     if ($ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias()){
  291.                     //         $extension['roomB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getAlias();
  292.                     //     } else {
  293.                     //         $extension['roomB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getRoom()->getTitle();
  294.                     //     }
  295.                     //     $extension['rackB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getRack()->getTitle();
  296.                     //     $extension['equipmentB'] = $ext->getPortB()->getInterfaceSpecific()->getEquipmentSpecific()->getAlias();
  297.                     //     $extension['interfaceB'] = $ext->getPortB()->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber();
  298.                     //     $extension['portB'] = $ext->getPortA()->getOrderNo();
  299.                     //
  300.                     // }
  301.                     if (!in_array($linkExtensionSequenceNo,$sequence) && is_null($linkExtensionTrunk)){
  302.                         $extensions[] = [
  303.                             'line1' => $extension['id'],
  304.                             'line2' => $extension['siteA'].'_'.$extension['roomA'].'_B'$extension['rackA'],
  305.                             'line3' => $extension['equipmentA'].'_S'.$extension['interfaceA'].'_P'.$extension['portA'],
  306.                             'line4' => '-------------------',
  307.                             'line5' => $extension['siteB'].'_'.$extension['roomB'].'_B'$extension['rackB'],
  308.                             'line6' => $extension['equipmentB'].'_S'.$extension['interfaceB'].'_P'.$extension['portB']
  309.                         ];
  310.                     }
  311.                     $sequence[] = $linkExtensionSequenceNo;
  312.                 }
  313.                 $list[] = $extensions;
  314.             }
  315.         }
  316.         return $this->render('label/link_labels.html.twig', [
  317.             'page_title' => $translator->trans('Link Labels'),
  318.             'list' => $list,
  319.         ]);
  320.     }
  321. }