/** * 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)'); }
/** * Rewrite printrequests in the way that subselection are cut down to normal property selections * in order to display them properly. * * @param SMWPrintRequest $pr * @return SMWPrintRequest */ private function rewritePrintrequest($pr) { $data = $pr->getData(); $rewritten_prs = $pr; if ($data instanceof Title) { // property chain appear as Title $titleText = $data->getText(); $chain = explode(".", $titleText); if (count($chain) > 1) { $newtitle = Title::newFromText($chain[count($chain) - 1], SMW_NS_PROPERTY); if ($newtitle->exists()) { $newlabel = $pr->getLabel() != $titleText ? $pr->getLabel() : $newtitle->getText(); $newData = SMWPropertyValue::makeUserProperty($newtitle->getText()); } else { $newlabel = $pr->getLabel() != $titleText ? $pr->getLabel() : $newtitle->getText(); $newData = $newtitle; } $rewritten_prs = new SMWPrintRequest($newtitle->exists() ? SMWPrintRequest::PRINT_PROP : SMWPrintRequest::PRINT_THIS, $newlabel, $newData, $pr->getOutputFormat()); $rewritten_prs->getHash(); } } return $rewritten_prs; }