Example #1
0
 public static function validateRelation($reltypeid, $subjectguid, $targetguid, $userid = null, $parentid = null, $reverse = false)
 {
     if ($reverse === true) {
         $tmp = $subjectguid;
         $subjectguid = $targetguid;
         $targetguid = $tmp;
     }
     $relationtype = EntityRelations::getRelationTypeByID($reltypeid);
     if ($relationtype === null) {
         return "No relation type found";
     }
     $subtype = EntityTypes::getTypeByGuid($subjectguid);
     $tartype = EntityTypes::getTypeByGuid($targetguid);
     if ($subtype !== $relationtype->subjectType || $tartype !== $relationtype->targetType) {
         return "Invalid relation identifiers";
     }
     $subobj = EntityTypes::getEntity($subtype, $subjectguid);
     if ($subobj === null) {
         return "Subject " . $subtype . " not found";
     }
     $tarobj = EntityTypes::getEntity($tartype, $targetguid);
     if ($tarobj === null) {
         return "Target " . $tartype . " not found";
     }
     $user = null;
     if (is_numeric($userid) && $userid > 0 || !is_numeric($userid) && trim($userid) !== "") {
         $user = EntityTypes::getPerson($userid);
         if ($user === null) {
             return "User not found";
         }
         $obj = $subobj;
         if ($reverse === true) {
             $obj = $tarobj;
         }
         $res = self::canRelateSubject($relationtype, $user, $obj);
         if ($res === false) {
             return "No user permissions to relate " . $relationtype->subjectType . " with " . $relationtype->targetType;
         }
     }
     if ($parentid !== null && EntityRelations::getRelationByID($parentid) === null) {
         return "Parent relation not found";
     }
     return true;
 }