/** * Add a node. Requires login * * @param string $name * @param string $desc * @param string $nodetypename, the name of the nodetype this node is. * @param string $focalnodeid, the id of the node to connect this new node to. * @param string $direction optional, whether the new node is a 'from' or 'to' in the connection. The focalnode then becomes the other end. Defaults to 'from'; * @param string $private optional, can be Y or N, defaults to users preferred setting * @param string $groupid optional, the id of any group to add the new node and the new connection to. * @param string $imageurlid optional, the urlid of the url for the image that is being used as this node's icon * @param string $imagethumbnail optional, the local server path to the thumbnail of the image used for this node * * @return Node or Error */ function addNodeAndConnect($name, $desc, $nodetypename, $focalnodeid, $linktypename, $direction = "from", $groupid = "", $private = "N", $imageurlid = "", $imagethumbnail = "", $resources = "") { global $USER, $CFG; if ($private == "") { $private = $USER->privatedata; } $conndesc = ""; // if groupid given, check current user in group before going any further. if ($groupid != "") { $group = new Group($groupid); if (!$group instanceof Error) { if (!$group->ismember($USER->userid)) { $error = new Error(); return $error->createNotInGroup($group->name); } } else { return $group; } } $r = getRoleByName($nodetypename); if (!$r instanceof Error) { $nodetypeid = $r->roleid; $n = new CNode(); $node = $n->add($name, $desc, $private, $nodetypeid, $imageurlid, $imagethumbnail); if (!$node instanceof Error) { // Add to group if (isset($groupid) && $groupid != "") { addGroupToNode($node->nodeid, $groupid); } foreach ($resources as $url) { $url = trim($url); if ($url != "") { $urlobj = new URL(); $urlobj = $urlobj->add($url, $title, "", $private, "", ""); if (!$urlobj instanceof Error) { $node->addURL($urlobj->urlid, ""); } else { return $urlobj; } } } // Connect to focal node $focalnode = new CNode($focalnodeid); $focalnode = $focalnode->load(); if (!$focalnode instanceof Error) { $focalrole = getRoleByName($focalnode->role->name); $focalroleid = $focalrole->roleid; $lt = getLinkTypeByLabel($linktypename); $linkType = $lt->linktypeid; if ($direction == 'from') { $connection = addConnection($node->nodeid, $nodetypeid, $linkType, $focalnodeid, $focalroleid, $private, $conndesc); } else { $connection = addConnection($focalnodeid, $focalroleid, $linkType, $node->nodeid, $nodetypeid, $private, $conndesc); } if (!$connection instanceof Error) { // add to group if (isset($groupid) && $groupid != "") { addGroupToConnection($connection->connid, $groupid); } } return $connection; } else { return $focalnode; } } else { return $node; } } else { return $r; } }
/** * Adds a new view * @param string $name the name of the view * @param string $desc the description of the view * @param string $private optional, can be Y or N, defaults to users preferred setting. * @param string $nodetypeid optional, the id of the nodetype this node is, defaults to 'Idea' node type id. * @param string $groupid optional, the is of the group, if any, this view is in. * @param string $xpos optional, the x position to place the challenge node at (defaults to 0). * @param string $ypos optional, the y position to place the challenge node at (defaults to 0). * * @param string $groupname * @return Group object (this) */ function add($name, $desc, $private, $nodetypeid, $groupid = "", $xpos = 0, $ypos = 0) { global $DB, $CFG, $USER, $HUB_SQL; //check user can add a view try { $this->canadd(); } catch (Exception $e) { return access_denied_error(); } $node = new CNode(); $this->viewnode = $node->add($name, $desc, $private, $nodetypeid); $this->nodes = array(); if (!$this->viewnode instanceof Error) { $this->nodeid = $this->viewnode->nodeid; if (isset($groupid) && $groupid != "") { $this->viewnode->addGroup($groupid); } // Create a new Challenge node and place in center of map. //$r = getRoleByName("Challenge"); //$roleChallenge = $r->roleid; //$challengenode = new CNode(); //$challengenode = $challengenode->add($name, $desc, $private, $roleChallenge); //if (isset($groupid) && $groupid != "") { // $challengenode->addGroup($groupid); //} //$this->addNode($challengenode->nodeid, $xpos, $ypos); //$this->load(); } else { return $this->viewnode; } return $this; }