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 relateReverseEntity($entityguid, $entitytype, $userid, $relations) { $rels = self::filterByEntityType($entitytype, self::filterRelations($relations, $entityguid, true)); $relatedids = array(); foreach ($rels as $r) { if (is_numeric($r["subjectguid"])) { $imp = Harvest::importRecord($r["subjectguid"], $userid); if (is_string($imp) === true || $imp === false) { throw new Exception($imp); } $r["subjectguid"] = $imp->guid; } $r = EntityRelations::relate($r["id"], $entityguid, $r["subjectguid"], $userid, $r["parentid"], true); if (is_string($r) || $r == false || $r == null) { throw new Exception($r); } $relatedids[] = $r->id; } return $relatedids; }