<?php
namespace App\Controller;
use App\Entity\LinkExtension;
use App\Entity\LinkValidation;
use App\Entity\Trunk;
use App\Entity\TrunkCableFiber;
use App\Entity\TrunkExtension;
use App\Entity\Port;
use App\Entity\ExtensionOrder;
use App\Entity\EquipmentSpecific;
use App\Entity\InterfaceSpecific;
use App\EventListener\LinkTrunkEventListener;
use Symfony\Component\Routing\Annotation\Route;
use Symfony\Bundle\FrameworkBundle\Controller\AbstractController;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Security;
use Pagerfanta\Adapter\ArrayAdapter;
use Pagerfanta\Pagerfanta;
use Symfony\Component\Cache\Adapter\FilesystemAdapter;
// use Pagerfanta\Adapter\DoctrineORMAdapter;
use Psr\Log\LoggerInterface;
use Symfony\Contracts\Translation\TranslatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
class TrunkController extends AbstractController
{
/**
* @Route("/trunk/create/step1", name="trunk_create_form_step1")
*/
public function createAction(Request $request, TranslatorInterface $translator)
{
//get the cable type
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
//get a new trunk id
$trunkID = $this->getDoctrine()->getRepository('App\Entity\Trunk')->getNewId();
//send everything needed to create a form to create a trunk
return $this->render('trunk/create_step1.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Create Trunk - Step 1'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'typeCable' => $typeCable,
'trunkID' => $trunkID
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/create/step2", name="trunk_create_process_step1")
* Process trunk creation form
*/
public function processTrunkAction(Request $request, TranslatorInterface $translator)
{
//get the user
$user = $this->get('security.token_storage')->getToken()->getUser();
//get the entity manager
$em = $this->getDoctrine()->getManager();
// create a new trunk by processing the data from the form
$trunk = new Trunk();
$trunk->setTrunkID($request->request->get('trunkID'));
$trunk->setOperatorID($request->request->get('operatorID'));
$trunk->setTypeCable($this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable')));
$trunk->setCapacity($request->request->get('capacity'));
$trunk->setTypeCreation($request->request->get('typeCreation'));
$trunk->setCreatedBy($user);
$trunk->setUpdatedBy($user);
//store the trunk to the database
$em->persist($trunk);
$em->flush();
//check if the trunk already exists or to be reserved
if ($request->request->get('action') == 'reserve'){
//redirect to trunk list page
return $this->redirectToRoute('trunk_list');
}
//get all the sites, generic equipments, racks and rack faces
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$trunkCapacity = $trunk->getCapacity();
$typeCreation = $trunk->getTypeCreation();
switch ($typeCreation){ // $typeCreation = 1=>equipment to equipment, 2=>interface to interface or 3=>port to port
case 1:
//send everything needed to create a form to add more data to trunk
return $this->render('trunk/create_step2_equipment.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Create Trunk - Step 2'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'trunk' => $trunk,
'sites' => $sites,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
case 2:
//send everything needed to create a form to add more data to trunk
return $this->render('trunk/create_step2_interface.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Create Trunk - Step 2'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'trunk' => $trunk,
'sites' => $sites,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
case 3:
//send everything needed to create a form to add more data to trunk
return $this->render('trunk/create_step2_port.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Create Trunk - Step 2'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'trunk' => $trunk,
'sites' => $sites,
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
}
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/create/process/fibers", name="trunk_create_process_step2")
* Process trunk creation form step 2 (add/update data to the trunk)
*/
public function processFibersAction(Request $request, LoggerInterface $logger, TranslatorInterface $translator)
{
$logger = $logger;
//get the user
$user = $this->get('security.token_storage')->getToken()->getUser();
//get the entity manager
$em = $this->getDoctrine()->getManager();
//get the trunk by id
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
//get the trunk capacity : it may be modified
$trunkCapacity = $request->request->get('capacity');
//store the trunk to the database
$trunk->setCapacity($trunkCapacity);
$trunk->setUpdatedBy($user);
$em->persist($trunk);
$em->flush();
//get the cables and update the trunk capacity
$trunkCableFiber = $trunk->getCableFiber();
foreach ($trunkCableFiber as $item) {
$trunkCapacity -= 1;
}
$typeCreation = $request->request->get('type_creation');
// PORT TO PORT
if ($typeCreation == 3){
$intA = array();
$intB = array();
for ($i = 1; $i <= $trunkCapacity; $i++){
if ($_POST['pointA_'.$i] != 0 && $_POST['pointB_'.$i] != 0){
//MODIFIED
$portA = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointA_'.$i]);
$portB = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$i]);
$intA[] = $portA->getInterfaceSpecific()->getId();
$intB[] = $portB->getInterfaceSpecific()->getId();
}
}
$intA = array_unique($intA);
$intB = array_unique($intB);
$tempArray = array_intersect($intA, $intB);
if (count($tempArray) > 0) {
$this->addFlash(
'error',
'Opération échouée : Trunk en boucle (interface A == interface B)'
);
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
// store port points
//create the cables and store them to the database
for ($i = 1; $i <= $trunkCapacity; $i++){
// $tcf = new TrunkCableFiber();
//
// $tcf->setTrunk($trunk);
// //check if point A and B are selected
if ($_POST['pointA_'.$i] != 0 && $_POST['pointB_'.$i] != 0){
//MODIFIED
$portA = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointA_'.$i]);
$portB = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$i]);
$typeLnk = null;
if ($portA->getPortExterne()) {
$typeLnk = $portA->getPortExterne()->getTypeLink()->getTitle();
}
else {
$typeLnk = $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
}
if ($typeLnk == "Duplex") {
for ($j=0; $j < 2; $j++) {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($portA);
$tcf->setPortB($portB);
$em->persist($tcf);
$em->flush();
}
}
else {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($portA);
$tcf->setPortB($portB);
$em->persist($tcf);
$em->flush();
}
}
}
// I-I || E-E
} else if ($typeCreation == 2 || $typeCreation == 1) {
$eqA = null;
$eqB = null;
// get the type of equipment A : 1 => generic or 2 => specific
$equipmentTypeA = $request->request->get('equipmentTypeA');
//if generic, process the form to create a new sepcific equipment
if ($equipmentTypeA == 1){
$eqA = new EquipmentSpecific();
//get the generic parent equipment
$equipmentGenericA = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointA'));
$eqA->setEquipmentGeneric($equipmentGenericA);
$eqA->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointA')));
$eqA->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointA')));
$eqA->setPositionRack($request->request->get('positionRackPointA'));
$eqA->setEquipmentSpecificName($request->request->get('equipmentSpecificNameA'));
$eqA->setAlias($request->request->get('aliasA'));
$eqA->setOwner($request->request->get('ownerA'));
$em->persist($eqA);
$em->flush();
// create specific interfaces
$totalPortsA = 0;
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericA);
foreach ($interfacesGeneric as $interfaceGeneric) {
if ($interfaceGeneric->getTypeLink() && $interfaceGeneric->getTypeLink()->getTitle() == "Port Externe") {
$this->addFlash(
'error',
'Impossible de créer trunk: équipement générique a des interfaces PORT EXTERNE'
);
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eqA);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$alias = json_decode($interfaceGeneric->getAlias(), true);
$em->persist($interfaceSpecific);
$em->flush();
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
if ($typeLinkTitle == "Duplex") {
$numberOfPorts = 2*$numberOfPorts;
}
$totalPortsA += $numberOfPorts;
for ($i = 1; $i <= $numberOfPorts; $i++) {
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias) {
$port->setAlias($alias[$i]);
}
$em->persist($port);
$em->flush();
}
}
//if specific equipment
} else {
// get the equipment
$eqA = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointA'));
}
// equipment B
// get the type of equipment B : 1 => generic or 2 => specific
$equipmentTypeB = $request->request->get('equipmentTypeB');
//if generic, process the form to create a new sepcific equipment
if ($equipmentTypeB == 1) {
$eqB = new EquipmentSpecific();
$equipmentGenericB = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointB'));
$eqB->setEquipmentGeneric($equipmentGenericB);
$eqB->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointB')));
$eqB->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointB')));
$eqB->setPositionRack($request->request->get('positionRackPointB'));
$eqB->setEquipmentSpecificName($request->request->get('equipmentSpecificNameB'));
$eqB->setAlias($request->request->get('aliasB'));
$eqB->setOwner($request->request->get('ownerB'));
$em->persist($eqB);
$em->flush();
// create specific interfaces
$totalPortsB = 0;
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericB);
foreach ($interfacesGeneric as $interfaceGeneric) {
if ($interfaceGeneric->getTypeLink() && $interfaceGeneric->getTypeLink()->getTitle() == "Port Externe") {
$this->addFlash(
'error',
'Impossible de créer trunk: équipement générique a des interfaces PORT EXTERNE'
);
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eqB);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$alias = json_decode($interfaceGeneric->getAlias(), true);
$em->persist($interfaceSpecific);
$em->flush();
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
if ($typeLinkTitle == "Duplex") {
$numberOfPorts = 2*$numberOfPorts;
}
$totalPortsB += $numberOfPorts;
for ($i = 1; $i <= $numberOfPorts; $i++) {
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias) {
$port->setAlias($alias[$i]);
}
$em->persist($port);
$em->flush();
}
}
//if specific equipment
} else {
//get the equipment
$eqB = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointB'));
}
// INTERFACE TO INTERFACE
if ($typeCreation == 2) {
// FIBERS A
//MODIFIED on 07 fevrier 2019
$countTcfA = 0;
$countTcfB = 0;
$interfacesA = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqA);
foreach ($interfacesA as $interface) {
//ADDED by Soupra
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
if ($equipmentTypeA == 1) {
$interface_id = $interface->getInterfaceGeneric()->getId(); // get generic interfaces
} else {
$interface_id = $interface->getId(); // get specific interfaces
}
//check if interface is selected
if (isset($_POST['interfaceA_' . $interface_id])) {
if ($typeLinkTitle == "Port Externe") {
$this->addFlash(
'error',
'Impossible de créer trunk: équipement générique a des interfaces PORT EXTERNE'
);
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
$logger->info(count($ports));
foreach ($ports as $port) {
//ADDED by Soupra
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$logger->info(count($usedA));
if($usedA == null){
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($port);
$em->persist($tcf);
$em->flush();
$countTcfA++;
}
}
else {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($port);
$em->persist($tcf);
$em->flush();
$countTcfA++;
}
}
if($trunkCapacity <= $countTcfA){
break;
}
}
}
if($trunkCapacity <= $countTcfA){
break;
}
}
// FIBERS B
$interfacesB = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
foreach ($interfacesB as $interface) {
//ADDED by Soupra
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
if ($equipmentTypeB == 1) {
$interface_id = $interface->getInterfaceGeneric()->getId(); // get generic interfaces
} else {
$interface_id = $interface->getId(); // get specific interfaces
}
//check if interface is selected
if (isset($_POST['interfaceB_' . $interface_id])) {
if ($typeLinkTitle == "Port Externe") {
$this->addFlash(
'error',
'Impossible de créer trunk: équipement générique a des interfaces PORT EXTERNE'
);
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
//get the cable which corresponds to the portA
//ADDED by Soupra
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
$logger->info(count($usedA));
if($usedB == null){
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
if ($tcf instanceof TrunkCableFiber) {
$tcf->setPortB($port);
$em->persist($tcf);
$em->flush();
$countTcfB++;
}
}
}
else {
$tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
if ($tcf instanceof TrunkCableFiber) {
$tcf->setPortB($port);
$em->persist($tcf);
$em->flush();
$countTcfB++;
}
}
}
if($trunkCapacity <= $countTcfB){
break;
}
}
}
if($trunkCapacity <= $countTcfB){
break;
}
}
}
// EQUIPMENT TO EQUIPMENT
else {
// max number of connections to make
$cf_max_number = min($totalPortsA, $totalPortsB, $trunkCapacity);
// FIBERS A
$counter = 1;
$interfacesA = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqA);
foreach ($interfacesA as $interface) {
//ADDED by Soupra begin
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();//end
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
if ($counter <= $cf_max_number) {
//ADDED by Soupra begin
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($port);
$em->persist($tcf);
$em->flush();
$counter++;
}
}
else {
$tcf = new TrunkCableFiber();
$tcf->setTrunk($trunk);
$tcf->setPortA($port);
$em->persist($tcf);
$em->flush();
$counter++;
} //end
// $tcf = new TrunkCableFiber();
// $tcf->setTrunk($trunk);
// $tcf->setPortA($port);
//
// $em->persist($tcf);
// $em->flush();
//
// $counter++;
}
}
}
// FIBERS B
$counter = 1;
$interfacesB = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
foreach ($interfacesB as $interface) {
//ADDED by Soupra
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
if ($counter <= $cf_max_number) {
//ADDED by Soupra begin
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
if ($tcf instanceof TrunkCableFiber) {
$tcf->setPortB($port);
$em->persist($tcf);
$em->flush();
$counter ++;
}
}
}
else {
$tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
if ($tcf instanceof TrunkCableFiber) {
$tcf->setPortB($port);
$em->persist($tcf);
$em->flush();
$counter ++;
}
} //end
// $tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->getFirstEmpty($trunk);
// $tcf->setPortB($port);
//
// $em->persist($tcf);
// $em->flush();
//
// $counter ++;
}
}
}
}
}
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
// AFTER ACTION - REDIRECT
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/edit/fiber/{id}", name="trunk_edit_fiber")
*
*/
public function editFiberAction($id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunkCableFiber = $em->getRepository(TrunkCableFiber::class)->find($id);
$trunk = $trunkCableFiber->getTrunk();
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
return $this->render('trunk/edit_fiber.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Edit Cable / Fiber'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'tcf' => $trunkCableFiber,
'sites' => $sites,
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'trunk' => $trunk
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/edit/process/fiber", name="trunk_edit_process_fiber")
*/
public function editProcessFiberAction(Request $request, TranslatorInterface $translator)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$trunkCableFiber = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneById($request->request->get('fiber_id'));
$trunk = $trunkCableFiber->getTrunk();
//get the affected ports and store them in a array
// $portsAffected = [];
//MODIFIED BY Soupra;
// $portsAffected[] = $trunkCableFiber->getPortB()
// $portsAffected[] = $trunkCableFiber->getPortA();
// $portsAffected[] = $trunkCableFiber->getPortB();
//get new ports and store them in the database
$portA = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointA_1'));
$portB = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($request->request->get('pointB_1'));
//check for loop
if ($portA->getInterfaceSpecific()->getId() == $portB->getInterfaceSpecific()->getId()) {
$this->addFlash(
'error',
'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
);
return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
}
$tempInts = array();
foreach ($trunkCableFiber->getExtensions() as $value) {
$tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
}
if (in_array($portA->getInterfaceSpecific()->getId(), $tempInts) || in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
$this->addFlash(
'error',
'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
);
return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
}
$matchedPortB = $trunkCableFiber->getPortB();
$matchedPortA = $trunkCableFiber->getPortA();
$trunkCableFiber->setPortA($portA);
$trunkCableFiber->setPortB($portB);
//get the link extension if any matches
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPortB);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPortB->getLinkExtension();
if ($extMatch) {
// $orderNoExt = $matchedPortB->getOrderNoExtension();
$matchedPortB->setLink(null);
$matchedPortB->setLinkExtension(null);
// $matchedPortB->setOrderNoExtension(1);
$em->persist($matchedPortB);
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPortB->getId(), $tempIds)) {
// if (count($matchedPortB->getExtensionOrder()) <= 1) {
// $matchedPortB->setLink(null);
// }
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortB, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityB);
$portB->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->removePort($matchedPortB);
// $extrmityB->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityB);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $portB->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $portB);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPortB->getId(), $tempIds)) {
// if (count($matchedPortB->getExtensionOrder()) <= 1) {
// $matchedPortB->setLink(null);
// }
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortB, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityA);
$portB->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPortB);
// $extrmityA->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityA);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
//
// $lastExtB = $lastExtension->getExtremityB();
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $portB->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $portB);
}
}
}
//Port A
//get the link extension if any matches
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPortA);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPortA->getLinkExtension();
if ($extMatch) {
// $orderNoExt = $matchedPortA->getOrderNoExtension();
$matchedPortA->setLink(null);
$matchedPortA->setLinkExtension(null);
// $matchedPortA->setOrderNoExtension(1);
$em->persist($matchedPortA);
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPortA->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortA, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portA);
$extensinOrder->setExtremity($extrmityB);
$portA->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->removePort($matchedPortA);
// $extrmityB->addPort($portA);
// $portA->setOrderNoExtension($orderNoExt);
// $portA->addExtremity($extrmityB);
$portA->setLink($linkMatch);
$portA->setLinkExtension($extMatch);
$em->persist($portA);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portA->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $portA->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $portA);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPortA->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPortA, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portA);
$extensinOrder->setExtremity($extrmityA);
$portA->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPortA);
// $extrmityA->addPort($portA);
// $portA->setOrderNoExtension($orderNoExt);
// $portA->addExtremity($extrmityA);
$portA->setLink($linkMatch);
$portA->setLinkExtension($extMatch);
$em->persist($portA);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
//
// $lastExtB = $lastExtension->getExtremityB();
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portA->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $portA->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $portA);
}
}
}
$em->persist($trunkCableFiber);
$em->flush();
$trunk->setUpdatedBy($user);
$em->persist($trunk);
$em->flush();
// check links for validation
// foreach($portsAffected as $port){
// $linkExtsB = null;
// $extremities = array();
// foreach ($port->getExtensionOrder() as $value) {
// $extremities[] = $value->getExtremity();
// }
// $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
// if (count($extremities) > 1) {
// $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
// }
// // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $port]);
// // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $port]);
//
// if ($linkExtsA){
//
// foreach ($linkExtsA as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// if ($linkExtsB){
//
// foreach ($linkExtsB as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// }
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/edit/{id}/{typeCreation}", name="trunk_edit")
* trunk creation step 2 page
*/
public function editTrunkAction($id, $typeCreation, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $em->getRepository(Trunk::class)->find($id);
$trunkCapacity = $trunk->getCapacity();
$trunkCableFiber = $trunk->getCableFiber();
foreach ($trunkCableFiber as $item) {
$trunkCapacity -= 1;
}
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
switch ($typeCreation){
case 1:
return $this->render('trunk/create_step2_equipment.html.twig', [
'action' => 'edit',
'page_title' => $translator->trans('Edit Trunk'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'trunk' => $trunk,
'sites' => $sites,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
case 2:
return $this->render('trunk/create_step2_interface.html.twig', [
'action' => 'edit',
'page_title' => $translator->trans('Edit Trunk'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'trunk' => $trunk,
'sites' => $sites,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
case 3:
return $this->render('trunk/create_step2_port.html.twig', [
'action' => 'edit',
'page_title' => $translator->trans('Edit Trunk'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'trunk' => $trunk,
'sites' => $sites,
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'trunkCapacity' => $trunkCapacity
]);
break;
}
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/delete/fibers", name="trunk_delete_fibers")
* process the delete action of a trunk
*/
public function deleteFibersAction(Request $request, TranslatorInterface $translator)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
$trunkCableFiber = $trunk->getCableFiber();
$portsAffected = [];
$portsAllTemp = $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
$portsAll = array();
foreach ($portsAllTemp as $tempArray) {
foreach ($tempArray as $key => $value) {
$portsAll[] = $value;
}
}
$error = [];
foreach ($trunkCableFiber as $item){
$id = $item->getId();
if (isset($_POST['tcf_'.$id])){
$portsAffected[] = $item->getPortA();
$portsAffected[] = $item->getPortB();
if (in_array($item->getPortA()->getId(), $portsAll) || in_array($item->getPortB()->getId(), $portsAll)) {
$error = array('error' => 'usage');
}
else {
$error = array('error' => null);
$em->remove($item);
$em->flush();
}
}
}
if ($error['error']) {
$this->addFlash(
'error',
'usage'
);
}
$trunk->setUpdatedBy($user);
$em->persist($trunk);
$em->flush();
// check links for validation
// foreach($portsAffected as $port){
// $linkExtsB = null;
// $extremities = array();
// foreach ($port->getExtensionOrder() as $value) {
// $extremities[] = $value->getExtremity();
// }
// $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
// if (count($extremities) > 1) {
// $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
// }
// // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $port]);
// // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $port]);
//
// if ($linkExtsA){
//
// foreach ($linkExtsA as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// if ($linkExtsB){
//
// foreach ($linkExtsB as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// }
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extend/fibers", name="trunk_extend_fibers")
* creates a page which gives an user a function to extend the selected cables of a trunk
*/
public function extendFibersAction(Request $request, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
$trunkCableFiber = $trunk->getCableFiber();
$tcfs = [];
foreach ($trunkCableFiber as $item){
$id = $item->getId();
//check if the cable is selected
if (isset($_POST['tcf_'.$id])){
$tcfs[] = $item;
}
}
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
return $this->render('trunk/extend_fibers.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Extend Cable / Fiber'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Extend Cable / Fiber'),
'sites' => $sites,
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'typeCable' => $typeCable,
'trunk' => $trunk,
'tcfs' => $tcfs
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/fibers/orerator", name="trunk_add_fibers_operator")
* Add operator ID to fibers
*/
public function addFibersOperator(Request $request, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
$operatorID = $request->request->get('operator_id_to_add');
$trunkCableFiber = $trunk->getCableFiber();
foreach ($trunkCableFiber as $item){
$id = $item->getId();
//check if the cable is selected
if (isset($_POST['tcf_'.$id])){
$item->setOperatorID($operatorID);
$em->persist($item);
$em->flush();
}
foreach ($item->getExtensions() as $ext) {
$extId = $ext->getId();
//check if the cable is selected
if (isset($_POST['extension_'.$extId])){
$ext->setOperatorID($operatorID);
$em->persist($ext);
$em->flush();
}
}
}
return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extend/interfaces/{id}", name="trunk_extend_interfaces")
* creates a page which gives an user a function to extend the interfaces of a trunk
*/
public function extendInterfacesAction(Request $request, $id, TranslatorInterface $translator)
{
//get the user
$user = $this->get('security.token_storage')->getToken()->getUser();
//get the entity manager
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->find($id);
//get all the sites, generic equipments, racks and rack faces
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
$portBArray = [];
//get all the interfaces associated with the trunk
$tcfs = $trunk->getCableFiber();
$interfaces = array();
$interfacesTemp = array();
$portB = null;
foreach ($tcfs as $tcf) {
$lenTemp = count($tcf->getExtensions());
if ($lenTemp > 0) {
$trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$lenTemp]);
$portB = $trunkExtTemp->getPortB();
$portBArray[] = $portB->getId();
}
else {
$portB = $tcf->getPortB();
$portBArray[] = $portB->getId();
}
$interfacesTemp[] = $portB->getInterfaceSpecific()->getId();
}
$interfacesTemp = array_unique($interfacesTemp);
foreach ($interfacesTemp as $interface) {
$temp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interface);
$ports = $temp->getPort();
$nbPortsFree = 0;
foreach ($ports as $port){
if (in_array($port->getId(), $portBArray)){
$nbPortsFree++;
// $used = 1;
}
}
$temp->nbPorts = $temp->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex" ? $nbPortsFree*2 : $nbPortsFree;
$eqName = null;
if ($temp->getEquipmentSpecific()->getParent()) {
$eqName = $temp->getEquipmentSpecific()->getParent()->getEquipmentSpecificName() . " â•‘ " . $temp->getEquipmentSpecific()->getEquipmentSpecificName();
}
else {
$eqName = $temp->getEquipmentSpecific()->getEquipmentSpecificName();
}
if (isset($interfaces[$eqName])) {
$interfaces[$eqName][] = $temp;
}
else {
$interfaces[$eqName] = array();
$interfaces[$eqName][] = $temp;
}
}
return $this->render('trunk/extend_interfaces.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Etendre Interfaces'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Etendre Interfaces'),
'trunk' => $trunk,
'sites' => $sites,
'rackFaces' => $rackFaces,
'interfaces'=>$interfaces,
'typeCable' => $typeCable
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extension/edit/{id}", name="trunk_edit_extension")
* page to edit the selected trunk extension
*/
public function editExtensionAction($id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunkExtension = $em->getRepository(TrunkExtension::class)->find($id);
$trunkCableFiber = $trunkExtension->getTrunkCableFiber();
$trunk = $trunkCableFiber->getTrunk();
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy([], ['title' => 'ASC']);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findBy([], ['title' => 'ASC']);
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
return $this->render('trunk/edit_extension.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Edit Extension'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'tcf' => $trunkCableFiber,
'extension' => $trunkExtension,
'sites' => $sites,
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'trunk' => $trunk
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extension/process", name="trunk_edit_process_extension")
* process the trunk extexsion edition form
*/
public function editExtensionProcess(Request $request, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$extension_id = $request->request->get('extension_id');
$trunkExtension = $em->getRepository(TrunkExtension::class)->find($extension_id);
$tcf = $trunkExtension->getTrunkCableFiber();
$trunk = $tcf->getTrunk();
$portBext = $trunkExtension->getPortB();
$currentOperatorID = $trunkExtension->getOperatorID();
$trunkExtension->setOperatorID($request->request->get('operatorID'));
$portB = $em->getRepository(Port::class)->find($request->request->get('pointB'));
//check for loop
$tempInts = array();
$tempInts[] = $tcf->getPortA()->getInterfaceSpecific()->getId();
$tempInts[] = $tcf->getPortB()->getInterfaceSpecific()->getId();
foreach ($tcf->getExtensions() as $value) {
if ($value->getId() != $trunkExtension->getId()) {
$tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
}
}
if (in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
$this->addFlash(
'error',
'Trunk en boucle : Veuillez vérifier le port choisis, SVP'
);
return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
}
$matchedPort = $trunkExtension->getPortB();
$trunkExtension->setPortB($portB);
//get the link extension if any matches
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
// var_dump($extId);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityB->removePort($matchedPort);
// $extrmityB->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityB);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityB);
$portB->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $portB->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $portB);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityA);
$portB->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityA);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
//
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $portB->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $portB);
}
}
}
$em->persist($trunkExtension);
$em->flush();
// set operator id for all in sequence
// MODIFIED on 13 mars 2019 begin
// $trunkExtensionsInSequence = $em->getRepository(TrunkExtension::class)->findBy(['operatorID' => $currentOperatorID]);
// foreach ($trunkExtensionsInSequence as $item){
// $item->setOperatorID($request->request->get('operatorID'));
// $em->persist($item);
// $em->flush();
// }
// MODIFIED on 13 mars 2019 end
// check links for validation
// $trunk = $trunkExtension->getTrunkCableFiber()->getTrunk();
//
// $linkExtsB = null;
// $extremities = array();
//
// foreach ($portBext->getExtensionOrder() as $value) {
// $extremities[] = $value->getExtremity();
// }
// $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
// if (count($extremities) > 1) {
// $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
// }
// // $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portA' => $portBext]);
// // $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'portB' => $portBext]);
// if ($linkExtsA){
//
// foreach ($linkExtsA as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $portB]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($portB);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// if ($linkExtsB){
//
// foreach ($linkExtsB as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $portB]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($portB);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extend", name="trunk_create_process_extend")
* process the trunk extension form
*/
public function processExtensionsAction(Request $request, TranslatorInterface $translator)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
// from form
$noFibers = $request->request->get('noFibers');
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
$operatorId = $request->request->get('operatorID');
$tcfs = [];
// $portsAffected = [];
foreach ($_POST['tcf'] as $tcf_id){
$tcf = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneById($tcf_id);
// $portsAffected[] = $tcf->getPortA();
// $portsAffected[] = $tcf->getPortB();
$tcfs[] = $tcf;
}
$redirect = false;
$counter = 0;
$duplexPort = false;
for ($i=0; $i<$noFibers; $i++){
$j = $i+1;
$tcf = $tcfs[$i];
$sequence_no = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
$portB = $this->getDoctrine()->getRepository('App\Entity\Port')->findOneById($_POST['pointB_'.$j]);
//check for the loop
$tempInts = array();
$tempInts[] = $tcf->getPortA()->getInterfaceSpecific()->getId();
$tempInts[] = $tcf->getPortB()->getInterfaceSpecific()->getId();
foreach ($tcf->getExtensions() as $value) {
$tempInts[] = $value->getPortB()->getInterfaceSpecific()->getId();
}
if (in_array($portB->getInterfaceSpecific()->getId(), $tempInts)) {
$redirect = true;
}
if ($redirect) {
break;
}
else {
// $portsAffected[] = $portB;
$typeCable = $tcf->getTrunk()->getTypeCable();
$ext = new TrunkExtension();
$ext->setTrunkCableFiber($tcf);
$ext->setTypeCable($typeCable);
$ext->setOperatorID($operatorId);
$ext->setPortB($portB);
$ext->setSequenceNo($sequence_no);
$em->persist($ext);
$em->flush();
//get the link extension if any matches
$extMatch = null;
$matchedPort = null;
// var_dump($sequence_no);
if ($sequence_no == 1) {
$matchedPort = $tcf->getPortB();
}
else {
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$sequence_no-1]);
$matchedPort = $lastTrunkExt->getPortB();
}
// var_dump($matchedPort);
if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
$duplexPort = true;
$counter++;
}
else {
$duplexPort = false;
$counter = 2;
}
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// var_dump($extId);
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// var_dump($extMatch->getId());
// $orderNoExt = $matchedPort->getOrderNoExtension();
if ($counter == 2) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
// $counter = 0;
}
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
// var_dump($tempIds);
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
// var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityB);
$portB->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityB);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
// var_dump('hi');
// var_dump($extMatch->getSequenceNo());
// var_dump(count($linkMatch->getLinkExtension()));
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
// $errMsg = $nextExtension->getError();
// $errMsg = str_replace("EquipmentA", "", $errMsg);
// $nextExtension->setError($errMsg);
// if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
// $nextExtension->setIsValid(false);
// }
// else {
// $nextExtension->setIsValid(true);
// }
//
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $portB->getId()) {
// $nextExtension->setIsValid(false);
// if ($nextExtension->getError()) {
// $nextExtension->setError($nextExtension->getError() . "," . "PortA");
// }
// else {
// $nextExtension->setError("PortA");
// }
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $errMsg = str_replace("PortA", "", $errMsg);
// $nextExtension->setError($errMsg);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $portB);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
// var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityA);
$portB->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityA);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $errMsg = $lastExtension->getError();
// $errMsg = str_replace("EquipmentB", "", $errMsg);
// $lastExtension->setError($errMsg);
// if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
// $lastExtension->setIsValid(false);
// }
// else {
// $lastExtension->setIsValid(true);
// $lastExtension->setError(null);
// }
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $portB->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $portB);
}
}
}
}
}
if ($redirect) {
$this->addFlash(
'error',
'Trunk en boucle : Veuillez vérifier les ports choisis, SVP'
);
return $this->redirectToRoute('trunk_view', array("id"=>$trunk->getId()));
}
else {
$trunk->setUpdatedBy($user);
$em->persist($trunk);
$em->flush();
}
//
// check links for validation
// foreach($portsAffected as $port){
// $linkExtsB = null;
// $extremities = array();
// foreach ($port->getExtensionOrder() as $value) {
// $extremities[] = $value->getExtremity();
// }
// $linkExtsA = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityA' => $extremities[0]]);
// if (count($extremities) > 1) {
// $linkExtsB = $em->getRepository(LinkExtension::class)->findBy(['trunk' => $trunk, 'extremityB' => $extremities[1]]);
// }
//
//
// if ($linkExtsA){
//
// foreach ($linkExtsA as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// if ($linkExtsB){
//
// foreach ($linkExtsB as $linkExt){
//
// $link = $linkExt->getLink();
// $linkValidation = $em->getRepository(LinkValidation::class)->findBy(['link' => $link, 'trunk' => $trunk, 'port' => $port]);
//
// if (!$linkValidation){
//
// $linkValidation = new LinkValidation();
// $linkValidation->setLink($link);
// $linkValidation->setTrunk($trunk);
// $linkValidation->setPort($port);
//
// $em->persist($linkValidation);
// $em->flush();
//
// }
// }
// }
//
// }
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/extend/interfaces", name="trunk_extend_interface_process")
* process the trunk extension interface form
*/
public function processExtensionsInterfaceAction(Request $request, LoggerInterface $logger)
{
// $logger = $this->get('logger');
//get the user
$user = $this->get('security.token_storage')->getToken()->getUser();
//get the entity manager
$em = $this->getDoctrine()->getManager();
//get the trunk by id
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable'));
$operatorId = $request->request->get('operatorID');
//get all the interfaces associated with the trunk
$tcfs = $trunk->getCableFiber();
$interfaces = array();
$interfacesTemp = array();
$portB = null;
foreach ($tcfs as $tcf) {
$lenTemp = count($tcf->getExtensions());
if ($lenTemp > 0) {
$trunkExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$lenTemp]);
$portB = $trunkExtTemp->getPortB();
}
else {
$portB = $tcf->getPortB();
}
$interfacesTemp[] = $portB->getInterfaceSpecific()->getId();
}
$interfacesTemp = array_unique($interfacesTemp);
foreach ($interfacesTemp as $interface) {
$interfaces[] = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interface);
}
$typeCreation = $request->request->get('type_creation');
if ($typeCreation == 2) {
$eqB = null;
// equipment B
// get the type of equipment B : 1 => generic or 2 => specific
$equipmentTypeB = $request->request->get('equipmentTypeB');
//if generic, process the form to create a new sepcific equipment
if ($equipmentTypeB == 1) {
$eqB = new EquipmentSpecific();
$equipmentGenericB = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentPointB'));
$eqB->setEquipmentGeneric($equipmentGenericB);
$eqB->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rackPointB')));
$eqB->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFacePointB')));
$eqB->setPositionRack($request->request->get('positionRackPointB'));
$eqB->setEquipmentSpecificName($request->request->get('equipmentSpecificNameB'));
$eqB->setAlias($request->request->get('aliasB'));
$eqB->setOwner($request->request->get('ownerB'));
$em->persist($eqB);
$em->flush();
// create specific interfaces
$totalPortsB = 0;
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGenericB);
foreach ($interfacesGeneric as $interfaceGeneric) {
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eqB);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$alias = json_decode($interfaceGeneric->getAlias(), true);
$em->persist($interfaceSpecific);
$em->flush();
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$typeLinkTitle = ($interfaceGeneric->getTypeLink()) ? $interfaceGeneric->getTypeLink()->getTitle() : "";
if ($typeLinkTitle == "Duplex") {
$numberOfPorts = 2*$numberOfPorts;
}
$totalPortsB += $numberOfPorts;
for ($i = 1; $i <= $numberOfPorts; $i++) {
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias) {
$port->setAlias($alias[$i]);
}
$em->persist($port);
$em->flush();
}
}
//if specific equipment
} else {
//get the equipment
$eqB = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('equipmentPointB'));
}
// INTERFACE TO INTERFACE
if ($typeCreation == 2) {
// FIBERS A
$tcfFound = [];
//get all the interfaces associated with the trunk
$tcfs = $trunk->getCableFiber();
foreach ($interfaces as $interface) {
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
$logger->info($typeLinkTitle);
$interface_id = $interface->getId(); // get specific interfaces
//check if interface is selected
if (isset($_POST['interfaceA_' . $interface_id])) {
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
$tExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findByPortB($port);
if (count($tExt) > 0) {
foreach ($tExt as $value) {
$tcfFound[] = $value->getTrunkCableFiber();
}
}
else {
$k = 0;
foreach ($tcfs as $tcf) {
if ($tcf->getPortB() == $port) {
$logger->info($tcf->getId());
$tcfFound[] = $tcf;
$k++;
}
if ($typeLinkTitle == "Duplex" && $k == 2) {
$k = 0;
break;
}
elseif ($typeLinkTitle == "Simplex" && $k == 1) {
$k = 0;
break;
}
}
}
}
}
}
// FIBERS B
$countTcf = 0;
if ($eqB->isModulaire()) {
$modules = $eqB->getModules();
$chassisModule = $eqB->getChassisModule();
if ($chassisModule) {
$modules->add($chassisModule);
}
foreach ($modules as $module) {
$interfacesB = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($module);
foreach ($interfacesB as $interface) {
//ADDED by Soupra
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
if ($equipmentTypeB == 1) {
$interface_id = $interface->getInterfaceGeneric()->getId(); // get generic interfaces
} else {
$interface_id = $interface->getId(); // get specific interfaces
}
//check if interface is selected
if (isset($_POST['interfaceB_' . $interface_id])) {
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
//get the cable which corresponds to the portA
//ADDED by Soupra
$usedTmpA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$usedTmpB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
$usedTmpExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if($usedTmpA == null && $usedTmpB == null && $usedTmpExt == null){
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = $tcfFound[$countTcf++];
$ext = new TrunkExtension();
$sequence_no = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
$ext->setTrunkCableFiber($tcf);
$ext->setTypeCable($typeCable);
$ext->setOperatorID($operatorId);
$ext->setPortB($port);
$ext->setSequenceNo($sequence_no);
$em->persist($ext);
//check for continuity
//get the link extension if any matches
$extMatch = null;
$matchedPort = null;
// var_dump($sequence_no);
if ($sequence_no == 1) {
$matchedPort = $tcf->getPortB();
}
else {
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$sequence_no-1]);
$matchedPort = $lastTrunkExt->getPortB();
}
// var_dump($matchedPort);
if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
$duplexPort = true;
$counter++;
}
else {
$duplexPort = false;
$counter = 2;
}
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// var_dump($extMatch->getId());
// $orderNoExt = $matchedPort->getOrderNoExtension();
if ($counter == 2) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
// $counter = 0;
}
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
// var_dump($tempIds);
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityB);
$port->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityB);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
// var_dump('hi');
// var_dump($extMatch->getSequenceNo());
// var_dump(count($linkMatch->getLinkExtension()));
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $port->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $port);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityA);
$port->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityA);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $port->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $port);
}
}
}//end of check for continuity
}
}
else {
$tcf = $tcfFound[$countTcf++];
$ext = new TrunkExtension();
$sequence_no = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
$ext->setTrunkCableFiber($tcf);
$ext->setTypeCable($typeCable);
$ext->setOperatorID($operatorId);
$ext->setPortB($port);
$ext->setSequenceNo($sequence_no);
$em->persist($ext);
//check for continuity
//get the link extension if any matches
$extMatch = null;
$matchedPort = null;
// var_dump($sequence_no);
if ($sequence_no == 1) {
$matchedPort = $tcf->getPortB();
}
else {
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$sequence_no-1]);
$matchedPort = $lastTrunkExt->getPortB();
}
// var_dump($matchedPort);
if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
$duplexPort = true;
$counter++;
}
else {
$duplexPort = false;
$counter = 2;
}
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// var_dump($extMatch->getId());
// $orderNoExt = $matchedPort->getOrderNoExtension();
if ($counter == 2) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
// $counter = 0;
}
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
// var_dump($tempIds);
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityB);
$port->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityB);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
// var_dump('hi');
// var_dump($extMatch->getSequenceNo());
// var_dump(count($linkMatch->getLinkExtension()));
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $port->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $port);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityA);
$port->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityA);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $port->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $port);
}
}
}//end of check for continuity
}
}
}
}
}
}
}
else {
$interfacesB = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->findByEquipmentSpecific($eqB);
foreach ($interfacesB as $interface) {
//ADDED by Soupra
$typeLinkTitle = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
if ($equipmentTypeB == 1) {
$interface_id = $interface->getInterfaceGeneric()->getId(); // get generic interfaces
} else {
$interface_id = $interface->getId(); // get specific interfaces
}
//check if interface is selected
if (isset($_POST['interfaceB_' . $interface_id])) {
$ports = $this->getDoctrine()->getRepository('App\Entity\Port')->findByInterfaceSpecific($interface);
foreach ($ports as $port) {
//get the cable which corresponds to the portA
$usedTmpA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$usedTmpB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
$usedTmpExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if($usedTmpA == null && $usedTmpB == null && $usedTmpExt == null){
if ($typeLinkTitle == "Duplex") {
for ($i=0; $i < 2; $i++) {
$tcf = $tcfFound[$countTcf++];
$ext = new TrunkExtension();
$sequence_no = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
$ext->setTrunkCableFiber($tcf);
$ext->setTypeCable($typeCable);
$ext->setOperatorID($operatorId);
$ext->setPortB($port);
$ext->setSequenceNo($sequence_no);
$em->persist($ext);
//check for continuity
//get the link extension if any matches
$extMatch = null;
$matchedPort = null;
// var_dump($sequence_no);
if ($sequence_no == 1) {
$matchedPort = $tcf->getPortB();
}
else {
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$sequence_no-1]);
$matchedPort = $lastTrunkExt->getPortB();
}
// var_dump($matchedPort);
if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
$duplexPort = true;
$counter++;
}
else {
$duplexPort = false;
$counter = 2;
}
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// var_dump($extMatch->getId());
// $orderNoExt = $matchedPort->getOrderNoExtension();
if ($counter == 2) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
// $counter = 0;
}
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
// var_dump($tempIds);
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityB);
$port->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityB);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
// var_dump('hi');
// var_dump($extMatch->getSequenceNo());
// var_dump(count($linkMatch->getLinkExtension()));
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $port->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $port);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityA);
$port->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityA);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $port->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $port);
}
}
}//end of check for continuity
}
}
else {
$tcf = $tcfFound[$countTcf++];
$ext = new TrunkExtension();
$sequence_no = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->getNextSequenceNo($tcf);
$ext->setTrunkCableFiber($tcf);
$ext->setTypeCable($typeCable);
$ext->setOperatorID($operatorId);
$ext->setPortB($port);
$ext->setSequenceNo($sequence_no);
$em->persist($ext);
//check for continuity
//get the link extension if any matches
$extMatch = null;
$matchedPort = null;
// var_dump($sequence_no);
if ($sequence_no == 1) {
$matchedPort = $tcf->getPortB();
}
else {
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$tcf, "sequenceNo"=>$sequence_no-1]);
$matchedPort = $lastTrunkExt->getPortB();
}
// var_dump($matchedPort);
if ($matchedPort->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle() == "Duplex") {
$duplexPort = true;
$counter++;
}
else {
$duplexPort = false;
$counter = 2;
}
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// var_dump($extMatch->getId());
// $orderNoExt = $matchedPort->getOrderNoExtension();
if ($counter == 2) {
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
// $counter = 0;
}
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
// var_dump($tempIds);
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
if ($counter == 2 && $duplexPort) {
var_dump($duplexPort);
$orderNoExt = 2;
$em->remove($extensinOrder);
$duplexPort = false;
$counter = 0;
}
elseif ($counter == 2) {
$em->remove($extensinOrder);
$counter = 0;
}
// $extrmityB->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityB);
$port->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityB);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityB);
//check if it's last link extension
//if it's last, DO NOTHING
// var_dump('hi');
// var_dump($extMatch->getSequenceNo());
// var_dump(count($linkMatch->getLinkExtension()));
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
//
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
//
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $port->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $port);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($port);
$extensinOrder->setExtremity($extrmityA);
$port->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($port);
// $port->setOrderNoExtension($orderNoExt);
// $port->addExtremity($extrmityA);
$port->setLink($linkMatch);
$port->setLinkExtension($extMatch);
$em->persist($port);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $port->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $port->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $port);
}
}
}//end of check for continuity
}
}
}
}
}
}
}
}
$em->flush();
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @Route("/trunk/list", name="trunk_list")
* trunk list page ???
*/
public function listAction(Request $request, LoggerInterface $logger, TranslatorInterface $translator)
{
// $cache = new FilesystemAdapter();
// $trunkList = $cache->getItem('pagerfanta.list.trunk');
// $trunkList->expiresAfter(1);
$trunks = null;
// if (!$trunkList->isHit()) {
//get all the trunks
$trunks = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
foreach ($trunks as $trunk){
$usedPorts = 0;
$operators = [];
$operators[] = $trunk->getOperatorID();
$tcfs = $trunk->getCableFiber();
if ( !($tcfs->isEmpty()) ) {
//get the first equipment ???
$firstTcf = $tcfs[0];
$eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
$trunk->eqA = $eqA;
//MODIFIED on 28 janvier 2019
$portB = $firstTcf->getPortB();
if($portB){
$eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
}
else{
$eqB = null;
}
foreach ($tcfs as $tcf) {
if (!in_array($tcf->getOperatorID(), $operators)){
if ($tcf->getOperatorID()) {
$operators[] = $tcf->getOperatorID();
}
}
$extensions = $tcf->getExtensions();
if ($extensions) {
foreach ($extensions as $extension) {
//MODIFIED on 28 janvier 2019
$portBtemp = $extension->getPortB();
if($portBtemp){
$eqB = $portBtemp->getInterfaceSpecific()->getEquipmentSpecific();
}
if (!in_array($extension->getOperatorID(), $operators)){
if ($extension->getOperatorID()) {
$operators[] = $extension->getOperatorID();
}
}
}
}
$portA = $tcf->getPortA();
$typeLnk = $portA->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getTitle();
if (count($portA->getExtensionOrder()) > 0){
$usedPorts++;
}
// $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portA' => $portA]);
// $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portB' => $portA]);
// //ADDED by Soupra
// if (!$linkExtA && !$linkExtB){
// $freePorts++;
//
// }
}
//get the last equipment ???
$trunk->eqB = $eqB;
}
$trunk->operators = $operators;
$trunk->freePorts = $trunk->getCapacity() - $usedPorts;
}
// $cache->save($trunkList->set($trunks));
// }
// else {
// $trunks = $trunkList->get();
// // var_dump($links);
// }
// $adapter = new ArrayAdapter($trunks);
// $pagerfanta = new Pagerfanta($adapter);
$pageLength = $request->query->get("pageLength", $this->getParameter("trunk.maxPerPage"));
// if ($pageLength == "Tout") {
// $pagerfanta->setMaxPerPage(count($trunks)); // 10 by default
// }
// else {
// $pagerfanta->setMaxPerPage($pageLength); // 10 by default
// }
// // $this->container->setParameter("link.maxPerPage", $pageLength);
// $page = $request->query->get("page", 1);
// $pagerfanta->setCurrentPage($page);
$logger->info(count($trunks));
// $logger->info(count($pagerfanta->getCurrentPageResults()));
return $this->render('trunk/list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunks'),
'list' => $trunks,
// 'my_pager' => $pagerfanta,
'pageLength' => $pageLength,
]);
}
/**
* @Route("/trunk/usage/all", name="trunk_usage_all")
*/
public function overviewListFullAction(Request $request, TranslatorInterface $translator)
{
$list = [];
$maxPorts = 0;
//get all the ports used by Links
$portsAllTemp = $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
$portsAll = array();
foreach ($portsAllTemp as $tempArray) {
foreach ($tempArray as $key => $value) {
$portsAll[] = $value;
}
}
// $cache = new FilesystemAdapter();
// $trunkList = $cache->getItem('pagerfanta.list.overview.trunk"');
// $maxPortsFromCache = $cache->getItem('pagerfanta.list.overview.maxPorts"');
//
// if (!$trunkList->isHit()) {
$trunks = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
foreach ($trunks as $trunk){
$eqBArray = array();
// $eqBArray = [];
$tcfs = $trunk->getCableFiber();
if ( !($tcfs->isEmpty()) ) {
foreach ($tcfs as $firstTcf) {
$eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
//check if eqA is modulaire
// if ($eqATemp->isModule()) {
// foreach ($eqATemp->getParent()->getModules() as $value) {
// $eqAArray[] = $value;
// }
// }
// else {
// $eqAArray[] = $eqATemp;
// }
$eqB = null;
if (count($firstTcf->getExtensions()) > 0) {
$trunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
$eqB = $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
}
else {
$eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
}
//check if eqB is modulaire
// if ($eqBTemp->isModule()) {
// foreach ($eqBTemp->getParent()->getModules() as $value) {
// $eqBArray[] = $value;
// }
// }
// else {
// $eqBArray[] = $eqBTemp;
// }
// var_dump($eqA->getId());
if (!in_array($eqA->getId(), $eqBArray)) {
$trunk->eqA = $eqA;
$res = $this->createEquipment($trunk, $eqA, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
$eqBArray[] = $eqA->getId();
}
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// // $used = 0;
// // $usedLinkID = '';
// // $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtensionOrder();
// // foreach ( $tempExts as $value) {
// // $extremityB = $value->getExtremity();
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// // $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
// //
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// //
// // if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
// //
// // }
// // else if($trunkExtension) {
// // // var_dump("Got it");
// // $used = 1;
// // $usedLinkID = $port->getLink()->getLinkID();
// // $usedLink_id = $port->getLink()->getId();
// // }
// // if ($tcfB && $usedBLink) {
// //
// // }
// // else if($tcfB){
// // $used = 1;
// // $usedLinkID = $port->getLink()->getLinkID();
// // $usedLink_id = $port->getLink()->getId();
// //
// // }
//
// // $port->used = $used;
// $port->used = 1;
// $port->usedLinkID = $port->getLink()->getLinkID();
// $port->usedLink_id = $port->getLink()->getId();
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
// $list[] = $eq;
if (!in_array($eqB->getId(), $eqBArray)) {
$trunk->eqB = $eqB;
$res = $this->createEquipment($trunk, $eqB, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
$eqBArray[] = $eqB->getId();
}
// if (in_array()$eqB != $eqA) {
// //eqB
//
// $trunk->eqB = $eqB;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtensionOrder();
// // foreach ( $tempExts as $value) {
// // $extremityB = $value->getExtremity();
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// // $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
// //
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// //
// // if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
// //
// // }
// // else if($trunkExtension) {
// // // var_dump("Got it");
// // $used = 1;
// // $usedLinkID = $port->getLink()->getLinkID();
// // $usedLink_id = $port->getLink()->getId();
// // }
// // if ($tcfB && $usedBLink) {
// //
// // }
// // else if($tcfB){
// // $used = 1;
// // $usedLinkID = $port->getLink()->getLinkID();
// // $usedLink_id = $port->getLink()->getId();
// //
// // }
//
// $port->used = 1;
// $port->usedLinkID = $port->getLink()->getLinkID();
// $port->usedLink_id = $port->getLink()->getId();
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
// }
//version long avec tous les équipements intermédiaire
// foreach ($tcfs as $firstTcf) {
// // $firstTcf = $tcfs[0];
// $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
// if (!in_array($eqA->getId(), $eqBArray)) {
// $eqBArray[] = $eqA->getId();
// $trunk->eqA = $eqA;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
// }
//
//
// $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// if (!in_array($eqB->getId(), $eqBArray)) {
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// $extensions = $firstTcf->getExtensions();
// foreach ($extensions as $extension) {
// $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
//
// if (!in_array($eqB->getId(), $eqBArray)) {
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extrmityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// }
// }
// }
// // var_dump($firstTcf);
// // var_dump($firstTcf->getPortB()->getId());
// // var_dump($eqB->getId());
//
// // foreach ($tcfs as $tcf) {
// //
// // }
//
// // $trunk->eqB = $eqB;
// //
// // $rackTitle = $eqB->getRack()->getTitle();
// //
// // $eq['trunkID'] = $trunk->getTrunkID();
// // $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// // $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// // $eq['rack'] = $rackTitle;
// // $eq['equipment'] = $eqB->getEquipmentSpecificName();
// // $eq['interfaces'] = [];
// //
// // $interfaces = $eqB->getInterfaceSpecific();
// // foreach ($interfaces as $interface){
// // // var_dump($interface->getId());
// // $totalPorts = 0;
// // $totalPortsUsed = 0;
// // $totalPortsInInterface = 0;
// //
// // $ports = $interface->getPort();
// //
// // $portList = [];
// //
// // $isInterfaceInTrunk = 0;
// //
// // foreach ($ports as $port){
// // // var_dump($port->getId());
// // $isPortInTrunk = 0;
// //
// // $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// //
// // if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// // $isInterfaceInTrunk = 1;
// // $isPortInTrunk = 1;
// // $totalPorts++;
// // }
// //
// //
// // $port->nPort = 0;
// //
// // $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// // if ($nPorts){
// // $nPorts = json_decode($nPorts);
// // if (in_array($port->getOrderNo(), $nPorts)){
// // $port->nPort = 1;
// // }
// // }
// //
// // $used = 0;
// // $usedLinkID = '';
// // $usedLink_id = '';
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
// // // var_dump($used);
// // $p['used'] = $used;
// // $p['usedLinkID'] = $usedLinkID;
// // $p['usedLink_id'] = $usedLink_id;
// // $p['nPort'] = $port->nPort;
// // $p['inTrunk'] = $isPortInTrunk;
// //
// //
// // if ($port->nPort == 1 && $port->used == 1){
// //
// // $p['id'] = $port->getId();
// //
// // }
// //
// // $totalPortsInInterface++;
// //
// // if ($used == 1){
// // $totalPortsUsed ++;
// // }
// //
// // $portList[] = $p;
// //
// // }
// //
// // $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// // $int['totalPorts'] = $totalPorts;
// // $int['totalPortsUsed'] = $totalPortsUsed;
// // $int['ports'] = $portList;
// //
// // if ($isInterfaceInTrunk == 1){
// //
// // $eq['interfaces'][] = $int;
// //
// // if ($totalPortsInInterface > $maxPorts){
// // $maxPorts = $totalPortsInInterface;
// // }
// //
// // }
// //
// //
// // }
// //
// // $list[] = $eq;
//
// }
}
}
}
// $cache->save($trunkList->set($list));
// $cache->save($maxPortsFromCache->set($maxPorts));
// }
// else {
// $list = $trunkList->get();
// $maxPorts = $maxPortsFromCache->get();
// // var_dump($links);
// }
// $adapter = new ArrayAdapter($list);
// $pagerfanta = new Pagerfanta($adapter);
$pageLength = $request->query->get("pageLength", $this->getParameter("trunk.details.maxPerPage"));
// if ($pageLength == "Tout") {
// $pagerfanta->setMaxPerPage(count($list)); // 10 by default
// }
// else {
// $pagerfanta->setMaxPerPage($pageLength); // 10 by default
// }
// // $this->container->setParameter("link.maxPerPage", $pageLength);
// $page = $request->query->get("page", 1);
// $pagerfanta->setCurrentPage($page);
return $this->render('overview/trunk_usage_full.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunk Usage'),
'list' => $list,
'maxPorts' => $maxPorts,
// 'my_pager' => $pagerfanta,
'pageLength' => $pageLength,
]);
}
/**
* @Route("/trunk/usage/all/extended", name="trunk_usage_all_extended")
*/
public function overviewListFullExtendedAction(TranslatorInterface $translator)
{
$list = [];
$trunks = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
$maxPorts = 0;
//get all the ports used by Links
$portsAllTemp = $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
$portsAll = array();
foreach ($portsAllTemp as $tempArray) {
foreach ($tempArray as $key => $value) {
$portsAll[] = $value;
}
}
foreach ($trunks as $trunk){
$eqBArray = [];
$tcfs = $trunk->getCableFiber();
if ( !($tcfs->isEmpty()) ) {
// $firstTcf = $tcfs[0];
// $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
// $eqB = null;
//
// if (count($firstTcf->getExtensions()) > 0) {
// $trunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
// $eqB = $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// }
// else {
// $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// }
// $trunk->eqA = $eqA;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
// if ($eqB != $eqA) {
// //eqB
// $trunk->eqB = $eqB;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
// }
//version long avec tous les équipements intermédiaire
foreach ($tcfs as $firstTcf) {
// $firstTcf = $tcfs[0];
$eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
if (!in_array($eqA->getId(), $eqBArray)) {
$eqBArray[] = $eqA->getId();
$res = $this->createEquipment($trunk, $eqA, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
// $trunk->eqA = $eqA;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
}
$eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
if (!in_array($eqB->getId(), $eqBArray)) {
$eqBArray[] = $eqB->getId();
$res = $this->createEquipment($trunk, $eqB, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
$extensions = $firstTcf->getExtensions();
foreach ($extensions as $extension) {
$eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
if (!in_array($eqB->getId(), $eqBArray)) {
$eqBArray[] = $eqB->getId();
$res = $this->createEquipment($trunk, $eqB, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extrmityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
}
}
}
// var_dump($firstTcf);
// var_dump($firstTcf->getPortB()->getId());
// var_dump($eqB->getId());
// foreach ($tcfs as $tcf) {
//
// }
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
// // var_dump($port->getId());
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtremities();
// foreach ( $tempExts as $extremityB) {
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
//
// if ($usedALink){
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
//
// if ($usedBLink){
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// // var_dump($used);
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
}
}
}
return $this->render('overview/trunk_usage_full_extended.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunk Usage'),
'list' => $list,
'maxPorts' => $maxPorts
]);
}
/**
* @Route("/trunk/nPort/links", name="trunk_usage_nPort")
*/
public function nPortLinksAction()
{
$port = $this->getDoctrine()->getRepository('App\Entity\Port')->find($_POST['id']);
$extremities = array();
foreach ($port->getExtensionOrder() as $value) {
$extremities[] = $value->getExtremity();
}
// $extremities = $port->getExtremities();
$usedALinks = array();
$usedBLinks = array();
foreach ($extremities as $extremity) {
$usedALinks[] = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremity);
$usedBLinks[] = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremity);
}
$links = [];
foreach ($usedALinks as $usedALink){
if ($usedALink) {
$links[] = $usedALink->getLink()->getId();
// $links[] = array('link_id' => $usedALink->getLink()->getId(), 'linkID' => $usedALink->getLink()->getLinkID());
}
}
foreach ($usedBLinks as $usedBLink){
if ($usedBLink) {
$links[] = $usedBLink->getLink()->getId();
// $links[] = array('link_id' => $usedBLink->getLink()->getId(), 'linkID' => $usedBLink->getLink()->getLinkID());
}
}
$temp = array_unique($links);
$res = [];
foreach ($temp as $value) {
$link = $this->getDoctrine()->getRepository('App\Entity\Link')->find($value);
$res[] = array('link_id' => $link->getId(), 'linkID' => $link->getLinkID());
}
return $this->json($res);
}
/**
* @Route("/trunk/overview/list", name="trunk_overview_list")
*/
public function overviewListAction(Request $request, LoggerInterface $logger, TranslatorInterface $translator)
{
// $logger = $this->get('logger');
// $cache = new FilesystemAdapter();
// $trunkList = $cache->getItem('pagerfanta.list.trunk"');
// $trunkList->expiresAfter(1);
$trunks = null;
// if (!$trunkList->isHit()) {
$trunks = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findAll();
foreach ($trunks as $trunk){
$logger->info("trunk");
$logger->info($trunk->getId());
$freePorts = 0;
$operators = [];
$operators[] = $trunk->getOperatorID();
$tcfs = $trunk->getCableFiber();
if ( !($tcfs->isEmpty()) ) {
$firstTcf = $tcfs[0];
$eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
$trunk->eqA = $eqA;
$logger->info($firstTcf->getId());
$eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
foreach ($tcfs as $tcf) {
$extensions = $tcf->getExtensions();
if ($extensions) {
foreach ($extensions as $extension) {
$eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
if (!in_array($extension->getOperatorID(), $operators)){
$operators[] = $extension->getOperatorID();
}
}
}
$portA = $tcf->getPortA();
if (count($portA->getExtensionOrder()) == 0){
$freePorts++;
}
// $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portA' => $portA]);
// $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findBy(['portB' => $portA]);
//
// if (!$linkExtA && !$linkExtB){
// $freePorts++;
// }
}
$trunk->eqB = $eqB;
}
$trunk->operators = $operators;
$trunk->freePorts = $freePorts;
}
// $cache->save($trunkList->set($trunks));
// }
// else {
// $trunks = $trunkList->get();
// // var_dump($links);
// }
// $adapter = new ArrayAdapter($trunks);
// $pagerfanta = new Pagerfanta($adapter);
$pageLength = $request->query->get("pageLength", $this->getParameter("trunk.maxPerPage"));
// if ($pageLength == "Tout") {
// $pagerfanta->setMaxPerPage(count($trunks)); // 10 by default
// }
// else {
// $pagerfanta->setMaxPerPage($pageLength); // 10 by default
// }
// // $this->container->setParameter("link.maxPerPage", $pageLength);
// $page = $request->query->get("page", 1);
// $pagerfanta->setCurrentPage($page);
return $this->render('overview/trunk_list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunk Overview'),
'list' => $trunks,
// 'my_pager' => $pagerfanta,
'pageLength' => $pageLength,
]);
}
/**
* @Route("/trunk/view/{id}", name="trunk_view")
*/
public function viewAction(Request $request, $id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $em->getRepository(Trunk::class)->find($id);
$typeCable = $this->getDoctrine()->getRepository('App\Entity\TypeCable')->findAll();
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
// $tcfs = $trunk->getCableFiber();
//
// foreach ($tcfs as $tcf){
//
// $ext = $tcf->getExtensions();
//
// }
$linkValidationList = '';
// $queryBuilder = $em->createQueryBuilder()
// ->select('tcf')
// ->from('App\Entity\TrunkCableFiber', 'tcf')
// ->where("tcf.trunk = :trunk")
// ->setParameter("trunk", $trunk);
// $adapter = new DoctrineORMAdapter($queryBuilder);
// $pagerfanta = new Pagerfanta($adapter);
$pageLength = $request->query->get("pageLength", $this->getParameter("trunk.details.maxPerPage"));
// if ($pageLength == "Tout") {
// $qb = $em->createQueryBuilder()
// ->select('COUNT(tcf.id)')
// ->from('App\Entity\TrunkCableFiber', 'tcf')
// ->where("tcf.trunk = :trunk")
// ->setParameter("trunk", $trunk);
//
// $count = $qb->getQuery()->getSingleScalarResult();
// $pagerfanta->setMaxPerPage($count); // 10 by default
// }
// else {
// $pagerfanta->setMaxPerPage($pageLength); // 10 by default
// }
// $page = $request->query->get("page", 1);
// $pagerfanta->setCurrentPage($page);
//
// $linkValidations = $em->getRepository(LinkValidation::class)->findBy(['trunk' => $trunk]);
// if ($linkValidations){
//
// $linkValidationList = [];
//
// foreach ($linkValidations as $linkValidation){
//
// $linkValidationList[] = array('link_id' => $linkValidation->getLink()->getId(), 'linkID' => $linkValidation->getLink()->getLinkID());
//
// }
//
// }
return $this->render('trunk/list_details.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunk').' '.$trunk->getTrunkID(),
'trunk' => $trunk,
'typeCable' => $typeCable,
'sites' => $sites,
'rackFaces' => $rackFaces,
'linkValidationList' => $linkValidationList,
// 'my_pager' => $pagerfanta,
'pageLength' => $pageLength,
]);
}
/**
* @Route("/trunk/usage/item/{id}", name="trunk_usage")
*/
public function usageAction($id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $em->getRepository(Trunk::class)->find($id);
$maxPorts = 0;
$list = [];
$eqBArray = [];
$tcfs = $trunk->getCableFiber();
if ( !($tcfs->isEmpty()) ) {
//get all the ports used by Links
$portsAllTemp = $this->getDoctrine()->getRepository('App\Entity\Port')->findAllUsedPorts();
$portsAll = array();
foreach ($portsAllTemp as $tempArray) {
foreach ($tempArray as $key => $value) {
$portsAll[] = $value;
}
}
foreach ($tcfs as $firstTcf) {
$eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
//check if eqA is modulaire
// if ($eqATemp->isModule()) {
// foreach ($eqATemp->getParent()->getModules() as $value) {
// $eqAArray[] = $value;
// }
// }
// else {
// $eqAArray[] = $eqATemp;
// }
$eqB = null;
if (count($firstTcf->getExtensions()) > 0) {
$trunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByTrunkCableFiber($firstTcf, ["sequenceNo"=>"DESC"]);
$eqB = $trunkExt->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
}
else {
$eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
}
//check if eqB is modulaire
// if ($eqBTemp->isModule()) {
// foreach ($eqBTemp->getParent()->getModules() as $value) {
// $eqBArray[] = $value;
// }
// }
// else {
// $eqBArray[] = $eqBTemp;
// }
// var_dump($eqA->getId());
if (!in_array($eqA->getId(), $eqBArray)) {
$trunk->eqA = $eqA;
$res = $this->createEquipment($trunk, $eqA, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
$eqBArray[] = $eqA->getId();
// $trunk->eqA = $eqA;
// // var_dump($eqA->getId());
//
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
// // var_dump($interface->getId());
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
// // var_dump($port->getId());
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// // var_dump($usedInTrunkPointA);
// // var_dump($usedInTrunkPointB);
// // var_dump($usedInTrunkExtension);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// // // var_dump($used);
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
// $list[] = $eq;
}
// $extCount = count($firstTcf->getExtensions());
// if ($extCount > 0) {
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$trunkCableFiber, "sequenceNo"=>$extCount]);
// $eqB = $lastExtension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// }
// else {
// $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// }
if (!in_array($eqB->getId(), $eqBArray)) {
$trunk->eqB = $eqB;
$res = $this->createEquipment($trunk, $eqB, $portsAll, $maxPorts);
$list[] = $res["eq"];
$maxPorts = $res["maxPorts"];
$eqBArray[] = $eqB->getId();
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// $extensions = $firstTcf->getExtensions();
// foreach ($extensions as $extension) {
// $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
//
// if (!in_array($eqB->getId(), $eqBArray)) {
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extrmityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// }
// }
}
}
// $firstTcf = $tcfs[0];
// $eqA = $firstTcf->getPortA()->getInterfaceSpecific()->getEquipmentSpecific();
// $eqBArray[] = $eqA->getId();
//
// $trunk->eqA = $eqA;
//
// $rackTitle = $eqA->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqA->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqA->getEquipmentSpecificName()/*. ' (' . $eqA->getEquipmentGeneric()->getTitle() . ')'*/;
// $eq['interfaces'] = [];
//
// $interfaces = $eqA->getInterfaceSpecific();
// foreach ($interfaces as $interface) {
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port) {
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
// $port->nPort = 0;
// $port->used = 0;
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
//
// /*$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);*/
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
//
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// // //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink) {
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink) {
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
// //
// // $port->used = $used;
// // $port->usedLinkID = $usedLinkID;
// // $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
//
// $totalPortsInInterface++;
//
// if ($used == 1) {
// $totalPortsUsed++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
// }
//
//
// $list[] = $eq;
//
// $eqB = $firstTcf->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
// if ($eqB->getId() != $eqA->getId()){
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// foreach ($tcfs as $tcf) {
// $extensions = $tcf->getExtensions();
// foreach ($extensions as $extension) {
// $eqB = $extension->getPortB()->getInterfaceSpecific()->getEquipmentSpecific();
//
// if (!in_array($eqB->getId(), $eqBArray)) {
// $eqBArray[] = $eqB->getId();
// $trunk->eqB = $eqB;
//
// $rackTitle = $eqB->getRack()->getTitle();
//
// $eq['trunkID'] = $trunk->getTrunkID();
// $eq['site'] = $eqB->getRack()->getRoom()->getSite()->getTitle();
// $eq['room'] = $eqB->getRack()->getRoom()->getTitle();
// $eq['rack'] = $rackTitle;
// $eq['equipment'] = $eqB->getEquipmentSpecificName();
// $eq['interfaces'] = [];
//
// $interfaces = $eqB->getInterfaceSpecific();
// foreach ($interfaces as $interface){
//
// $totalPorts = 0;
// $totalPortsUsed = 0;
// $totalPortsInInterface = 0;
//
// $ports = $interface->getPort();
//
// $portList = [];
//
// $isInterfaceInTrunk = 0;
//
// foreach ($ports as $port){
//
// $isPortInTrunk = 0;
//
// $usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// $usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// $usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
//
// if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
// $isInterfaceInTrunk = 1;
// $isPortInTrunk = 1;
// $totalPorts++;
// }
//
//
// $port->nPort = 0;
// $port->used = 0;
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
//
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
// if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB =$value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
// }
// // $usedALink = null;
// // $usedBLink = null;
// // $tempExts = $port->getExtremities();
// // foreach ( $tempExts as $extremityB) {
// // if ($usedALink && $usedBLink) {
// // break;
// // }
// // if(!$usedALink) {
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// // }
// // if (!$usedBLink) {
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// // }
// // }
// //
// // // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// //
// // if ($usedALink){
// // $used = 1;
// // $usedLinkID = $usedALink->getLink()->getLinkID();
// // $usedLink_id = $usedALink->getLink()->getId();
// // }
// //
// // if ($usedBLink){
// // $used = 1;
// // $usedLinkID = $usedBLink->getLink()->getLinkID();
// // $usedLink_id = $usedBLink->getLink()->getId();
// // }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $p['used'] = $used;
// $p['usedLinkID'] = $usedLinkID;
// $p['usedLink_id'] = $usedLink_id;
// $p['nPort'] = $port->nPort;
// $p['inTrunk'] = $isPortInTrunk;
//
//
// if ($port->nPort == 1 && $port->used == 1){
//
// $p['id'] = $port->getId();
//
// }
//
// $totalPortsInInterface ++;
//
// if ($used == 1){
// $totalPortsUsed ++;
// }
//
// $portList[] = $p;
//
// }
//
// $int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
// $int['totalPorts'] = $totalPorts;
// $int['totalPortsUsed'] = $totalPortsUsed;
// $int['ports'] = $portList;
//
// if ($isInterfaceInTrunk == 1){
//
// $eq['interfaces'][] = $int;
//
// if ($totalPortsInInterface > $maxPorts){
// $maxPorts = $totalPortsInInterface;
// }
//
// }
//
//
// }
//
// $list[] = $eq;
// }
// }
// }
// // var_dump($eqA);
// // var_dump($eqB);
// // print_r($eqBArray);
//
// } //end
}
return $this->render('overview/trunk_usage.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Trunk Usage'),
'trunk' => $trunk,
'list' => $list,
'maxPorts' => $maxPorts
]);
}
/**
* @Route("/trunk/overview/item/{id}", name="trunk_overview")
*/
public function overviewAction(Request $request, $id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $em->getRepository(Trunk::class)->find($id);
// $queryBuilder = $em->createQueryBuilder()
// ->select('tcf')
// ->from('App\Entity\TrunkCableFiber', 'tcf')
// ->where("tcf.trunk = :trunk")
// ->setParameter("trunk", $trunk);
// $adapter = new DoctrineORMAdapter($queryBuilder);
// $pagerfanta = new Pagerfanta($adapter);
$pageLength = $request->query->get("pageLength", $this->getParameter("trunk.details.maxPerPage"));
// if ($pageLength == "Tout") {
// $qb = $em->createQueryBuilder()
// ->select('COUNT(tcf.id)')
// ->from('App\Entity\TrunkCableFiber', 'tcf')
// ->where("tcf.trunk = :trunk")
// ->setParameter("trunk", $trunk);
//
// $count = $qb->getQuery()->getSingleScalarResult();
// $pagerfanta->setMaxPerPage($count); // 10 by default
// }
// else {
// $pagerfanta->setMaxPerPage($pageLength); // 10 by default
// }
// $page = $request->query->get("page", 1);
// $pagerfanta->setCurrentPage($page);
// $tcfs = $trunk->getCableFiber();
//
// foreach ($tcfs as $tcf){
//
// $ext = $tcf->getExtensions();
//
// }
return $this->render('overview/trunk_view.html.twig', [
'page_title' => $translator->trans('Trunk Overview'),
'trunk' => $trunk,
// 'my_pager' => $pagerfanta,
'pageLength' => $pageLength,
]);
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/process/basic", name="trunk_edit_basic")
*/
public function editBasicAction(Request $request, TranslatorInterface $translator)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$trunk = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findOneById($request->request->get('trunk_id'));
$trunk->setTrunkID($request->request->get('trunkID'));
$trunk->setOperatorID($request->request->get('operatorID'));
$trunk->setTypeCable($this->getDoctrine()->getRepository('App\Entity\TypeCable')->findOneById($request->request->get('typeCable')));
$trunk->setUpdatedBy($user);
$usedCapacity = 0;
$trunkCableFiber = $trunk->getCableFiber();
foreach ($trunkCableFiber as $item) {
$usedCapacity += 1;
}
$newCapacity = $request->request->get('capacity');
if ($newCapacity >= $usedCapacity){
$trunk->setCapacity($newCapacity);
}
$em->persist($trunk);
$em->flush();
// return $this->redirectToRoute('trunk_list');
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/delete/{id}", name="trunk_delete")
*/
public function deleteAction($id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$trunk = $em->getRepository(Trunk::class)->find($id);
$used = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByTrunk($trunk);
$error = [];
if (!$used){
$sql = "delete from trunk_cable_fiber where trunk_id = " . $id;
$conn = $em->getConnection();
$stmt = $conn->prepare($sql);
$stmt->execute();
// $em->flush();
$em->remove($trunk);
$em->flush();
$error = array('error' => null);
} else {
$error = array('error' => 'usage');
}
if ($error['error']) {
$this->addFlash(
'error',
'usage'
);
}
return $this->redirectToRoute('trunk_list');
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/trunk/delete/extension/{id}", name="trunk_delete_extension")
*/
public function deleteExtensionAction($id, TranslatorInterface $translator)
{
$user = $this->get('security.token_storage')->getToken()->getUser();
$em = $this->getDoctrine()->getManager();
$trunkExtension = $em->getRepository(TrunkExtension::class)->find($id);
$trunkCableFiber = $trunkExtension->getTrunkCableFiber();
$trunkExtensionSequenceNo = $trunkExtension->getSequenceNo();
$lastTrunkExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(["trunkCableFiber"=>$trunkCableFiber, "sequenceNo"=>$trunkExtensionSequenceNo-1]);
$portB = null;
if ($lastTrunkExt) {
$portB = $lastTrunkExt->getPortB();
}
else {
$portB = $trunkCableFiber->getPortB();
}
$trunkExts = $em->getRepository(TrunkExtension::class)->getAllNextExtensions($trunkCableFiber, $trunkExtensionSequenceNo);
foreach ($trunkExts as $trunkExt) {
$matchedPort = $trunkExt->getPortB();
//get the link extension if any matches
$extMatch = null;
$extId = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getTrunkLinkExtensionByPort($matchedPort);
if ($extId) {
$extMatch = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->find($extId["id"]);
}
// $extMatch = $matchedPort->getLinkExtension();
if ($extMatch) {
// $orderNoExt = $matchedPort->getOrderNoExtension();
$matchedPort->setLink(null);
$matchedPort->setLinkExtension(null);
// $matchedPort->setOrderNoExtension(1);
$em->persist($matchedPort);
$linkMatch = $extMatch->getLink();
$extrmityB = $extMatch->getExtremityB();
$extBPorts = $extrmityB->getExtensionOrder();
$tempIds = array();
foreach ($extBPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityB]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityB->removePort($matchedPort);
if (!$this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$portB, "extremity"=>$extrmityB])) {
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityB);
$portB->addExtensionOrder($extensinOrder);
$extrmityB->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityB->removePort($matchedPort);
// $extrmityB->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityB);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityB);
}
//check if it's last link extension
//if it's last, DO NOTHING
if ($extMatch->getSequenceNo() != count($linkMatch->getLinkExtension())) {
// // var_dump("entering ...");
// //else get the last extension's extremity B's equipment
// $nextExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()+1]);
// $nextExtA = $nextExtension->getExtremityA();
// $nextPorts = array();
// foreach ($nextExtA->getExtensionOrder() as $value) {
// $nextPorts[] = $value->getPort();
// }
// // $nextPorts = $nextExtA->getPorts();
// $nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
// $nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
// $nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $nextEquipment->getId()) {
// // var_dump("entering not equals equipments...");
//
// //if false, set the link and las link extension as INVALID
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// // var_dump("entering checking ports...");
//
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// //else get the next extension's extremity B's interface
// //check if it's 1:1
// if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // var_dump("entering checking 1 to 1...");
//
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($nextPorts as $nextPort) {
// if ($nextPort->getId() != $portB->getId()) {
// $nextExtension->setIsValid(false);
// $em->persist($nextExtension);
// }
// else {
// $nextExtension->setIsValid(true);
// $em->persist($nextExtension);
// }
// }
// }
// }
TrunkController::validateNextExtension($em, $linkMatch, $extMatch, $portB);
}
}
$extrmityA = $extMatch->getExtremityA();
$extAPorts = $extrmityA->getExtensionOrder();
$tempIds = array();
foreach ($extAPorts as $value) {
$tempIds[] = $value->getPort()->getId();
}
if (in_array($matchedPort->getId(), $tempIds)) {
$extensinOrder = $this->getDoctrine()->getRepository('App\Entity\ExtensionOrder')->findOneBy(["port"=>$matchedPort, "extremity"=>$extrmityA]);
$orderNoExt = $extensinOrder->getOrderNumber();
$em->remove($extensinOrder);
// $extrmityA->removePort($matchedPort);
$extensinOrder = new ExtensionOrder();
$extensinOrder->setOrderNumber($orderNoExt);
$extensinOrder->setPort($portB);
$extensinOrder->setExtremity($extrmityA);
$portB->addExtensionOrder($extensinOrder);
$extrmityA->addExtensionOrder($extensinOrder);
$em->persist($extensinOrder);
// $extrmityA->removePort($matchedPort);
// $extrmityA->addPort($portB);
// $portB->setOrderNoExtension($orderNoExt);
// $portB->addExtremity($extrmityA);
$portB->setLink($linkMatch);
$portB->setLinkExtension($extMatch);
$em->persist($portB);
$em->persist($extrmityA);
if ($extMatch->getSequenceNo() > 1) {
// //else get the last extension's extremity B's equipment
// $lastExtension = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$linkMatch, "sequenceNo"=>$extMatch->getSequenceNo()-1]);
//
// $lastExtB = $lastExtension->getExtremityB();
//
// $lastPorts = array();
// foreach ($lastExtB->getExtensionOrder() as $value) {
// $lastPorts[] = $value->getPort();
// }
//
// // $lastPorts = $lastExtB->getPorts();
// // var_dump($lastPorts);
// $lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
// $lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
// $lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
//
// $currentInterfaceSpecific = $portB->getInterfaceSpecific();
// $currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//
// //check if it's same as current modified link ext
// if ($currentEquipment->getId() != $lastEquipment->getId()) {
// //if false, set the link and las link extension as INVALID
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// // var_dump('hi');
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// //else get the last extension's extremity B's interface
// //check if it's 1:1
// if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// // if true, check ports are the same
// //if true, DO NOTHING
// //else set the link and las link extension as INVALID
// foreach ($lastPorts as $lastPort) {
// // var_dump($lastPort);
// if ($lastPort->getId() != $portB->getId()) {
// $lastExtension->setIsValid(false);
// $em->persist($lastExtension);
// }
// else {
// $lastExtension->setIsValid(true);
// $em->persist($lastExtension);
// }
// }
// }
// }
TrunkController::validateLastExtension($em, $linkMatch, $extMatch, $portB);
}
}
}
}
// delete action
$this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->deleteExtension($trunkCableFiber, $trunkExtensionSequenceNo);
$trunk = $trunkCableFiber->getTrunk();
$trunk->setUpdatedBy($user);
$em->persist($trunk);
$em->flush();
// $trunks = $em->getRepository('App\Entity\Trunk')->findAll();
// $cache = new FilesystemAdapter();
// LinkTrunkEventListener::treateTrunkList($trunks, $cache);
// LinkTrunkEventListener::treateTrunkOverviewList($trunks, $cache, $em);
return $this->redirectToRoute('trunk_view', array('id' => $trunk->getId()));
}
/**
* @Route("/trunk/findTrunkIdDuplicate", name="ajax_find_trunk_id")
*/
public function findTrunkIdDuplicate()
{
$response = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findTrunkIdDuplicate($_POST['trunkID']);
return $this->json($response);
}
/**
* @Route("/trunk/findTrunkIdDuplicateOther", name="ajax_find_trunk_id_other")
*/
public function findTrunkIdDuplicateOther()
{
$response = $this->getDoctrine()->getRepository('App\Entity\Trunk')->findTrunkIdDuplicateOther($_POST['trunkID'], $_POST['id']);
return $this->json($response);
}
/**
* @Route("/trunk/findOperatorIdExtensionOther", name="ajax_find_operator_id_extension_other")
*/
public function findOperatorIdDuplicateOther()
{
$trunk_id = $_POST['trunk_id'];
$operatorId = $_POST['operatorId'];
$response = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOperatorIdDuplicateOther($trunk_id, $operatorId);
return $this->json($response);
}
public function createEquipment($trunk, $eqA, $portsAll, $maxPorts)
{
$rackTitle = $eqA->getRack()->getTitle();
$eq['trunkID'] = $trunk->getTrunkID();
$eq['site'] = $eqA->getRack()->getRoom()->getSite()->getTitle();
$eq['room'] = $eqA->getRack()->getRoom()->getTitle();
$eq['rack'] = $rackTitle;
if ($eqA->isModule()) {
// $eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName() . " â•‘ " . $eqA->getEquipmentSpecificName();
$eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName();
}
elseif ($eqA->isChassisModule()) {
// $eq['equipment'] = $eqA->getParent()->getEquipmentSpecificName() . " â•‘ " . $eqA->getEquipmentSpecificName();
$eq['equipment'] = $eqA->getChassisParent()->getEquipmentSpecificName();
}
else {
$eq['equipment'] = $eqA->getEquipmentSpecificName();
}
$eq['interfaces'] = [];
$interfaces = $eqA->getInterfaceSpecific();
foreach ($interfaces as $interface) {
// var_dump($interface->getId());
$totalPorts = 0;
$totalPortsUsed = 0;
$totalPortsInInterface = 0;
$ports = $interface->getPort();
$portList = [];
$isInterfaceInTrunk = 0;
foreach ($ports as $port) {
// var_dump($port->getId());
$used = 0;
$usedLinkID = null;
$usedLink_id = null;
$isPortInTrunk = 0;
$usedInTrunkPointA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
$usedInTrunkPointB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
$usedInTrunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->isPortInTrunkExtension($port, $trunk);
// var_dump($usedInTrunkPointA);
// var_dump($usedInTrunkPointB);
// var_dump($usedInTrunkExtension);
if ($usedInTrunkPointA || $usedInTrunkPointB || $usedInTrunkExtension == 1){
$isInterfaceInTrunk = 1;
$isPortInTrunk = 1;
$totalPorts++;
}
$port->nPort = 0;
$port->used = 0;
$nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
if ($nPorts){
$nPorts = json_decode($nPorts);
if (in_array($port->getOrderNo(), $nPorts)){
$port->nPort = 1;
}
}
// $used = 0;
// $usedLinkID = '';
// $usedLink_id = '';
if (in_array($port->getId(), $portsAll)) {
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtensionOrder();
// foreach ( $tempExts as $value) {
// $extremityB = $value->getExtremity();
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// $tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
//
// if (($trunkExtension && $usedALink) || ($trunkExtension && $usedALink)) {
//
// }
// else if($trunkExtension) {
// // var_dump("Got it");
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
// }
// if ($tcfB && $usedBLink) {
//
// }
// else if($tcfB){
// $used = 1;
// $usedLinkID = $port->getLink()->getLinkID();
// $usedLink_id = $port->getLink()->getId();
//
// }
$used = 1;
$usedLinkID = $port->getLink()->getLinkID();
$usedLink_id = $port->getLink()->getId();
// $port->used = $used;
$port->used = $used;
$port->usedLinkID = $usedLinkID;
$port->usedLink_id = $usedLink_id;
}
// $usedALink = null;
// $usedBLink = null;
// $tempExts = $port->getExtremities();
// foreach ( $tempExts as $extremityB) {
// if ($usedALink && $usedBLink) {
// break;
// }
// if(!$usedALink) {
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityA' => $extremityB, 'trunk' => $trunk]);
// }
// if (!$usedBLink) {
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['extremityB' => $extremityB, 'trunk' => $trunk]);
// }
// }
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portA' => $port, 'trunk' => $trunk]);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['portB' => $port, 'trunk' => $trunk]);
// if ($usedALink) {
// $used = 1;
// $usedLinkID = $usedALink->getLink()->getLinkID();
// $usedLink_id = $usedALink->getLink()->getId();
// }
//
// if ($usedBLink) {
// $used = 1;
// $usedLinkID = $usedBLink->getLink()->getLinkID();
// $usedLink_id = $usedBLink->getLink()->getId();
// }
// // var_dump($used);
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
$p['used'] = $used;
$p['usedLinkID'] = $usedLinkID;
$p['usedLink_id'] = $usedLink_id;
$p['nPort'] = $port->nPort;
$p['inTrunk'] = $isPortInTrunk;
if ($port->nPort == 1 && $port->used == 1){
$p['id'] = $port->getId();
}
$totalPortsInInterface++;
if ($used == 1 && $isPortInTrunk == 1) {
$totalPortsUsed++;
}
$portList[] = $p;
}
if ($eqA->isModule() || $eqA->isChassisModule()) {
if (count($interfaces) == 1) {
$int['interfaceNumber'] = $eqA->getEquipmentSpecificName();
}
else {
$int['interfaceNumber'] = $eqA->getEquipmentSpecificName()."-".$interface->getInterfaceGeneric()->getInterfaceNumber();
}
}
else {
$int['interfaceNumber'] = $interface->getInterfaceGeneric()->getInterfaceNumber();
}
$int['totalPorts'] = $totalPorts;
$int['totalPortsUsed'] = $totalPortsUsed;
$int['ports'] = $portList;
if ($isInterfaceInTrunk == 1){
$eq['interfaces'][] = $int;
if ($totalPortsInInterface > $maxPorts){
$maxPorts = $totalPortsInInterface;
}
}
}
return array("eq"=>$eq, "maxPorts"=>$maxPorts);
}
public static function validateLastExtension($em, $link, $extension, $portA1)
{
$lastExtension = $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$extension->getSequenceNo()-1]);
$lastExtB = $lastExtension->getExtremityB();
$lastPorts = [];
$lastPortsTemp = $lastExtB->getExtensionOrder();
foreach ($lastPortsTemp as $value) {
$lastPorts[] = $value->getPort();
}
// $lastPorts = $lastExtB->getPorts();
// var_dump($lastPorts);
$lastInterfaceSpecific = $lastPorts[0]->getInterfaceSpecific();
$lastInterfaceGeneric = $lastInterfaceSpecific->getInterfaceGeneric();
$lastEquipment = $lastInterfaceSpecific->getEquipmentSpecific();
$currentInterfaceSpecific = $portA1->getInterfaceSpecific();
$currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//check if it's same as current modified link ext
if ($currentEquipment->getId() != $lastEquipment->getId()) {
//if false, set the link and las link extension as INVALID
$lastExtension->setIsValid(false);
if ($lastExtension->getError()) {
$lastExtension->setError($lastExtension->getError() . "," . "EquipmentB");
}
else {
$lastExtension->setError("EquipmentB");
}
$em->persist($lastExtension);
}
else {
// var_dump('hi');
$errMsg = $lastExtension->getError();
$errMsg = str_replace("EquipmentB", "", $errMsg);
$lastExtension->setError($errMsg);
if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
$lastExtension->setIsValid(false);
}
else {
$lastExtension->setIsValid(true);
$lastExtension->setError(null);
}
$em->persist($lastExtension);
//else get the last extension's extremity B's interface
//check if it's 1:1
if ($lastInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// if true, check ports are the same
//if true, DO NOTHING
//else set the link and las link extension as INVALID
foreach ($lastPorts as $lastPort) {
if ($lastPort->getId() != $portA1->getId()) {
$lastExtension->setIsValid(false);
if ($lastExtension->getError()) {
$lastExtension->setError($lastExtension->getError() . "," . "PortB");
}
else {
$lastExtension->setError("PortB");
}
$em->persist($lastExtension);
}
else {
$errMsg = str_replace("PortB", "", $errMsg);
$lastExtension->setError($errMsg);
if (!$errMsg && (strpos($errMsg, 'EquipmentA') !== false || strpos($errMsg, 'PortA') !== false)) {
$lastExtension->setIsValid(false);
}
else {
$lastExtension->setIsValid(true);
$lastExtension->setError(null);
}
$em->persist($lastExtension);
}
}
}
}
}
public static function validateNextExtension($em, $link, $extension, $portB1){
$nextExtension = $em->getRepository('App\Entity\LinkExtension')->findOneBy(["link"=>$link, "sequenceNo"=>$extension->getSequenceNo()+1]);
$nextExtA = $nextExtension->getExtremityA();
$nextPorts = [];
$nextPortsTemp = $nextExtA->getExtensionOrder();
foreach ($nextPortsTemp as $value) {
$nextPorts[] = $value->getPort();
}
// $nextPorts = $nextExtA->getPorts();
$nextInterfaceSpecific = $nextPorts[0]->getInterfaceSpecific();
$nextInterfaceGeneric = $nextInterfaceSpecific->getInterfaceGeneric();
$nextEquipment = $nextInterfaceSpecific->getEquipmentSpecific();
$currentInterfaceSpecific = $portB1->getInterfaceSpecific();
$currentEquipment = $currentInterfaceSpecific->getEquipmentSpecific();
//check if it's same as current modified link ext
if ($currentEquipment->getId() != $nextEquipment->getId()) {
//if false, set the link and las link extension as INVALID
$nextExtension->setIsValid(false);
if ($nextExtension->getError()) {
$nextExtension->setError($nextExtension->getError() . "," . "EquipmentA");
}
else {
$nextExtension->setError("EquipmentA");
}
$em->persist($nextExtension);
}
else {
$errMsg = $nextExtension->getError();
$errMsg = str_replace("EquipmentA", "", $errMsg);
$nextExtension->setError($errMsg);
if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
$nextExtension->setIsValid(false);
}
else {
$nextExtension->setIsValid(true);
$nextExtension->setError(null);
}
$em->persist($nextExtension);
//else get the next extension's extremity B's interface
//check if it's 1:1
if ($nextInterfaceGeneric->getTypeInterconnection()->getTitle() == '1-1') {
// if true, check ports are the same
//if true, DO NOTHING
//else set the link and las link extension as INVALID
foreach ($nextPorts as $nextPort) {
if ($nextPort->getId() != $portB1->getId()) {
$nextExtension->setIsValid(false);
if ($nextExtension->getError()) {
$nextExtension->setError($nextExtension->getError() . "," . "PortA");
}
else {
$nextExtension->setError("PortA");
}
$em->persist($nextExtension);
}
else {
$errMsg = str_replace("PortA", "", $errMsg);
$nextExtension->setError($errMsg);
if (!$errMsg && (strpos($errMsg, 'EquipmentB') !== false || strpos($errMsg, 'PortB') !== false)) {
$nextExtension->setIsValid(false);
}
else {
$nextExtension->setIsValid(true);
$nextExtension->setError(null);
}
$em->persist($nextExtension);
}
}
}
}
}
}