[], 'edges' => [] ]; $childOf = new \core_kernel_classes_Property(self::PROPERTY_CHILD_OF); foreach ($tree->getInstances() as $node) { $returnValue['nodes'][] = [ 'id' => $node->getUri(), 'label' => is_callable($labelProcessor) ? $labelProcessor($node->getLabel()) : $node->getLabel(), ]; foreach ($node->getPropertyValues($childOf) as $childUri) { $returnValue['edges'][] = [ 'from' => $childUri, 'to' => $node->getUri() ]; } } return $returnValue; } /** * Used to build jsTree visualization widget * * @param array $nodes * * @return array */ public function getNestedStructure(array $nodes) { $childOf = new \core_kernel_classes_Property(self::PROPERTY_CHILD_OF); $tmpTree = []; foreach ($nodes as $node) { $nodeData = [ 'data' => $node->getLabel(), 'parent' => 0, 'attributes' => [ 'id' => tao_helpers_Uri::encode($node->getUri()), 'class' => 'node-instance', ] ]; foreach ($node->getPropertyValues($childOf) as $childUri) { $nodeData['parent'] = tao_helpers_Uri::encode($childUri); } if (isset($nodeData['parent'])) { $tmpTree[$nodeData['parent']][] = $nodeData; } } $tree = self::createTree($tmpTree, array_shift($tmpTree)); return $tree; } /** * get all the tree classes * * @return array */ public function getTrees() { $returnValue = []; foreach ($this->getRootClass()->getSubClasses(false) as $tree) { $returnValue[] = $tree; } return $returnValue; } /** * @param $list * @param $parent * * @return array */ protected static function createTree($list, $parent) { $tree = []; foreach ($parent as $k => $node) { if (isset($list[$node['attributes']['id']])) { $node['children'] = self::createTree($list, $list[$node['attributes']['id']]); $node['state'] = 'open'; } $tree[] = $node; } return $tree; } }