コード例 #1
0
function delete($nid)
{
    $row = getNodeByNid($nid);
    // $row['isActive']="no";
    //delete the whole pattern
    $list = array();
    $list[0] = $row['nid'];
    iniRecordList($list);
    if ($row['isConnector'] == 2) {
        return "domainFail";
    } else {
        if ($row['isConnector'] == 1) {
            if (countPatternNodes($row['pid']) > 1) {
                return "patternFail";
            }
            $neighbourList = findNodeNeighbour($row['nid']);
            $did = getDidByNid($nid);
            $domainId = getDomainByDid($did)['nid'];
            if (count($neighbourList) > 1) {
                for ($i = 0; $i < count($neighbourList); $i++) {
                    if ($neighbourList[$i] != $domainId) {
                        if (count(sendMessageIgnoreInactive($neighbourList[$i], $domainId, $list)) == 0) {
                            return "fail";
                        }
                    }
                }
                deleteNodesByNid($row['nid']);
                deleteLinksByNid($row['nid']);
                return "connectorSuccess";
            } else {
                //get all neighbors of this domain, includes one connector node
                $tempDid = $neighbourList[0];
                //echo "did ".$tempDid."</br>";
                $tempNeighbourList = findNodeNeighbour($tempDid);
                $tempCount = 0;
                for ($i = 0; $i < count($tempNeighbourList); $i++) {
                    $tempNode = $tempNeighbourList[$i];
                    if ($tempDid == getDidByNid($tempNode)) {
                        $tempCount++;
                    }
                }
                //echo "count ".$tempCount;
                if ($tempCount >= 1) {
                    deleteNodesByNid($row['nid']);
                    deleteLinksByNid($row['nid']);
                    return "connectorSuccess";
                } else {
                    $domainNeighborList = findNodeNeighbour($domainId);
                    $domainNeighborsCount = count($domainNeighborList);
                    if ($domainNeighborsCount >= 2) {
                        $list[0] = $domainId;
                        iniRecordList($list);
                        for ($i = 0; $i < $domainNeighborsCount; $i++) {
                            for ($j = 0; $j < $domainNeighborsCount; $j++) {
                                if ($domainNeighborList[$i] != $domainNeighborList[$j]) {
                                    if (count(sendMessageIgnoreInactive($domainNeighborList[$i], $domainNeighborList[$j], $list)) == 0) {
                                        return "fail";
                                    }
                                }
                            }
                        }
                    }
                    deleteNodesByNid($domainId);
                    deleteLinksByNid($domainId);
                    deleteNodesByNid($row['nid']);
                    deleteLinksByNid($row['nid']);
                    return $domainId;
                }
            }
        } else {
            $neighbourList = findNodeNeighbour($row['nid']);
            $pid = getPidByNid($nid);
            //  echo $pid;
            $connectorId = getConnectorByPid($pid)['nid'];
            // echo $connectorId;
            for ($i = 0; $i < count($neighbourList); $i++) {
                // echo $neighbourList[$i];
                if ($neighbourList[$i] == $connectorId) {
                } else {
                    if (count(sendMessageIgnoreInactive($neighbourList[$i], $connectorId, $list)) == 0) {
                        return "fail";
                    }
                }
            }
            deleteLinksByNid($row['nid']);
            deleteNodesByNid($row['nid']);
            return "normalSuccess";
        }
    }
}
コード例 #2
0
<?php

include_once "../dao/getNode.php";
include_once "../dao/getLink.php";
$pName = "";
$nName = "";
$nid = getMaxNid() + 1;
$did = $_POST['did'];
$pid = getMaxPatternID() + 1;
$domains = $_POST['nodes1'];
$domain = getDomainByDid($did)[0];
insertNode($nid, 1, $pid, $pName, $nName, "yes", $did);
foreach ($domains as $key => $value) {
    insertLink($nid, $value);
}
insertLink($domain, $nid);
echo "success";