/**
  * Loads the data for the connection from the database
  *
  * @param String $style (optional - default 'long') may be 'short' or 'long' of 'cif'
  * @return Connection object (this) or Error
  */
 function load($style = 'long')
 {
     global $DB, $CFG, $HUB_SQL;
     try {
         $this->canview();
     } catch (Exception $e) {
         return access_denied_error();
     }
     $this->style = $style;
     $params = array();
     $params[0] = $this->connid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT, $params);
     $count = count($resArray);
     if ($count == 0) {
         $ERROR = new error();
         $ERROR->createConnectionNotFoundError($this->connid);
         return $ERROR;
     }
     $fromid = 0;
     $toid = 0;
     for ($i = 0; $i < $count; $i++) {
         $array = $resArray[$i];
         $fromid = trim($array['FromID']);
         $toid = trim($array['ToID']);
         $this->fromcontexttypeid = trim($array['FromContextTypeID']);
         $this->tocontexttypeid = trim($array['ToContextTypeID']);
         $this->creationdate = trim($array['CreationDate']);
         $this->modificationdate = trim($array['ModificationDate']);
         $this->userid = trim($array['UserID']);
         $this->users = array();
         $this->users[0] = getUser($this->userid, $style);
         $this->linktypeid = trim($array['LinkTypeID']);
         $this->private = $array['Private'];
         $this->description = $array['Description'];
     }
     //now add in from/to nodes
     $from = new CNode($fromid);
     $this->from = $from->load($style);
     // we need to for the resource node title
     // $this->from->description = ""; // we don't need the long descriptions on connections - even if style for rest is long
     $to = new CNode($toid);
     $this->to = $to->load($style);
     // we need to for the resource node title
     //$this->to->description = ""; // we don't need the long descriptions on connections - even if style for rest is long
     $r = new Role($this->fromcontexttypeid);
     $this->fromrole = $r->load();
     $r = new Role($this->tocontexttypeid);
     $this->torole = $r->load();
     //If both ends of the connection are Comments, it's part of a chat tree.
     //and if the description holds a nodeid, load it as the parent item the chat is against
     if (isset($this->fromrole->name) && $this->fromrole->name == "Comment" || isset($this->torole->name) && $this->torole->name == "Comment") {
         if (isset($this->description) && $this->description != "") {
             // the description could hold a list of id'd id1:id2:id3 etc
             // if it does, the first item is the one to use.
             //echo $this->description;
             $reply = split(":", $this->description);
             $id = $reply[0];
             if ($reply[0] == "") {
                 $id = $reply[1];
             }
             $parentnode = new CNode($id);
             $parentnode = $parentnode->load();
             if (!$parentnode instanceof Error) {
                 $this->parentnode = $parentnode;
             }
         }
     }
     $l = new LinkType($this->linktypeid);
     $this->linktype = $l->load();
     if ($style == 'long') {
         // add in the groups
         $resArray2 = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_GROUP, $params);
         $count2 = count($resArray2);
         if ($count2 > 0) {
             $this->groups = array();
             for ($i = 0; $i < $count2; $i++) {
                 $array = $resArray2[$i];
                 $group = new Group(trim($array['GroupID']));
                 array_push($this->groups, $group->load());
             }
         }
         //now add in any tags
         $resArray3 = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_TAGS, $params);
         $count3 = count($resArray3);
         if ($count3 > 0) {
             $this->tags = array();
             for ($i = 0; $i < $count3; $i++) {
                 $array = $resArray3[$i];
                 $tag = new Tag(trim($array['TagID']));
                 array_push($this->tags, $tag->load());
             }
         }
     }
     if ($style != 'cif') {
         $this->loadVotes();
     }
     return $this;
 }
示例#2
0
/**
 * Get a node
 *
 * @param string $nodeid
 * @param string $style (optional - default 'long') may be 'short' or 'long'
 * @return Node or Error
 */
function getNode($nodeid, $style = 'long')
{
    $n = new CNode($nodeid);
    return $n->load($style);
}
示例#3
0
/**
 * Make all the users nodes and connections in a group private or public.
 * Requires login, user must be member of the group, and this will only update the nodes/connections
 * that the user is the owner of.
 *
 * @param string $groupid
 * @param string $private (must be either 'Y' or 'N')
 * @return Result or Error
 */
