/** * Return an SMWDataValue object for the next SMWDataItem object or * false if no further object exists. * * @since 1.6 * * @return SMWDataValue|false */ public function getNextDataValue() { $dataItem = $this->getNextDataItem(); if ($dataItem === false) { return false; } if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_rec') !== false && $this->mPrintRequest->getParameter('index') !== false) { $recordValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $this->mPrintRequest->getData()->getDataItem()); $diProperty = $recordValue->getPropertyDataItemByIndex($this->mPrintRequest->getParameter('index')); } elseif ($this->mPrintRequest->isMode(PrintRequest::PRINT_PROP)) { $diProperty = $this->mPrintRequest->getData()->getDataItem(); } elseif ($this->mPrintRequest->isMode(PrintRequest::PRINT_CHAIN)) { $diProperty = $this->mPrintRequest->getData()->getLastPropertyChainValue()->getDataItem(); } else { $diProperty = null; } // refs #1314 if ($this->mPrintRequest->getMode() == PrintRequest::PRINT_PROP && strpos($this->mPrintRequest->getTypeID(), '_txt') !== false && $dataItem instanceof DIBlob) { $dataItem = new DIBlob(InTextAnnotationParser::removeAnnotation($dataItem->getString())); } $dataValue = DataValueFactory::getInstance()->newDataValueByItem($dataItem, $diProperty); $dataValue->setContextPage($this->mResult); if ($this->mPrintRequest->getOutputFormat()) { $dataValue->setOutputFormat($this->mPrintRequest->getOutputFormat()); } if ($this->entityListAccumulator !== null && $dataItem instanceof DataItem) { $this->entityListAccumulator->addToEntityList($dataItem, $diProperty); } return $dataValue; }
/** * @since 2.5 * * @param PrintRequest $printRequest * @param boolean $showparams that sets if the serialization should include * the extra print request parameters * * @return string */ public static function serialize(PrintRequest $printRequest, $showparams = false) { $parameters = ''; if ($showparams) { foreach ($printRequest->getParameters() as $key => $value) { $parameters .= "|+" . $key . "=" . $value; } } switch ($printRequest->getMode()) { case PrintRequest::PRINT_CATS: return self::doSerializeCat($printRequest, $parameters); case PrintRequest::PRINT_CCAT: return self::doSerializeCcat($printRequest, $parameters); case PrintRequest::PRINT_CHAIN: case PrintRequest::PRINT_PROP: return self::doSerializeProp($printRequest, $parameters); case PrintRequest::PRINT_THIS: return self::doSerializeThis($printRequest, $parameters); default: return ''; } return ''; // no current serialisation }
/** * Load results of the given print request and result subject. This is only * done when needed. */ protected function loadContent() { if ($this->mContent !== false) { return; } switch ($this->mPrintRequest->getMode()) { case PrintRequest::PRINT_THIS: // NOTE: The limit is ignored here. $this->mContent = array($this->mResult); break; case PrintRequest::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 PrintRequest::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 (strpos($this->mPrintRequest->getTypeID(), '_rec') !== false && $this->mPrintRequest->getParameter('index') !== false) { $pos = $this->mPrintRequest->getParameter('index') - 1; $newcontent = array(); foreach ($this->mContent as $diContainer) { /* SMWRecordValue */ $recordValue = \SMW\DataValueFactory::getInstance()->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 PrintRequest::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); }