array of uris that depend on the URI $toTest = []; foreach ($uris as $uri) { $resource = new core_kernel_classes_Resource($uri); foreach ($resource->getTypes() as $type) { $toTest[$type->getUri()] = []; } } $toOpen = [$rootNode->getUri()]; while (!empty($toTest)) { reset($toTest); $classUri = key($toTest); $depends = current($toTest); unset($toTest[$classUri]); if (in_array($classUri, $toOpen)) { $toOpen = array_merge($toOpen, $depends); } else { $class = new core_kernel_classes_Class($classUri); /** @var core_kernel_classes_Class $parent */ foreach ($class->getParentClasses(false) as $parent) { if ($parent->getUri() === OntologyRdfs::RDFS_CLASS) { continue; } if (!isset($toTest[$parent->getUri()])) { $toTest[$parent->getUri()] = []; } $toTest[$parent->getUri()] = array_merge( $toTest[$parent->getUri()], [$classUri], $depends ); } } } return $toOpen; } /** * generis tree representation of a resource node * * @param core_kernel_classes_Resource $resource * @param core_kernel_classes_Class $class * @param array $extraProperties * @return array */ public static function buildResourceNode(core_kernel_classes_Resource $resource, core_kernel_classes_Class $class, array $extraProperties = []) { $label = $resource->getLabel(); $label = empty($label) ? __('no label') : $label; $extraValues = []; if (!empty($extraProperties)) { foreach ($extraProperties as $key => $value) { $extraValues[$key] = $resource->getOnePropertyValue($class->getProperty($value)); } } $signatureGenerator = ServiceManager::getServiceManager()->get(SignatureGenerator::class); return [ 'data' => _dh($label), 'type' => 'instance', 'attributes' => array_merge([ 'id' => tao_helpers_Uri::encode($resource->getUri()), 'class' => 'node-instance', 'data-uri' => $resource->getUri(), 'data-classUri' => $class->getUri(), 'data-signature' => $signatureGenerator->generate($resource->getUri()), ], $extraValues) ]; } }