예제 #1
0
 /**
  * Edit a connection
  * after the update need to update the nodes so they're in the same groups as the connection
  * @param string $fromnodeid
  * @param string $fromroleid
  * @param string $linktypeid
  * @param string $tonodeid
  * @param string $toroleid
  * @param string $private
  * @param string $description
  * @return Connection object (this) (or Error object)
  */
 function edit($fromnodeid, $fromroleid, $linktypeid, $tonodeid, $toroleid, $private, $description = "")
 {
     global $DB, $CFG, $USER, $HUB_SQL;
     $dt = time();
     //check user can edit connection
     try {
         $this->canedit();
     } catch (Exception $e) {
         return access_denied_error();
     }
     $currentuser = '';
     if (isset($USER->userid)) {
         $currentuser = $USER->userid;
     }
     try {
         $fromnode = new CNode($fromnodeid);
         $fromnode = $fromnode->load();
         //$fromnode->canedit();
     } catch (Exception $e) {
         //return access_denied_error();
     }
     try {
         $tonode = new CNode($tonodeid);
         $tonode = $tonode->load();
         //$tonode->canedit();
     } catch (Exception $e) {
         //return access_denied_error();
     }
     $params = array();
     $params[0] = $dt;
     $params[1] = $fromnode->name;
     $params[2] = $tonode->name;
     $params[3] = $linktypeid;
     $params[4] = $fromnodeid;
     $params[5] = $tonodeid;
     $params[6] = $fromroleid;
     $params[7] = $toroleid;
     $params[8] = $private;
     $params[9] = $description;
     $params[10] = $this->connid;
     $params[11] = $currentuser;
     $res = $DB->insert($HUB_SQL->DATAMODEL_CONNECTION_UPDATE_ALL, $params);
     if (!$res) {
         return database_error();
     }
     // now also add groups to the from and to nodes
     $params = array();
     $params[0] = $this->connid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_GROUP, $params);
     if (!$resArray) {
         return database_error();
     } else {
         $count = count($resArray);
         for ($i = 0; $i < $count; $i++) {
             $array = $resArray[$i];
             $groupid = $array['GroupID'];
             $fromnode = new CNode($fromnodeid);
             $fromnode->addGroup($groupid);
             $tonode = new CNode($tonodeid);
             $tonode->addGroup($groupid);
         }
     }
     $temp = $this->load();
     if (!auditConnection($USER->userid, $temp->connid, "", $fromnodeid, $tonodeid, $linktypeid, $fromroleid, $toroleid, $CFG->actionEdit, format_object('xml', $temp))) {
         return database_error();
     }
     return $temp;
 }
예제 #2
0
/**
 * 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 ViewNode or Error
 */
function addNodeToView($viewid, $nodeid, $xpos, $ypos, $groupid = "")
{
    global $USER;
    $v = new View($viewid);
    $viewnode = $v->addNode($nodeid, $xpos, $ypos);
    if (!$viewnode instanceof Error) {
        if (isset($groupid) && $groupid != "") {
            $group = new Group($groupid);
            if (!$group instanceof Error) {
                if ($group->ismember($USER->userid)) {
                    $node = new CNode($nodeid);
                    $node->addGroup($groupid);
                }
            }
        } else {
            // if not given get groups for map node and add it to those. Should only be one at present.
            $mapnode = new CNode($viewid);
            $mapnode = $mapnode->load();
            if (isset($mapnode->groups)) {
                $groups = $mapnode->groups;
                $count = count($groups);
                for ($i = 0; $i < $count; $i++) {
                    $nextgroup = $groups[$i];
                    if (isset($nextgroup)) {
                        if ($nextgroup->ismember($USER->userid)) {
                            $node = new CNode($nodeid);
                            $node->addGroup($nextgroup->groupid);
                        }
                    }
                }
            }
        }
    }
    return $viewnode;
}