protected function addQueryResult(SMWQueryResult $queryResult) { $serialized = $queryResult->serializeToArray(); $result = $this->getResult(); $result->setIndexedTagName($serialized['results'], 'result'); $result->setIndexedTagName($serialized['printrequests'], 'printrequest'); foreach ($serialized['results'] as $subjectName => $subject) { if (is_array($subject) && array_key_exists('printouts', $subject)) { foreach ($subject['printouts'] as $property => $values) { if (is_array($values)) { $result->setIndexedTagName($serialized['results'][$subjectName]['printouts'][$property], 'value'); } } } } $output = array(); header("Content-type: Application/JSON"); foreach ($serialized['results'] as $r) { $common = count($r['printouts']['Has common name']) > 0 ? $r['printouts']['Has common name'][0]['fulltext'] : ''; $taxo = count($r['printouts']['Is taxonomy type']) > 0 ? $r['printouts']['Is taxonomy type'][0]['fulltext'] : ''; $output[$r['fulltext']] = array('taxonomy' => $taxo, 'common' => $common); } echo json_encode($output); exit; }
protected function addQueryResult( SMWQueryResult $queryResult ) { $serialized = $queryResult->serializeToArray(); $result = $this->getResult(); $result->setIndexedTagName( $serialized['results'], 'result' ); $result->setIndexedTagName( $serialized['printrequests'], 'printrequest' ); foreach ( $serialized['results'] as $subjectName => $subject ) { if ( is_array( $subject ) && array_key_exists( 'printouts', $subject ) ) { foreach ( $subject['printouts'] as $property => $values ) { if ( is_array( $values ) ) { $result->setIndexedTagName( $serialized['results'][$subjectName]['printouts'][$property], 'value' ); } } } } $result->addValue( null, 'query', $serialized ); if ( $queryResult->hasFurtherResults() ) { // TODO: obtain continuation data from store $result->disableSizeCheck(); $result->addValue( null, 'query-continue', 0 ); $result->enableSizeCheck(); } }
public function testVerifyThatAfterSerializeToArrayResultNextCanBeUsed() { $query = $this->getMockBuilder('\\SMWQuery')->disableOriginalConstructor()->getMock(); $store = $this->getMockBuilder('\\SMW\\Store')->disableOriginalConstructor()->getMockForAbstractClass(); $printRequests = array(); $results = array(new DIWikiPage('Foo', 0), new DIWikiPage('Bar', 0)); $instance = new QueryResult($printRequests, $query, $results, $store); $instance->serializeToArray(); $this->assertInternalType('array', $instance->getNext()); $instance->getHash(); $this->assertInternalType('array', $instance->getNext()); }
/** * Add the query result to the API output. * * @since 1.6.2 * * @param SMWQueryResult $queryResult */ protected function addQueryResult(SMWQueryResult $queryResult) { $serialized = $queryResult->serializeToArray(); $result = $this->getResult(); $result->setIndexedTagName($serialized['results'], 'result'); $result->setIndexedTagName($serialized['printrequests'], 'printrequest'); foreach ($serialized['results'] as $subjectName => $subject) { if (is_array($subject) && array_key_exists('printouts', $subject)) { foreach ($subject['printouts'] as $property => $values) { if (is_array($values)) { $result->setIndexedTagName($serialized['results'][$subjectName]['printouts'][$property], 'value'); } } } } $result->addValue(null, 'query', $serialized); if ($queryResult->hasFurtherResults()) { $result->disableSizeCheck(); // TODO: right now this returns an offset that we can use for continuation, just like done // in other places in SMW. However, this is not efficient, so we should change this at some point. $result->addValue(null, 'query-continue-offset', $this->parameters['offset']->getValue() + $queryResult->getCount()); $result->enableSizeCheck(); } }