Example #1
0
function checkAddNode($pid, $isConnector, $link1, $link2, $link3)
{
    $count = getCountByPid($pid);
    if ($count >= 6) {
        return "Pattern is full";
    }
    if ($isConnector == 1) {
        if (getConnectorByPid($pid) != null) {
            return "already exist a connector in this pattern";
        }
    } elseif ($isConnector == 0) {
        if (getConnectorByPid($pid) == null) {
            return "This pattern do not exist,please create a connector for it";
        }
        if ($link1 == null && $link2 == null && $link3 == null) {
            return "A normal node must need to connect to the other node(s)";
        }
    }
    if (getLinkCountByNid($link1) >= 3) {
        return "Can not connect to Node" . $link1 . " because it has already connected with three nodes";
    }
    if (getLinkCountByNid($link2) >= 3) {
        return "Can not connect to Node" . $link2 . " because it has already connected with three nodes";
    }
    if (getLinkCountByNid($link3) >= 3) {
        return "Can not connect to Node" . $link3 . " because it has already connected with three nodes";
    }
    return "true";
}
Example #2
0
            insertLink($from, $value);
        }
        //            else  {
        //                $result = "Link already exists";
        //            }
        //        }
        //        if ($receiver == 0 && $linkCount == 3)  {
        //            echo "111";
        //            $result = "failure";
        //        }
    }
}
$count = getLinkCountByNid($from);
if ($connector == 0 && $count < 3) {
    foreach ($to as $key => $value) {
        $linkCount = getLinkCountByNid($value);
        $receiver = getNodeConnector($value);
        if ($receiver != 0) {
            if (linkExists($from, $value) == 0) {
                insertLink($from, $value);
            } else {
                $result = "Link already exists";
            }
        }
        if ($receiver == 0 && $linkCount < 3) {
            if (linkExists($from, $value) == 0) {
                insertLink($from, $value);
            } else {
                $result = "Link already exists";
            }
        }
Example #3
0
        $flag = false;
    }
    foreach ($nodes0 as $key => $value) {
        if (getNodeByNid($value)['isConnector'] == 1) {
            $links = getLinksArrayByNid($value);
            foreach ($links as $key1 => $value1) {
                if (getNodeByNid($value1)['isConnector'] == 1 || getNodeByNid($value1)['isConnector'] == 2) {
                    unset($links[$key1]);
                }
            }
            if (count($links) >= 3) {
                echo "Can not connect to Node" . $value . " because it is already connected with three nodes\n";
                $flag = false;
                break;
            }
        } else {
            if (getLinkCountByNid($value) >= 3) {
                echo "Can not connect to Node" . $value . " because it is already connected with three nodes\n";
                $flag = false;
                break;
            }
        }
    }
    if ($flag) {
        foreach ($nodes0 as $key => $value) {
            insertLink($nid, $value);
        }
        insertNode($nid, 0, $pid, $pName, $nName, "yes", $did);
        echo "success";
    }
}