Esempio n. 1
0
            } 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($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['groupid'] = '<?php 
Esempio n. 2
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;
}