/** * 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; }
/** * 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; }