示例#1
0
                        $thisuser->concount = $thisuser->concount + 1;
                    }
                    if ($fromNode->role->name == 'Solution') {
                        $thisuser->ideacount = $thisuser->ideacount + 1;
                    }
                    if ($fromNode->role->name == 'Issue') {
                        $thisuser->debatecount = $thisuser->debatecount + 1;
                    }
                    $localusers[$thisuser->userid] = $thisuser;
                }
            }
        }
    }
    $usersToDebates[$node->nodeid] = $localusers;
}
$conSet = new ConnectionSet();
$count = count($usersToDebates);
foreach ($usersToDebates as $nodeid => $users) {
    foreach ($users as $userid => $user) {
        $to = $user;
        $connection = new Connection();
        $procount = $user->procount;
        $concount = $user->concount;
        $ideacount = $user->ideacount;
        $debatecount = $user->debatecount;
        $totalnodes = $totalnodes + ($ideacount + $debatecount + $procount + $concount);
        $connection->procount = $procount;
        $connection->concount = $concount;
        $connection->ideacount = $ideacount;
        $connection->debatecount = $debatecount;
        $connection->toid = $userid;
示例#2
0
/**
 * Get all the connections for the given node types and link types
 *
 * @param string $groupid the id of the group to get social connections for
 * @param string $scope (either 'all' or 'my')
 * @param integer $start (optional - default: 0)
 * @param integer $max (optional - default: 20)
 * @param string $orderby (optional, either 'date', 'name' or 'moddate' - default: 'date')
 * @param string $sort (optional, either 'ASC' or 'DESC' - default: 'DESC')
 * @param string $linklabels (optional, comma separated strings of the connection labels to filter the results by)
 * @param string $filternodetypes (optional, a list of node type names to filter by)
 * @param String $style (optional - default 'long') may be 'short' or 'long'
 * @return ConnectionSet or Error
 */
function getConnectionsByGroup($groupid, $scope, $start = 0, $max = 20, $orderby = 'date', $sort = 'ASC', $linklabels = '', $filternodetypes = '', $style = 'long')
{
    global $DB, $USER, $CFG, $HUB_SQL;
    $params = array();
    $params[0] = $groupid;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $sql = $HUB_SQL->APILIB_CONNECTIONS_BY_GROUP_SELECT;
    $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GROUP_FILTER;
    // FILTER BY NODE TYPES - AND
    if ($filternodetypes != "") {
        $sql .= $HUB_SQL->AND;
        $nodetypeArray = array();
        $innersql = getSQLForNodeTypeIDsForLabels($nodetypeArray, $filternodetypes);
        $params = array_merge($params, $nodetypeArray);
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_NODETYPE_FILTER_PART1;
        $sql .= $innersql;
        $params = array_merge($params, $nodetypeArray);
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_NODETYPE_FILTER_PART2;
        $sql .= $innersql;
        $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->CLOSING_BRACKET;
    }
    // FILTER BY LINK TYPES
    if ($linklabels != "") {
        $innersql = getSQLForLinkTypeIDsForLabels($params, $linklabels);
        $sql .= $HUB_SQL->AND;
        $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_LINKTYPE_FILTER;
        $sql .= $HUB_SQL->OPENING_BRACKET;
        $sql .= $innersql;
        $sql .= $HUB_SQL->CLOSING_BRACKET;
    }
    // PERMISSIONS
    if ($scope == "my") {
        $params[count($params)] = $currentuser;
        $sql .= $HUB_SQL->AND;
        $sql .= $HUB_SQL->FILTER_USER;
    }
    $sql .= $HUB_SQL->AND;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $params[count($params)] = 'N';
    $params[count($params)] = $currentuser;
    $params[count($params)] = $currentuser;
    $sql .= $HUB_SQL->APILIB_CONNECTIONS_BY_GLOBAL_PERMISSIONS;
    $cs = new ConnectionSet();
    //error_log(print_r($sql, true));
    return $cs->load($sql, $params, $start, $max, $orderby, $sort, $style);
}
示例#3
0
/**
 * Load the data for the Sunburst visulaisation
 * @param url the url for the CIF data to load
 * @param timeout how long (in seconds) to cache the visualisation data
 * before it is considered out of date and should be refetched and recalculated.
 * Defaults to 60 seconds.
 * @return an associative array of arrays of nodes, connections and users from the data loaded from the CIF.
 * and converted to the structure required by the Sunburst visualisation.
 * The keys are 'nodes', 'cons' and 'users'.
 */
function getSunburstData($url, $timeout = 60)
{
    global $CFG, $HUB_CACHE;
    $withhistory = false;
    $withvotes = false;
    $withposts = false;
    $data = $HUB_CACHE->getObjData($CFG->VIS_PAGE_SUNBURST . $url . $withhistory . $withvotes . $withposts);
    if ($data === FALSE) {
        //error_log("DATA not FOUND: getSunburstData");
        $reader = $HUB_CACHE->getObjData('reader' . $url . $withhistory . $withvotes . $withposts);
        if ($reader === FALSE) {
            error_log("READER not FOUND: getSunburstData");
            $reader = new catalyst_jsonld_reader();
            $reader = $reader->load($url, $timeout, $withhistory, $withvotes, $withposts);
            $HUB_CACHE->setObjData('reader' . $url . $withhistory . $withvotes . $withposts, $reader, $timeout);
        } else {
            error_log("READER FOUND: getSunburstData");
        }
        //$reader = new catalyst_jsonld_reader();
        //$reader = $reader->load($url,$timeout,$withhistory,$withvotes,$withposts);
        $jsonnodes = array();
        $jsonusers = array();
        $jsoncons = array();
        $data = array();
        if (!$reader instanceof Error) {
            $userHashtable = array();
            $userCheck = array();
            $usersToDebates = array();
            $nodeCheck = array();
            $totalnodes = 0;
            $issueCheck = array();
            $issueNodes = array();
            $issueConnections = array();
            $solutionNodes = array();
            $connections = $reader->connectionSet->connections;
            $count = count($connections);
            $nodeSet = new NodeSet();
            // GET ISSUES
            for ($i = 0; $i < $count; $i++) {
                $connection = $connections[$i];
                $from = $connection->from;
                $to = $connection->to;
                if ($from->rolename == "Issue") {
                    if (!in_array($from->nodeid, $issueCheck)) {
                        array_push($issueNodes, $from);
                        $nodeSet->add($from);
                        array_push($issueCheck, $from->nodeid);
                    }
                }
                if ($to->rolename == "Issue") {
                    if (!in_array($to->nodeid, $issueCheck)) {
                        array_push($issueNodes, $to);
                        $nodeSet->add($to);
                        array_push($issueCheck, $to->nodeid);
                    }
                }
            }
            // GET ISSUE TREES
            function loadMoreIssueChildNodes(&$connections, $nextArray, &$parentlist)
            {
                global $issueConnections;
                $countj = count($nextArray);
                for ($j = 0; $j < $countj; $j++) {
                    $nextid = $nextArray[$j];
                    $newNextArray = array();
                    foreach ($connections as $connection) {
                        $from = $connection->from;
                        $to = $connection->to;
                        if ($to->nodeid == $nextid || $from->nodeid == $nextid) {
                            if ($from->nodeid == $nextid) {
                                array_push($newNextArray, $to->nodeid);
                            } else {
                                array_push($newNextArray, $from->nodeid);
                            }
                            array_push($parentlist, $connection);
                            if (($key = array_search($connection, $connections)) !== false) {
                                unset($connections[$key]);
                            }
                        }
                    }
                    if (count($newNextArray) > 0 && count($connections) > 0) {
                        loadMoreIssueChildNodes($connections, $newNextArray, $parentlist);
                    }
                }
            }
            set_time_limit(60);
            $nextArray = array();
            $countj = count($issueNodes);
            for ($j = 0; $j < $countj; $j++) {
                $next = $issueNodes[$j];
                $nextid = $next->nodeid;
                $list = array();
                foreach ($connections as $connection) {
                    $from = $connection->from;
                    $to = $connection->to;
                    if ($to->nodeid == $nextid || $from->nodeid == $nextid) {
                        if ($from->nodeid == $nextid) {
                            array_push($nextArray, $to->nodeid);
                        } else {
                            array_push($nextArray, $from->nodeid);
                        }
                        array_push($list, $connection);
                        if (($key = array_search($connection, $connections)) !== false) {
                            unset($connections[$key]);
                        }
                    }
                }
                $issueConnections[$nextid] = $list;
                loadMoreIssueChildNodes($connections, $nextArray, $issueConnections[$nextid]);
            }
            // COUNT TYPES FOR DETAILS PANEL
            $count = count($issueNodes);
            for ($i = 0; $i < $count; $i++) {
                $node = $issueNodes[$i];
                if (isset($node->users[0])) {
                    if (!array_key_exists($node->nodeid, $nodeCheck)) {
                        $nodeCheck[$node->nodeid] = $node;
                    }
                    if (!array_key_exists($node->users[0]->userid, $userHashtable)) {
                        $globaluser = clone $node->users[0];
                        $globaluser->procount = 0;
                        $globaluser->concount = 0;
                        $globaluser->ideacount = 0;
                        $globaluser->debatecount = 1;
                        $userHashtable[$node->users[0]->userid] = $globaluser;
                    } else {
                        $globaluser = $userHashtable[$node->users[0]->userid];
                        $globaluser->debatecount = $globaluser->debatecount + 1;
                        $userHashtable[$node->users[0]->userid] = $globaluser;
                    }
                    if (array_key_exists($node->nodeid, $issueConnections)) {
                        $cons = $issueConnections[$node->nodeid];
                        $countcons = count($cons);
                        $localusers = array();
                        $debateowner = $node->users[0];
                        $debateowner->procount = 0;
                        $debateowner->concount = 0;
                        $debateowner->ideacount = 0;
                        $debateowner->debatecount = 1;
                        $localusers[$node->users[0]->userid] = $debateowner;
                        if (!array_key_exists($node->users[0]->userid, $userCheck)) {
                            $userCheck[$node->users[0]->userid] = $node->users[0];
                        }
                        for ($j = 0; $j < $countcons; $j++) {
                            $con = $cons[$j];
                            $fromNode = $con->from;
                            if (!array_key_exists($fromNode->nodeid, $nodeCheck)) {
                                $nodeCheck[$fromNode->nodeid] = $fromNode;
                            }
                            //$toNode = $con->to;
                            $thisuser = clone $fromNode->users[0];
                            if (!array_key_exists($thisuser->userid, $userCheck)) {
                                $userCheck[$thisuser->userid] = $thisuser;
                            }
                            if (!array_key_exists($thisuser->userid, $userHashtable)) {
                                $globaluser = clone $fromNode->users[0];
                                $globaluser->procount = 0;
                                $globaluser->concount = 0;
                                $globaluser->ideacount = 0;
                                $globaluser->debatecount = 0;
                                if ($fromNode->role->name == 'Pro') {
                                    $globaluser->procount = 1;
                                }
                                if ($fromNode->role->name == 'Con') {
                                    $globaluser->concount = 1;
                                }
                                if ($fromNode->role->name == 'Solution') {
                                    $globaluser->ideacount = 1;
                                }
                                $userHashtable[$thisuser->userid] = $globaluser;
                            } else {
                                $globaluser = $userHashtable[$thisuser->userid];
                                if ($fromNode->role->name == 'Pro') {
                                    $globaluser->procount = $globaluser->procount + 1;
                                }
                                if ($fromNode->role->name == 'Con') {
                                    $globaluser->concount = $globaluser->concount + 1;
                                }
                                if ($fromNode->role->name == 'Solution') {
                                    $globaluser->ideacount = $globaluser->ideacount + 1;
                                }
                                $userHashtable[$thisuser->userid] = $globaluser;
                            }
                            if (!array_key_exists($thisuser->userid, $localusers)) {
                                $thisuser->procount = 0;
                                $thisuser->concount = 0;
                                $thisuser->ideacount = 0;
                                $thisuser->debatecount = 0;
                                if ($fromNode->role->name == 'Pro') {
                                    $thisuser->procount = 1;
                                }
                                if ($fromNode->role->name == 'Con') {
                                    $thisuser->concount = 1;
                                }
                                if ($fromNode->role->name == 'Solution') {
                                    $thisuser->ideacount = 1;
                                }
                                $localusers[$thisuser->userid] = $thisuser;
                            } else {
                                $thisuser = $localusers[$thisuser->userid];
                                if ($fromNode->role->name == 'Pro') {
                                    $thisuser->procount = $thisuser->procount + 1;
                                }
                                if ($fromNode->role->name == 'Con') {
                                    $thisuser->concount = $thisuser->concount + 1;
                                }
                                if ($fromNode->role->name == 'Solution') {
                                    $thisuser->ideacount = $thisuser->ideacount + 1;
                                }
                                $localusers[$thisuser->userid] = $thisuser;
                            }
                        }
                    }
                    $usersToDebates[$node->nodeid] = $localusers;
                }
            }
            $conSet = new ConnectionSet();
            $count = count($usersToDebates);
            //$userHashtable = $userCheck;
            foreach ($usersToDebates as $nodeid => $users) {
                //$from = $nodeCheck[$nodeid];
                foreach ($users as $userid => $user) {
                    $to = $user;
                    $connection = new Connection();
                    $procount = $user->procount;
                    $concount = $user->concount;
                    $ideacount = $user->ideacount;
                    $debatecount = $user->debatecount;
                    $totalnodes = $totalnodes + ($ideacount + $debatecount + $procount + $concount);
                    $connection->procount = $procount;
                    $connection->concount = $concount;
                    $connection->ideacount = $ideacount;
                    $connection->debatecount = $debatecount;
                    $connection->toid = $userid;
                    $connection->fromid = $nodeid;
                    $graycount = $ideacount + $debatecount;
                    if ($procount > $concount && $procount > $graycount) {
                        $connection->linklabelname = $CFG->LINK_PRO_SOLUTION;
                    } else {
                        if ($concount > $procount && $concount > $graycount) {
                            $connection->linklabelname = $CFG->LINK_CON_SOLUTION;
                        } else {
                            if ($procount == $graycount && $procount > $concount) {
                                $connection->linklabelname = $CFG->LINK_PRO_SOLUTION;
                            } else {
                                if ($concount == $graycount && $concount > $procount) {
                                    $connection->linklabelname = $CFG->LINK_CON_SOLUTION;
                                } else {
                                    $connection->linklabelname = $CFG->LINK_SOLUTION_ISSUE;
                                }
                            }
                        }
                    }
                    $conSet->add($connection);
                }
            }
            $format_json = new format_json();
            $userset = new UserSet();
            foreach ($userHashtable as $userid => $user) {
                $userset->add($user);
            }
            $conSet->totalnodes = $totalnodes;
            $jsonnodes = $format_json->format($nodeSet);
            $jsonusers = $format_json->format($userset);
            $jsoncons = $format_json->format($conSet);
        }
        $data['nodes'] = $jsonnodes;
        $data['cons'] = $jsoncons;
        $data['users'] = $jsonusers;
        $HUB_CACHE->setObjData($CFG->VIS_PAGE_SUNBURST . $url . $withhistory . $withvotes . $withposts, $data, $timeout);
    } else {
        //error_log("DATA FOUND: getSunburstData");
    }
    return $data;
}
示例#4
0
function getInformationBrokeringForUser($userid)
{
    global $DB, $CFG, $USER, $HUB_SQL;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $params = array();
    $params[0] = $userid;
    $params[1] = 'N';
    $params[2] = $currentuser;
    $params[3] = $currentuser;
    $params[4] = 'N';
    $params[5] = $currentuser;
    $params[6] = $currentuser;
    $params[7] = 'N';
    $params[8] = $currentuser;
    $params[9] = $currentuser;
    $params[10] = $userid;
    $params[11] = 'N';
    $params[12] = $currentuser;
    $params[13] = $currentuser;
    $params[14] = 'N';
    $params[15] = $currentuser;
    $params[16] = $currentuser;
    $params[17] = 'N';
    $params[18] = $currentuser;
    $params[19] = $currentuser;
    $params[20] = $userid;
    $params[21] = $userid;
    $brokerConnectionSet = new ConnectionSet();
    $sql = $HUB_SQL->STATSLIB_USER_INFORMATION_BROKERING;
    $resArray = $DB->select($sql, $params);
    $nodeArray = array();
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $array = $resArray[$i];
            $id = $array['TripleID'];
            $con = new Connection();
            $con->connid = $id;
            $con = $con->load();
            if (!$con instanceof error) {
                $brokerConnectionSet->add($con);
            }
        }
        $brokerConnectionSet->totalno = count($brokerConnectionSet->connections);
        $brokerConnectionSet->start = 0;
        $brokerConnectionSet->count = $brokerConnectionSet->totalno;
    }
    return $brokerConnectionSet;
}
/**
 * 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);
}