00001 <?php
00028 class SMWQuery {
00029
00030 const MODE_INSTANCES = 1;
00031 const MODE_COUNT = 2;
00032 const MODE_DEBUG = 3;
00033 const MODE_NONE = 4;
00034
00035 public $sort = false;
00036 public $sortkeys = array();
00037 public $querymode = SMWQuery::MODE_INSTANCES;
00038
00039 protected $m_limit;
00040 protected $m_offset = 0;
00041 protected $m_description;
00042 protected $m_errors = array();
00043 protected $m_querystring = false;
00044 protected $m_inline;
00045 protected $m_concept;
00046 protected $m_extraprintouts = array();
00047 protected $m_mainlabel = '';
00048
00057 public function __construct( $description = null, $inline = false, $concept = false ) {
00058 global $smwgQMaxLimit, $smwgQMaxInlineLimit;
00059 $this->m_limit = $inline ? $smwgQMaxInlineLimit : $smwgQMaxLimit;
00060 $this->m_inline = $inline;
00061 $this->m_concept = $concept;
00062 $this->m_description = $description;
00063 $this->applyRestrictions();
00064 }
00065
00073 public function setMainLabel( $mainlabel ) {
00074 $this->m_mainlabel = $mainlabel;
00075 }
00076
00084 public function getMainLabel() {
00085 return $this->m_mainlabel;
00086 }
00087
00088 public function setDescription( SMWDescription $description ) {
00089 $this->m_description = $description;
00090 foreach ( $this->m_extraprintouts as $printout ) {
00091 $this->m_description->addPrintRequest( $printout );
00092 }
00093 $this->applyRestrictions();
00094 }
00095
00096 public function getDescription() {
00097 return $this->m_description;
00098 }
00099
00100 public function setExtraPrintouts( $extraprintouts ) {
00101 $this->m_extraprintouts = $extraprintouts;
00102
00103 if ( !is_null( $this->m_description ) ) {
00104 foreach ( $extraprintouts as $printout ) {
00105 $this->m_description->addPrintRequest( $printout );
00106 }
00107 }
00108 }
00109
00110 public function getExtraPrintouts() {
00111 return $this->m_extraprintouts;
00112 }
00113
00114 public function getErrors() {
00115 return $this->m_errors;
00116 }
00117
00118 public function addErrors( $errors ) {
00119 $this->m_errors = array_merge( $this->m_errors, $errors );
00120 }
00121
00122 public function setQueryString( $querystring ) {
00123 $this->m_querystring = $querystring;
00124 }
00125
00126 public function getQueryString() {
00127 if ( $this->m_querystring !== false ) {
00128 return $this->m_querystring;
00129 } elseif ( !is_null( $this->m_description ) ) {
00130 return $this->m_description->getQueryString();
00131 } else {
00132 return '';
00133 }
00134 }
00135
00136 public function getOffset() {
00137 return $this->m_offset;
00138 }
00139
00148 public function setOffset( $offset ) {
00149 global $smwgQMaxLimit;
00150 $this->m_offset = min( $smwgQMaxLimit, $offset );
00151 $this->m_limit = min( $smwgQMaxLimit - $this->m_offset, $this->m_limit );
00152 return $this->m_offset;
00153 }
00154
00155 public function getLimit() {
00156 return $this->m_limit;
00157 }
00158
00166 public function setLimit( $limit, $restrictinline = true ) {
00167 global $smwgQMaxLimit, $smwgQMaxInlineLimit;
00168 $maxlimit = ( $this->m_inline && $restrictinline ) ? $smwgQMaxInlineLimit : $smwgQMaxLimit;
00169 $this->m_limit = min( $smwgQMaxLimit - $this->m_offset, $limit, $maxlimit );
00170 return $this->m_limit;
00171 }
00172
00176 public function applyRestrictions() {
00177 global $smwgQMaxSize, $smwgQMaxDepth, $smwgQConceptMaxSize, $smwgQConceptMaxDepth;
00178
00179 if ( !is_null( $this->m_description ) ) {
00180 if ( $this->m_concept ) {
00181 $maxsize = $smwgQConceptMaxSize;
00182 $maxdepth = $smwgQConceptMaxDepth;
00183 } else {
00184 $maxsize = $smwgQMaxSize;
00185 $maxdepth = $smwgQMaxDepth;
00186 }
00187
00188 $log = array();
00189 $this->m_description = $this->m_description->prune( $maxsize, $maxdepth, $log );
00190
00191 if ( count( $log ) > 0 ) {
00192 $this->m_errors[] = wfMsgForContent( 'smw_querytoolarge', str_replace( '[', '[', implode( ', ' , $log ) ) );
00193 }
00194 }
00195 }
00196
00197 }