src/wcmf/lib/model/NodeUtil.php
protected static function getConnectionsImpl($type, $otherRole, $otherType,
          $hierarchyType, array &$result=[], array $currentPath=[]) {
    $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
    $mapper = $persistenceFacade->getMapper($type);

    // check relations
    $relationDescs = $mapper->getRelations($hierarchyType);
    foreach ($relationDescs as $relationDesc) {
      // loop detection
      $loopDetected = false;
      foreach ($currentPath as $pathPart) {
        if ($relationDesc->isSameRelation($pathPart)) {
          $loopDetected = true;
          break;
        }
      }
      if ($loopDetected) {
        // continue with next relation
        continue;
      }

      $pathFound = null;
      $nextType = $relationDesc->getOtherType();
      $nextRole = $relationDesc->getOtherRole();
      $otherTypeFq = $otherType != null ? $persistenceFacade->getFullyQualifiedType($otherType) : null;
      if (($otherRole != null && $nextRole == $otherRole) || ($otherType != null && $nextType == $otherTypeFq)) {
        // other end found -> terminate
        $pathFound = $currentPath;
        $pathFound[] = $relationDesc;
      }
      else {
        // nothing found -> proceed with next generation
        $nextCurrentPath = $currentPath;
        $nextCurrentPath[] = $relationDesc;
        self::getConnectionsImpl($nextType, $otherRole, $otherType, $hierarchyType, $result, $nextCurrentPath);
      }

      // if a path is found, add it to the result
      if ($pathFound) {
        $result[] = new PathDescription($pathFound);
      }
    }
  }
protected static function getConnectionsImpl($type, $otherRole, $otherType,
          $hierarchyType, array &$result=[], array $currentPath=[]) {
    $persistenceFacade = ObjectFactory::getInstance('persistenceFacade');
    $mapper = $persistenceFacade->getMapper($type);

    // check relations
    $relationDescs = $mapper->getRelations($hierarchyType);
    foreach ($relationDescs as $relationDesc) {
      // loop detection
      $loopDetected = false;
      foreach ($currentPath as $pathPart) {
        if ($relationDesc->isSameRelation($pathPart)) {
          $loopDetected = true;
          break;
        }
      }
      if ($loopDetected) {
        // continue with next relation
        continue;
      }

      $pathFound = null;
      $nextType = $relationDesc->getOtherType();
      $nextRole = $relationDesc->getOtherRole();
      $otherTypeFq = $otherType != null ? $persistenceFacade->getFullyQualifiedType($otherType) : null;
      if (($otherRole != null && $nextRole == $otherRole) || ($otherType != null && $nextType == $otherTypeFq)) {
        // other end found -> terminate
        $pathFound = $currentPath;
        $pathFound[] = $relationDesc;
      }
      else {
        // nothing found -> proceed with next generation
        $nextCurrentPath = $currentPath;
        $nextCurrentPath[] = $relationDesc;
        self::getConnectionsImpl($nextType, $otherRole, $otherType, $hierarchyType, $result, $nextCurrentPath);
      }

      // if a path is found, add it to the result
      if ($pathFound) {
        $result[] = new PathDescription($pathFound);
      }
    }
  }
protected static function getConnectionsImpl ( $ type , $ otherRole , $ otherType , $ hierarchyType , array & $ result = [ ] , array $ currentPath = [ ] ) { $ persistenceFacade = ObjectFactory :: getInstance ( 'persistenceFacade' ) ; $ mapper = $ persistenceFacade -> getMapper ( $ type ) ; // check relations $ relationDescs = $ mapper -> getRelations ( $ hierarchyType ) ; foreach ( $ relationDescs as $ relationDesc ) { // loop detection $ loopDetected = false ; foreach ( $ currentPath as $ pathPart ) { if ( $ relationDesc -> isSameRelation ( $ pathPart ) ) { $ loopDetected = true ; break ; } } if ( $ loopDetected ) { // continue with next relation continue ; } $ pathFound = null ; $ nextType = $ relationDesc -> getOtherType ( ) ; $ nextRole = $ relationDesc -> getOtherRole ( ) ; $ otherTypeFq = $ otherType != null ? $ persistenceFacade -> getFullyQualifiedType ( $ otherType ) : null ; if ( ( $ otherRole != null && $ nextRole == $ otherRole ) || ( $ otherType != null && $ nextType == $ otherTypeFq ) ) { // other end found -> terminate $ pathFound = $ currentPath ; $ pathFound [ ] = $ relationDesc ; } else { // nothing found -> proceed with next generation $ nextCurrentPath = $ currentPath ; $ nextCurrentPath [ ] = $ relationDesc ; self :: getConnectionsImpl ( $ nextType , $ otherRole , $ otherType , $ hierarchyType , $ result , $ nextCurrentPath ) ; } // if a path is found, add it to the result if ( $ pathFound ) { $ result [ ] = new PathDescription ( $ pathFound ) ; } } }
Get the relations that connect a type to another type.
@param $type The type to start from
@param $otherRole The role of the type at the other end (maybe null, if only type shoudl match)
@param $otherType The type at the other end (maybe null, if only role shoudl match)
@param $hierarchyType The hierarchy type that the other type has in relation to this type
'parent', 'child', 'undefined' or 'all' to get all relations (default: 'all')
@param $result Array of PathDescriptions after execution
@param $currentPath Internal use only
Get the relations that connect a type to another type .