Exemplo n.º 1
0
 /**
  * Get the list of items to populate the checkbox tree of related items.
  * It prints to the HTTP response the tree data formated using json.
  * @return void
  */
 public function getTreeData()
 {
     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'));
     }
     $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : 10;
     $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0;
     $showInst = $this->hasRequestParameter('hideInstances') ? !$this->getRequestParameter('hideInstances') : true;
     $propertyFilter = $this->getTreeFilter();
     $factory = new tao_models_classes_GenerisTreeFactory();
     $array = $factory->buildTree($class, $showInst, $openNodes, $limit, $offset, $propertyFilter);
     if ($hideNode) {
         $array = isset($array['children']) ? $array['children'] : array();
     }
     header('Content-Type : application/json');
     echo json_encode($array);
 }
Exemplo n.º 2
0
 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'));
     }
     $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 tao_models_classes_GenerisTreeFactory();
     $array = $factory->buildTree($class, $showInst, $openNodes, $limit, $offset);
     if ($hideNode) {
         $array = isset($array['children']) ? $array['children'] : array();
     }
     echo json_encode($array);
 }
 /**
  * @deprecated
  * @see taoTests_models_classes_TestModel::getAuthoring()
  */
 public function getAuthoring(core_kernel_classes_Resource $test)
 {
     $ext = common_ext_ExtensionsManager::singleton()->getExtensionById('taoWfTest');
     $testService = taoTests_models_classes_TestsService::singleton();
     $itemSequence = array();
     $itemUris = array();
     $i = 1;
     foreach ($testService->getTestItems($test) as $item) {
         $itemUris[] = $item->getUri();
         $itemSequence[$i] = array('uri' => tao_helpers_Uri::encode($item->getUri()), 'label' => $item->getLabel());
         $i++;
     }
     // data for item sequence, terrible solution
     // @todo implement an ajax request for labels or pass from tree to sequence
     $allItems = array();
     foreach ($testService->getAllItems() as $itemUri => $itemLabel) {
         $allItems['item_' . tao_helpers_Uri::encode($itemUri)] = $itemLabel;
     }
     $widget = new Renderer($ext->getConstant('DIR_VIEWS') . 'templates' . DIRECTORY_SEPARATOR . 'authoring.tpl');
     $widget->setData('uri', $test->getUri());
     $widget->setData('allItems', json_encode($allItems));
     $widget->setData('itemSequence', $itemSequence);
     // data for generis tree form
     $widget->setData('relatedItems', json_encode(tao_helpers_Uri::encodeArray($itemUris)));
     $openNodes = tao_models_classes_GenerisTreeFactory::getNodesToOpen($itemUris, new core_kernel_classes_Class(TAO_ITEM_CLASS));
     $widget->setData('itemRootNode', TAO_ITEM_CLASS);
     $widget->setData('itemOpenNodes', $openNodes);
     $widget->setData('saveUrl', _url('saveItems', 'Authoring', 'taoWfTest'));
     return $widget->render();
 }
 /**
  * Renders the auhtoring for simple tests
  */
 public function index()
 {
     $test = $this->getCurrentInstance();
     $itemSequence = array();
     $itemUris = array();
     $counter = 1;
     foreach ($this->service->getTestItems($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 ($this->service->getAllItems() as $itemUri => $itemLabel) {
         $allItems['item_' . tao_helpers_Uri::encode($itemUri)] = $itemLabel;
     }
     $this->setData('uri', $test->getUri());
     $this->setData('allItems', json_encode($allItems));
     $this->setData('itemSequence', $itemSequence);
     // data for generis tree form
     $this->setData('relatedItems', json_encode(tao_helpers_Uri::encodeArray($itemUris)));
     $openNodes = tao_models_classes_GenerisTreeFactory::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', 'taoWfTest'));
     $this->setView('authoring.tpl');
 }
Exemplo n.º 5
0
 /**
  * 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 = tao_models_classes_GenerisTreeFactory::getNodesToOpen($values, $domain);
         $tree->setData('openNodes', $openNodeUris);
     }
     return $tree;
 }
Exemplo n.º 6
0
 /**
  * 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;
 }
Exemplo n.º 7
0
 /**
  * simplified Version of TaoModule function
  * 
  * @return void
  */
 public function sasGetOntologyData()
 {
     if (!tao_helpers_Request::isAjax()) {
         throw new common_exception_IsAjaxAction(__FUNCTION__);
     }
     $showInstances = $this->hasRequestParameter('hideInstances') ? !(bool) $this->getRequestParameter('hideInstances') : true;
     $hideNode = $this->hasRequestParameter('classUri');
     $clazz = $this->hasRequestParameter('classUri') ? $this->getCurrentClass() : $this->getRootClass();
     if ($this->hasRequestParameter('offset')) {
         $options['offset'] = $this->getRequestParameter('offset');
     }
     $limit = $this->hasRequestParameter('limit') ? $this->getRequestParameter('limit') : 0;
     $offset = $this->hasRequestParameter('offset') ? $this->getRequestParameter('offset') : 0;
     $factory = new tao_models_classes_GenerisTreeFactory();
     $tree = $factory->buildTree($clazz, $showInstances, array($clazz->getUri()), $limit, $offset);
     $returnValue = $hideNode ? $tree['children'] : $tree;
     echo json_encode($returnValue);
 }