Example #1
0
function deleteEdge($nid1, $nid2)
{
    $result1 = getNodeByNid($nid1);
    $result2 = getNodeByNid($nid2);
    if ($result1['isConnector'] + $result2['isConnector'] == 3) {
        return "failed";
    } else {
        $list = array();
        //first delete edge from two nodes
        deleteEdgeBetweenNodes($nid1, $nid2);
        deleteEdgeBetweenNodes($nid2, $nid1);
        //send message from node1 to node2 to check if msg can be sent
        if (count(sendMessageIgnoreInactive($nid1, $nid2, $list)) == 0) {
            addEdgeBetweenNodes($nid1, $nid2);
            return "failed";
        } else {
            return "success";
        }
    }
}
 */
include_once "findShortestPath.php";
include_once "../dao/getMessage.php";
$type = $_POST['type'];
$from = $_POST['from'];
//$next=$_POST['next'];
$message = $_POST['message'];
$to = $_POST['to'];
if ($type == "first") {
    $path = sendMessage($from, $to, array());
    if (count($path) == 0) {
        if ($from == $to) {
            insertMessage($from, $to, $message, "received");
            echo "received";
        } else {
            $path = sendMessageIgnoreInactive($from, $to, array());
            echo json_encode($path);
        }
    } else {
        //        if($from==$to){
        //            insertMessage($from,$to,$message,"received");
        //            echo "received";
        //        }else {
        echo json_encode($path);
        //        }
    }
} else {
    if ($type == "second") {
        $path = sendMessage($from, $to, array());
        if (count($path) == 0) {
            echo "blocked";
Example #3
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";
        }
    }
}