00001 <?php
00002
00015 abstract class ApiSMWQuery extends ApiBase {
00016
00023 protected $parameters;
00024
00029 protected function getQuery( $queryString, array $printouts ) {
00030 SMWQueryProcessor::addThisPrintout( $printouts, $this->parameters );
00031
00032 return SMWQueryProcessor::createQuery(
00033 $queryString,
00034 SMWQueryProcessor::getProcessedParams( $this->parameters, $printouts ),
00035 SMWQueryProcessor::SPECIAL_PAGE,
00036 '',
00037 $printouts
00038 );
00039 }
00040
00047 protected function getQueryResult( SMWQuery $query ) {
00048 return smwfGetStore()->getQueryResult( $query );
00049 }
00050
00051 protected function addQueryResult( SMWQueryResult $queryResult ) {
00052 $serialized = $queryResult->serializeToArray();
00053 $result = $this->getResult();
00054
00055 $result->setIndexedTagName( $serialized['results'], 'result' );
00056 $result->setIndexedTagName( $serialized['printrequests'], 'printrequest' );
00057
00058 foreach ( $serialized['results'] as $subjectName => $subject ) {
00059 if ( is_array( $subject ) && array_key_exists( 'printouts', $subject ) ) {
00060 foreach ( $subject['printouts'] as $property => $values ) {
00061 if ( is_array( $values ) ) {
00062 $result->setIndexedTagName( $serialized['results'][$subjectName]['printouts'][$property], 'value' );
00063 }
00064 }
00065 }
00066 }
00067
00068 $result->addValue( null, 'query', $serialized );
00069
00070 if ( $queryResult->hasFurtherResults() ) {
00071
00072 $result->disableSizeCheck();
00073 $result->addValue( null, 'query-continue', 0 );
00074 $result->enableSizeCheck();
00075 }
00076 }
00077
00079 protected function requireParameters( array $params, array $required ) {
00080 foreach ( $required as $param ) {
00081 if ( !isset( $params[$param] ) ) {
00082 $this->dieUsageMsg( array( 'missingparam', $param ) );
00083 }
00084 }
00085 }
00086
00087 }