/** * Add a node to a view. Requires login * * @param string $viewid * @param string $nodeid * @param string $xpos. * @param string $ypos. * @param string $groupid (optional) the id of the group to add the node to. * * @return View with new node and connection in or Error */ function addNodeToViewAndConnect($viewid, $focalnodeid, $nodeid, $xpos, $ypos, $linktypename, $direction, $groupid = "") { global $USER; // make sure current user in group, if group set. if (isset($groupid) && $groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if (!$group->ismember($USER->userid)) { $error = new Error(); return $error->createNotInGroup($group->name); } } } $node = new CNode($nodeid); $node = $node->load(); if (!$node instanceof Error) { if (isset($groupid) && $groupid != "") { $node->addGroup($groupid); } $view = new View($viewid); $viewnode = $view->addNode($nodeid, $xpos, $ypos); if (!$viewnode instanceof Error) { // Connect to focal node $focalnode = new CNode($focalnodeid); $focalnode = $focalnode->load(); if (!$focalnode instanceof Error) { $focalrole = getRoleByName($focalnode->role->name); $focalroleid = $focalrole->roleid; $role = getRoleByName($node->role->name); if ($role instanceof Error) { $role = addRole($node->role->name); } $roleid = $role->roleid; $lt = getLinkTypeByLabel($linktypename); $linkType = $lt->linktypeid; // connection always public, so drawing determined by node privacy. if ($direction == 'from') { $connection = addConnection($node->nodeid, $roleid, $linkType, $focalnodeid, $focalroleid, 'N', ""); } else { $connection = addConnection($focalnodeid, $focalroleid, $linkType, $node->nodeid, $roleid, 'N', ""); } if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { $connection->addGroup($groupid); } $viewcon = $view->addConnection($connection->connid); return $view; } else { return $connection; } } else { return $focalnode; } } else { return $viewnode; } } else { return $node; } }
/** * Return a ViewSet for the given groupid; */ function getConversationData($groupid) { $issueNodes = getNodesByGroup($groupid, 0, -1, 'date', 'DESC', '', 'Issue', 'cif'); $checkNodes = array(); $checkConns = array(); $group = new Group($groupid); $view = new View($groupid); if (!$issueNodes instanceof Error) { $nodes = $issueNodes->nodes; $count = count($nodes); for ($i = 0; $i < $count; $i++) { $node = $nodes[$i]; if (!$node instanceof Error) { if (array_key_exists($node->nodeid, $checkNodes) === FALSE) { $checkNodes[$node->nodeid] = $node->nodeid; $view->addNode($node); } $conSet = getDebate($node->nodeid, 'cif'); if (!$conSet instanceof Error) { $countj = count($conSet->connections); for ($j = 0; $j < $countj; $j++) { $con = $conSet->connections[$j]; if (array_key_exists($con->connid, $checkConns) === FALSE) { $checkConns[$con->connid] = $con->connid; $view->addConnection($con); } $from = $con->from; if (!$from instanceof Error && array_key_exists($from->nodeid, $checkNodes) === FALSE) { $checkNodes[$from->nodeid] = $from->nodeid; $view->addNode($from); } $to = $con->to; if (!$to instanceof Error && array_key_exists($to->nodeid, $checkNodes) === FALSE) { $checkNodes[$to->nodeid] = $to->nodeid; $view->addNode($to); } } } } } } $group->view = $view; return $group; }