/**
  * Filters for attribute containg the given hint as substring (case-insensitive)
  * Returns the attribute tree from root to this found entities as xml string.
  *
  * @return xml string (attribute tree)
  */
 function filterForPropertyTree($propertyHints)
 {
     $reqfilter = new SMWAdvRequestOptions();
     $reqfilter->sort = true;
     $reqfilter->disjunctiveStrings = true;
     if (count($propertyHints) == 0) {
         return "<result isEmpty=\"true\" textToDisplay=\"" . wfMsg('smw_ob_no_attributes') . "\"/>";
     }
     foreach ($propertyHints as $hint) {
         $reqfilter->addStringCondition($hint, SMWStringCondition::STRCOND_MID);
     }
     $reqfilter->isCaseSensitive = false;
     $foundAttributes = smwfGetSemanticStore()->getPages(array(SMW_NS_PROPERTY), $reqfilter, false);
     // create root object
     $root = new TreeObject(null);
     // get all paths to the root
     $allPaths = array();
     $visitedNodes = array();
     foreach ($foundAttributes as $cat) {
         $init_path = array();
         $this->getAllPropertyPaths($cat, $init_path, $allPaths, $visitedNodes);
     }
     // reverse paths
     $reversedPaths = array();
     foreach ($allPaths as $path) {
         $reversedPaths[] = array_reverse($path);
     }
     // build tree of TreeObjects
     foreach ($reversedPaths as $path) {
         $node = $root;
         foreach ($path as $c) {
             $node = $node->addChild($c);
         }
     }
     // sort first level
     $root->sortChildren();
     // serialize tree as XML
     $serializedXML = $root->serializeAsXML('propertyTreeElement');
     return $serializedXML == '' ? "<result isEmpty=\"true\" textToDisplay=\"" . wfMsg('smw_ob_no_attributes') . "\"/>" : '<result>' . $serializedXML . '</result>';
 }
Example #2
0
 public function testPropertiesWithSchemaByName()
 {
     $exp_properties = array("Is parent of");
     $exp_schema = array("Is parent of" => array(0, 2147483647, '_wpg', NULL, NULL, 'Car', false));
     $requestoptions = new SMWAdvRequestOptions();
     $requestoptions->addStringCondition("parent", SMWStringCondition::STRCOND_MID);
     $properties = smwfGetSemanticStore()->getPropertiesWithSchemaByName($requestoptions);
     foreach ($properties as $prop) {
         list($p, $minCard, $maxCard, $type, $symCat, $transCat, $range, $inherited) = $prop;
         $this->assertContains($p->getText(), $exp_properties, $p->getText() . " missing");
         $this->assertEquals($minCard, $exp_schema[$p->getText()][0]);
         $this->assertEquals($maxCard, $exp_schema[$p->getText()][1]);
         $this->assertEquals($type, $exp_schema[$p->getText()][2]);
         $this->assertEquals($symCat, $exp_schema[$p->getText()][3]);
         $this->assertEquals($transCat, $exp_schema[$p->getText()][4]);
         $this->assertEquals($range, $exp_schema[$p->getText()][5]);
         $this->assertEquals($inherited, $exp_schema[$p->getText()][6]);
     }
 }