示例#1
0
/**
 * Get the connections for the given network search parameters from the given node.
 *
 * @param string $nodeid the id of the node to search outward from.
 * @param string $linklabels the string of link types.
 * @param string $userid optional for searching only a specified user's data. (only used if scope is 'all') - NOT USED AT PRESENT
 * @param string $scope (either 'all' or 'my', default 'all')
 * @param string $linkgroup (optional, either Positive, Negative, or Neutral - default: empty string);
 * @param integer $depth (optional, 1-7, or 7 for full depth;
 * @param string $direction (optional, 'outgoing', 'incoming', or 'both - default: 'both',
 * @param string $labelmatch (optional, 'true', 'false' - default: false;
 * @param string $nodetypes a comman separated list of the node type names to include in the search.
 * @param String $style (optional - default 'long') may be 'short' or 'long'
 * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired)
 * @return ConnectionSet or Error
 */
function getConnectionsByPath($nodeid, $linklabels, $userid, $scope = 'all', $linkgroup = '', $depth = 7, $direction = "both", $labelmatch = 'false', $nodetypes = '', $style = 'long', $status = 0)
{
    global $DB, $USER, $CFG;
    $searchLinkLabels = "";
    $searchLinkLabelsArray = array();
    //$searchLinkLabels = getSQLForLinkTypeIDsForLabels(&$searchLinkLabelsArray, $linklabels)
    if ($linklabels != "" && $linkgroup == "") {
        $pieces = explode(",", $linklabels);
        $loopCount = 0;
        foreach ($pieces as $value) {
            $searchLinkLabelsArray[$loopCount] = $value;
            if ($loopCount == 0) {
                $searchLinkLabels .= "?";
            } else {
                $searchLinkLabels .= ",?";
            }
            $loopCount++;
        }
    }
    $nodeTypeNames = "";
    $nodeTypeNamesArray = array();
    //$nodeTypeNames = getSQLForNodeTypeIDsForLabels($nodeTypeNamesArray,$nodetypes);
    if ($nodetypes != "") {
        $nodeTypeNames = "";
        $pieces = explode(",", $nodetypes);
        $loopCount = 0;
        foreach ($pieces as $value) {
            $nodeTypeNamesArray[$loopCount] = $value;
            if ($loopCount == 0) {
                $nodeTypeNames .= "?";
            } else {
                $nodeTypeNames .= ",?";
            }
            $loopCount++;
        }
    }
    // GET TEXT FOR PASSED IDEA ID IF REQUIRED
    $text = "";
    if ($labelmatch == 'true') {
        $params = array();
        $params[0] = $nodeid;
        $qry = $HUB_SQL->APILIB_NODE_NAME_BY_ID_SELECT;
        $resArray = $DB->select($sql, $params);
        if ($resArray !== false && count($resArray) > 0) {
            $text = $resArray[0]['Name'];
        } else {
            return database_error();
        }
    }
    $matchesFound = array();
    if ($labelmatch == 'true' && $text != "" || $labelmatch == 'false' && $nodeid != "") {
        $checkConnections = array();
        $matchedConnections = null;
        if ($labelmatch == 'true') {
            $nextNodes[0] = $text;
        } else {
            $nextNodes[0] = $nodeid;
        }
        $matchesFound = searchNetworkConnections($checkConnections, $matchedConnections, $nextNodes, $searchLinkLabels, $searchLinkLabelsArray, $linkgroup, $labelmatch, $depth, 0, $direction, $nodeTypeNames, $nodeTypeNamesArray, $scope, $status);
    }
    //return database_error($matchesFound);
    //print_r($matchesFound);
    $cs = new ConnectionSet($matchesFound);
    return $cs->loadConnections($matchesFound, $style);
}
/**
 * Get the connections for the given netowrk search paramters from the given node.
 *
 * @param string $scope (either 'all' or 'my', deafult 'all')
 * @param string $labelmatch (optional, 'true', 'false' - default: false;
 * @param string $nodeid the id of the node to search outward from.
 * @param integer $depth (optional, 1-7, default 1);
 * @param string $linklabels Array of strings of link types. Array length must match depth specified. Each array level is mutually exclusive with linkgroups - there can only be one.
 * @param string $linkgroups Array of either Positive, Negative, or Neutral - default: empty string). Array length must match depth specified.Each array level is mutually exclusive with linklabels - there can only be one.
 * @param string $directions Array of 'outgoing', 'incmong', or 'both' - default: 'both'. Array length must match depth specified.
 * @param string $nodetypes Array of strings of node type names. Array length must match depth specified.
 * @param string $nodeids Array of strings of nodeids. Array length must match depth specified.
 * @param String $style (optional - default 'long') may be 'short' or 'long'
 * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired)
 * @return ConnectionSet or Error
 */
function getConnectionsByPathByDepthOR($scope = 'all', $labelmatch = 'false', $nodeid, $depth = 1, $linklabels, $linkgroups, $directions, $nodetypes, $nodeids, $uniquepath = 'true', $style = 'long', $status)
{
    global $DB, $USER, $CFG, $HUB_SQL;
    // GET TEXT FOR PASSED IDEA ID IF REQUIRED
    $text = "";
    if ($labelmatch == 'true') {
        $params = array();
        $params[0] = $nodeid;
        $sql = $HUB_SQL->UTILLIB_NODE_NAME_BY_NODEID;
        $resArray = $DB->select($sql, $params);
        $array = array();
        if ($resArray !== false) {
            $count = count($resArray);
            for ($i = 0; $i < $count; $i++) {
                $array = $resArray[$i];
                $text = $array['Name'];
            }
        } else {
            return database_error();
        }
    }
    $messages = '';
    $matchesFound = array();
    if ($labelmatch == 'true' && $text != "" || $labelmatch == 'false' && $nodeid != "") {
        $checkConnections = array();
        $matchedConnections = null;
        if ($labelmatch == 'true') {
            $nextNodes[0] = $text;
        } else {
            $nextNodes[0] = $nodeid;
        }
        $matchesFound = searchNetworkConnectionsByDepthOR($checkConnections, $matchedConnections, $nextNodes, $labelmatch, $depth, 0, $linklabels, $linkgroups, $directions, $nodetypes, $nodeids, $uniquepath, $scope, $status, $messages);
    }
    //return database_error($messages);
    $cs = new ConnectionSet();
    return $cs->loadConnections($matchesFound, $style);
}