00001 <?php
00002
00020 class SMWQueryResult {
00021
00026 protected $mResults;
00027
00032 protected $mPrintRequests;
00033
00038 protected $mFurtherResults;
00039
00045 protected $mQuery;
00046
00051 protected $mStore;
00052
00065 public function __construct( array $printRequests, SMWQuery $query, array $results, SMWStore $store, $furtherRes = false ) {
00066 $this->mResults = $results;
00067 reset( $this->mResults );
00068 $this->mPrintRequests = $printRequests;
00069 $this->mFurtherResults = $furtherRes;
00070 $this->mQuery = $query;
00071 $this->mStore = $store;
00072 }
00073
00079 public function getStore() {
00080 return $this->mStore;
00081 }
00082
00089 public function getNext() {
00090 $page = current( $this->mResults );
00091 next( $this->mResults );
00092
00093 if ( $page === false ) return false;
00094
00095 $row = array();
00096
00097 foreach ( $this->mPrintRequests as $p ) {
00098 $row[] = new SMWResultArray( $page, $p, $this->mStore );
00099 }
00100
00101 return $row;
00102 }
00103
00109 public function getCount() {
00110 return count( $this->mResults );
00111 }
00112
00119 public function getResults() {
00120 return $this->mResults;
00121 }
00122
00129 public function getColumnCount() {
00130 return count( $this->mPrintRequests );
00131 }
00132
00139 public function getPrintRequests() {
00140 return $this->mPrintRequests;
00141 }
00142
00149 public function getQueryString() {
00150 return $this->mQuery->getQueryString();
00151 }
00152
00158 public function hasFurtherResults() {
00159 return $this->mFurtherResults;
00160 }
00161
00167 public function getErrors() {
00168
00169 return $this->mQuery->getErrors();
00170 }
00171
00177 public function addErrors( array $errors ) {
00178 $this->mQuery->addErrors( $errors );
00179 }
00180
00195 public function getQueryLink( $caption = false ) {
00196 $params = array( trim( $this->mQuery->getQueryString() ) );
00197
00198 foreach ( $this->mQuery->getExtraPrintouts() as $printout ) {
00199 $serialization = $printout->getSerialisation();
00200
00201
00202
00203 if ( $serialization !== '?#' ) {
00204 $params[] = $serialization;
00205 }
00206 }
00207
00208 if ( $this->mQuery->getMainLabel() !== false ) {
00209 $params['mainlabel'] = $this->mQuery->getMainLabel();
00210 }
00211
00212 $params['offset'] = $this->mQuery->getOffset() + count( $this->mResults );
00213
00214 if ( $params['offset'] === 0 ) {
00215 unset( $params['offset'] );
00216 }
00217
00218 if ( $this->mQuery->getLimit() > 0 ) {
00219 $params['limit'] = $this->mQuery->getLimit();
00220 }
00221
00222 if ( count( $this->mQuery->sortkeys ) > 0 ) {
00223 $order = implode( ',', $this->mQuery->sortkeys );
00224 $sort = implode( ',', array_keys( $this->mQuery->sortkeys ) );
00225
00226 if ( $sort !== '' || $order != 'ASC' ) {
00227 $params['order'] = $order;
00228 $params['sort'] = $sort;
00229 }
00230 }
00231
00232 if ( $caption == false ) {
00233 $caption = ' ' . wfMsgForContent( 'smw_iq_moreresults' );
00234 }
00235
00236
00237 $result = SMWInfolink::newInternalLink( $caption, ':Special:Ask', false, $params );
00238
00239 return $result;
00240 }
00241
00247 public function serializeToArray() {
00248 return SMWDISerializer::getSerializedQueryResult( $this );
00249 }
00250
00251 }