public function entityJoin($entity1, $entity2) { include_once 'EntityRelations.php'; $eRelations = new EntityRelations(); $joinArray = $eRelations->getJoins($entity1, $entity2); //var_dump('joinEntities' , $entity1 , $entity2); //var_dump('joinArray' , $joinArray); foreach ($joinArray as $join) { if ($join != null) { //if($join[1] != null && $join[2] != null && $join[3] != null && $join[4] != null ) $this->sqlArray['join'][] = array('table' => $join[2], 'jointype' => 'INNER', 'field1' => $join[1], 'field2' => $join[3], 'entity1' => $join[0], 'entity2' => $join[2], 'as' => $join['as']); } } }
private function handleEntityRelations() { $subjectguid = $this->swappliance->guid; $reltype = EntityRelations::getRelationType("swappliance", "usage", "vappliance"); if ($reltype === null) { throw new Exception("No relation type for sofwtare appliance and virtual appliance"); } $vappguids = $this->getRelatedSWApplianceGuids(); $result = EntityRelations::unrelateAll($subjectguid, array(), false, array($reltype->id)); if ($result !== true) { throw new Exception($result); } if (count($vappguids) > 0) { $userid = null; if ($this->user && is_numeric($this->user->id) && $this->user->id > 0) { $userid = $this->user->id; } foreach ($vappguids as $vg) { $result = EntityRelations::relate($reltype->id, $subjectguid, $vg, $userid); if (is_string($result)) { throw new Exception($result); } } } return true; }
public static function syncRelations($entityguid, $userid, $relations = array()) { $entityname = EntityTypes::getTypeByGuid($entityguid); if ($entityname === null) { throw new Exception("Object entity type not found for relation"); } $relids = EntityRelations::relateDirectEntity($entityguid, "organization", $userid, $relations); EntityRelations::unrelateAll($entityguid, $relids, false, EntityRelations::getRelationTypePairIDs($entityname, "organization")); $relids = EntityRelations::relateDirectEntity($entityguid, "project", $userid, $relations); EntityRelations::unrelateAll($entityguid, $relids, false, EntityRelations::getRelationTypePairIDs($entityname, "project")); }
public function createnewprofileAction() { $this->_helper->layout->disableLayout(); if ($this->session->userid !== -1 || $this->session->isNewUser !== true) { $this->_helper->viewRenderer->setNoRender(); header("HTTP/1.0 404 Not Found"); return; } $firstname = isset($_POST["firstName"]) ? trim($_POST["firstName"]) : null; $lastname = isset($_POST["lastName"]) ? trim($_POST["lastName"]) : null; $gender = isset($_POST["gender"]) ? trim($_POST["gender"]) : null; $institution = isset($_POST["institution"]) ? trim($_POST["institution"]) : null; $countryid = isset($_POST["countryID"]) ? intval($_POST["countryID"]) : null; $positiontypeid = isset($_POST["positionTypeID"]) ? intval($_POST["positionTypeID"]) : null; $error = array(); if ($firstname === null) { array_push($error, "Invalid user first name given"); } if ($lastname === null) { array_push($error, "Invalid user last name given"); } //if( $institution === null ) array_push($error, "Invalid user institute given"); if ($countryid === null) { array_push($error, "Invalid user country given"); } if ($positiontypeid === null) { array_push($error, "Invalid user role given"); } if (count($error) > 0) { //todo: Add Error handler $this->view->error = $error; return; } //Collect user information $entry = new Default_Model_Researcher(); $entry->lastName = $lastname; $entry->firstName = $firstname; $entry->gender = $gender; $entry->institution = ""; $entry->countryID = $countryid; $entry->positionTypeID = $positiontypeid; //Collect user contacts $conts = array(); foreach ($_POST as $key => $value) { if (trim($value) === "") { continue; } if (substr($key, 0, 7) === "contact" && substr($key, 0, 11) !== "contactType") { $cnum = substr($key, 7); $cont = new Default_Model_Contact(); $cont->data = $value; $cont->contactTypeID = $_POST['contactType' . $cnum]; if (is_numeric($cont->contactTypeID) === false) { array_push($error, "Invalid contact type given"); } if (trim($value) === "") { array_push($error, "Empty contact value given"); } if (count($error) > 0) { continue; } array_push($conts, $cont); } } //Collect user relations $relations = array(); foreach ($_POST as $key => $value) { if (trim($value) === "") { continue; } if (strtolower(trim($key)) === "organization") { $data = json_decode($value); $relations[] = array("id" => trim(strval($data->id)), "targetguid" => trim(strval($data->targetguid)), "parentid" => null); } } if (count($error) > 0) { //todo: Add error handler $this->view->error = $error; return; } //Check if user account has been registered in the meanwhile $uid = $this->session->authUid; $source = $this->session->authSource; $useraccounts = new Default_Model_UserAccounts(); $f1 = new Default_Model_UserAccountsFilter(); $f2 = new Default_Model_UserAccountsFilter(); $f1->accountid->equals($uid); $f2->accounttype->equals($source); $useraccounts->filter->chain($f1, "AND"); $useraccounts->filter->chain($f2, "AND"); if (count($useraccounts->items) > 0) { array_push($error, "User account is already registered"); $this->view->error = $error; return; } //Everything is ok. Continue with saving new profile //Save entry $entry->save(); //Save entry contacts for ($i = 0; $i < count($conts); $i += 1) { $cont = $conts[$i]; $cont->researcherID = $entry->id; $cont->save(); } //extract IDP Trace in case it is returned from SAML $attrs = $this->session->samlattrs; $idptrace = array(); if (isset($attrs['idp:traceidp']) && is_array($attrs['idp:traceidp'])) { $idptrace = $attrs['idp:traceidp']; } //Save user account $useraccount = new Default_Model_UserAccount(); $useraccount->researcherid = $entry->id; $useraccount->accountid = $this->session->authUid; $useraccount->accounttypeid = str_replace("-sp", "", $this->session->authSource); $useraccount->IDPTrace = $idptrace; $useraccount->save(); //Save user relations (organization) if ($entry && count($relations) > 0) { //ensure permissions are built $try_counter = 0; while ($try_counter < 25) { $try_counter += 1; $confs = db()->query("select data from config where var = 'permissions_cache_dirty';")->fetchAll(); if (count($confs) > 0) { $conf = $confs[0]; if (isset($conf["data"]) && trim($conf["data"]) === '0') { break; } } sleep(1); } //Refetch entry (user) to retrieve guid $us = new Default_Model_Researchers(); $us->filter->id->numequals($entry->id); if (count($us->items) > 0) { $u = $us->items[0]; EntityRelations::syncRelations($u->guid, $u->id, $relations); } } //Setup new session if ($entry) { //ensure race condition $try_counter = 0; while ($try_counter < 10) { $try_counter += 1; $ppl = new Default_Model_Researchers(); $ppl->filter->id->equals($entry->id); if (count($ppl->items) > 0) { break; } sleep(1); } unset($this->session->isNewUser); $this->session->userid = $entry->id; SamlAuth::setupSamlAuth($this->session); } $this->view->session = $this->session; $this->view->error = array(); }
public function detailsAction() { $pplID = $this->_getParam("id"); trackPage('/people/details?id=' . $pplID, $this->_getParam("format")); if ($pplID == '') { $pplID = $this->session->lastPplID; } $this->_helper->layout->disableLayout(); $ppl = new Default_Model_Researchers(); if ($this->session->userid !== null) { if (userIsAdminOrManager($this->session->userid)) { $ppl->viewModerated = true; } } if ($this->_getParam("id") == "0") { $this->view->entry = new Default_Model_Researcher(); $this->view->entry->countryID = '0'; } else { if (is_numeric($pplID) === true) { $ppl->filter->id->equals($pplID); } else { if (substr($pplID, 0, 2) === "s:") { $pplCname = substr($pplID, 2); $ppl->filter->cname->ilike($pplCname); } } $ppl->refresh($this->_getParam('format'), $this->_getParam('userid')); if (count($ppl->items) > 0) { $this->view->entry = $ppl->items[0]; $pplID = $this->view->entry->id; } // BEGIN: API logging hack $cid = 0; // clientID: 0 --> appDB portal if (isset($_SERVER['REMOTE_ADDR']) && $_SERVER['REMOTE_ADDR'] != '') { $src = "'" . $_SERVER['REMOTE_ADDR'] . "'"; } else { $src = ''; } if (is_numeric($this->session->userid) && $this->view->entry) { // only log if we have a valid userid $sql = "INSERT INTO ppl_api_log (pplid, timestamp, researcherid, source, ip) VALUES (" . $pplID . ", NOW(), " . $this->session->userid . ", " . $cid . ", " . $src . ");"; db()->query($sql)->fetchAll(); } // END: API logging hack if (isnull($this->view->entry->image) === false) { $this->view->image = "/people/getimage?id=" . $this->view->entry->id . "&req=" . urlencode($this->view->entry->lastUpdated); } } $this->view->dialogCount = $_GET['dc']; $this->view->positionTypes = new Default_Model_PositionTypes(); $this->view->positionTypes->filter->orderBy('ord'); $this->view->countries = new Default_Model_Countries(); $this->view->countries->filter->orderBy('name'); $this->view->contactTypes = new Default_Model_ContactTypes(); if (isnull($this->_getParam("tab")) == false) { $this->view->selectedTab = $this->_getParam("tab"); } $this->view->session = $this->session; if ($this->session->username !== null && $this->session->userid !== null) { $users = new Default_Model_Researchers(); $users->filter->id->equals($this->session->userid); $this->view->user = $users->items[0]; } else { $this->view->user = null; } //Setup vo membership data $this->view->entryVoMemberShip = "[]"; $this->view->entryRelationsXml = EntityRelations::relationsToXml($this->view->entry->guid); if (is_null($this->view->entry) === false && is_numeric($this->view->entry->id) && intval($this->view->entry->id) > 0) { $this->view->entryVoMemberShip = html_entity_decode(VoAdmin::getUserMembership($this->view->entry, true)); } }