/** * 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; }
break; case "deleteconnection": $connid = required_param('connid', PARAM_ALPHANUMEXT); $response = deleteConnection($connid); break; /** ROLES aka NODE TYPES **/ /** ROLES aka NODE TYPES **/ case "getrolebyname": $rolename = required_param('rolename', PARAM_TEXT); $response = getRoleByName($rolename); break; /** LINK TYPES **/ /** LINK TYPES **/ case "getlinktypebylabel": $label = required_param('label', PARAM_TEXT); $response = getLinkTypeByLabel($label); break; /** USERS **/ /** USERS **/ case "getuser": $userid = required_param('userid', PARAM_ALPHANUMEXT); $response = getUser($userid, $style); break; case "getactiveconnectionusers": $response = getActiveConnectionUsers($start, $max, $style); break; case "getactiveideausers": $response = getActiveIdeaUsers($start, $max, $style); break; case "getusersbyfollowing": $itemid = required_param('itemid', PARAM_ALPHANUMEXT);
} /*if ($_FILES['image']['error'] == 0) { $imagedir = $HUB_FLM->getUploadsNodeDir($issuenode->nodeid); $photofilename = uploadImageToFit('image',$errors,$imagedir); if($photofilename == ""){ $photofilename = $CFG->DEFAULT_ISSUE_PHOTO; } $issuenode->updateImage($photofilename); }*/ if (isset($groupid) && $groupid != "") { $issuenode->addGroup($groupid); } /** ADD RESOURCES **/ if (empty($errors)) { $lt = getLinkTypeByLabel('is related to'); $linkRelated = $lt->linktypeid; $i = 0; foreach ($resourceurlarray as $resourceurl) { // connect exisitng resource /*if (isset($resourcenodeidsarray[$i]) && $resourcenodeidsarray[$i] != "") { $refnode = getNode($resourcenodeidsarray[$i]); $r = getRoleByName($refnode->role->name); $refrole = $r->roleid; $connection = addConnection($refnode->nodeid, $refrole, $linkRelated, $evidencenode->nodeid, $roleType, "N"); } else { // create and connect new resource */ //$r = getRoleByName($resourcetype); //$refrole = $r->roleid; $resourcetitle = trim($resourcetitlearray[$i]); // If they have entered nothing, don't do anything.
function mergeSelectedNodes($issuenodeid, $groupid, $ids, $title, $desc) { global $CFG; $mainConnections = getConnectionsByNode($issuenodeid, 0, -1, 'date', 'ASC', 'all', '', 'Solution'); $mainconns = $mainConnections->connections; $r = getRoleByName("Solution"); $rolesolution = $r->roleid; // CREATE THE solution NODE $solutionnode = addNode($title, $desc, 'N', $rolesolution); if (!$solutionnode instanceof Error) { // Add to group if (isset($groupid) && $groupid != "") { addGroupToNode($solutionnode->nodeid, $groupid); } // CONNECT NODE TO FOCAL $node = getNode($issuenodeid); $r = getRoleByName($node->role->name); $focalroleid = $r->roleid; $lt = getLinkTypeByLabel($CFG->LINK_SOLUTION_ISSUE); $linkType = $lt->linktypeid; $conndesc = ""; $connection = addConnection($solutionnode->nodeid, $rolesolution, $linkType, $issuenodeid, $focalroleid, "N", $conndesc); if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { addGroupToConnection($connection->connid, $groupid); } // CONNECT NEW NODE TO SELECT NODES $lt2 = getLinkTypeByLabel($CFG->LINK_BUILT_FROM); $linkTypeBuiltFrom = $lt2->linktypeid; //error_log(print_r($linkTypeBuiltFrom, true)); $nodesArr = split(",", $ids); foreach ($nodesArr as $nodeid2) { $n = new CNode($nodeid2); $n = $n->load(); $r = getRoleByName($n->role->name); $roleid = $r->roleid; $connection2 = addConnection($solutionnode->nodeid, $rolesolution, $linkTypeBuiltFrom, $nodeid2, $roleid, "N", $conndesc); //error_log(print_r($connection2, true)); if (!$connection2 instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { addGroupToConnection($connection2->connid, $groupid); } // Link kids to new parent $conSetKids = getConnectionsByNode($nodeid2, 0, -1, 'date', 'ASC', 'all', '', 'Pro,Con,Comment'); $conns = $conSetKids->connections; foreach ($conns as $con) { $from = $con->from; $r2 = getRoleByName($from->role->name); $fromroleid = $r2->roleid; //error_log('nextfrom:'.print_r($from, true)); $lt3 = getLinkTypeByLabel($CFG->LINK_COMMENT_NODE); $linkType3 = $lt3->linktypeid; if ($from->role->name == "Pro") { $lt3 = getLinkTypeByLabel($CFG->LINK_PRO_SOLUTION); $linkType3 = $lt3->linktypeid; } else { if ($from->role->name == "Con") { $lt3 = getLinkTypeByLabel($CFG->LINK_CON_SOLUTION); $linkType3 = $lt3->linktypeid; } } // Connect the children of each node being merged to the new node $connection3 = addConnection($from->nodeid, $fromroleid, $linkType3, $solutionnode->nodeid, $rolesolution, "N", $conndesc); if (!$connection3 instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { addGroupToConnection($connection3->connid, $groupid); } } else { //error_log(print_r($connection3, true)); } // retire old connection $con->updateStatus($CFG->STATUS_RETIRED); } // retire connection to parent foreach ($mainconns as $con) { $from = $con->from; if ($from->nodeid == $nodeid2) { $con->updateStatus($CFG->STATUS_RETIRED); } } // retire node $n->updateStatus($CFG->STATUS_RETIRED); } else { return $connection2; } } } else { return $connection; } } return $solutionnode; }
$newtoroleid = $con->tocontexttypeid; if ($con->from->nodeid == $nodeid) { $newfromroleid = $newroleid; } else { if ($con->to->nodeid == $nodeid) { $newtoroleid = $newroleid; } } // Update Link Type on Change if ($nodetypename == 'Pro') { $ltp = getLinkTypeByLabel($CFG->LINK_PRO_SOLUTION); $linkpro = $ltp->linktypeid; $con->edit($con->from->nodeid, $newfromroleid, $linkpro, $con->to->nodeid, $newtoroleid, $con->private, $con->description); } else { if ($nodetypename == 'Con') { $ltc = getLinkTypeByLabel($CFG->LINK_CON_SOLUTION); $linkcon = $ltc->linktypeid; $con->edit($con->from->nodeid, $newfromroleid, $linkcon, $con->to->nodeid, $newtoroleid, $con->private, $con->description); } } } $USER = $currentuser; } /** ADD RESOURCES/URLS **/ if (empty($errors)) { // remove all the existing urls so they can be re-added below $evidencenode->removeAllURLs(); $i = 0; foreach ($resourceurlarray as $resourceurl) { $resourcetitle = trim($resourcetitlearray[$i]); // If they have entered nothing, don't do anything.
array_push($errors, $LNG->{$LNG}->FORM_SPLIT_IDEA_ERROR); } if (empty($errors)) { $currentUser = $USER; $orinode = getNode($nodeid); $r = getRoleByName($orinode->role->name); $roleid = $r->roleid; $i = 0; $count = count($ideanamearray); for ($i = 0; $i < $count; $i++) { $name = $ideanamearray[$i]; $desc = $ideadescarray[$i]; $newconn = addNodeAndConnect($name, $desc, 'Solution', $debateid, $CFG->LINK_SOLUTION_ISSUE, 'from', $groupid = "", 'N'); $newnode = $newconn->from; // CONNECT NEW NODE TO SELECT NODES $lt2 = getLinkTypeByLabel($CFG->LINK_BUILT_FROM); $linkTypeBuiltFrom = $lt2->linktypeid; $connection = addConnection($newnode->nodeid, $newnode->role->roleid, $linkTypeBuiltFrom, $orinode->nodeid, $roleid, "N", ""); // add to group if (!$connection instanceof Error && isset($groupid) && $groupid != "") { addGroupToConnection($connection->connid, $groupid); } } // need to become the owner of the node you are editing the status of //$USER = $orinode->users[0]; $orinode->updateStatus($CFG->STATUS_RETIRED); echo '<script type=\'text/javascript\'>'; //echo 'window.opener.location.href = "'.$CFG->homeAddress.'user.php?id='.$USER->userid.'";'; echo "\t window.opener.location.reload(true);"; echo 'window.close();'; echo '</script>';