/** * load in the linktypes for the given SQL statement * * @param string $sql * @param array $params the parameters that go into the sql statement * @return LinkTypeSet (this) */ function load($sql, $params) { global $DB; if (!isset($params)) { $params = array(); } $resArray = $DB->select($sql, $params); $count = count($resArray); for ($i = 0; $i < $count; $i++) { $array = $resArray[$i]; $lt = new LinkType($array['LinkTypeID']); $this->add($lt->load()); } 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 $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; }
/** * Add a Connection. Requires login.<br> * @param string $fromnodeid * @param string $fromroleid * @param string $linktypeid * @param string $tonodeid * @param string $toroleid * @param string $private optional, can be Y or N, defaults to users preferred setting * @param string $description * @return Connection or Error */ function addConnection($fromnodeid, $fromroleid, $linktypeid, $tonodeid, $toroleid, $private = "", $description = "") { global $USER, $HUB_DATAMODEL, $ERROR; //echo "linktypeid=".$linktypeid; //echo("<br>".$fromnodeid); //echo("<br>".$fromroleid); //echo("<br>".$tonodeid); //echo("<br>".$toroleid); if ($private == "") { $private = $USER->privatedata; } // Check connection adheres to datamodel rules $fromNode = getNode($fromnodeid, 'short'); $toNode = getNode($tonodeid, 'short'); $link = new LinkType($linktypeid); $linkType = $link->load(); $from = new Role($fromroleid); $fromRole = $from->load(); $to = new Role($toroleid); $toRole = $to->load(); $allowed = false; //echo("<br>".$fromNode->role->name); //echo("<br>".$fromRole->name); //echo("<br>".$toNode->role->name); //echo("<br>".$toRole->name); //echo $linkType->label; if ($fromNode instanceof Error) { $ERROR = new Error(); return $ERROR->createInvalidConnectionError("fromnodeid:" . $fromnodeid); } if ($toNode instanceof Error) { $ERROR = new Error(); return $ERROR->createInvalidConnectionError("tonodeid:" . $tonodeid); } if (!$linkType instanceof Error) { if ($fromNode->role->name == $fromRole->name && $toNode->role->name == $toRole->name) { //error_log("HERE1"); //error_log($fromRole->name); //error_log($linkType->label); //error_log($toRole->name); $allowed = $HUB_DATAMODEL->matchesModel($fromRole->name, $linkType->label, $toRole->name); } else { if ($fromRole->name == 'Pro') { //error_log("HERE2"); $allowed = $HUB_DATAMODEL->matchesModelPro($fromNode->role->name, $linkType->label, $toNode->role->name); } else { if ($fromRole->name == 'Con') { //error_log("HERE3"); $allowed = $HUB_DATAMODEL->matchesModelCon($fromNode->role->name, $linkType->label, $toNode->role->name); } } } if (!$allowed) { //error_log("NOT ALLOWED"); $ERROR = new Error(); return $ERROR->createInvalidConnectionError(); } else { //error_log("ALLOWED"); $cobj = new Connection(); return $cobj->add($fromnodeid, $fromroleid, $linktypeid, $tonodeid, $toroleid, $private, $description); } } else { //error_log("NOT ALLOWED - LINK ERROR"); $ERROR = new Error(); return $ERROR->createInvalidConnectionError("linktypeid" . $linktypeid); } }