00001 <?php
00020 class SMWCategoryResultPrinter extends SMWResultPrinter {
00021
00022 protected $mDelim;
00023 protected $mTemplate;
00024 protected $mUserParam;
00025 protected $mNumColumns;
00026
00035 protected function handleParameters( array $params, $outputmode ) {
00036 parent::handleParameters( $params, $outputmode );
00037
00038 $this->mUserParam = trim( $params['userparam'] );
00039 $this->mDelim = trim( $params['delim'] );
00040 $this->mNumColumns = $params['columns'];
00041 $this->mTemplate = $params['template'];
00042 }
00043
00044 public function getName() {
00045 return wfMsg( 'smw_printername_' . $this->mFormat );
00046 }
00047
00048 protected function getResultText( SMWQueryResult $res, $outputmode ) {
00049 global $wgContLang;
00050
00051
00052
00053 $result = '__NOTOC__';
00054
00055 $num = $res->getCount();
00056
00057 $prev_first_char = "";
00058 $rows_per_column = ceil( $num / $this->mNumColumns );
00059
00060 $column_width = floor( 100 / $this->mNumColumns );
00061
00062
00063 $rowindex = 0;
00064 $row = $res->getNext();
00065
00066 while ( $row !== false ) {
00067 $nextrow = $res->getNext();
00068
00069 $content = $row[0]->getContent();
00070
00071 $cur_first_char = $wgContLang->firstChar(
00072 $content[0]->getDIType() == SMWDataItem::TYPE_WIKIPAGE ?
00073 $res->getStore()->getWikiPageSortKey( $content[0] )
00074 : $content[0]->getSortKey()
00075 );
00076
00077 if ( $rowindex % $rows_per_column == 0 ) {
00078 $result .= "\n <div style=\"float: left; width: $column_width%;\">\n";
00079 if ( $cur_first_char == $prev_first_char )
00080 $result .= " <h3>$cur_first_char " . wfMsg( 'listingcontinuesabbrev' ) . "</h3>\n <ul>\n";
00081 }
00082
00083
00084
00085 if ( $cur_first_char != $prev_first_char ) {
00086 if ( $rowindex % $rows_per_column > 0 )
00087 $result .= " </ul>\n";
00088 $result .= " <h3>$cur_first_char</h3>\n <ul>\n";
00089 }
00090 $prev_first_char = $cur_first_char;
00091
00092 $result .= '<li>';
00093 $first_col = true;
00094
00095 if ( $this->mTemplate !== '' ) {
00096 $this->hasTemplates = true;
00097 $wikitext = ( $this->mUserParam ) ? "|userparam=$this->mUserParam":'';
00098 $i = 1;
00099
00100 foreach ( $row as $field ) {
00101 $wikitext .= '|' . $i++ . '=';
00102 $first_value = true;
00103
00104 while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getLinker( $first_col ) ) ) !== false ) {
00105 if ( $first_value ) $first_value = false; else $wikitext .= $this->mDelim . ' ';
00106 $wikitext .= $text;
00107 }
00108
00109 $first_col = false;
00110 }
00111
00112 $wikitext .= "|#=$rowindex";
00113 $result .= '{{' . $this->mTemplate . $wikitext . '}}';
00114
00115 } else {
00116 $first_col = true;
00117 $found_values = false;
00118
00119 foreach ( $row as $field ) {
00120 $first_value = true;
00121
00122 while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getLinker( $first_col ) ) ) !== false ) {
00123 if ( !$first_col && !$found_values ) {
00124 $result .= ' (';
00125 $found_values = true;
00126 } elseif ( $found_values || !$first_value ) {
00127
00128 $result .= ', ';
00129 }
00130
00131 if ( $first_value ) {
00132 $first_value = false;
00133
00134 if ( $this->mShowHeaders && ( $field->getPrintRequest()->getLabel() !== '' ) ) {
00135 $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, $this->mLinker ) . ' ';
00136 }
00137 }
00138
00139 $result .= $text;
00140 }
00141
00142 $first_col = false;
00143 }
00144
00145 if ( $found_values ) $result .= ')';
00146 }
00147
00148 $result .= '</li>';
00149 $row = $nextrow;
00150
00151
00152
00153 if ( ( $rowindex + 1 ) % $rows_per_column == 0 && ( $rowindex + 1 ) < $num ) {
00154 $result .= " </ul>\n </div> <!-- end column -->";
00155 }
00156
00157 $rowindex++;
00158 }
00159
00160
00161 if ( $this->linkFurtherResults( $res ) ) {
00162 $link = $res->getQueryLink();
00163
00164 if ( $this->getSearchLabel( SMW_OUTPUT_WIKI ) ) {
00165 $link->setCaption( $this->getSearchLabel( SMW_OUTPUT_WIKI ) );
00166 }
00167
00168 $link->setParameter( 'category', 'format' );
00169
00170 if ( $this->mNumColumns != 3 ) $link->setParameter( $this->mNumColumns, 'columns' );
00171
00172 if ( $this->mTemplate !== '' ) {
00173 $link->setParameter( $this->mTemplate, 'template' );
00174
00175 if ( array_key_exists( 'link', $this->m_params ) ) {
00176 $link->setParameter( $this->m_params['link'], 'link' );
00177 }
00178 }
00179
00180 $result .= '<br /><li>' . $link->getText( SMW_OUTPUT_WIKI, $this->mLinker ) . '</li>';
00181 }
00182
00183 $result .= " </ul>\n </div> <!-- end column -->";
00184
00185 $result .= "\n" . '<br style="clear: both;"/>';
00186
00187 return $result;
00188 }
00189
00190 public function getParameters() {
00191 $params = array_merge( parent::getParameters(), $this->textDisplayParameters() );
00192
00193 $params['columns'] = new Parameter( 'columns', Parameter::TYPE_INTEGER );
00194 $params['columns']->setDescription( wfMsg( 'smw_paramdesc_columns', 3 ) );
00195 $params['columns']->setDefault( 3, false );
00196
00197 $params['delim'] = new Parameter( 'delim' );
00198 $params['delim']->setDescription( wfMsg( 'smw-paramdesc-category-delim' ) );
00199 $params['delim']->setDefault( ',' );
00200
00201 $params['template'] = new Parameter( 'template' );
00202 $params['template']->setDescription( wfMsg( 'smw-paramdesc-category-template' ) );
00203 $params['template']->setDefault( '' );
00204
00205 $params['userparam'] = new Parameter( 'userparam' );
00206 $params['userparam']->setDescription( wfMsg( 'smw-paramdesc-category-userparam' ) );
00207 $params['userparam']->setDefault( '' );
00208
00209 return $params;
00210 }
00211
00212 }