/** * Create an SMWSparqlCondition from an SMWClassDescription. * * @param $description SMWClassDescription * @param $joinVariable string name, see buildSparqlCondition() * @param $orderByProperty mixed SMWDIProperty or null, see buildSparqlCondition() * @return SMWSparqlCondition */ protected function buildClassCondition(SMWClassDescription $description, $joinVariable, $orderByProperty) { $condition = ''; $namespaces = array(); $instExpElement = SMWExporter::getSpecialPropertyResource('_INST'); foreach ($description->getCategories() as $diWikiPage) { $categoryExpElement = SMWExporter::getResourceElementForWikiPage($diWikiPage); $categoryName = SMWTurtleSerializer::getTurtleNameForExpElement($categoryExpElement); $namespaces[$categoryExpElement->getNamespaceId()] = $categoryExpElement->getNamespace(); $newcondition = "{ ?{$joinVariable} " . $instExpElement->getQName() . " {$categoryName} . }\n"; if ($condition === '') { $condition = $newcondition; } else { $condition .= "UNION\n{$newcondition}"; } } if ($condition === '') { // empty disjunction: always false, no results to order return new SMWSparqlFalseCondition(); } $result = new SMWSparqlWhereCondition($condition, true, $namespaces); $this->addOrderByDataForProperty($result, $joinVariable, $orderByProperty, SMWDataItem::TYPE_WIKIPAGE); return $result; }
/** * @param SMWClassDescription $description */ public function addDescription( SMWClassDescription $description ) { $this->m_diWikiPages = array_merge( $this->m_diWikiPages, $description->getCategories() ); }