function setGroupPrivacy($groupid, $private)
{
    global $DB, $CFG, $USER, $HUB_SQL;
    $currentuser = '';
    if (isset($USER->userid)) {
        $currentuser = $USER->userid;
    }
    $params = array();
    $params[0] = $groupid;
    $params[1] = $currentuser;
    // set the nodes
    $sql = $HUB_SQL->APILIB_NODE_GROUP_PRIVACY_SELECT;
    $resArray = $DB->select($sql, $params);
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $array = $resArray[$i];
            $n = new CNode($array['NodeID']);
            $n->load();
            $n->setPrivacy($private);
        }
    }
    // set the connections
    $sql = APILIB_CONNECTION_GROUP_PRIVACY_SELECT;
    $resArray = $DB->select($sql, $params);
    if ($resArray !== false) {
        $count = count($resArray);
        for ($i = 0; $i < $count; $i++) {
            $array = $resArray[$i];
            $c = new Connection($array['TripleID']);
            $c = $c->load();
            $c->setPrivacy($private);
        }
    }
    return new Result("privacy updated", "true");
}
 /**
  * Loads the data for the connection from the database
  *
  * @param String $style (optional - default 'long') may be 'short' or 'long' of 'cif'
  * @return Connection object (this) or Error
  */
 function load($style = 'long')
 {
     global $DB, $CFG, $HUB_SQL;
     try {
         $this->canview();
     } catch (Exception $e) {
         return access_denied_error();
     }
     $this->style = $style;
     $params = array();
     $params[0] = $this->connid;
     $resArray = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT, $params);
     $count = count($resArray);
     if ($count == 0) {
         $ERROR = new error();
         $ERROR->createConnectionNotFoundError($this->connid);
         return $ERROR;
     }
     $fromid = 0;
     $toid = 0;
     for ($i = 0; $i < $count; $i++) {
         $array = $resArray[$i];
         $fromid = trim($array['FromID']);
         $toid = trim($array['ToID']);
         $this->fromcontexttypeid = trim($array['FromContextTypeID']);
         $this->tocontexttypeid = trim($array['ToContextTypeID']);
         $this->creationdate = trim($array['CreationDate']);
         $this->modificationdate = trim($array['ModificationDate']);
         $this->userid = trim($array['UserID']);
         $this->users = array();
         $this->users[0] = getUser($this->userid, $style);
         $this->linktypeid = trim($array['LinkTypeID']);
         $this->private = $array['Private'];
         $this->description = $array['Description'];
     }
     //now add in from/to nodes. Try from the cache first?
     $from = new CNode($fromid);
     $this->from = $from->load($style);
     $to = new CNode($toid);
     $this->to = $to->load($style);
     $r = new Role($this->fromcontexttypeid);
     $this->fromrole = $r->load();
     $r = new Role($this->tocontexttypeid);
     $this->torole = $r->load();
     $l = new LinkType($this->linktypeid);
     $this->linktype = $l->load();
     if ($style == 'long') {
         // add in the groups
         $resArray2 = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_GROUP, $params);
         $count2 = count($resArray2);
         if ($count2 > 0) {
             $this->groups = array();
             for ($i = 0; $i < $count2; $i++) {
                 $array = $resArray2[$i];
                 $group = new Group(trim($array['GroupID']));
                 array_push($this->groups, $group->load());
             }
         }
         //now add in any tags
         $resArray3 = $DB->select($HUB_SQL->DATAMODEL_CONNECTION_SELECT_TAGS, $params);
         $count3 = count($resArray3);
         if ($count3 > 0) {
             $this->tags = array();
             for ($i = 0; $i < $count3; $i++) {
                 $array = $resArray3[$i];
                 $tag = new Tag(trim($array['TagID']));
                 array_push($this->tags, $tag->load());
             }
         }
     }
     if ($style != 'cif') {
         $this->loadVotes();
     }
     return $this;
 }
 /**
  * load in the nodes for the given SQL statement
  *
  * @param string $sql
  * @param array $params the parameters that go into the sql statement
  * @param int $start starting from record item
  * @param int $max for a record limit of this given count
  * @param string $orderby the name of the field to sort by
  * @param string $sort 'ASC' or 'DESC' (ascending or descending ordering)
  * @param string the style of each record in the collection (defaults to 'short' , can be 'long');
  * @return NodeSet (this)
  */
 function load($sql, $params, $start, $max, $orderby, $sort, $style = 'short')
 {
     global $DB, $HUB_SQL;
     if (!isset($params)) {
         $params = array();
     }
     // GET TOTAL RECORD COUTN BEFORE LIMITING
     $csql = $HUB_SQL->DATAMODEL_NODE_LOAD_PART1;
     $csql .= $sql;
     $csql .= $HUB_SQL->DATAMODEL_NODE_LOAD_PART2;
     $carray = $DB->select($csql, $params);
     $totalconns = $carray[0]["totalnodes"];
     // ADD SORTING
     $sql = $DB->nodeOrderString($sql, $orderby, $sort);
     // ADD LIMITING
     $sql = $DB->addLimitingResults($sql, $start, $max);
     //error_log("Search1=".$sql);
     $resArray = $DB->select($sql, $params);
     //create new nodeset and loop to add each node to the set
     $count = count($resArray);
     $this->totalno = $totalconns;
     $this->start = $start;
     $this->count = $count;
     for ($i = 0; $i < $count; $i++) {
         $array = $resArray[$i];
         $node = new CNode($array["NodeID"]);
         $this->add($node->load($style));
     }
     return $this;
 }