<?php
namespace App\Controller;
use Psr\Log\LoggerInterface;
use App\Entity\Site;
use App\Entity\Room;
use App\Entity\Rack;
use App\Entity\RackFace;
use App\Entity\EquipmentSpecific;
use App\Entity\EquipmentGeneric;
use App\Entity\InterfaceSpecific;
use App\Entity\Link;
use App\Entity\LinkExtension;
use App\Entity\Port;
use App\Entity\Trunk;
use App\Entity\TrunkCableFiber;
use App\Entity\TrunkExtension;
use App\Entity\Slot;
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\Pagerfanta;
// use Pagerfanta\Adapter\DoctrineORMAdapter;
use Symfony\Contracts\Translation\TranslatorInterface;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\IsGranted;
class EquipmentSpecificController extends AbstractController
{
/**
* @Route("/equipment/specific/create", name="equipment_specific_create")
*/
public function createAction(Request $request, TranslatorInterface $translator)
{
$user = $this->getUser();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
// var_dump($request);
$em = $this->getDoctrine()->getManager();
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eq->setAlias($request->request->get('alias'));
$eq->setOwner($request->request->get('owner'));
$equipmentGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
$eq->setEquipmentGeneric($equipmentGeneric);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eq->setPositionRack($request->request->get('positionRack'));
$em->persist($eq);
$em->flush();
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
$em->flush();
}
}
return $this->redirectToRoute('equipment_specific_list');
// show form
} else {
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=>false, "isModulaire"=>false], ["title"=>"ASC"]);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$portExternes = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
return $this->render('equipment/specific_create.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Specific Equipment'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'portExternes' => $portExternes
]);
}
}
public function createInterfaceSpecific($em, $interfaceGeneric, &$interfaceSpecific, &$eq, &$portMpo){
// $interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$interfaceSpecific->setEquipmentSpecificMpo($eq);
$em->persist($interfaceSpecific);
$em->flush();
$alias = $this->getAlias($interfaceGeneric);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
$port->setPortMpo($portMpo);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
$em->persist($port);
// $em->flush();
}
// return $interfaceSpecific;
}
public function getAlias($interfaceGeneric){
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
return $alias;
}
/**
* @Route("/equipment/specific/create/ajax", name="ajax_equipment_specific_create")
*/
public function createAjaxAction(Request $request, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$eq->setOwner($_POST['owner']);
$equipmentGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
$eq->setEquipmentGeneric($equipmentGeneric);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($_POST['rack']));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($_POST['rackFace']));
$eq->setPositionRack($_POST['positionRack']);
$em->persist($eq);
$em->flush();
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
$em->persist($port);
$em->flush();
}
}
return $this->json(array('title' => $eq->getEquipmentSpecificName(), 'id' => $eq->getId()));
}
/**
* @Route("/equipment/specific/list", name="equipment_specific_list")
*/
public function listAction(Request $request, TranslatorInterface $translator)
{
$eqGenerics = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=> false, "isModulaire"=>false]);
$tempRack = $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneByTitle("Temp");
$eqModulaires = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["rack"=> $tempRack, "isModulaire" => true]);
$list = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["isModule"=>false, "isModulaire"=>false]);
// $em = $this->getDoctrine()->getManager();
// $queryBuilder = $em->createQueryBuilder()
// ->select('eqs')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModule = :isModule")
// ->andWhere("eqs.isModulaire = :isModulaire")
// ->setParameter("isModule", false)
// ->setParameter("isModulaire", false)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
// $adapter = new DoctrineORMAdapter($queryBuilder);
// $pagerfanta = new Pagerfanta($adapter);
// $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
// if ($pageLength == "Tout") {
// $qb = $em->createQueryBuilder()
// ->select('COUNT(eqs.id)')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModule = :isModule")
// ->andWhere("eqs.isModulaire = :isModulaire")
// ->setParameter("isModule", false)
// ->setParameter("isModulaire", false)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
//
// $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);
/*foreach ($list as $equipmentSpecific){
$inUse = 'No';
$interfacesSpecific = $equipmentSpecific->getInterfaceSpecific();
foreach ($interfacesSpecific as $interfaceSpecific){
$ports = $interfaceSpecific->getPort();
foreach ($ports as $port){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
if ($usedA || $usedB){
$inUse = 'Yes';
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if ($usedExt){
$inUse = 'Yes';
}
}
}
$equipmentSpecific->inUse = $inUse;
}*/
return $this->render('equipment/specific_list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Specific Equipment'),
'path_default' => 'equipment_specific_create',
'path_update' => 'equipment_specific_update',
'path_delete' => 'equipment_specific_delete',
'list' => $list,
'eqGenerics'=>$eqGenerics,
'eqModulaires'=>$eqModulaires,
// 'my_pager' => $pagerfanta,
// 'pageLength' => $pageLength,
]);
}
/**
* @Route("/equipment/specific/overview/list", name="equipment_specific_ovreview_list")
*/
public function overviewListAction(Request $request, TranslatorInterface $translator)
{
// $list = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findByIsModule(false);
$list = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(['isModule'=>false, 'isChassisModule'=>false]);
// $em = $this->getDoctrine()->getManager();
// $queryBuilder = $em->createQueryBuilder()
// ->select('eqs')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModule = :isModule")
// ->setParameter("isModule", false)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
// $adapter = new DoctrineORMAdapter($queryBuilder);
// $pagerfanta = new Pagerfanta($adapter);
// $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
// if ($pageLength == "Tout") {
// $qb = $em->createQueryBuilder()
// ->select('COUNT(eqs.id)')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModule = :isModule")
// ->setParameter("isModule", false)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
//
// $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);
return $this->render('overview/specific_list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Specific Equipment Overview'),
'path_view' => 'equipment_specific_overview',
'list' => $list,
// 'my_pager' => $pagerfanta,
// 'pageLength' => $pageLength,
]);
}
/**
* @Route("/equipment/specific/overview/item/{id}", name="equipment_specific_overview")
*/
public function overviewAction($id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$modules = array();
$eq = $em->getRepository(EquipmentSpecific::class)->find($id);
$isModulaire = false;
$portList = [];
//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;
}
}
if ($eq->isModulaire()) {
$isModulaire = true;
$modules = $eq->getModules();
$chassisModule = $eq->getChassisModule();
if($chassisModule){
$modules->add($chassisModule);
}
foreach ($modules as $module) {
$interfaces = $module->getInterfaceSpecific();
// var_dump($portsAll);
$tcfs = array();
foreach ($interfaces as $interface){
$ports = $interface->getPort();
foreach ($ports as $port){
if (in_array($port->getId(), $portsAll)) {
$port->nPort = 0;
$nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
if ($nPorts){
$nPorts = json_decode($nPorts);
if (in_array($port->getOrderNo(), $nPorts)){
$port->nPort = 1;
}
}
$port->used = 1;
$port->usedLinkID = $port->getLink()->getLinkId();
$port->usedLink_id = $port->getLink()->getId();;
$portList[] = $port;
}
}
}
}
}
else {
$interfaces = $eq->getInterfaceSpecific();
// var_dump($portsAll);
$tcfs = array();
foreach ($interfaces as $interface){
$ports = $interface->getPort();
foreach ($ports as $port){
if (in_array($port->getId(), $portsAll)) {
$port->nPort = 0;
$nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
if ($nPorts){
$nPorts = json_decode($nPorts);
if (in_array($port->getOrderNo(), $nPorts)){
$port->nPort = 1;
}
}
$port->used = 1;
$port->usedLinkID = $port->getLink()->getLinkId();
$port->usedLink_id = $port->getLink()->getId();;
$portList[] = $port;
}
// $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 = '';
// $extremityA = $port->getExtremities()[0];
//
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByextremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByextremityB($extremityA);
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->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();
// }
//
// $port->used = $used;
// $port->usedLinkID = $usedLinkID;
// $port->usedLink_id = $usedLink_id;
//
// $portList[] = $port;
}
}
}
return $this->render('overview/specific_view.html.twig', [
'page_title' => $translator->trans('Specific Equipment Overview'),
'box_title' => '',
'eq' => $eq,
'isModulaire'=> $isModulaire,
'portList' => $portList,
'modules' => $modules
]);
}
/**
* @Route("/equipment/usage/list", name="equipment_specific_usage_list")
*/
public function overviewUsageListAction(TranslatorInterface $translator)
{
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
return $this->render('overview/equipment_usage_list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Equipment Usage'),
'path_view' => 'equipment_specific_overview',
'sites' => $sites
]);
}
/**
* @Route("/equipment/usage", name="equipment_specific_usage", methods={"GET","POST"})
*/
public function overviewUsageAction(TranslatorInterface $translator)
{
set_time_limit(300);
$interface = null;
$eqMod = null;
$eqModules = null;
if (isset($_GET['id'])) {
$interface = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_GET['id']);
}
elseif (isset($_GET['modulaire_id'])) {
$eqMod = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_GET['modulaire_id']);
$eqModules = $eqMod->getModules();
$chassisModule = $eqMod->getChassisModule();
if ($chassisModule) {
$eqModules->add($chassisModule);
}
if (count($eqModules) > 0) {
$interface = $eqModules[0]->getInterfaceSpecific()[0];
}
// $interface = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_GET['id']);
}
elseif (isset($_POST['interface'])) {
$interface = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($_POST['interface']);
}
if ($interface == null) {
return $this->redirectToRoute('equipment_specific_usage_list');
}
$eq = $interface->getEquipmentSpecific();
if (isset($_POST['module'])) {
$eqMod = $eq->getParent();
if ($eqMod) {
$eqModules = $eqMod->getModules();
}
}
$rack = $interface->getEquipmentSpecific()->getRack();
$room = $interface->getEquipmentSpecific()->getRack()->getRoom();
$site = $interface->getEquipmentSpecific()->getRack()->getRoom()->getSite();
$sites = $this->getDoctrine()->getRepository('App\Entity\Site')->findBy([], ['title' => 'ASC']);
$rooms = $site->getRooms();
$racks = $room->getRacks();
$eqs = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(['rack' => $rack, "isModule"=>false], ['equipmentSpecificName' => 'ASC']);
$intefaces = $eq->getInterfaceSpecific();
$ports = $interface->getPort();
//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;
}
}
// var_dump($portsAll);
$tcfs = array();
foreach ($ports as $port){
if (in_array($port->getId(), $portsAll)) {
$port->nPort = 0;
$nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
if ($nPorts){
$nPorts = json_decode($nPorts);
if (in_array($port->getOrderNo(), $nPorts)){
$port->nPort = 1;
}
}
// $port->nPort = 0;
//
// $nPorts = $port->getInterfaceSpecific()->getInterfaceGeneric()->getNPorts();
// if ($nPorts){
// $nPorts = json_decode($nPorts);
// if (in_array($port->getOrderNo(), $nPorts)){
// $port->nPort = 1;
// }
// }
$linkExtA = null;
$linkExtB = null;
$extremities = array();
foreach ($port->getExtensionOrder() as $value) {
$extremities[] = $value->getExtremity();
}
foreach ($extremities as $extremityA) {
$linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
// $tcfs[] = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
// $tcfs[] = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$tcfA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$tcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
$trunkExtension = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
// $linkExtA = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $linkExtB = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
// var_dump($linkExtA);
// var_dump($linkExtB);
if ($linkExtA){
$link = $linkExtA->getLink();
// var_dump($link);
$port->linkID = $link->getLinkID();
$port->link_id = $link->getId();
//Modified on 13 juin 2019
// $port->usage = $link->getTypeUsage()->getTitle();
$port->usage = $link->getTypeUsage() ? $link->getTypeUsage()->getTitle() : "";
$trunk = $linkExtA->getTrunk();
if ($trunk){
$port->type_cable = $trunk->getTypeCable()->getTitle();
} else {
$port->type_cable = $linkExtA->getTypeCable()->getTitle();
}
$seqNumber = $linkExtA->getSequenceNo();
$nextSeqNumber = $seqNumber + 1;
$prevSeqNumber = $seqNumber - 1;
if ($seqNumber == 1){
$port->extA = '';
$port->extB = '';
}
if ($seqNumber == 2){
$port->extA = '';
// for extB next extension
$linkExtNext = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber, 'link' => $link]);
if ($linkExtNext){
$trunk = $linkExtNext->getTrunk();
if ($trunk){
$port->extB = $trunk->getTrunkID();
} else {
$port->extB = 'E1';
}
} else {
$port->extB = '';
}
}
if ($seqNumber > 2){
$linkExtPrevNoTrunk = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber, $link);
$linkExtPrev = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $prevSeqNumber, 'link' => $link]);
// for extA previous extension
$trunk = $linkExtPrev->getTrunk();
if ($trunk){
$port->extA = $trunk->getTrunkID();
} else {
$numberOfPrevExts = sizeof($linkExtPrevNoTrunk);
if ($numberOfPrevExts != 0 ){
$port->extA = 'E'.$numberOfPrevExts;
} else {
$port->extA = '';
}
}
// for extB current extension
$trunk = $linkExtA->getTrunk();
if ($trunk){
$port->extB = $trunk->getTrunkID();
} else {
$numberOfPrevExts = sizeof($linkExtPrevNoTrunk);
$port->extB = 'E'.$numberOfPrevExts;
}
}
}
// var_dump($port);
if ($linkExtB){
$link = $linkExtB->getLink();
$port->linkID = $link->getLinkID();
$port->link_id = $link->getId();
//Modified on 13 juin 2019
// $port->usage = $link->getTypeUsage()->getTitle();
$port->usage = $link->getTypeUsage() ? $link->getTypeUsage()->getTitle() : "";
$trunk = $linkExtB->getTrunk();
if ($trunk){
$port->type_cable = $trunk->getTypeCable()->getTitle();
} else {
$port->type_cable = $linkExtB->getTypeCable()->getTitle();
}
$seqNumber = $linkExtB->getSequenceNo();
$nextSeqNumber = $seqNumber + 1;
$prevSeqNumber = $seqNumber - 1;
$lastSeqNumber = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->getLastNextSequenceNo($link);
if ($seqNumber == 1){
$port->extA = '';
// for extB next extension
$linkExtNext = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber, 'link' => $link]);
if ($linkExtNext){
$trunk = $linkExtNext->getTrunk();
if ($trunk){
$port->extB = $trunk->getTrunkID();
} else {
$port->extB = 'E1';
}
} else {
$port->extB = '';
}
}
if ($seqNumber > 1 && $seqNumber < $lastSeqNumber){
$linkExtPrevNoTrunk = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber, $link);
// for extA current extension
$trunk = $linkExtB->getTrunk();
if ($trunk){
$port->extA = $trunk->getTrunkID();
} else {
$numberOfPrevExts = sizeof($linkExtPrevNoTrunk);
if ($numberOfPrevExts != 0 ){
$port->extA = 'E'.$numberOfPrevExts;
} else {
$port->extA = '';
}
}
// for extB next extension
$linkExtNext = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $nextSeqNumber, 'link' => $link]);
if ($linkExtNext){
$trunk = $linkExtNext->getTrunk();
if ($trunk){
$port->extB = $trunk->getTrunkID();
} else {
$port->extB = 'E'.$numberOfPrevExts;
}
} else {
$port->extB = '';
}
}
if ($seqNumber > 1 && $seqNumber == $lastSeqNumber){
$linkExtPrevNoTrunk = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findPrevNoTrunk($seqNumber, $link);
$linkExtPrev = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneBy(['sequenceNo' => $prevSeqNumber, 'link' => $link]);
// for extA current extension
$trunk = $linkExtB->getTrunk();
if ($trunk){
$port->extA = $trunk->getTrunkID();
} else {
$numberOfPrevExts = sizeof($linkExtPrevNoTrunk);
if ($numberOfPrevExts != 0 ){
$port->extA = 'E'.$numberOfPrevExts;
} else {
$port->extA = '';
}
}
// for extB no extension
$port->extB = '';
}
}
if (!$linkExtA && !$linkExtB) {
$port->linkID = '';
$port->link_id = '';
$port->type_cable = '';
$port->extA = '';
$port->extB = '';
$port->usage = '';
$port->nPort = 0;
}
if (($trunkExtension && $linkExtA) || ($trunkExtension && $linkExtB)) {
}
else if($trunkExtension) {
// var_dump("Got it");
$port->linkID = $port->getLink()->getLinkID();
$port->link_id = $port->getLink()->getId();
// $port->usage = $port->getLink()->getTypeUsage()->getTitle();
$port->usage = $port->getLink()->getTypeUsage() ? $port->getLink()->getTypeUsage()->getTitle() : "";
$port->type_cable = $trunkExtension->getTrunkCableFiber()->getTrunk()->getTypeCable()->getTitle();
$port->extA = $trunkExtension->getTrunkCableFiber()->getTrunk()->getTrunkID();
}
if ($tcfB && $linkExtB) {
}
else if($tcfB){
$port->linkID = $port->getLink()->getLinkID();
$port->link_id = $port->getLink()->getId();
// $port->usage = $port->getLink()->getTypeUsage()->getTitle();
$port->usage = $port->getLink()->getTypeUsage() ? $port->getLink()->getTypeUsage()->getTitle() : "";
$port->type_cable = $tcfB->getTrunk()->getTypeCable()->getTitle();
$port->extA = $tcfB->getTrunk()->getTrunkID();
}
// var_dump($trunkExtension);
if ($port->nPort == 1){
$port->linkID = '';
$port->link_id = '';
$port->extB = '';
$port->usage = '';
$port->extA = '';
$port->type_cable = '';
$usedTcfA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portA' => $port]);
$usedTcfB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneBy(['portB' => $port]);
$usedTExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneBy(['portB' => $port]);
if ($usedTcfA){
$port->extA = $usedTcfA->getTrunk()->getTrunkID();
$port->type_cable = $usedTcfA->getTrunk()->getTypeCable()->getTitle();
}
if ($usedTcfB){
$port->extA = $usedTcfB->getTrunk()->getTrunkID();
$port->type_cable = $usedTcfB->getTrunk()->getTypeCable()->getTitle();
}
if ($usedTExt){
$port->extA = $usedTExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
$port->type_cable = $usedTExt->getTrunkCableFiber()->getTrunk()->getTypeCable()->getTitle();
}
}
}
// var_dump($port->nPort);
else{
$tcfATemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
if($tcfATemp){
$port->extB = $tcfATemp->getTrunk()->getTrunkID();
}
else{
$tcfBTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
if($tcfBTemp){
$port->extB = $tcfBTemp->getTrunk()->getTrunkID();
}
else {
$tcfExtTemp = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if($tcfExtTemp){
$port->extB = $tcfExtTemp->getTrunkCableFiber()->getTrunk()->getTrunkID();
}
}
}
}
}
// var_dump($tcfs);
return $this->render('overview/equipment_usage.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Equipment Usage'),
'path_view' => 'equipment_specific_overview',
'sites' => $sites,
'rooms' => $rooms,
'racks' => $racks,
'eqs' => $eqs,
'site' => $site,
'room' => $room,
'rack' => $rack,
'eq' => $eq,
'eqMod' => $eqMod,
'eqModules' => $eqModules,
'interface' => $interface,
'interfaces' => $intefaces,
'ports' => $ports
]);
}
/**
* @Route("/equipment/specific/edit/{id}", name="equipment_specific_update")
*/
public function updateAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
$em = $this->getDoctrine()->getManager();
$eq = $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
// find in usage
/*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
if ($specific){
$eq->setTitle($request->request->get('title'));
$em->persist($eq);
$em->flush();
$error = array('error' => 'title');
return $this->redirectToRoute('equipment_generic_list', $error);
}*/
$eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eq->setAlias($request->request->get('alias'));
$eq->setOwner($request->request->get('owner'));
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eq->setPositionRack($request->request->get('positionRack'));
$em->persist($eq);
$em->flush();
return $this->redirectToRoute('equipment_specific_list');
} else {
$em = $this->getDoctrine()->getManager();
$eq = $em->getRepository(EquipmentSpecific::class)->find($id);
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findAll();
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$portExternes = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
$portList = [];
$interfaces = $eq->getInterfaceSpecific();
foreach ($interfaces as $interface){
$ports = $interface->getPort();
$typeLnk = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
foreach ($ports as $port){
$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;
$trunk = 0;
$connected = 0;
$usedLinkID = '';
$usedLink_id = '';
$usedALink = null;
$usedBLink = null;
$usedTrunkId = 0;
$usedTrunk_Id = 0;
$mpo = 0;
$mpoPorts = null;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
$tcfA = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
$tcfB = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
$tExt = $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
if($tcfA || $tcfB || $tExt){
$trunk = 1;
if ($tcfA ) {
$usedTrunkId = $tcfA->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfA->getTrunk()->getId();
}elseif ($tcfB) {
$usedTrunkId = $tcfB->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfB->getTrunk()->getId();
}
else {
$usedTrunkId = $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
$usedTrunk_Id = $tExt->getTrunkCableFiber()->getTrunk()->getId();
}
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->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 ($typeLnk == "Port Externe") {
if ($port->getPortExterne()) {
$connected = 1;
}
else {
$connected = 0;
}
}
if ($connected == 1 && $port->getInterfaceSpecificPortExterne() != null) {
$ifPE = $port->getInterfaceSpecificPortExterne();
$mpo = 1;
$mpoPorts = $this->getPortDetails($ifPE);
}
$port->trunk = $trunk;
$port->used = $used;
$port->connected = $connected;
$port->usedLinkID = $usedLinkID;
$port->usedLink_id = $usedLink_id;
$port->usedTrunkId = $usedTrunkId;
$port->usedTrunk_Id = $usedTrunk_Id;
$port->mpo = $mpo;
$port->mpoPorts = $mpoPorts;
$portList[] = $port;
}
}
return $this->render('equipment/specific_edit.html.twig', [
'action' => 'process',
'page_title' => $translator->trans('Specific Equipment'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'path_process' => 'equipment_specific_update_process',
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces,
'eq' => $eq,
'portList' => $portList,
'portExternes' => $portExternes
]);
}
}
public function getPortDetails($interface){
$portList = array();
$ports = $interface->getPort();
$typeLnk = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
foreach ($ports as $port){
$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;
$trunk = 0;
$connected = 0;
$usedLinkID = '';
$usedLink_id = '';
$usedALink = null;
$usedBLink = null;
$usedTrunkId = 0;
$usedTrunk_Id = 0;
$mpo = 0;
$mpoPorts = null;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
$tcfA = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
$tcfB = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
$tExt = $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
if($tcfA || $tcfB || $tExt){
$trunk = 1;
if ($tcfA ) {
$usedTrunkId = $tcfA->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfA->getTrunk()->getId();
}elseif ($tcfB) {
$usedTrunkId = $tcfB->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfB->getTrunk()->getId();
}
else {
$usedTrunkId = $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
$usedTrunk_Id = $tExt->getTrunkCableFiber()->getTrunk()->getId();
}
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->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 ($typeLnk == "Port Externe") {
if ($port->getPortExterne()) {
$connected = 1;
}
else {
$connected = 0;
}
}
if ($connected == 1 && $port->getInterfaceSpecificPortExterne() != null) {
$ifPE = $port->getInterfaceSpecificPortExterne();
$mpo = 1;
$mpoPorts = $this->getPortDetails($em, $ifPE);
}
$port->trunk = $trunk;
$port->used = $used;
$port->connected = $connected;
$port->usedLinkID = $usedLinkID;
$port->usedLink_id = $usedLink_id;
$port->usedTrunkId = $usedTrunkId;
$port->usedTrunk_Id = $usedTrunk_Id;
$port->mpo = $mpo;
$portList[] = $port;
}
return $portList;
}
/**
* @Route("/equipment/specific/port-externe/edit", name="equipment_specific_port_externe_edit")
*/
public function updatePortExterneAction(Request $request, TranslatorInterface $translator)
{
$idTemp = $_POST["id"];
$em = $this->getDoctrine()->getManager();
$interfaceSpecific = $em->getRepository(InterfaceSpecific::class)->find($idTemp);
$ports = $interfaceSpecific->getPort();
foreach ($ports as $port) {
$idPortExt = $_POST["portExterne"][$port->getId()];
$interfaceSpecificPortExterne = $port->getInterfaceSpecificPortExterne();
if ($idPortExt) {
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($idPortExt);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($port->getPortExterne() == null) {
$port->setPortExterne($pe);
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $interfaceSpecific->getEquipmentSpecific(), $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
elseif ($interfaceGenericPortExterne == null && $interfaceSpecificPortExterne == null) {
$port->setPortExterne($pe);
} elseif ($interfaceGenericPortExterne != null && $interfaceSpecificPortExterne == null) {
//create interface spécific and attach it to the port
$port->setPortExterne($pe);
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $interfaceSpecific->getEquipmentSpecific(), $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
elseif($interfaceSpecificPortExterne != null){
$inUse = 0;
foreach ($interfaceSpecificPortExterne->getPort() as $pMpo){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
if ($usedA || $usedB){
$inUse = 1;
break;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
if ($usedExt){
$inUse = 1;
break;
}
$usedALink = null;
$usedBLink = null;
if (count($pMpo->getExtensionOrder()) > 0) {
$extremityA = $pMpo->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
if ($usedALink || $usedBLink){
$inUse = 1;
break;
}
}
if ($inUse == 0){
// $sql = "delete from port where port_mpo_id = " . $interfaceSpecificPortExterne->getId();
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
// $em->remove($interfaceSpecificPortExterne);
// $em->flush();
//create interface spécific and attach it to the port
$port->setPortExterne($pe);
if ($interfaceGenericPortExterne != null) {
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $interfaceSpecific->getEquipmentSpecific(), $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
else {
$port->setInterfaceSpecificPortExterne(null);
}
} else {
$this->addFlash(
'error',
'usage'
);
}
}
}
else {
$port->setPortExterne(null);
}
$em->persist($port);
}
$em->flush();
if ($_POST["ref"] == "module") {
return $this->redirectToRoute('equipment_specific_module_update', ["id"=>$_POST["moduleId"]]);
}
else {
return $this->redirectToRoute('equipment_specific_update', ["id"=>$_POST["eqId"]]);
}
}
/**
* @IsGranted("ROLE_CRUD")
* @Route("/equipment/specific/delete/{id}", name="equipment_specific_delete")
*/
public function deleteAction(Request $request, $id, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$equipmentSpecific = $em->getRepository(EquipmentSpecific::class)->find($id);
$inUse = 0;
if ($equipmentSpecific->isModulaire()) {
$modules = $equipmentSpecific->getModules();
$chassisModule = $equipmentSpecific->getChassisModule();
if ($chassisModule) {
$modules->add($chassisModule);
}
foreach ($modules as $value) {
$interfacesSpecific = $value->getInterfaceSpecific();
foreach ($interfacesSpecific as $interfaceSpecific){
$ports = $interfaceSpecific->getPort();
foreach ($ports as $port){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
if ($usedA || $usedB){
$inUse = 1;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if ($usedExt){
$inUse = 1;
}
$usedALink = null;
$usedBLink = null;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
if ($usedALink || $usedBLink){
$inUse = 1;
}
if ($port->getInterfaceSpecificPortExterne()) {
foreach ($port->getInterfaceSpecificPortExterne()->getPort() as $pMpo){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
if ($usedA || $usedB){
$inUse = 1;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
if ($usedExt){
$inUse = 1;
}
$usedALink = null;
$usedBLink = null;
if (count($pMpo->getExtensionOrder()) > 0) {
$extremityA = $pMpo->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($pMpo);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
if ($usedALink || $usedBLink){
$inUse = 1;
}
if ($inUse) {
break;
}
}
}
if ($inUse) {
break;
}
}
if ($inUse) {
break;
}
}
if ($inUse) {
break;
}
}
}
else {
$interfacesSpecific = $equipmentSpecific->getInterfaceSpecific();
foreach ($interfacesSpecific as $interfaceSpecific){
$ports = $interfaceSpecific->getPort();
foreach ($ports as $port){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
if ($usedA || $usedB){
$inUse = 1;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if ($usedExt){
$inUse = 1;
}
$usedALink = null;
$usedBLink = null;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
if ($usedALink || $usedBLink){
$inUse = 1;
}
if ($port->getInterfaceSpecificPortExterne()) {
foreach ($port->getInterfaceSpecificPortExterne()->getPort() as $pMpo){
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($pMpo);
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($pMpo);
if ($usedA || $usedB){
$inUse = 1;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($pMpo);
if ($usedExt){
$inUse = 1;
}
$usedALink = null;
$usedBLink = null;
if (count($pMpo->getExtensionOrder()) > 0) {
$extremityA = $pMpo->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($pMpo);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
if ($usedALink || $usedBLink){
$inUse = 1;
}
if ($inUse) {
break;
}
}
}
if ($inUse) {
break;
}
}
if ($inUse) {
break;
}
}
}
$error = [];
if ($inUse == 0){
$sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$conn = $em->getConnection();
$stmt = $conn->prepare($sql);
$stmt->execute();
$sql1 = "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " . $equipmentSpecific->getId();
$conn = $em->getConnection();
$stmt = $conn->prepare($sql1);
$stmt->execute();
$sql = "update equipment_specific set chassis_module_id=null where id = " . $equipmentSpecific->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$stmt = $conn->prepare($sql);
$stmt->execute();
$em->remove($equipmentSpecific);
$em->flush();
$error = array('error' => null);
} else {
$error = array('error' => 'usage');
}
if ($error['error']) {
$this->addFlash(
'error',
'usage'
);
}
if ($request->query->get('ref') == 'module') {
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$equipmentSpecific->getParent()->getId()]);
}
elseif ($request->query->get('ref') == 'modulaire') {
return $this->redirectToRoute('equipment_specific_modulaire_list', ['id'=>$id]); }
else {
// return $this->redirect($request->headers->get('referer'));
return $this->redirectToRoute('equipment_specific_list');
}
}
/**
* @Route("/equipment/specific/modulaire/create", name="equipment_specific_modulaire_create")
*/
public function createModulaireAction(Request $request, TranslatorInterface $translator)
{
$user = $this->getUser();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
// var_dump($request->request->all());
$em = $this->getDoctrine()->getManager();
$eqParent = new EquipmentSpecific();
$eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eqParent->setAlias($request->request->get('alias'));
$eqParent->setOwner($request->request->get('owner'));
$equipmentGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
$eqParent->setEquipmentGeneric($equipmentGeneric);
$eqParent->setIsModulaire(true);
$rack = $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack'));
$eqParent->setRack($rack);
$eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eqParent->setPositionRack($request->request->get('positionRack'));
//create and attach slots to modulaire equipments
for ($i=0; $i < $equipmentGeneric->getNumberOfSlots(); $i++) {
$slot = new Slot();
$slot->setSlotNumber($i+1);
$slot->setModulaire($eqParent);
$em->persist($slot);
}
$em->persist($eqParent);
$em->flush();
//module chassis
$chassisModule = $equipmentGeneric->getChassisModule();
if($chassisModule){
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName("CHASSIS");
$eq->setAlias("CHASSIS");
$eq->setEquipmentGeneric($chassisModule);
$eq->setChassisParent($eqParent);
$eq->setRack($rack);
$eq->setIsChassisModule(true);
$eqParent->setChassisModule($eq);
$em->persist($eqParent);
// $em->persist($eq);
$em->flush();
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($chassisModule);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
$em->flush();
}
// create ports
// $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
// for ($j=1; $j<=$numberOfPorts; $j++){
//
// $port = new Port();
// $port->setInterfaceSpecific($interfaceSpecific);
// $port->setOrderNo($j);
//
// $em->persist($port);
// $em->flush();
//
// }
}
}
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
} else {
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findByIsModulaire(true);
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
return $this->render('equipment/specific_modulaire_create.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Equipement Spécifique Modulaire'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'eqGeneric' => $eqGeneric,
'racks' => $racks,
'rackFaces' => $rackFaces
]);
}
}
/**
* @Route("/equipment/specific/modulaire/create_temp", name="equipment_specific_modulaire_create_temp")
*/
public function createModulaireTempAction(Request $request, TranslatorInterface $translator)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
// var_dump($request->request->all());
$eqParent = new EquipmentSpecific();
$eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eqParent->setAlias($request->request->get('alias'));
$eqParent->setOwner($request->request->get('owner'));
$equipmentGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
$eqParent->setEquipmentGeneric($equipmentGeneric);
$eqParent->setIsModulaire(true);
$eqParent->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
$eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eqParent->setPositionRack($request->request->get('positionRack'));
//create and attach slots to modulaire equipments
for ($i=0; $i < $equipmentGeneric->getNumberOfSlots(); $i++) {
$slot = new Slot();
$slot->setSlotNumber($i+1);
$slot->setModulaire($eqParent);
$em->persist($slot);
}
$em->persist($eqParent);
$em->flush();
//module chassis
$chassisModule = $equipmentGeneric->getChassisModule();
if($chassisModule){
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName("CHASSIS");
$eq->setAlias("CHASSIS");
$eq->setEquipmentGeneric($chassisModule);
$eq->setChassisParent($eqParent);
$eq->setRack($rack);
$eq->setIsChassisModule(true);
$eqParent->setChassisModule($eq);
$em->persist($eqParent);
// $em->persist($eq);
$em->flush();
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($chassisModule);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
$em->flush();
}
}
}
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
} else {
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findByIsModulaire(true);
$site = $this->getDoctrine()->getRepository('App\Entity\Site')->findOneByTitle("Temp");
if (is_null($site)) {
$site = new Site();
$site->setTitle("Temp");
$em->persist($site);
$em->flush();
}
$room = $this->getDoctrine()->getRepository('App\Entity\Room')->findOneBy(["site"=>$site, "title"=>"Temp"]);
if (is_null($room)) {
$room = new Room();
$room->setTitle("Temp");
$room->setSite($site);
$em->persist($room);
$em->flush();
}
$rack = $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneBy(["room"=>$room, "title"=>"Temp"]);
if (is_null($rack)) {
$rack = new Rack();
$rack->setTitle("Temp");
$rack->setNumberOfUnits(80);
$rack->setRoom($room);
$em->persist($rack);
$em->flush();
}
$rackFace = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneByTitle("Front");
return $this->render('equipment/specific_modulaire_create_temp.html.twig', [
'action' => 'insert',
'page_title' => $translator->trans('Equipement Spécifique Modulaire Temporaire'),
'box_title' => '<i class="fa fa-plus-circle fa-fw"></i> '.$translator->trans('Add new'),
'eqGeneric' => $eqGeneric,
'tempRack' => $rack->getId(),
'tempRackFace' => $rackFace->getId(),
'tempPositionRack' => 1
]);
}
}
/**
* @Route("/equipment/specific/modulaire/list", name="equipment_specific_modulaire_list")
*/
public function listModulaireAction(Request $request, TranslatorInterface $translator)
{
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$eqGenerics = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findBy(["isModule"=> false, "isModulaire"=>false]);
$tempRack = $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneByTitle("Temp");
$eqModulaires = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findBy(["rack"=> $tempRack, "isModulaire" => true]);
$list = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findByIsModulaire(true);
// $em = $this->getDoctrine()->getManager();
// $queryBuilder = $em->createQueryBuilder()
// ->select('eqs')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModulaire = :isModulaire")
// ->setParameter("isModulaire", true)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
// $adapter = new DoctrineORMAdapter($queryBuilder);
// $pagerfanta = new Pagerfanta($adapter);
// $pageLength = $request->query->get("pageLength", $this->getParameter("eqs.maxPerPage"));
// if ($pageLength == "Tout") {
// $qb = $em->createQueryBuilder()
// ->select('COUNT(eqs.id)')
// ->from('App\Entity\EquipmentSpecific', 'eqs')
// ->where("eqs.isModulaire = :isModulaire")
// ->setParameter("isModulaire", true)
// ->orderBy("eqs.equipmentSpecificName", "ASC");
//
// $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);
return $this->render('equipment/specific_modulaire_list.html.twig', [
'action' => 'list',
'page_title' => $translator->trans('Specific Equipment') . " - Modulaire",
'path_default' => 'equipment_specific_modulaire_create',
'path_update' => 'equipment_specific_modulaire_update',
'path_delete' => 'equipment_specific_delete',
'racks' => $racks,
'rackFaces' => $rackFaces,
"eqGenerics" => $eqGenerics,
"eqModulaires" => $eqModulaires,
'list' => $list,
// 'my_pager' => $pagerfanta,
// 'pageLength' => $pageLength,
]);
}
/**
* @Route("/equipment/specific/modulaire/edit/{id}", name="equipment_specific_modulaire_update")
*/
public function updateModulaireAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
$em = $this->getDoctrine()->getManager();
$eq = $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
// find in usage
/*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
if ($specific){
$eq->setTitle($request->request->get('title'));
$em->persist($eq);
$em->flush();
$error = array('error' => 'title');
return $this->redirectToRoute('equipment_generic_list', $error);
}*/
$eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eq->setAlias($request->request->get('alias'));
$eq->setOwner($request->request->get('owner'));
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eq->setPositionRack($request->request->get('positionRack'));
foreach ($eq->getModules() as $value) {
$value->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
$em->persist($value);
}
$em->persist($eq);
$em->flush();
return $this->redirectToRoute('equipment_specific_modulaire_list');
} else {
$em = $this->getDoctrine()->getManager();
$eq = $em->getRepository(EquipmentSpecific::class)->find($id);
$moduleGenerics = $eq->getEquipmentGeneric()->getModules();
$racks = $this->getDoctrine()->getRepository('App\Entity\Rack')->findAll();
$rackFaces = $this->getDoctrine()->getRepository('App\Entity\RackFace')->findAll();
$modules = $eq->getModules();
$slots = $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($id);
return $this->render('equipment/specific_modulaire_edit.html.twig', [
'action' => 'process',
'page_title' => $translator->trans('Specific Equipment') . " - Modulaire",
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'path_process' => 'equipment_specific_update_process',
'eqGeneric' => $moduleGenerics,
'racks' => $racks,
'rackFaces' => $rackFaces,
'eq' => $eq,
'modules' => $modules,
'slots' => $slots
]);
}
}
/**
* @Route("/equipment/specific/module/create/{id}", name="equipment_specific_module_create")
*/
public function createModuleAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
// var_dump($request->request->all());
$em = $this->getDoctrine()->getManager();
$eqParent = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
$eq->setEquipmentGeneric($moduleGeneric);
foreach ($_POST['slots'] as $key => $value) {
$slot = $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
$slot->setModule($eq);
$em->persist($slot);
}
$eq->setIsModule(true);
$eq->setParent($eqParent);
//
// $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
// $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
// $eq->setPositionRack($request->request->get('positionRack'));
$em->persist($eq);
$em->flush();
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
$em->flush();
}
// create ports
// $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
// for ($j=1; $j<=$numberOfPorts; $j++){
//
// $port = new Port();
// $port->setInterfaceSpecific($interfaceSpecific);
// $port->setOrderNo($j);
//
// $em->persist($port);
// $em->flush();
//
// }
}
// var_dump($request->request->all());
// for ($i=0; $i < $equipmentGeneric->getNumberOfModules() ; $i++) {
// $eq = new EquipmentSpecific();
//
// $eq->setEquipmentSpecificName($_POST['moduleName'][$i]);
// $eq->setAlias($_POST['moduleAlias'][$i]);
//
// $moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['moduleGeneric'][$i]);
//
// $eq->setEquipmentGeneric($moduleGeneric);
// $slots = implode($_POST['slots'][$i], '/');
// $eq->setSlots($slots);
// $eq->setIsModule(true);
// $eq->setParent($eqParent);
// //
// // $eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack')));
// // $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
// // $eq->setPositionRack($request->request->get('positionRack'));
//
// $em->persist($eq);
// $em->flush();
//
// // create specific interfaces
// $interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
// foreach ($interfacesGeneric as $interfaceGeneric){
//
// $interfaceSpecific = new InterfaceSpecific();
// $interfaceSpecific->setEquipmentSpecific($eq);
// $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
//
// $em->persist($interfaceSpecific);
// $em->flush();
//
// // create ports
// $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
// for ($j=1; $j<=$numberOfPorts; $j++){
//
// $port = new Port();
// $port->setInterfaceSpecific($interfaceSpecific);
// $port->setOrderNo($j);
//
// $em->persist($port);
// $em->flush();
//
// }
//
// }
// }
// create specific interfaces
// $interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($equipmentGeneric);
// foreach ($interfacesGeneric as $interfaceGeneric){
//
// $interfaceSpecific = new InterfaceSpecific();
// $interfaceSpecific->setEquipmentSpecific($eq);
// $interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
//
// $em->persist($interfaceSpecific);
// $em->flush();
//
// // create ports
// $numberOfPorts = $interfaceGeneric->getNumberOfPorts();
// for ($i=1; $i<=$numberOfPorts; $i++){
//
// $port = new Port();
// $port->setInterfaceSpecific($interfaceSpecific);
// $port->setOrderNo($i);
//
// $em->persist($port);
// $em->flush();
//
// }
//
// }
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
}
}
/**
* @Route("/equipment/specific/module/edit/{id}", name="equipment_specific_module_update")
*/
public function updateModuleAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
$chassisModule = $request->query->get("chassisModule");
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
$em = $this->getDoctrine()->getManager();
$eq = $em->getRepository(EquipmentSpecific::class)->find($request->request->get('id'));
// find in usage
/*$specific = $em->getRepository(EquipmentSpecific::class)->findByEquipmentGeneric($eq);
if ($specific){
$eq->setTitle($request->request->get('title'));
$em->persist($eq);
$em->flush();
$error = array('error' => 'title');
return $this->redirectToRoute('equipment_generic_list', $error);
}*/
$eq->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eq->setAlias($request->request->get('alias'));
foreach ($eq->getSlotModule() as $slot) {
$slot->setModule(null);
$em->persist($slot);
}
foreach ($_POST['slots'] as $key => $value) {
$slot = $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
$slot->setModule($eq);
$em->persist($slot);
}
$em->persist($eq);
$em->flush();
return $this->redirectToRoute('equipment_specific_modulaire_update', ["id" => $eq->getParent()->getId()]);
} else {
$em = $this->getDoctrine()->getManager();
$eq = null;
if (!$id) {
$eq = $em->getRepository(EquipmentSpecific::class)->find($request->request->get("id"));
}
else {
$eq = $em->getRepository(EquipmentSpecific::class)->find($id);
}
$portExternes = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findAll();
$slots = null;
$isChassisModule = 1;
if ($chassisModule != 1) {
$slots = $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eq->getParent()->getId());
$isChassisModule = 0;
}
$portList = [];
$interfaces = $eq->getInterfaceSpecific();
foreach ($interfaces as $interface){
$ports = $interface->getPort();
$typeLnk = $interface->getInterfaceGeneric()->getTypeLink()->getTitle();
foreach ($ports as $port){
$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;
$trunk = 0;
$connected = 0;
$usedLinkID = '';
$usedLink_id = '';
$usedALink = null;
$usedBLink = null;
$usedTrunkId = 0;
$usedTrunk_Id = 0;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
$tcfA = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortA($port);
$tcfB = $this->getDoctrine()->getRepository(TrunkCableFiber::class)->findOneByPortB($port);
$tExt = $this->getDoctrine()->getRepository(TrunkExtension::class)->findOneByPortB($port);
if($tcfA || $tcfB || $tExt){
$trunk = 1;
if ($tcfA ) {
$usedTrunkId = $tcfA->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfA->getTrunk()->getId();
}elseif ($tcfB) {
$usedTrunkId = $tcfB->getTrunk()->getTrunkID();
$usedTrunk_Id = $tcfB->getTrunk()->getId();
}
else {
$usedTrunkId = $tExt->getTrunkCableFiber()->getTrunk()->getTrunkID();
$usedTrunk_Id = $tExt->getTrunkCableFiber()->getTrunk()->getId();
}
}
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->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 ($typeLnk == "Port Externe") {
if ($port->getPortExterne()) {
$connected = 1;
}
else {
$connected = 0;
}
}
$port->trunk = $trunk;
$port->used = $used;
$port->connected = $connected;
$port->usedLinkID = $usedLinkID;
$port->usedLink_id = $usedLink_id;
$port->usedTrunkId = $usedTrunkId;
$port->usedTrunk_Id = $usedTrunk_Id;
$portList[] = $port;
}
}
return $this->render('equipment/specific_module_edit.html.twig', [
'action' => 'process',
'page_title' => $translator->trans('Specific Equipment'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Edit'),
'path_process' => 'equipment_specific_update_process',
'eq' => $eq,
'portList' => $portList,
"slots" => $slots,
'portExternes' => $portExternes,
'isChassisModule'=> $isChassisModule
]);
}
}
/**
* @Route("/equipment/specific/modulaire/duplicate", name="equipment_specific_modulaire_duplicate")
*/
public function duplicateModulaireAction(Request $request, TranslatorInterface $translator)
{
$em = $this->getDoctrine()->getManager();
$eqParent = new EquipmentSpecific();
$eqParent->setEquipmentSpecificName($request->request->get('equipmentSpecificName'));
$eqParent->setAlias($request->request->get('alias'));
$eqParent->setOwner($request->request->get('owner'));
$equipmentGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($request->request->get('equipmentGeneric'));
$eqParent->setEquipmentGeneric($equipmentGeneric);
$eqParent->setIsModulaire(true);
$rack = $this->getDoctrine()->getRepository('App\Entity\Rack')->findOneById($request->request->get('rack'));
$eqParent->setRack($rack);
$eqParent->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
$eqParent->setPositionRack($request->request->get('positionRack'));
//create and attach slots to modulaire equipments
for ($i=0; $i < $equipmentGeneric->getNumberOfSlots(); $i++) {
$slot = new Slot();
$slot->setSlotNumber($i+1);
$slot->setModulaire($eqParent);
$em->persist($slot);
}
$em->persist($eqParent);
$em->flush();
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->findOneById($request->request->get('idEquipment'));
//get all the modules associated with old equipment
$modulesOld = $eqOld->getModules();
$chassisModule = $eqOld->getChassisModule();
if ($chassisModule) {
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($chassisModule->getEquipmentSpecificName());
$eq->setAlias($chassisModule->getAlias());
$moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->find($chassisModule->getEquipmentGeneric());
$eq->setEquipmentGeneric($moduleGeneric);
$eq->setIsChassisModule(true);
$eqParent->setChassisModule($eq);
$eq->setRack($rack);
$em->persist($eqParent);
$em->flush();
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($j=1; $j<=$numberOfPorts; $j++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($j);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$j]);
}
$em->persist($port);
$em->flush();
}
}
}
foreach ($modulesOld as $moduleOld) {
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($moduleOld->getEquipmentSpecificName());
$eq->setAlias($moduleOld->getAlias());
$moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->find($moduleOld->getEquipmentGeneric());
$eq->setEquipmentGeneric($moduleGeneric);
foreach ($moduleOld->getSlotModule() as $key => $value) {
$slot = $this->getDoctrine()->getRepository('App\Entity\Slot')->findOneBy(["modulaire"=>$eqParent, "slotNumber"=>$value->getSlotNumber()]);
$slot->setModule($eq);
$em->persist($slot);
}
$eq->setIsModule(true);
$eq->setParent($eqParent);
//
// $eq->setRack($rack);
// $eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\RackFace')->findOneById($request->request->get('rackFace')));
// $eq->setPositionRack($request->request->get('positionRack'));
$em->persist($eq);
$em->flush();
$eq->setRack($rack);
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
$em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
for ($j=1; $j<=$numberOfPorts; $j++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($j);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$j]);
}
$em->persist($port);
$em->flush();
}
}
}
return $this->redirectToRoute('equipment_specific_modulaire_list');
}
/**
* @Route("/equipment/specific/module/substitute/{id}", name="equipment_specific_module_substitute")
*/
public function substituteModuleAction(Request $request, LoggerInterface $logger, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
// process form
if ($request->request->has('equipmentSpecificName') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
// get all the used ports of the old equipment
$usedPorts = $this->getUsedPortsEquipment($eqOld);
$eqParent = $eqOld->getParent();
$interfaceSpecificOld = $_POST['interfaces'];
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$moduleGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
$eq->setEquipmentGeneric($moduleGeneric);
foreach ($_POST['slots'] as $key => $value) {
$slot = $this->getDoctrine()->getRepository('App\Entity\Slot')->find($value);
$slot->setModule($eq);
$em->persist($slot);
}
$eq->setIsModule(true);
$eq->setParent($eqParent);
$em->persist($eq);
// $em->flush();
$eq->setRack($eqParent->getRack());
$interfaceGenericPortOrderNoArray = array();
if (isset($_POST['port'])) {
foreach ($_POST['port'] as $port => $value) {
foreach ($value as $key => $value1) {
$portOrderNoArray = array("orderNo"=> explode("__", $value1)[1], "port"=>$port);
$interfaceGenericPortOrderNoArray[explode("__", $value1)[0]][] = $portOrderNoArray;
}
}
// var_dump($interfaceGenericPortOrderNoArray);
}
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($moduleGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$orderPortArray = array();
$portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
if ($portOrderNoArray) {
foreach ($portOrderNoArray as $value) {
$orderPortArray[$value['orderNo']][] = $value['port'];
}
}
// var_dump($orderPortArray);
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
// $em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$interfaceGenericNew = array();
foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
foreach ($value as $keyNew => $intGenNew) {
if ($intGenNew == $interfaceGeneric->getId()) {
$interfaceGenericNew[$interfaceSpecificId] = $value;
}
}
}
// var_dump($interfaceGenericNew);
$portsOld = array();
if (count($interfaceGenericNew) == 1) {
$interfaceSpecificId = array_keys($interfaceGenericNew)[0];
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
$typeLnkSpc = $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
$index = 0;
foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
if ($value && $value != $interfaceGeneric->getId()) {
$intGenTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
$numPortTemp = $intGenTemp->getNumberOfPorts();
$typeLnkGen = $intGenTemp->getTypeLink()->getId();
if ($typeLnkSpc == $typeLnkGen) {
$index += $numPortTemp;
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$index += ($numPortTemp*2);
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$index += ($numPortTemp/2);
}
}
}
$ports = $interfaceSpecificTemp->getPort();
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
if ($typeLnkSpc == $typeLnkGen) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$lengthTemp = $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*2 ? $interfaceGeneric->getNumberOfPorts()*2 : $lengthTemp;
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts()/2;
}
for ($i=$index; $i < $lengthTemp; $i++) {
// $portsOld[] = $ports{$i};
$portsOld[] = $ports[$i];
}
}
elseif (count($interfaceGenericNew) > 1) {
foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
foreach ($interfaceSpecificTemp->getPort() as $value) {
$portsOld[] = $value;
}
}
}
// var_dump($portsOld);
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$k = 0;
// if ($numberOfPorts < count($portsOld)) {
// $this->addFlash(
// 'error',
// 'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
// );
// $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
//
// $em->remove($equipmentSpecific);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
// $em->flush();
if (array_key_exists($i, $orderPortArray)) {
foreach ($orderPortArray[$i] as $portOld) {
//remove the replaced port from usedports array
$portOld = $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
$usedPorts = array_diff($usedPorts, [$portOld->getId()]);
$this->replacePort($port, $portOld);
}
}
else {
if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$port1 = new Port();
$port1->setInterfaceSpecific($interfaceSpecific);
$j = $i+1;
$port1->setOrderNo($j);
if ($alias && count($alias) > 0) {
$port1->setAlias($alias[$j]);
}
if ($portExternes) {
if (isset($portExternes[$j]) && $portExternes[$j]) {
$port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
}
}
$em->persist($port1);
// $em->flush();
$this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
$i++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
}
}
}
if (count($usedPorts) > 0) {
$msgTemp = "Opération échouée ! ";
$msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés \n";
foreach ($usedPorts as $usedPort) {
$usedPort = $em->getRepository(Port::class)->find($usedPort);
$msgTemp = " " . $msgTemp . " ". $usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ". $usedPort->getOrderNo() . "\n";
}
$this->addFlash(
'error',
$msgTemp
);
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
}
else {
$sql = "update slot set module_id=null where module_id = " . $eqOld->getId() ." or modulaire_id=" . $eqOld->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$conn = $em->getConnection();
$stmt = $conn->prepare($sql);
$stmt->execute();
$em->remove($eqOld);
$em->flush();
$this->addFlash(
'error',
'Opération terminée avec succès !'
);
return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
}
// foreach ($portsOld as $port){
// if($port){
// $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
// $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
//
// if ($usedA || $usedB){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
// // // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// // $conn = $em->getConnection();
// // $stmt = $conn->prepare($sql);
// // $stmt->execute();
// //
// // $em->remove($eq);
// // $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
//
// $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedExt){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
// // $conn = $em->getConnection();
// // $stmt = $conn->prepare($sql);
// // $stmt->execute();
// //
// // $em->remove($eq);
// // $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
// $usedALink = null;
// $usedBLink = null;
// if (count($port->getExtensionOrder()) > 0) {
// $extremityA = $port->getExtensionOrder()[0]->getExtremity();
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
//
// if ($usedALink || $usedBLink){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// // $sql = "update slot set module_id=null where module_id = " . $eq->getId() ." or modulaire_id=" . $eq->getId();
// // // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// // $conn = $em->getConnection();
// // $stmt = $conn->prepare($sql);
// // $stmt->execute();
// //
// // $em->remove($eq);
// // $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
// }
// }
// $sql = "update slot set module_id=null where module_id = " . $eqOld->getId() ." or modulaire_id=" . $eqOld->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
// $em->remove($eqOld);
// $em->flush();
//
// $eqGeneric = $eqParent->getEquipmentGeneric()->getModules();
// $slots = $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eqParent->getId());
// return $this->render('equipment/module_substitute.html.twig', [
// 'page_title' => $translator->trans('Substitution du module'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution du module'),
// 'eq' => $eqOld,
// 'eqGeneric' => $eqGeneric,
// "slots" => $slots,
// ]);
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
}
else {
$eq = $em->getRepository(EquipmentSpecific::class)->find($id);
$eqParent = $eq->getParent();
$eqGeneric = $eqParent->getEquipmentGeneric()->getModules();
$chassisModule = $eqParent->getChassisModule();
if ($chassisModule) {
$eqGeneric->add($chassisModule);
}
$slots = $this->getDoctrine()->getRepository('App\Entity\Slot')->getFreeSlots($eqParent->getId());
return $this->render('equipment/module_substitute.html.twig', [
'page_title' => $translator->trans('Substitution du module'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution du module'),
'eq' => $eq,
'eqGeneric' => $eqGeneric,
"slots" => $slots,
]);
}
}
/**
* @Route("/equipment/specific/substitute/{id}", name="equipment_specific_substitute")
*/
public function substituteEquipmentAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
// process form
if ($request->request->has('equipmentToEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
//get the old equipment
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
// get all the used ports of the old equipment
$usedPorts = $this->getUsedPortsEquipment($eqOld);
//$eqParent = $eqOld->getParent();
$interfaceSpecificOld = $_POST['interfaces'];
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$eq->setOwner($_POST['owner']);
$eq->setPositionRack($_POST['positionRack']);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
$eq->setEquipmentGeneric($eqGeneric);
$em->persist($eq);
// $em->flush();
$interfaceGenericPortOrderNoArray = array();
if (isset($_POST['port'])) {
foreach ($_POST['port'] as $port => $value) {
foreach ($value as $key => $value1) {
$portOrderNoArray = array("orderNo"=> explode("__", $value1)[1], "port"=>$port);
$interfaceGenericPortOrderNoArray[explode("__", $value1)[0]][] = $portOrderNoArray;
}
}
// var_dump($interfaceGenericPortOrderNoArray);
}
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($eqGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$orderPortArray = array();
$portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
if ($portOrderNoArray) {
foreach ($portOrderNoArray as $value) {
$orderPortArray[$value['orderNo']][] = $value['port'];
}
}
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
// $em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$interfaceGenericNew = array();
foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
foreach ($value as $keyNew => $intGenNew) {
if ($intGenNew == $interfaceGeneric->getId()) {
$interfaceGenericNew[$interfaceSpecificId] = $value;
}
}
}
var_dump($interfaceGenericNew);
$portsOld = array();
if (count($interfaceGenericNew) == 1) {
$interfaceSpecificId = array_keys($interfaceGenericNew)[0];
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
$typeLnkSpc = $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
$index = 0;
foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
if ($value && $value != $interfaceGeneric->getId()) {
$intGenTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
$numPortTemp = $intGenTemp->getNumberOfPorts();
$typeLnkGen = $intGenTemp->getTypeLink()->getId();
if ($typeLnkSpc == $typeLnkGen) {
$index += $numPortTemp;
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$index += ($numPortTemp*2);
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$index += ($numPortTemp/2);
}
}
}
$ports = $interfaceSpecificTemp->getPort();
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
if ($typeLnkSpc == $typeLnkGen) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$lengthTemp = $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*2 ? $interfaceGeneric->getNumberOfPorts()*2 : $lengthTemp;
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts()/2;
}
for ($i=$index; $i < $lengthTemp; $i++) {
// $portsOld[] = $ports{$i};
$portsOld[] = $ports[$i];
}
}
elseif (count($interfaceGenericNew) > 1) {
foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
foreach ($interfaceSpecificTemp->getPort() as $value) {
$portsOld[] = $value;
}
}
}
// var_dump($portsOld);
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$k = 0;
// if ($numberOfPorts < count($portsOld)) {
// $this->addFlash(
// 'error',
// 'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
// );
// $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
//
// $em->remove($equipmentSpecific);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
// $em->flush();
//port to port
if (array_key_exists($i, $orderPortArray)) {
foreach ($orderPortArray[$i] as $portOld) {
//remove the replaced port from usedports array
$portOld = $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
$usedPorts = array_diff($usedPorts, [$portOld->getId()]);
$this->replacePort($port, $portOld);
}
}
else {
if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$port1 = new Port();
$port1->setInterfaceSpecific($interfaceSpecific);
$j = $i+1;
$port1->setOrderNo($j);
if ($alias && count($alias) > 0) {
$port1->setAlias($alias[$j]);
}
if ($portExternes) {
if (isset($portExternes[$j]) && $portExternes[$j]) {
$port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
}
}
$em->persist($port1);
// $em->flush();
$this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
$i++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
}
// if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $port1 = new Port();
// $port1->setInterfaceSpecific($interfaceSpecific);
// $j = $i+1;
// $port1->setOrderNo($j);
// if ($alias && count($alias) > 0) {
// $port1->setAlias($alias[$j]);
// }
// if ($portExternes) {
// if (isset($portExternes[$j]) && $portExternes[$j]) {
// $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
// }
// }
// $em->persist($port1);
// // $em->flush();
// $this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// //interface to interface
// if (array_key_exists($i, $orderPortArray)) {
// foreach ($orderPortArray[$i] as $portOld) {
// $this->replacePort($port, $portOld);
// }
// }
}
}
// foreach ($portsOld as $port){
// if($port){
// $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
// $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
//
// if ($usedA || $usedB){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
//
// $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedExt){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// $usedALink = null;
// $usedBLink = null;
// if (count($port->getExtensionOrder()) > 0) {
// $extremityA = $port->getExtensionOrder()[0]->getExtremity();
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
//
// if ($usedALink || $usedBLink){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// }
// }
//check if all the used ports have been repalced
if (count($usedPorts) > 0) {
$msgTemp = "Opération échouée !";
$msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
foreach ($usedPorts as $usedPort) {
$usedPort = $em->getRepository(Port::class)->find($usedPort);
$msgTemp = " " . $msgTemp . " ". $usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() . " - ". $usedPort->getOrderNo();
}
$this->addFlash(
'error',
$msgTemp
);
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
return $this->render('equipment/equipment_substitute_equipment.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eqOld,
'eqGen' => $eqGeneric,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
else {
$em->remove($eqOld);
$em->flush();
$this->addFlash(
'error',
'Opération terminée avec succès !'
);
return $this->redirectToRoute('equipment_specific_list');
}
}
elseif ($request->request->has('equipmentToModulaire') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
// $eqParent = $eqOld->getParent();
// get all the used ports of the old equipment
$usedPorts = $this->getUsedPortsEquipment($eqOld);
$interfaceSpecificOld = $_POST['interfaces'];
$eq = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_POST['equipmentGeneric']);
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$eq->setOwner($_POST['owner']);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
$eq->setPositionRack($_POST['positionRack']);
$em->persist($eq);
$interfaceGenericPortOrderNoArray = array();
if (isset($_POST['port'])) {
foreach ($_POST['port'] as $port => $value) {
foreach ($value as $key => $value1) {
$portOrderNoArray = array("orderNo"=> explode("__", $value1)[1], "port"=>$port);
$interfaceGenericPortOrderNoArray[explode("__", $value1)[0]][] = $portOrderNoArray;
}
}
}
// var_dump($interfaceGenericPortOrderNoArray);
$modules = $eq->getModules();
$chassisModule = $eq->getChassisModule();
if ($chassisModule) {
$modules->add($chassisModule);
}
// create specific interfaces
foreach ($modules as $module) {
$module->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$em->persist($module);
foreach ($module->getInterfaceSpecific() as $interfaceSpecific) {
$orderPortArray = array();
$portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()] : null;
if ($portOrderNoArray) {
foreach ($portOrderNoArray as $value) {
$orderPortArray[$value['orderNo']][] = $value['port'];
}
}
// var_dump($portExternes);
// create ports
$interfaceGeneric = $interfaceSpecific->getInterfaceGeneric();
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$interfaceGenericNew = array();
foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
foreach ($value as $keyNew => $intGenNew) {
if ($intGenNew == $interfaceSpecific->getId()) {
$interfaceGenericNew[$interfaceSpecificId] = $value;
}
}
}
// var_dump($interfaceGenericNew);
$portsOld = array();
if (count($interfaceGenericNew) == 1) {
$interfaceSpecificId = array_keys($interfaceGenericNew)[0];
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
$typeLnkSpc = $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
$index = 0;
foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
if ($value && $value != $interfaceSpecific->getId()) {
$intGenTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($value)->getInterfaceGeneric();
$numPortTemp = $intGenTemp->getNumberOfPorts();
$typeLnkGen = $intGenTemp->getTypeLink()->getId();
if ($typeLnkSpc == $typeLnkGen) {
$index += $numPortTemp;
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$index += ($numPortTemp*2);
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$index += ($numPortTemp/2);
}
}
}
$ports = $interfaceSpecificTemp->getPort();
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
if ($typeLnkSpc == $typeLnkGen) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$lengthTemp = $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*2 ? $interfaceGeneric->getNumberOfPorts()*2 : $lengthTemp;
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts()/2;
}
for ($i=$index; $i < $lengthTemp; $i++) {
// $portsOld[] = $ports{$i};
$portsOld[] = $ports[$i];
}
}
elseif (count($interfaceGenericNew) > 1) {
foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
foreach ($interfaceSpecificTemp->getPort() as $value) {
$portsOld[] = $value;
}
}
}
// var_dump($portsOld);
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$k = 0;
// if ($numberOfPorts < count($portsOld)) {
// $this->addFlash(
// 'error',
// 'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
// );
// $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
//
// $em->remove($equipmentSpecific);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
$portsTemp = $interfaceSpecific->getPort();
for ($i=0; $i<$numberOfPorts; $i++){
// $port = $portsTemp{$i};
$port = $portsTemp[$i];
if (array_key_exists($i, $orderPortArray)) {
foreach ($orderPortArray[$i] as $portOld) {
//remove the replaced port from usedports array
$portOld = $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
$usedPorts = array_diff($usedPorts, [$portOld->getId()]);
$this->replacePort($port, $portOld);
}
}
else {
if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$j = $i+1;
// $port1 = $portsTemp{$j};
$port1 = $portsTemp[$j];
$this->replacePort($port1, $portsOld[$k]);
$k++;
$i++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
}
// if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
// //remove the replaced port from usedports array
// $usedPorts = array_diff($usedPorts, [$portOld->getId()]);
//
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// $port1 = $portsTemp{$i};
// $this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// if (array_key_exists($i+1, $orderPortArray)) {
// foreach ($orderPortArray[$i+1] as $portOld) {
// $this->replacePort($port, $portOld);
// }
// }
}
}
}
if (count($usedPorts) > 0) {
$msgTemp = "Opération échouée ! ";
$msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
foreach ($usedPorts as $usedPort) {
$usedPort = $em->getRepository(Port::class)->find($usedPort);
$msgTemp = " " . $msgTemp . " ". $usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ". $usedPort->getOrderNo();
}
$this->addFlash(
'error',
$msgTemp
);
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eqOld,
'eqMod' => $eq,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
else {
$em->remove($eqOld);
$em->flush();
$this->addFlash(
'error',
'Opération terminée avec succès !'
);
return $this->redirectToRoute('equipment_specific_list');
}
// foreach ($portsOld as $port){
// if($port){
// $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
// $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
//
// if ($usedA || $usedB){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
//
// $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedExt){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// $usedALink = null;
// $usedBLink = null;
// if (count($port->getExtensionOrder()) > 0) {
// $extremityA = $port->getExtensionOrder()[0]->getExtremity();
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
//
// if ($usedALink || $usedBLink){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// }
// }
//
// $em->remove($eqOld);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_list');
}
elseif ($request->request->has('idEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
$eq = $em->getRepository(EquipmentSpecific::class)->find($_POST["idEquipment"]);
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
if ($_POST["eqModulaire"]) {
// return $this->render('equipment/test1.html.twig');
$eqMod = $em->getRepository(EquipmentSpecific::class)->findOneById($_POST["eqModulaire"]);
return $this->render('equipment/equipment_substitute_modulaire.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eq,
'eqMod' => $eqMod,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
elseif ($_POST["eqGeneric"]) {
$eqGen = $em->getRepository(EquipmentGeneric::class)->findOneById($_POST["eqGeneric"]);
return $this->render('equipment/equipment_substitute_equipment.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eq,
'eqGen' => $eqGen,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
}
}
/**
* @Route("/equipment/modulaire/substitute/{id}", name="equipment_modulaire_substitute")
*/
public function substituteModulaireAction(Request $request, $id, TranslatorInterface $translator)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
// process form
if ($request->request->has('modulaireToEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))){
//get the old equipment
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
//$eqParent = $eqOld->getParent();
// get all the used ports of the old equipment
$usedPorts = [];
$modulesTemp = $eqOld->getModules();
$chassisModule = $eqOld->getChassisModule();
if ($chassisModule) {
$modulesTemp->add($chassisModule);
}
foreach ($modulesTemp as $tmpMod) {
$usedPorts = array_merge($usedPorts, $this->getUsedPortsEquipment($tmpMod));
}
$interfaceSpecificOld = $_POST['interfaces'];
$eq = new EquipmentSpecific();
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$eq->setOwner($_POST['owner']);
$eq->setPositionRack($_POST['positionRack']);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
$eqGeneric = $this->getDoctrine()->getRepository('App\Entity\EquipmentGeneric')->findOneById($_POST['equipmentGeneric']);
$eq->setEquipmentGeneric($eqGeneric);
$em->persist($eq);
// $em->flush();
$interfaceGenericPortOrderNoArray = array();
if (isset($_POST['port'])) {
foreach ($_POST['port'] as $port => $value) {
foreach ($value as $key => $value1) {
$portOrderNoArray = array("orderNo"=> explode("__", $value1)[1], "port"=>$port);
$interfaceGenericPortOrderNoArray[explode("__", $value1)[0]][] = $portOrderNoArray;
}
}
}
// var_dump($interfaceGenericPortOrderNoArray);
// create specific interfaces
$interfacesGeneric = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->findByEquipmentGeneric($eqGeneric);
foreach ($interfacesGeneric as $interfaceGeneric){
$orderPortArray = array();
$portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceGeneric->getId()] : null;
if ($portOrderNoArray) {
foreach ($portOrderNoArray as $value) {
$orderPortArray[$value['orderNo']][] = $value['port'];
}
}
$interfaceSpecific = new InterfaceSpecific();
$interfaceSpecific->setEquipmentSpecific($eq);
$interfaceSpecific->setInterfaceGeneric($interfaceGeneric);
$em->persist($interfaceSpecific);
// $em->flush();
$alias = null;
if ($interfaceGeneric->getAlias()) {
$alias = json_decode($interfaceGeneric->getAlias(), true);
}
$portExternes = null;
$idTemp = $interfaceGeneric->getId();
// var_dump($_POST["portExterne[$idTemp]"]);
if (isset($_POST["portExterne"][$idTemp])) {
foreach ($_POST["portExterne"][$idTemp] as $key => $value) {
$portExternes[$key] = $value;
}
}
// var_dump($portExternes);
// create ports
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$interfaceGenericNew = array();
foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
foreach ($value as $keyNew => $intGenNew) {
if ($intGenNew == $interfaceGeneric->getId()) {
$interfaceGenericNew[$interfaceSpecificId] = $value;
}
}
}
// var_dump($interfaceGenericNew);
$portsOld = array();
if (count($interfaceGenericNew) == 1) {
$interfaceSpecificId = array_keys($interfaceGenericNew)[0];
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
$typeLnkSpc = $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
$index = 0;
foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
if ($value && $value != $interfaceGeneric->getId()) {
$intGenTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceGeneric')->find($value);
$numPortTemp = $intGenTemp->getNumberOfPorts();
$typeLnkGen = $intGenTemp->getTypeLink()->getId();
if ($typeLnkSpc == $typeLnkGen) {
$index += $numPortTemp;
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$index += ($numPortTemp*2);
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$index += ($numPortTemp/2);
}
}
}
$ports = $interfaceSpecificTemp->getPort();
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
if ($typeLnkSpc == $typeLnkGen) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$lengthTemp = $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*2 ? $interfaceGeneric->getNumberOfPorts()*2 : $lengthTemp;
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts()/2;
}
for ($i=$index; $i < $lengthTemp; $i++) {
// $portsOld[] = $ports{$i};
$portsOld[] = $ports[$i];
}
}
elseif (count($interfaceGenericNew) > 1) {
foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
foreach ($interfaceSpecificTemp->getPort() as $value) {
$portsOld[] = $value;
}
}
}
// var_dump($portsOld);
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$k = 0;
// if ($numberOfPorts < count($portsOld)) {
// $this->addFlash(
// 'error',
// 'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
// );
// $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
//
// $em->remove($equipmentSpecific);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
for ($i=1; $i<=$numberOfPorts; $i++){
$port = new Port();
$port->setInterfaceSpecific($interfaceSpecific);
$port->setOrderNo($i);
if ($alias && count($alias) > 0) {
$port->setAlias($alias[$i]);
}
if ($portExternes) {
if (isset($portExternes[$i]) && $portExternes[$i]) {
// $port->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$i]);
$port->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port);
$port->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port);
// $em->flush();
//port to port
if (array_key_exists($i, $orderPortArray)) {
foreach ($orderPortArray[$i] as $portOld) {
//remove the replaced port from usedports array
$portOld = $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
$usedPorts = array_diff($usedPorts, [$portOld->getId()]);
$this->replacePort($port, $portOld);
}
}
else {
if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$port1 = new Port();
$port1->setInterfaceSpecific($interfaceSpecific);
$j = $i+1;
$port1->setOrderNo($j);
if ($alias && count($alias) > 0) {
$port1->setAlias($alias[$j]);
}
if ($portExternes) {
if (isset($portExternes[$j]) && $portExternes[$j]) {
// $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
$pe = $this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]);
$port1->setPortExterne($pe);
$interfaceGenericPortExterne = $pe->getInterfaceGeneric();
if ($interfaceGenericPortExterne != null) {
//create interface spécific and attach it to the port
$ifPE = new InterfaceSpecific();
$this->createInterfaceSpecific($em, $interfaceGenericPortExterne, $ifPE, $eq, $port1);
$port1->setInterfaceSpecificPortExterne($ifPE);
}
}
}
$em->persist($port1);
// $em->flush();
$this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
$i++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
}
// if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $port1 = new Port();
// $port1->setInterfaceSpecific($interfaceSpecific);
// $j = $i+1;
// $port1->setOrderNo($j);
// if ($alias && count($alias) > 0) {
// $port1->setAlias($alias[$j]);
// }
// if ($portExternes) {
// if (isset($portExternes[$j]) && $portExternes[$j]) {
// $port1->setPortExterne($this->getDoctrine()->getRepository('App\Entity\PortExterne')->findOneById($portExternes[$j]));
// }
// }
// $em->persist($port1);
// // $em->flush();
// $this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// //interface to interface
// if (array_key_exists($i, $orderPortArray)) {
// foreach ($orderPortArray[$i] as $portOld) {
// $this->replacePort($port, $portOld);
// }
// }
}
}
if (count($usedPorts) > 0) {
$msgTemp = "Opération échouée ! ";
$msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
foreach ($usedPorts as $usedPort) {
$usedPort = $em->getRepository(Port::class)->find($usedPort);
$msgTemp = " " . $msgTemp . " ". $usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ". $usedPort->getOrderNo();
}
$this->addFlash(
'error',
$msgTemp
);
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eqOld,
'eqGen' => $eqGeneric,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
else {
$this->get('logger')->info("inside modulaire_equipment success");
try{
$sql = "update slot set module_id=null where module_id = " . $eqOld->getId() ." or modulaire_id=" . $eqOld->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$conn = $em->getConnection();
$stmt = $conn->prepare($sql);
$stmt->execute();
$sql1 = "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " . $eqOld->getId();
$conn = $em->getConnection();
$stmt = $conn->prepare($sql1);
$stmt->execute();
$sql = "update equipment_specific set chassis_module_id=null where id = " . $eqOld->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$stmt = $conn->prepare($sql);
$stmt->execute();
foreach ($eqOld as $modOld) {
$em->remove($modOld);
}
if ($eqOld->getChassisModule()) {
$em->remove($eqOld->getChassisModule());
}
$em->remove($eqOld);
$this->get('logger')->info("inside modulaire_equipment success");
$em->flush();
}
catch(Exception $ex){
$this->get('logger')->info($ex->getMessage());
}
$this->get('logger')->info("inside modulaire_equipment success");
$this->addFlash(
'error',
'Opération terminée avec succès !'
);
return $this->redirectToRoute('equipment_specific_modulaire_list');
}
// foreach ($portsOld as $port){
// if($port){
// $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
// $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
//
// if ($usedA || $usedB){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
//
// $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedExt){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// $usedALink = null;
// $usedBLink = null;
// if (count($port->getExtensionOrder()) > 0) {
// $extremityA = $port->getExtensionOrder()[0]->getExtremity();
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
//
// if ($usedALink || $usedBLink){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqGen' => $eqGeneric,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// }
// }
}
elseif ($request->request->has('modulaireToModulaire') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
$eqOld = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($id);
// $eqParent = $eqOld->getParent();
// get all the used ports of the old equipment
$usedPorts = [];
$modulesTemp = $eqOld->getModules();
$chassisModule = $eqOld->getChassisModule();
if ($chassisModule) {
$modulesTemp->add($chassisModule);
}
foreach ($modulesTemp as $tmpMod) {
$usedPorts = array_merge($usedPorts, $this->getUsedPortsEquipment($tmpMod));
}
$interfaceSpecificOld = $_POST['interfaces'];
$eq = $this->getDoctrine()->getRepository('App\Entity\EquipmentSpecific')->find($_POST['equipmentGeneric']);
$eq->setEquipmentSpecificName($_POST['equipmentSpecificName']);
$eq->setAlias($_POST['alias']);
$eq->setOwner($_POST['owner']);
$eq->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$eq->setRackFace($this->getDoctrine()->getRepository('App\Entity\Rackface')->find($_POST['rackFace']));
$eq->setPositionRack($_POST['positionRack']);
$em->persist($eq);
$interfaceGenericPortOrderNoArray = array();
if (isset($_POST['port'])) {
foreach ($_POST['port'] as $port => $value) {
foreach ($value as $key => $value1) {
$portOrderNoArray = array("orderNo"=> explode("__", $value1)[1], "port"=>$port);
$interfaceGenericPortOrderNoArray[explode("__", $value1)[0]][] = $portOrderNoArray;
}
}
}
// var_dump($interfaceGenericPortOrderNoArray);
$modulesTemp = $eq->getModules();
$chassisModule = $eq->getChassisModule();
if ($chassisModule) {
$modulesTemp->add($chassisModule);
}
// create specific interfaces
foreach ($modulesTemp as $module) {
$module->setRack($this->getDoctrine()->getRepository('App\Entity\Rack')->find($_POST['rack']));
$em->persist($module);
foreach ($module->getInterfaceSpecific() as $interfaceSpecific) {
$orderPortArray = array();
$portOrderNoArray = isset($interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()]) ? $interfaceGenericPortOrderNoArray[$interfaceSpecific->getId()] : null;
if ($portOrderNoArray) {
foreach ($portOrderNoArray as $value) {
$orderPortArray[$value['orderNo']][] = $value['port'];
}
}
// var_dump($portExternes);
// create ports
$interfaceGeneric = $interfaceSpecific->getInterfaceGeneric();
$numberOfPorts = $interfaceGeneric->getNumberOfPorts();
$interfaceGenericNew = array();
foreach ($interfaceSpecificOld as $interfaceSpecificId => $value) {
foreach ($value as $keyNew => $intGenNew) {
if ($intGenNew == $interfaceSpecific->getId()) {
$interfaceGenericNew[$interfaceSpecificId] = $value;
}
}
}
// var_dump($interfaceGenericNew);
$portsOld = array();
if (count($interfaceGenericNew) == 1) {
$interfaceSpecificId = array_keys($interfaceGenericNew)[0];
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
$typeLnkSpc = $interfaceSpecificTemp->getInterfaceGeneric()->getTypeLink()->getId();
$index = 0;
foreach ($interfaceGenericNew[$interfaceSpecificId] as $key => $value) {
if ($value && $value != $interfaceSpecific->getId()) {
$intGenTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($value)->getInterfaceGeneric();
$numPortTemp = $intGenTemp->getNumberOfPorts();
$typeLnkGen = $intGenTemp->getTypeLink()->getId();
if ($typeLnkSpc == $typeLnkGen) {
$index += $numPortTemp;
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$index += ($numPortTemp*2);
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$index += ($numPortTemp/2);
}
}
}
$ports = $interfaceSpecificTemp->getPort();
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
if ($typeLnkSpc == $typeLnkGen) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts();
}
elseif ($typeLnkSpc == 1 && $typeLnkGen == 2) {
$lengthTemp = $lengthTemp <= $interfaceGeneric->getNumberOfPorts()*2 ? $interfaceGeneric->getNumberOfPorts()*2 : $lengthTemp;
}
elseif ($typeLnkSpc == 2 && $typeLnkGen == 1) {
$lengthTemp = $interfaceGeneric->getNumberOfPorts()/2;
}
for ($i=$index; $i < $lengthTemp; $i++) {
// $portsOld[] = $ports{$i};
$portsOld[] = $ports[$i];
}
}
elseif (count($interfaceGenericNew) > 1) {
foreach ($interfaceGenericNew as $interfaceSpecificId => $value1) {
$interfaceSpecificTemp = $this->getDoctrine()->getRepository('App\Entity\InterfaceSpecific')->find($interfaceSpecificId);
foreach ($interfaceSpecificTemp->getPort() as $value) {
$portsOld[] = $value;
}
}
}
// var_dump($portsOld);
$typeLnkGen = $interfaceGeneric->getTypeLink()->getId();
$k = 0;
// if ($numberOfPorts < count($portsOld)) {
// $this->addFlash(
// 'error',
// 'Nombre de port dans la nouvelle équipement n\'est pas suffisant'
// );
// $sql = "update slot set module_id=null where module_id = " . $equipmentSpecific->getId() ." or modulaire_id=" . $equipmentSpecific->getId();
// // $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
// $conn = $em->getConnection();
// $stmt = $conn->prepare($sql);
// $stmt->execute();
//
// $em->remove($equipmentSpecific);
// $em->flush();
// return $this->redirectToRoute('equipment_specific_modulaire_update', ['id'=>$eqParent->getId()]);
// }
$portsTemp = $interfaceSpecific->getPort();
for ($i=0; $i<$numberOfPorts; $i++){
// $port = $portsTemp{$i};
$port = $portsTemp[$i];
if (array_key_exists($i, $orderPortArray)) {
foreach ($orderPortArray[$i] as $portOld) {
//remove the replaced port from usedports array
$portOld = $this->getDoctrine()->getRepository('App\Entity\Port')->find($portOld);
$usedPorts = array_diff($usedPorts, [$portOld->getId()]);
$this->replacePort($port, $portOld);
}
}
else {
if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$j = $i+1;
// $port1 = $portsTemp{$j};
$port1 = $portsTemp[$j];
$this->replacePort($port1, $portsOld[$k]);
$k++;
$i++;
}
elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
//remove the replaced port from usedports array
$usedPorts = array_diff($usedPorts, [$portsOld[$k]->getId()]);
$this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
$k++;
}
}
// if (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == $typeLnkGen) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 1 && $typeLnkGen == 2) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// $port1 = $portsTemp{$i};
// $this->replacePort($port1, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $i++;
// }
// elseif (isset($portsOld[$k]) && $portsOld[$k]->getInterfaceSpecific()->getInterfaceGeneric()->getTypeLink()->getId() == 2 && $typeLnkGen == 1) {
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// $this->replacePort($port, $portsOld[$k]);
// unset($portsOld[$k]);
// $k++;
// }
// if (array_key_exists($i+1, $orderPortArray)) {
// foreach ($orderPortArray[$i+1] as $portOld) {
// $this->replacePort($port, $portOld);
// }
// }
}
}
}
if (count($usedPorts) > 0) {
$msgTemp = "Opération échouée ! ";
$msgTemp .= "Les ports suivants sont occupés mais ils n'ont pas été remplacés";
foreach ($usedPorts as $usedPort) {
$usedPort = $em->getRepository(Port::class)->find($usedPort);
$msgTemp = " " . $msgTemp . " ". $usedPort->getInterfaceSpecific()->getInterfaceGeneric()->getInterfaceNumber() ." - ". $usedPort->getOrderNo();
}
$this->addFlash(
'error',
$msgTemp
);
$this->get('logger')->info("inside modulaire_modulaire failed");
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eqOld,
'eqMod' => $eq,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
else {
$this->get('logger')->info("inside modulaire_modulaire success");
try{
$sql = "update slot set module_id=null where module_id = " . $eqOld->getId() ." or modulaire_id=" . $eqOld->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$conn = $em->getConnection();
$stmt = $conn->prepare($sql);
$stmt->execute();
$sql1 = "update interface_specific set equipment_specific_mpo_id=null where equipment_specific_mpo_id = " . $eqOld->getId();
$conn = $em->getConnection();
$stmt = $conn->prepare($sql1);
$stmt->execute();
$sql = "update equipment_specific set chassis_module_id=null where id = " . $eqOld->getId();
// $extIds = [$temp[0]->getExtremityA()->getId(), $temp[0]->getExtremityB()->getId()];
$stmt = $conn->prepare($sql);
$stmt->execute();
foreach ($eqOld as $modOld) {
$em->remove($modOld);
}
if ($eqOld->getChassisModule()) {
$em->remove($eqOld->getChassisModule());
}
$em->remove($eqOld);
$this->get('logger')->info("inside modulaire_modulaire success");
$em->flush();
}
catch(Exception $ex){
$this->get('logger')->info($ex->getMessage());
}
$this->get('logger')->info("inside modulaire_modulaire success");
$this->addFlash(
'error',
'Opération terminée avec succès !'
);
return $this->redirectToRoute('equipment_specific_modulaire_list');
}
// foreach ($portsOld as $port){
// if($port){
// $usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
// $usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
//
// if ($usedA || $usedB){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
//
// $usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
//
// if ($usedExt){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// $usedALink = null;
// $usedBLink = null;
// if (count($port->getExtensionOrder()) > 0) {
// $extremityA = $port->getExtensionOrder()[0]->getExtremity();
// $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
// $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
// }
//
// // $usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortA($port);
// // $usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByPortB($port);
//
// if ($usedALink || $usedBLink){
// $this->addFlash(
// 'error',
// $interfaceGeneric->getInterfaceNumber() .' : Nombre de port n\'est pas suffisant pour remplacer l\'interface'
// );
// $racks = $em->getRepository(Rack::class)->findAll();
// $rackFaces = $em->getRepository(RackFace::class)->findAll();
// return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
// 'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
// 'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
// 'eq' => $eqOld,
// 'eqMod' => $eq,
// "racks" =>$racks,
// "rackFaces" =>$rackFaces
// ]);
// }
// }
// }
}
elseif ($request->request->has('idEquipment') && ($user->hasRole("ROLE_SUPER_ADMIN") || $user->hasRole("ROLE_ADMIN"))) {
$eq = $em->getRepository(EquipmentSpecific::class)->find($_POST["idEquipment"]);
$racks = $em->getRepository(Rack::class)->findAll();
$rackFaces = $em->getRepository(RackFace::class)->findAll();
if ($_POST["eqModulaire"]) {
// return $this->render('equipment/test1.html.twig');
$eqMod = $em->getRepository(EquipmentSpecific::class)->findOneById($_POST["eqModulaire"]);
return $this->render('equipment/modulaire_substitute_modulaire.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eq,
'eqMod' => $eqMod,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
elseif ($_POST["eqGeneric"]) {
$eqGen = $em->getRepository(EquipmentGeneric::class)->findOneById($_POST["eqGeneric"]);
return $this->render('equipment/modulaire_substitute_equipment.html.twig', [
'page_title' => $translator->trans('Substitution de l\'équipement modulaire'),
'box_title' => '<i class="fa fa-edit fa-fw"></i> '.$translator->trans('Substitution de l\'équipement modulaire'),
'eq' => $eq,
'eqGen' => $eqGen,
"racks" =>$racks,
"rackFaces" =>$rackFaces
]);
}
}
}
public function replacePort($portNew, $portOld)
{
// $logger->error("replaceport : new : " .$portNew->getId() . " old : " . $portOld->getId());
$em = $this->getDoctrine()->getManager();
$usedsA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findByPortA($portOld);
foreach ($usedsA as $usedA) {
$usedA->setPortA($portNew);
$em->persist($usedA);
// $em->flush();
}
$usedsB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findByPortB($portOld);
foreach ($usedsB as $usedB) {
$usedB->setPortB($portNew);
$em->persist($usedB);
// $em->flush();
}
$usedsExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findByPortB($portOld);
foreach ($usedsExt as $usedExt) {
$usedExt->setPortB($portNew);
$em->persist($usedExt);
// $em->flush();
}
$extOrders = $portOld->getExtensionOrder();
foreach ($extOrders as $extOrder) {
$extOrder->setPort($portNew);
$em->persist($extOrder);
// $em->flush();
}
$linkExt = $portOld->getLinkExtension();
if ($linkExt) {
$portNew->setLinkExtension($linkExt);
$em->persist($portNew);
// $em->flush();
}
$link = $portOld->getLink();
if ($link) {
$portNew->setLink($link);
$em->persist($portNew);
// $em->flush();
}
}
public function getUsedPortsEquipment($eqOld)
{
$usedPorts = array();
$interfaceSpecifics = $eqOld->getInterfaceSpecific();
foreach ($interfaceSpecifics as $interfaceSpecific) {
foreach ($interfaceSpecific->getPort() as $port) {
$usedA = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortA($port);
if ($usedA) {
$usedPorts[] = $port->getId();
continue;
}
$usedB = $this->getDoctrine()->getRepository('App\Entity\TrunkCableFiber')->findOneByPortB($port);
if ($usedB) {
$usedPorts[] = $port->getId();
continue;
}
$usedExt = $this->getDoctrine()->getRepository('App\Entity\TrunkExtension')->findOneByPortB($port);
if ($usedExt) {
$usedPorts[] = $port->getId();
continue;
}
$usedALink = null;
$usedBLink = null;
if (count($port->getExtensionOrder()) > 0) {
$extremityA = $port->getExtensionOrder()[0]->getExtremity();
$usedALink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityA($extremityA);
$usedBLink = $this->getDoctrine()->getRepository('App\Entity\LinkExtension')->findOneByExtremityB($extremityA);
}
if ($usedALink || $usedBLink){
$usedPorts[] = $port->getId();
continue;
}
}
}
return $usedPorts;
}
}