/** * Helper function to handle getPropertyValues() in both SMW 1.6 * and earlier versions. * * @param SMWStore $store * @param string $pageName * @param integer $pageNamespace * @param string $propID * @param null|SMWRequestOptions $requestOptions * * @return array of SMWDataItem */ public static function getSMWPropertyValues( SMWStore $store, $pageName, $pageNamespace, $propID, $requestOptions = null ) { // SMWDIProperty was added in SMW 1.6 if ( class_exists( 'SMWDIProperty' ) ) { $pageName = str_replace( ' ', '_', $pageName ); $page = new SMWDIWikiPage( $pageName, $pageNamespace, null ); $property = new SMWDIProperty( $propID ); return $store->getPropertyValues( $page, $property, $requestOptions ); } else { $title = Title::makeTitleSafe( $pageNamespace, $pageName ); $property = SMWPropertyValue::makeProperty( $propID ); return $store->getPropertyValues( $title, $property, $requestOptions ); } }
/** * Helper function to handle getPropertyValues(). * * @param SMWStore $store * @param string $pageName * @param integer $pageNamespace * @param string $propID * @param null|SMWRequestOptions $requestOptions * * @return array of SMWDataItem */ public static function getSMWPropertyValues(SMWStore $store, $pageName, $pageNamespace, $propID, $requestOptions = null) { $pageName = str_replace(' ', '_', $pageName); $page = new SMWDIWikiPage($pageName, $pageNamespace, ''); $property = new SMWDIProperty($propID); return $store->getPropertyValues($page, $property, $requestOptions); }
/** * Load results of the given print request and result subject. This is only * done when needed. */ protected function loadContent() { if ($this->mContent !== false) { return; } wfProfileIn('SMWQueryResult::loadContent (SMW)'); switch ($this->mPrintRequest->getMode()) { case SMWPrintRequest::PRINT_THIS: // NOTE: The limit is ignored here. $this->mContent = array($this->mResult); break; case SMWPrintRequest::PRINT_CATS: // Always recompute cache here to ensure output format is respected. self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST'), $this->getRequestOptions(false)); self::$catCacheObj = $this->mResult->getHash(); $limit = $this->mPrintRequest->getParameter('limit'); $this->mContent = $limit === false ? self::$catCache : array_slice(self::$catCache, 0, $limit); break; case SMWPrintRequest::PRINT_PROP: $propertyValue = $this->mPrintRequest->getData(); if ($propertyValue->isValid()) { $this->mContent = $this->mStore->getPropertyValues($this->mResult, $propertyValue->getDataItem(), $this->getRequestOptions()); } else { $this->mContent = array(); } // Print one component of a multi-valued string. // Known limitation: the printrequest still is of type _rec, so if printers check // for this then they will not recognize that it returns some more concrete type. if ($this->mPrintRequest->getTypeID() == '_rec' && $this->mPrintRequest->getParameter('index') !== false) { $pos = $this->mPrintRequest->getParameter('index') - 1; $newcontent = array(); foreach ($this->mContent as $diContainer) { /* SMWRecordValue */ $recordValue = SMWDataValueFactory::newDataItemValue($diContainer, $propertyValue->getDataItem()); $dataItems = $recordValue->getDataItems(); if (array_key_exists($pos, $dataItems) && !is_null($dataItems[$pos])) { $newcontent[] = $dataItems[$pos]; } } $this->mContent = $newcontent; } break; case SMWPrintRequest::PRINT_CCAT: ///NOTE: The limit is ignored here. if (self::$catCacheObj != $this->mResult->getHash()) { self::$catCache = $this->mStore->getPropertyValues($this->mResult, new SMWDIProperty('_INST')); self::$catCacheObj = $this->mResult->getHash(); } $found = false; $prkey = $this->mPrintRequest->getData()->getDBkey(); foreach (self::$catCache as $cat) { if ($cat->getDBkey() == $prkey) { $found = true; break; } } $this->mContent = array(new SMWDIBoolean($found)); break; default: $this->mContent = array(); // Unknown print request. } reset($this->mContent); wfProfileOut('SMWQueryResult::loadContent (SMW)'); }
/** * @see SMWStore::getPropertyValues() * @since 1.8 */ public function getPropertyValues($subject, SMWDIProperty $property, $requestoptions = null) { return $this->baseStore->getPropertyValues($subject, $property, $requestoptions); }