/** * @see SMWStore::getSemanticData() * @since 1.8 * * @param DIWikiPage $subject * @param string[]|bool $filter */ public function getSemanticData(DIWikiPage $subject, $filter = false) { // *** Find out if this subject exists ***// $sortKey = ''; $sid = $this->store->smwIds->getSMWPageIDandSort($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortKey, true, true); // Ensures that a cached item to contain an expected sortKey when // for example the ID was just created and the sortKey from the DB // is empty otherwise the DB wins over the invoked sortKey if (!$sortKey) { $sortKey = $subject->getSortKey(); } $subject->setSortKey($sortKey); if ($sid == 0) { // We consider redirects for getting $sid, // so $sid == 0 also means "no redirects". return new SMWSemanticData($subject); } $propertyTableHashes = $this->store->smwIds->getPropertyTableHashes($sid); foreach ($this->store->getPropertyTables() as $tid => $proptable) { if (!array_key_exists($proptable->getName(), $propertyTableHashes)) { continue; } if ($filter !== false) { $relevant = false; foreach ($filter as $typeId) { $diType = DataTypeRegistry::getInstance()->getDataItemId($typeId); $relevant = $relevant || $proptable->getDiType() == $diType; if ($relevant) { break; } } if (!$relevant) { continue; } } $this->getSemanticDataFromTable($sid, $subject, $proptable); } // Note: the sortkey is always set but belongs to no property table, // hence no entry in $this->store->m_sdstate[$sid] is made. self::$in_getSemanticData++; $this->initSemanticDataCache($sid, $subject); // Avoid adding a sortkey for an already extended stub if (!$this->store->m_semdata[$sid]->hasProperty(new DIProperty('_SKEY'))) { $this->store->m_semdata[$sid]->addPropertyStubValue('_SKEY', array('', $sortKey)); } self::$in_getSemanticData--; return $this->store->m_semdata[$sid]; }
/** * @see SMWStore::getSemanticData() * @since 1.8 * * @param DIWikiPage $subject * @param string[]|bool $filter */ public function getSemanticData(DIWikiPage $subject, $filter = false) { // *** Find out if this subject exists ***// $sortKey = ''; $sid = $this->store->smwIds->getSMWPageIDandSort($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $subject->getSubobjectName(), $sortKey, true, true); $subject->setSortKey($sortKey); if ($sid == 0) { // We consider redirects for getting $sid, // so $sid == 0 also means "no redirects". return new SMWSemanticData($subject); } $propertyTableHashes = $this->store->smwIds->getPropertyTableHashes($sid); foreach ($this->store->getPropertyTables() as $tid => $proptable) { if (!array_key_exists($proptable->getName(), $propertyTableHashes)) { continue; } if ($filter !== false) { $relevant = false; foreach ($filter as $typeId) { $diType = DataTypeRegistry::getInstance()->getDataItemId($typeId); $relevant = $relevant || $proptable->getDiType() == $diType; if ($relevant) { break; } } if (!$relevant) { continue; } } $this->getSemanticDataFromTable($sid, $subject, $proptable); } // Note: the sortkey is always set but belongs to no property table, // hence no entry in $this->store->m_sdstate[$sid] is made. self::$in_getSemanticData++; $this->initSemanticDataCache($sid, $subject); $this->store->m_semdata[$sid]->addPropertyStubValue('_SKEY', array('', $sortKey)); self::$in_getSemanticData--; return $this->store->m_semdata[$sid]; }
private function newDiWikiPage($dbkeys) { $diWikiPage = new DIWikiPage($dbkeys[0], intval($dbkeys[1]), $dbkeys[2], $dbkeys[4]); $diWikiPage->setSortKey($dbkeys[3]); return $diWikiPage; }
/** * @dataProvider sortKeyProvider */ public function testSortKeyRoundtrip($title, $sortkey, $expected) { $instance = new DIWikiPage($title, NS_MAIN); $instance->setSortKey($sortkey); $this->assertEquals($expected, $instance->getSortKey()); }
/** * Fetch all subobjects for a given subject using a lazy-mapping iterator * in order to only resolve one subobject per iteration step. * * @since 2.5 * * @param DIWikiPage $subject * * @return MappingIterator */ private function newMappingIterator(DIWikiPage $subject) { $callback = function ($row) use($subject) { // #1955 if ($subject->getNamespace() === SMW_NS_PROPERTY) { $property = new DIProperty($subject->getDBkey()); $subobject = $property->getCanonicalDiWikiPage($row->smw_subobject); } else { $subobject = new DIWikiPage($subject->getDBkey(), $subject->getNamespace(), $subject->getInterwiki(), $row->smw_subobject); } $subobject->setSortKey($row->smw_sortkey); $subobject->setId($row->smw_id); return $subobject; }; return $this->iteratorFactory->newMappingIterator($this->newResultIterator($subject), $callback); }