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")); }