Example #1
0
/**
 * Process network search results and flatten into one array.
 */
function getDepthConnectionResults(&$results, $nextArray)
{
    foreach ($nextArray as $key => $val) {
        $count = count($val);
        for ($j = 0; $j < $count; $j++) {
            $next = $val[$j];
            if (isset($next["TripleID"])) {
                $results[count($results)] = $next;
            } else {
                getDepthConnectionResults($results, $next);
            }
        }
    }
}
/**
 * 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 getConnectionsByPathByDepthAND($logictype = 'or', $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 = searchNetworkConnectionsByDepth($checkConnections, $matchedConnections, $nextNodes, $labelmatch, $depth, 0, $linklabels, $linkgroups, $directions, $nodetypes, $nodeids, $uniquepath, $scope, $status, $messages);
    }
    //return database_error($messages);
    //aggregate the connections that made it to last level
    $results = array();
    getDepthConnectionResults($results, $matchesFound);
    $cs = new ConnectionSet();
    return $cs->loadConnections($results, $style);
}