/** * Import nodes and connections from the given CIF url for the selected nodeids into the given map. * The node import limit is set by '$CFG->ImportLimit'. * @param url the url for the CIF data to load * @param mapid the id of the map to get alerts for * @param selectedids an array of the CIF node ides to import * @param poses an array of the positions of the nodes in the map each array item is in * the format 'x:y' and the position in the array should correspond ot the position of * its node in the selectednodeids array. * before it is considered out of date and should be refetched and recalculated. * Defaults to 60 seconds. * @param private true if the data should be created as private, else false. * @return View object of the map or Error. * */ function addNodesAndConnectionsFromJsonld($url, $mapid, $selectedids, $poses, $private) { global $USER, $HUB_FLM, $CFG, $ERROR; require_once $HUB_FLM->getCodeDirPath("core/io/catalyst/catalyst_jsonld_reader.class.php"); require_once $HUB_FLM->getCodeDirPath("core/lib/url-validation.class.php"); //error_log(print_r($selectedids, true)); if (count($selectedids) > $CFG->ImportLimit) { $ERROR = new error(); $ERROR->createAccessDeniedError(); return $ERROR; } //error_log(print_r($poses, true)); // Check if the map is in a group and if so get the group id. $groupid = ""; $v = new View($mapid); $view = $v->load(); if (!$view instanceof Error) { if (isset($view->viewnode->groups)) { $groups = $view->viewnode->groups; if (count($groups) > 0) { $groupid = $groups[0]->groupid; } } } else { return $view; } // make sure current user in group, if group set. if ($groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if (!$group->ismember($USER->userid)) { $error = new Error(); return $error->createNotInGroup($group->name); } } } $withhistory = false; $withvotes = false; $reader = new catalyst_jsonld_reader(); $reader = $reader->load($url, $withhistory, $withvotes); if (!$reader instanceof Error) { $nodeset = $reader->nodeSet; $nodes = $nodeset->nodes; $count = count($nodes); $newnodeSet = new NodeSet(); $newNodeCheck = array(); for ($i = 0; $i < $count; $i++) { $node = $nodes[$i]; $position = array_search($node->nodeid, $selectedids); //error_log("position:".$position); if ($position !== FALSE) { $position = intval($position); $positem = $poses[$position]; $positemArray = explode(":", $positem); $xpos = ""; $ypos = ""; if (count($positemArray) == 2) { $xpos = $positemArray[0]; $ypos = $positemArray[1]; } //error_log("xpos:".$xpos.":ypos:".$ypos); $role = getRoleByName($node->rolename); $description = ""; if (isset($node->description)) { $description = $node->description; } $newnode = addNode($node->name, $description, $private, $role->roleid); //error_log(print_r($newnode, true)); if (!$newnode instanceof Error) { $newNodeCheck[$node->nodeid] = $newnode; //error_log($node->nodeid); // if we have positioning information add the node to the map. if ($xpos != "" && $ypos != "") { $viewnode = $view->addNode($newnode->nodeid, $xpos, $ypos); //if (!$viewnode instanceof Error) { } if (isset($node->homepage) && $node->homepage != "") { $URLValidator = new mrsnk_URL_validation($node->homepage, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($URLValidator->isValid()) { $urlObj = addURL($node->homepage, $node->homepage, "", $private, "", "", "", "cohere", ""); $newnode->addURL($urlObj->urlid, ""); // Add url to group? - not done on forms at present } else { error_log('Invalid node homepage: ' . $node->homepage . ': for ' . $node->nodeid); } } if (isset($node->users[0])) { $user = $node->users[0]; if (isset($user->homepage) && $user->homepage != "") { $URLValidator = new mrsnk_URL_validation($user->homepage, MRSNK_URL_DO_NOT_PRINT_ERRORS, MRSNK_URL_DO_NOT_CONNECT_2_URL); if ($URLValidator->isValid()) { $urlObj = addURL($user->homepage, $user->homepage, "", $private, "", "", "", "cohere", ""); $newnode->addURL($urlObj->urlid, ""); // Add url to group? - not done on forms at present } else { error_log('Invalid user homepage: ' . $user->homepage . ': for ' . $user->userid); } } } //if ($groupid != "") { // $newnode->addGroup($groupid); //} $newnodeSet->add($newnode); } else { error_log(print_r($newnode, true)); } } } $connectionset = $reader->connectionSet; $connections = $connectionset->connections; $count = count($connections); for ($i = 0; $i < $count; $i++) { $conn = $connections[$i]; $from = $conn->from; $to = $conn->to; $fromrole = $conn->fromrole; $torole = $conn->torole; if (isset($newNodeCheck[$from->nodeid]) && isset($newNodeCheck[$to->nodeid])) { $newFromNode = $newNodeCheck[$from->nodeid]; $newToNode = $newNodeCheck[$to->nodeid]; // Might not need this as it might be done already //if ($newFromNode->role->name != $fromrole->name) { // updateNodeRole($newFromNode->nodeid,$fromrole->name); //} $linklabelname = $conn->linklabelname; //error_log($linklabelname); $lt = getLinkTypeByLabel($linklabelname); if (!$lt instanceof Error) { $linkType = $lt->linktypeid; //$frole = getRoleByName($fromrole->name); //$trole = getRoleByName($torole->name); $connection = addConnection($newFromNode->nodeid, $newFromNode->role->roleid, $linkType, $newToNode->nodeid, $newToNode->role->roleid, 'N', ""); //error_log(print_r($connection, true)); if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { $connection->addGroup($groupid); } $viewcon = $view->addConnection($connection->connid); //error_log(print_r($viewcon,true)); } else { error_log(print_r($connection, true)); } } else { error_log("for label:" . $linklabelname . ":" . print_r($lt, true)); } } } } else { return $reader; } return $view; }
********************************************************************************/ include_once $_SERVER['DOCUMENT_ROOT'] . '/config.php'; include_once $HUB_FLM->getCodeDirPath("core/formats/json.php"); include_once $HUB_FLM->getCodeDirPath("ui/headerstats.php"); $nodeid = required_param("nodeid", PARAM_ALPHANUMEXT); $userHashtable = array(); $userCheck = array(); $usersToMaps = array(); $nodeCheck = array(); $totalnodes = 0; $view = getView($nodeid); $node = $view->viewnode; $cons = $view->connections; $countcons = count($cons); $localusers = array(); $mapNodes = new NodeSet(); $nodeCheck[$node->nodeid] = $node; $mapowner = $node->users[0]; $mapowner->procount = 0; $mapowner->concount = 0; $mapowner->ideacount = 0; $mapowner->debatecount = 0; $mapowner->mapcount = 1; $localusers[$node->users[0]->userid] = $mapowner; if (!array_key_exists($node->users[0]->userid, $userCheck)) { $userCheck[$node->users[0]->userid] = $mapowner; $userHashtable[$node->users[0]->userid] = $mapowner; } for ($j = 0; $j < $countcons; $j++) { $viewcon = $cons[$j]; $con = $viewcon->connection;
function getAllVotingForUser($userid, $direction, $sort, $oldsort) { global $DB, $CFG, $HUB_SQL; $params = array(); $params[0] = $userid; $allNodeVotes = array(); if ($direction) { if ($oldsort === $sort) { if ($direction === 'ASC') { $direction = "DESC"; } else { $direction = "ASC"; } } else { $direction = "DESC"; } } else { $direction = "DESC"; } $allNodeVotes = array(); $sql = $HUB_SQL->STATSLIB_USER_ALL_VOTING; if ($sort != 'Name' && $sort != "NodeType") { $sql .= $HUB_SQL->STATSLIB_ALL_VOTING_ORDER_BY . $sort . " " . $direction; } $ns = new NodeSet(); $ns->loadNodesWithExtras($sql, $params, 'short'); // These properties had to be taken out of the original sql call // as Virtuoso complained about a long data type error // Do now data called as separate Nodes and these sorts are done afterwards. if ($sort === "Name") { if ($direction === "ASC") { usort($ns->nodes, 'nameSortASC'); } else { usort($ns->nodes, 'nameSortDESC'); } } else { if ($sort === "NodeType") { if ($direction === "ASC") { usort($ns->nodes, 'roleTextSortASC'); } else { usort($ns->nodes, 'roleTextSortDESC'); } } } return $ns; }
/** * Get the nodes for given group * * @param string $groupid * @param integer $start (optional - default: 0) * @param integer $max (optional - default: 20) * @param string $orderby (optional, either 'date', 'nodeid', 'name', 'connectedness' or 'moddate' - default: 'date') * @param string $sort (optional, either 'ASC' or 'DESC' - default: 'DESC') * @param string $filterusers (optional, a list of user ids to filter 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' - how much of a nodes details to load (long includes: description, tags, groups and urls). * @param string $q the query term(s) * @param integer $status, defaults to 0. (0 - active, 1 - reported, 2 - retired) * @return NodeSet or Error * @param string $connectionfilter filter by connections. Defaults to empty string which means disregard connection count. Possible values; '','connected','unconnected'. */ function getNodesByGroup($groupid, $start = 0, $max = 20, $orderby = 'date', $sort = 'DESC', $filterusers = '', $filternodetypes = '', $style = 'long', $q = "", $connectionfilter = '', $status = 0) { global $CFG, $USER, $HUB_SQL; $currentuser = ''; if (isset($USER->userid)) { $currentuser = $USER->userid; } $params = array(); $sql = $HUB_SQL->APILIB_NODES_BY_GROUP_SELECT; // FILTER NODE TYPES if ($filternodetypes != "") { // This comes first in HUB_SQL->APILIB_NODES_BY_GROUP_NODETYPE // Before node type list. $params[count($params)] = $groupid; $pieces = explode(",", $filternodetypes); $sqlList = ""; $loopCount = 0; foreach ($pieces as $value) { $params[count($params)] = $value; if ($loopCount == 0) { $sqlList .= "?"; } else { $sqlList .= ",?"; } $loopCount++; } $sql .= $HUB_SQL->APILIB_NODES_BY_GROUP_NODETYPE . $HUB_SQL->OPENING_BRACKET; $sql .= $sqlList; $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND; } else { $params[count($params)] = $groupid; $HUB_SQL->APILIB_NODES_BY_GROUP_NODETYPE_NONE . $HUB_SQL->AND; } if ($filterusers != "") { $pieces = explode(",", $filterusers); $loopCount = 0; $searchUsers = ""; foreach ($pieces as $value) { $params[count($params)] = $value; if ($loopCount == 0) { $searchUsers .= "?"; } else { $searchUsers .= ",?"; } $loopCount++; } $sql .= $HUB_SQL->FILTER_USERS . $HUB_SQL->OPENING_BRACKET; $sql .= $searchUsers; $sql .= $HUB_SQL->CLOSING_BRACKET . $HUB_SQL->AND; } // SEARCH if ($q != "") { $querySQL = getSearchQueryString($params, $q, true, true); $sql .= $querySQL; if ($querySQL != "") { $sql .= $HUB_SQL->AND; } } // PERMISSIONS $params[count($params)] = 'N'; $params[count($params)] = $currentuser; $params[count($params)] = $currentuser; $sql .= $HUB_SQL->APILIB_NODES_PERMISSIONS_ALL; // FILTER STATUS $params[count($params)] = $status; $sql .= $HUB_SQL->AND . $HUB_SQL->APILIB_FILTER_STATUS; // ORDER BY VOTE if ($orderby == 'vote') { $sql = $HUB_SQL->APILIB_NODE_ORDERBY_VOTE_PART1 . $sql . $HUB_SQL->APILIB_NODE_ORDERBY_VOTE_PART2; } if ($connectionfilter == 'unconnected') { $sql .= $HUB_SQL->APILIB_HAVING_UNCONNECTED; } else { if ($connectionfilter == 'connected') { $sql .= $HUB_SQL->APILIB_HAVING_CONNECTED; } } $ns = new NodeSet(); return $ns->load($sql, $params, $start, $max, $orderby, $sort, $style); }
/** * 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; }
} 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; $issueNodes = new NodeSet(); $issueNodes->add($node); $issueNodes->totalno = 1; $issueNodes->count = 1; $jsonnodes = $format_json->format($issueNodes); $jsonusers = $format_json->format($userset); $jsoncons = $format_json->format($conSet); $args = array(); $args["nodeid"] = $nodeid; $argsStr = "{"; $keys = array_keys($args); for ($i = 0; $i < sizeof($keys); $i++) { $argsStr .= '"' . $keys[$i] . '":"' . $args[$keys[$i]] . '"'; if ($i != sizeof($keys) - 1) { $argsStr .= ','; }
/** * Get the nodes with the given status. * * @param integer $status (0 = non-spam or 1 = spam) * @param integer $start (optional - default: 0) * @param integer $max (optional - default: 20) * @param string $orderby (optional, either 'date', 'nodeid', 'name', 'connectedness' or 'moddate' - default: 'date') * @param string $sort (optional, either 'ASC' or 'DESC' - default: 'DESC') * @param String $style (optional - default 'long') may be 'short' or 'long' - how much of a nodes details to load (long includes: description, tags, groups and urls). * @return NodeSet or Error */ function getNodesByStatus($status = 0, $start = 0, $max = 20, $orderby = 'date', $sort = 'DESC', $style = 'long') { global $CFG, $USER, $HUB_SQL; $params = array(); $params[0] = $status; $sql = $HUB_SQL->UTILLIB_NODES_BY_STATUS; $ns = new NodeSet(); return $ns->load($sql, $params, $start, $max, $orderby, $sort, $style); }
/** * Fetch a node list of lemons used against the given issue for the current user. * @param $issueid the id of the issue to get the lemons for. * @returns NodeSet or Error */ function getMyLemonsForIssue($issueid) { global $USER, $HUB_SQL; $params = array(); $params[0] = $USER->userid; $params[1] = $issueid; $ns = new NodeSet(); return $ns->loadNodesWithExtras($HUB_SQL->DATAMODEL_UTIL_USER_LEMONS_FOR_ISSUE, $params); }