/** * Format an RDFS Class to an array to be interpreted by the client tree * This is a closed array format. * * @access public * @author Jerome Bogaerts, <*****@*****.**> * @param Class clazz * @param array options * @return array */ public function toTree(core_kernel_classes_Class $clazz, $options) { $returnValue = array(); // show subclasses yes/no, not implemented $subclasses = isset($options['subclasses']) ? $options['subclasses'] : true; // show instances yes/no $instances = isset($options['instances']) ? $options['instances'] : true; // @todo describe how this option influences the behaviour $highlightUri = isset($options['highlightUri']) ? $options['highlightUri'] : ''; // filter results by label, and don't show them as a tree at all, but a flat list $labelFilter = isset($options['labelFilter']) ? $options['labelFilter'] : ''; // @todo describe how this option influences the behaviour $recursive = isset($options['recursive']) ? $options['recursive'] : false; // cut of the class and only display the children? $chunk = isset($options['chunk']) ? $options['chunk'] : false; // probably which subtrees should be opened $browse = isset($options['browse']) ? $options['browse'] : array(); // limit of instances shown by subclass if no search label is given // if a search string is given, this is the total limit of results, independant of classes $limit = isset($options['limit']) ? $options['limit'] : 0; // offset for limit $offset = isset($options['offset']) ? $options['offset'] : 0; //an array used to filter properties; use the format by core_kernel_classes_Class::searchInstances $propertyFilter = isset($options['propertyFilter']) ? $options['propertyFilter'] : array(); // A unique node URI to be returned from as a tree leaf. $uniqueNode = isset($options['uniqueNode']) ? $options['uniqueNode'] : null; $factory = new tao_models_classes_GenerisTreeFactory(); if (!empty($labelFilter) && $labelFilter != '*') { // The result must be a set of filtered nodes. $props = array(RDFS_LABEL => $labelFilter); $opts = array('like' => true, 'limit' => $limit, 'offset' => $offset, 'recursive' => true); $searchResult = $clazz->searchInstances($props, $opts); $results = array(); foreach ($searchResult as $instance) { $results[] = $factory->buildResourceNode($instance, $clazz); } if ($offset > 0) { $returnValue = $results; } else { if (count($results) > 0) { $returnValue = $factory->buildClassNode($clazz); $returnValue['count'] = $clazz->countInstances($props, $opts); $returnValue['children'] = $results; } } } elseif ($uniqueNode !== null) { $instance = new \core_kernel_classes_Resource($uniqueNode); $results[] = $factory->buildResourceNode($instance, $clazz); $returnValue = $results; } else { // Let's walk the tree with super walker! ~~~ p==[w]õ__ array_walk($browse, function (&$item) { $item = tao_helpers_Uri::decode($item); }); $openNodes = tao_models_classes_GenerisTreeFactory::getNodesToOpen($browse, $clazz); if (!in_array($clazz->getUri(), $openNodes)) { $openNodes[] = $clazz->getUri(); } $tree = $factory->buildTree($clazz, $instances, $openNodes, $limit, $offset, $propertyFilter); $returnValue = $chunk ? $tree['children'] : $tree; } return $returnValue; }