private function getResultContent(DataItem $dataItem) { $dataValue = $this->printRequest->getData(); $dataItems = array($dataItem); if (!$dataValue->isValid()) { return array(); } // If it is a chain then try to find a connected DIWikiPage subject that // matches the property on the chained PrintRequest. // For example, Number.Date.SomeThing will not return any meaningful results // because Number will return a DINumber object and not a DIWikiPage. // If on the other hand Has page.Number (with Number being the Last and // `Has page` is of type Page) then the iteration will lookup on results // for `Has page` and try to match a Number annotation on the results // retrieved from `Has page`. if ($this->printRequest->isMode(PrintRequest::PRINT_CHAIN)) { // Output of the previous iteration is the input for the next iteration foreach ($dataValue->getPropertyChainValues() as $pv) { $dataItems = $this->doFetchPropertyValues($dataItems, $pv); // If the results return empty then it means that for this element // the chain has no matchable items hence we stop if ($dataItems === array()) { return array(); } } $dataValue = $dataValue->getLastPropertyChainValue(); } return $this->doFetchPropertyValues($dataItems, $dataValue); }
/** * 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 }
public function testSetLabel() { $propertyValue = new PropertyValue('__pro'); $propertyValue->setDataItem(new DIProperty('Foo')); $instance = new PrintRequest(PrintRequest::PRINT_PROP, null, $propertyValue); $this->assertEquals(null, $instance->getLabel()); $this->assertEquals(null, $instance->getWikiText()); $instance->setLabel('Bar'); $this->assertEquals('Bar', $instance->getLabel()); $this->assertEquals('Bar', $instance->getWikiText()); }
/** * Make a request option object based on the given parameters, and * return NULL if no such object is required. The parameter defines * if the limit should be taken into account, which is not always desired * (especially if results are to be cached for future use). * * @param boolean $useLimit * * @return SMWRequestOptions|null */ protected function getRequestOptions($useLimit = true) { $limit = $useLimit ? $this->mPrintRequest->getParameter('limit') : false; $order = trim($this->mPrintRequest->getParameter('order')); // Important: use "!=" for order, since trim() above does never return "false", use "!==" for limit since "0" is meaningful here. if ($limit !== false || $order != false) { $options = new SMWRequestOptions(); if ($limit !== false) { $options->limit = trim($limit); } if ($order == 'descending' || $order == 'reverse' || $order == 'desc') { $options->sort = true; $options->ascending = false; } elseif ($order == 'ascending' || $order == 'asc') { $options->sort = true; $options->ascending = true; } } else { $options = null; } return $options; }
private function getColumnClass(PrintRequest $pr) { return str_replace(array(' ', '_'), '-', strip_tags($pr->getText(SMW_OUTPUT_WIKI))); }
/** * @see PrintRequest::newFromText * * @since 2.4 * * @param string $text * @param $showMode = false * * @return PrintRequest|null */ public function newPrintRequestFromText($text, $showMode = false) { return PrintRequest::newFromText($text, $showMode); }
public function testFromTextToReturnNullOnInvalidText() { $instance = PrintRequest::newFromText('--[[Foo'); $this->assertNull($instance); }