public static function initContextualization($app, $user = null) { $swapp = null; $person = null; //Get Software appliance if ($app instanceof Default_Model_Application) { $swapp = $app; } else { $swapp = EntityTypes::getEntity("swappliance", $app); } if ($swapp === null) { return null; } //Get user actor if ($user instanceof Default_Model_Researcher) { $person = $user; } else { $ps = new Default_Model_Researchers(); if (is_numeric($user)) { $ps->filter->id->numequals($user); } else { if (is_string($user)) { $ps->filter->guid->equals($user); } } if (count($ps->items) > 0) { $person = $ps->items[0]; } } //Check if software appliance has associated contextualization //If NOT create a new entry and return its Contextualization //class instance $context = self::getContextualizationForSWAppliance($swapp); if ($context === null) { $context = new Default_Model_Context(); $context->applicationID = $swapp->id; if ($person !== null) { $context->addedbyID = $person->id; } $context->save(); } return new Contextualization($context, $person); }
public static function syncRelations($entityguid, $userid, $relations = array(), $reverse = false, $unrelateold = true) { $entityname = EntityTypes::getTypeByGuid($entityguid); if ($entityname === null) { return "Object entity type not found for relation"; } $subject = EntityTypes::getEntity($entityname, $entityguid); $subjectguid = $subject->guid; $newrels = array(); foreach ($relations as $r) { if (is_numeric($r["targetguid"])) { $imp = Harvest::importRecord($r["targetguid"], $userid); if (is_string($imp) === true || $imp === false) { throw new Exception($imp); } $r["targetguid"] = $imp->guid; } $newrelation = EntityRelations::relate($r["id"], $entityguid, $r["targetguid"], $userid, $r["parentid"], $reverse); if (is_string($newrelation)) { throw new Exception($newrelation); } $newrels[] = $newrelation->id; } //remove old ones if ($unrelateold === true) { $dels = EntityRelations::unrelateAll($subjectguid, $newrels, $reverse); if ($dels !== true) { throw new Exception($dels); } } return true; }