/** * 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; }
/** * Get a linktype by label * * @param string $label * @return LinkType or Error */ function getLinkTypeByLabel($label) { $lt = new LinkType(); return $lt->loadByLabel($label); }
function do_delete() { $types_to_delete = KTUtil::arrayGet($_REQUEST, 'fLinksToDelete'); // is an array. if (empty($types_to_delete)) { $this->errorRedirectToMain(_kt('Please select one or more link types to delete.')); } $count = 0; foreach ($types_to_delete as $link_id) { $oLinkType = LinkType::get($link_id); $aLinks = DocumentLink::getList(sprintf("link_type_id = %d", $link_id)); if (!empty($aLinks)) { foreach ($aLinks as $oLink) { $oLink->delete(); } } $oLinkType->delete(); // technically, this is a bad thing $count += 1; } //$oLinkType =& LinkType::createFromArray(array("sName" => $name, "sDescription" => $description)); $this->successRedirectToMain($count . " " . _kt("Link types deleted.")); }
/** * 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 new users to database * * @param string $email * @param string $name * @param string $password * @param string $website * @param string $isgroup 'Y'/'N' * @param string $authtype * @param string $description * @param string $status * @param string $photo * @return User object (this) (or Error object) */ function add($email, $name, $password, $website, $isgroup = "N", $authtype = "", $description = "", $status = "", $photo = "") { global $DB, $CFG, $HUB_SQL; $params = array(); if ($isgroup == 'N') { $lasttestgroup = $DB->select($HUB_SQL->DATAMODEL_USER_LAST_TEST_GROUP, $params); } if ($isgroup == 'Y' || $lasttestgroup !== false && isset($lasttestgroup[0]['TestGroup'])) { $dt = time(); // If no authtype passed, set to default value if ($authtype == "") { $authtype = $CFG->AUTH_TYPE_EVHUB; } // if no status passed then set to default status // must be === otherwise status of 0=active will match if ($status === "") { $status = $CFG->USER_STATUS_UNVALIDATED; } // If no photo passed then set to the default one if ($photo == "") { if ($isgroup == 'Y') { $photo = $CFG->DEFAULT_GROUP_PHOTO; } else { $photo = $CFG->DEFAULT_USER_PHOTO; } } $this->userid = getUniqueID(); $registrationKey = createRegistrationKey(); $passwordcrypt = ""; if ($authtype == $CFG->AUTH_TYPE_EVHUB && $password != "") { $passwordcrypt = crypt($password); } $testGroup = 0; if ($isgroup == 'N') { $testGroup = 1; if ($lasttestgroup[0]['TestGroup'] == 1) { $testGroup = 2; } } $params[0] = $this->userid; $params[1] = $dt; $params[2] = $dt; $params[3] = $email; $params[4] = $name; $params[5] = $passwordcrypt; $params[6] = $website; $params[7] = 'N'; $params[8] = $dt; $params[9] = 'N'; $params[10] = $isgroup; $params[11] = $authtype; $params[12] = $description; $params[13] = $photo; $params[14] = $registrationKey; $params[15] = $status; $params[16] = $testGroup; $res = $DB->insert($HUB_SQL->DATAMODEL_USER_ADD, $params); if (!$res) { return database_error(); } else { $this->load(); // add the default roles for user $r = new Role(); $r->setUpDefaultRoles($this->userid); // add default links for user. $lt = new LinkType(); $lt->setUpDefaultLinkTypes($this->userid); // set email activity $this->updateFollowSendEmail($CFG->ACTIVITY_EMAIL_SENDING_ON); $this->updateFollowRunInterval($CFG->ACTIVITY_EMAIL_SENDING_INTERVAL); // add default node for user //$n = new CNode(); //$n->setUpDefaultUserNode($this->userid); return $this; } } else { return database_error(); } }