/** * 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; }
} 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; $mapNodes->add($node); $mapNodes->totalno = 1; $mapNodes->count = 1; $jsonnodes = $format_json->format($mapNodes); $jsonusers = $format_json->format($userset); $jsoncons = $format_json->format($conSet); ?> <script type='text/javascript'> var NODE_ARGS = new Array(); Event.observe(window, 'load', function() { NODE_ARGS['nodeid'] = '<?php echo $nodeid; ?> ';
/** * 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; }
//if (isset($suggestion->arguments)) { // $argumentsArray = $suggestion->arguments; //} //strip the id off the end of the post id (userid will need decrypting) $bits = explode('/', $nextpost); $nextpost = $bits[count($bits) - 1]; $targetType = $suggestion->targetType; //I encode psuedo user ids on the way out. //Not sure why. Possibly something to do with the cipher encoding. $nextpost = urldecode($nextpost); if ($targetType == 'user' && isset($cipher) && $nextpost != 'anonymous') { $nextpost = $cipher->decrypt($nextpost); } if ($targetType == 'post' && isset($nodeArray[$nextpost])) { $nextObj = $nodeArray[$nextpost]; $finalNodeArray->add($nextObj); } else { if ($targetType == 'user' && $nextpost != 'anonymous') { if (!isset($finalUserCheckArray[$nextpost])) { if (isset($userArray[$nextpost])) { $nextObj = $userArray[$nextpost]; $finalUserArray->add($nextObj); $finalUserCheckArray[$nextpost] = $nextpost; } else { //error_log("USER not found for:".$nextpost); $user = getUser($nextpost); if (!$user instanceof Error) { $finalUserArray->add($user); $finalUserCheckArray[$nextpost] = $nextpost; } else { continue;
$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 .= ','; } }