/** * Renders the auhtoring for simple tests */ public function index() { $test = new \core_kernel_classes_Resource($this->getRequestParameter('uri')); $model = $this->getServiceManager()->get(TestModel::SERVICE_ID); $itemSequence = array(); $itemUris = array(); $counter = 1; foreach ($model->getItems($test) as $item) { $itemUris[] = $item->getUri(); $itemSequence[$counter] = array('uri' => tao_helpers_Uri::encode($item->getUri()), 'label' => $item->getLabel()); $counter++; } // data for item sequence, terrible solution // @todo implement an ajax request for labels or pass from tree to sequence $allItems = array(); foreach (\taoTests_models_classes_TestsService::singleton()->getAllItems() as $itemUri => $itemLabel) { $allItems['item_' . tao_helpers_Uri::encode($itemUri)] = $itemLabel; } $config = $model->getConfig($test); $checked = isset($config['previous']) ? $config['previous'] : false; $testConfig['previous'] = array('label' => __('Allow test-taker to go back in test'), 'checked' => $checked); $this->setData('uri', $test->getUri()); $this->setData('allItems', json_encode($allItems)); $this->setData('itemSequence', $itemSequence); $this->setData('testConfig', $testConfig); // data for generis tree form $this->setData('relatedItems', json_encode(tao_helpers_Uri::encodeArray($itemUris))); $openNodes = TreeHelper::getNodesToOpen($itemUris, new core_kernel_classes_Class(TAO_ITEM_CLASS)); $this->setData('itemRootNode', TAO_ITEM_CLASS); $this->setData('itemOpenNodes', $openNodes); $this->setData('saveUrl', _url('saveItems', 'Authoring', 'taoTestLinear')); $this->setView('Authoring/index.tpl'); }
public function getData() { if (!tao_helpers_Request::isAjax()) { throw new common_exception_IsAjaxAction(__FUNCTION__); } if ($this->hasRequestParameter('classUri')) { $classUri = tao_helpers_Uri::decode($this->getRequestParameter('classUri')); $class = new core_kernel_classes_Class($classUri); $hideNode = true; } elseif ($this->hasRequestParameter('rootNode')) { $class = new core_kernel_classes_Class($this->getRequestParameter('rootNode')); $hideNode = false; } else { throw new common_Exception('Missing node information for ' . __FUNCTION__); } $openNodes = array($class->getUri()); if ($this->hasRequestParameter('openNodes') && is_array($this->getRequestParameter('openNodes'))) { $openNodes = array_merge($openNodes, $this->getRequestParameter('openNodes')); } else { if ($this->hasRequestParameter('openParentNodes') && is_array($this->getRequestParameter('openParentNodes'))) { $childNodes = $this->getRequestParameter('openParentNodes'); $openNodes = TreeHelper::getNodesToOpen($childNodes, $class); } } $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : self::DEFAULT_LIMIT; $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0; $showInst = $this->hasRequestParameter('hideInstances') ? !$this->getRequestParameter('hideInstances') : true; $factory = new GenerisTreeFactory($showInst, $openNodes, $limit, $offset); $array = $factory->buildTree($class); if ($hideNode) { $array = isset($array['children']) ? $array['children'] : array(); } echo json_encode($array); }
/** * Generates a form to define the reverse values of a specific property for a resource * This allows to set/remove multiple triples that share the same object * * @param core_kernel_classes_Resource $resource * @param core_kernel_classes_Property $property * @return tao_helpers_form_GenerisTreeForm */ public static function buildReverseTree(core_kernel_classes_Resource $resource, core_kernel_classes_Property $property) { $tree = new self($resource, $property); $domainCollection = $property->getDomain(); if (!$domainCollection->isEmpty()) { $domain = $domainCollection->get(0); $tree->setData('rootNode', $domain->getUri()); $tree->setData('dataUrl', _url('getData', 'GenerisTree', 'tao')); $tree->setData('saveUrl', _url('setReverseValues', 'GenerisTree', 'tao')); $values = array_keys($domain->searchInstances(array($property->getUri() => $resource), array('recursive' => true, 'like' => false))); $tree->setData('values', $values); $openNodeUris = TreeHelper::getNodesToOpen($values, $domain); $tree->setData('openNodes', $openNodeUris); } return $tree; }
/** * 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 core_kernel_classes_Class $clazz * @param array $options * @return array */ public function toTree(core_kernel_classes_Class $clazz, array $options = array()) { // show instances yes/no $instances = isset($options['instances']) ? $options['instances'] : true; // 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, independent of classes $limit = isset($options['limit']) ? $options['limit'] : 0; // offset for limit $offset = isset($options['offset']) ? $options['offset'] : 0; // A unique node URI to be returned from as a tree leaf. $uniqueNode = isset($options['uniqueNode']) ? $options['uniqueNode'] : null; if ($uniqueNode !== null) { $instance = new \core_kernel_classes_Resource($uniqueNode); $results[] = TreeHelper::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 = TreeHelper::getNodesToOpen($browse, $clazz); if (!in_array($clazz->getUri(), $openNodes)) { $openNodes[] = $clazz->getUri(); } $factory = new GenerisTreeFactory($instances, $openNodes, $limit, $offset, $browse); $tree = $factory->buildTree($clazz); $returnValue = $chunk ? isset($tree['children']) ? $tree['children'] : array() : $tree; } return $returnValue; }
/** * Builds the content of a class node including it's content * * @param core_kernel_classes_Class $class * * @return array */ private function buildChildNodes(core_kernel_classes_Class $class) { $childs = array(); // subclasses foreach ($class->getSubClasses(false) as $subclass) { $childs[] = $this->classToNode($subclass, $class); } // resources if ($this->showResources) { $limit = $this->limit; if (in_array($class->getUri(), $this->browsableTypes)) { $limit = 0; } $searchResult = $class->searchInstances(array(), array('limit' => $limit, 'offset' => $this->offset, 'recursive' => false, 'order' => RDFS_LABEL)); foreach ($searchResult as $instance) { $childs[] = TreeHelper::buildResourceNode($instance, $class); } } return $childs; }