public function addLink($predicate, Erfurt_Sparql_Query2_Abstraction_ClassNode $target) { if (is_string($predicate)) { $predicate = new Erfurt_Sparql_Query2_IriRef($predicate); } if (!$predicate instanceof Erfurt_Sparql_Query2_IriRef) { throw new RuntimeException('Argument 1 passed to Erfurt_Sparql_Query2_Abstraction_ClassNode::addFilter must be an instance of Erfurt_Sparql_Query2_IriRef instance of ' . typeHelper($predicate) . ' given'); } $this->outgoinglinks[] = new Erfurt_Sparql_Query2_Abstraction_Link($predicate, $target); $this->query->getWhere()->addElement(new Erfurt_Sparql_Query2_Triple($this->classVar, $predicate, new Erfurt_Sparql_Query2_Var($target->getClass()->getIri()))); return $this; //for chaining }
/** * addNode * * add a node to the tree of class-nodes * * @param Erfurt_Sparql_Query2_Abstraction_ClassNode $sourceNode where in the tree of nodes should the new node be added * @param Erfurt_Sparql_Query2_IriRef|string $LinkPredicate over which predicate you want to link * @param Erfurt_Sparql_Query2_IriRef|string|null $targetClass can be used to link to a subset of all possible * @param bool $withChilds wether to include subclasses of $class * @param string|null $varName the var-name to be used for instances of this class * @param string $member_predicate the predicate that stands between the class und its instances (mostly rdf:type) * @return Erfurt_Sparql_Query2_Abstraction_ClassNode the new node */ public function addNode(Erfurt_Sparql_Query2_Abstraction_ClassNode $sourceNode, $LinkPredicate, $targetClass = null, $withChilds = true, $varName = null, $member_predicate = EF_RDF_TYPE) { // hack for overloaded functioncalls if (!$LinkPredicate instanceof Erfurt_Sparql_Query2_IriRef) { if (is_string($LinkPredicate)) { $LinkPredicate = new Erfurt_Sparql_Query2_IriRef($LinkPredicate); } else { throw new RuntimeException("Argument 2 passed to Erfurt_Sparql_Query2_Abstraction::addNode must be an instance of Erfurt_Sparql_Query2_IriRef or string, instance of " . typeHelper($LinkPredicate) . " given"); } } if ($targetClass == null) { //TODO: find type of referenced objects } //add link from source node to new node $newnode = new Erfurt_Sparql_Query2_Abstraction_ClassNode($targetClass, $member_predicate, $this->query, $varName, $withChilds); $sourceNode->addLink($LinkPredicate, $newnode); return $newnode; //for chaining }
/** * Adds a property to the properties fetched for every resource. * * @param $propertyUri The URI of the property * @param $propertyName Name to be used for the variable * * @return OntoWiki_Model_Instances */ public function addShownProperty($propertyUri, $propertyName = null, $inverse = false, $datatype = null, $hidden = false) { if (in_array($propertyUri, $this->_ignoredShownProperties)) { return $this; //no action } if (!$propertyName) { $propertyName = preg_replace('/^.*[#\\/]/', '', $propertyUri); $propertyName = str_replace('-', '', $propertyName); } $used = false; foreach ($this->_shownProperties as $shownProp) { if ($shownProp['name'] == $propertyName) { $used = true; } } //solve duplicate name problem by adding counter if ($used) { $counter = 2; while ($used) { $name = $propertyName . $counter; ++$counter; $used = false; foreach ($this->_shownProperties as $shownProp) { if ($shownProp['name'] == $name) { $used = true; } } } $propertyName = $name; } $ret = Erfurt_Sparql_Query2_Abstraction_ClassNode::addShownPropertyHelper($this->_valueQuery, $this->_resourceVar, $propertyUri, $propertyName, $inverse); $this->_shownProperties[$propertyUri . '-' . ($inverse ? 'inverse' : 'direct')] = array('uri' => $propertyUri, 'name' => $propertyName, 'inverse' => $inverse, 'datatype' => $datatype, 'varName' => $ret['var']->getName(), 'var' => $ret['var'], 'optionalpart' => $ret['optional'], 'filter' => $ret['filter'], 'hidden' => $hidden); $this->_valuesUptodate = false; // getValues will not use the cache next time $this->_resultsUptodate = false; return $this; }