/** * Get the serialization for a SMWQueryResult object. * * @since 1.7 * * @param SMWQueryResult $result * * @return array */ public static function getSerializedQueryResult(SMWQueryResult $queryResult) { $results = array(); $printRequests = array(); foreach ($queryResult->getPrintRequests() as $printRequest) { $printRequests[] = array('label' => $printRequest->getLabel(), 'typeid' => $printRequest->getTypeID(), 'mode' => $printRequest->getMode()); } foreach ($queryResult->getResults() as $diWikiPage) { $result = array('printouts' => array()); foreach ($queryResult->getPrintRequests() as $printRequest) { $resultAarray = new SMWResultArray($diWikiPage, $printRequest, $queryResult->getStore()); if ($printRequest->getMode() === SMWPrintRequest::PRINT_THIS) { $dataItems = $resultAarray->getContent(); $result += self::getSerialization(array_shift($dataItems)); } else { $result['printouts'][$printRequest->getLabel()] = array_map(array(__CLASS__, 'getSerialization'), $resultAarray->getContent()); } } $results[$diWikiPage->getTitle()->getFullText()] = $result; } return array('results' => $results, 'printrequests' => $printRequests); }
/** * 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)'); }
/** * Code mostly copied from SMW's SMWListResultPrinter::getResultText() */ function printItem( $item ) { $first_col = true; $found_values = false; // has anything but the first column been printed? $result = ""; foreach ( $item->mRow as $orig_ra ) { // handling is somewhat simpler for SMW 1.5+ $realFunction = array( 'SMWQueryResult', 'getResults' ); if ( is_callable( $realFunction ) ) { // make a new copy of this, so that the call to // getNextText() will work again $ra = clone ( $orig_ra ); } else { // make a new copy of this, so that the call to // getNextText() will work again $ra = new SMWResultArray( $orig_ra->getContent(), $orig_ra->getPrintRequest() ); } $val = $ra->getPrintRequest()->getText( SMW_OUTPUT_WIKI, null ); if ( in_array( $val, $this->mOutlineProperties ) ) { continue; } $first_value = true; while ( ( $text = $ra->getNextText( SMW_OUTPUT_WIKI, $this->mLinker ) ) !== false ) { if ( !$first_col && !$found_values ) { // first values after first column $result .= ' ('; $found_values = true; } elseif ( $found_values || !$first_value ) { // any value after '(' or non-first values on first column $result .= ', '; } if ( $first_value ) { // first value in any column, print header $first_value = false; if ( $this->mShowHeaders && ( '' != $ra->getPrintRequest()->getLabel() ) ) { $result .= $ra->getPrintRequest()->getText( SMW_OUTPUT_WIKI, $this->mLinker ) . ' '; } } $result .= $text; // actual output value } $first_col = false; } if ( $found_values ) $result .= ')'; return $result; }
protected function deliverPropertiesManyValues($manyValue_items, $isMissingProperty, $isPageTitle, SMWResultArray $data) { if (empty($manyValue_items)) { return null; } $text = implode($this->mManySep, $manyValue_items); // if property names should be displayed and this is not the page titles value: if ($this->mShowHeaders != SMW_HEADERS_HIDE && !$isPageTitle) { $linker = $this->mShowHeaders == SMW_HEADERS_PLAIN ? null : $this->mLinker; $text = $data->getPrintRequest()->getText(SMW_OUTPUT_WIKI, $linker) . $this->mHeaderSep . $text; } return $text; }
/** * Basic SMW JSON layer * * This is a convenience layer which is eliminating some overhead from the * standard SMW JSON * * @since 1.8 * * @return array */ public function getBasicSerialization() { $results = array(); $printRequests = array(); foreach ($this->results->getPrintRequests() as $printRequest) { $printRequests[$printRequest->getLabel()] = array('label' => $printRequest->getLabel(), 'typeid' => $printRequest->getTypeID()); } foreach ($this->results->getResults() as $diWikiPage) { $result = array(); foreach ($this->results->getPrintRequests() as $printRequest) { $serializationItems = array(); $resultAarray = new SMWResultArray($diWikiPage, $printRequest, $this->results->getStore()); if ($printRequest->getMode() === SMWPrintRequest::PRINT_THIS) { $dataItems = $resultAarray->getContent(); $fulltext = SMWDISerializer::getSerialization(array_shift($dataItems)); $result += array('label' => $fulltext["fulltext"]); } else { $serializationItems = array_map(array('SMWDISerializer', 'getSerialization'), $resultAarray->getContent()); $type = $printRequest->getTypeID(); $items = array(); foreach ($serializationItems as $item) { if ($type == "_wpg") { $items[] = $item["fulltext"]; } else { $items[] = $item; } } $result[$printRequest->getLabel()] = $items; } } $results[$diWikiPage->getTitle()->getFullText()] = $result; } return array('printrequests' => $printRequests, 'results' => $results, 'rows' => $this->count); }
/** * Gets a table cell for all values of a property of a subject. * * @since 1.6.1 * * @param SMWResultArray $resultArray * @param $outputmode * * @return string */ protected function getCellForPropVals(SMWResultArray $resultArray, $outputmode, $columnClass) { $resultArray->reset(); $dataValues = array(); while (($dv = $resultArray->getNextDataValue()) !== false) { $dataValues[] = $dv; } $attribs = array(); $content = null; if (count($dataValues) > 0) { $sortkey = $dataValues[0]->getDataItem()->getSortKey(); if (is_numeric($sortkey)) { $attribs['data-sort-value'] = $sortkey; } $alignment = trim($resultArray->getPrintRequest()->getParameter('align')); if (in_array($alignment, array('right', 'left', 'center'))) { $attribs['style'] = "text-align:' . {$alignment} . ';"; } $attribs['class'] = $columnClass; $content = $this->getCellContent($dataValues, $outputmode, $resultArray->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS); } return Html::rawElement('td', $attribs, $content); }
public function SMWWSResultArray(SMWWikiPageValue $resultPage, SMWPrintRequest $printRequest, $results) { parent::__construct($resultPage, $printRequest, new SMWWSSMWStore()); $this->mContent = $results; // do not reload }
/** * Return the next result row as an array of SMWResultArray objects, and * advance the internal pointer. * * @return SMWResultArray[]|false */ public function getNext() { $page = current($this->mResults); next($this->mResults); if ($page === false) { return false; } $row = array(); foreach ($this->mPrintRequests as $p) { $resultArray = new SMWResultArray($page, $p, $this->mStore); $resultArray->setEntityListAccumulator($this->entityListAccumulator); $row[] = $resultArray; } return $row; }
public function SMWHaloResultArray(SMWWikiPageValue $resultpage, SMWPrintRequest $printrequest, SMWStore $store, $results) { parent::__construct($resultpage, $printrequest, $store); $this->mContent = $results; // do not reload }