1 | <?php |
||
23 | class SRFValueRank extends SMWResultPrinter { |
||
24 | |||
25 | /** |
||
26 | * @var array |
||
27 | */ |
||
28 | protected $tagsHtml = []; |
||
29 | |||
30 | /** |
||
31 | * @see SMWResultPrinter::getName |
||
32 | * |
||
33 | * @return string |
||
34 | */ |
||
35 | public function getName() { |
||
38 | |||
39 | /** |
||
40 | * @see SMWResultPrinter::getResultText |
||
41 | * |
||
42 | * @since 1.7 |
||
43 | * |
||
44 | * @param SMWQueryResult $results |
||
45 | * @param $outputMode |
||
46 | * |
||
47 | * @return string |
||
48 | */ |
||
49 | public function getResultText( SMWQueryResult $results, $outputMode ) { |
||
61 | |||
62 | /** |
||
63 | * Returns an array with the tags (keys) and the number of times they occur (values). |
||
64 | * |
||
65 | * @since 1.7 |
||
66 | * |
||
67 | * @param SMWQueryResult $results |
||
68 | * @param $outputMode |
||
69 | * |
||
70 | * @return array |
||
71 | */ |
||
72 | protected function getResultValues( SMWQueryResult $results, $outputMode ) { |
||
73 | $tags = []; |
||
74 | |||
75 | /** |
||
76 | * @var $row SMWResultArray Objects (pages) |
||
77 | * @var $dataValue SMWDataValue |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | while ( $row = $results->getNext() ) { |
||
82 | // SMWResultArray for a sinlge property |
||
83 | for ( $i = 0, $n = count( $row ); $i < $n; $i++ ) { |
||
84 | while ( ( $dataValue = $row[$i]->getNextDataValue() ) !== false ) { |
||
85 | |||
86 | $isSubject = $row[$i]->getPrintRequest()->getMode() == SMWPrintRequest::PRINT_THIS; |
||
87 | |||
88 | // If the main object should not be included, skip it. |
||
89 | if ( $i == 0 && !$this->params['includesubject'] && $isSubject ) { |
||
90 | continue; |
||
91 | } |
||
92 | |||
93 | // Get the HTML for the tag content. Pages are linked, other stuff is just plaintext. |
||
94 | if ( $dataValue->getTypeID() == '_wpg' && $dataValue->getDataItem()->getTitle() !== null ) { |
||
95 | $value = $dataValue->getDataItem()->getTitle()->getText(); |
||
96 | $html = $dataValue->getLongText( $outputMode, $this->getLinker( $isSubject ) ); |
||
97 | } else { |
||
98 | $html = $dataValue->getShortText( $outputMode, $this->getLinker( false ) ); |
||
99 | $value = $html; |
||
100 | } |
||
101 | |||
102 | if ( !array_key_exists( $value, $tags ) ) { |
||
103 | $tags[$value] = 0; |
||
104 | $this->tagsHtml[$value] = $html; // Store the HTML separetely, so sorting can be done easily. |
||
105 | } |
||
106 | |||
107 | $tags[$value]++; |
||
108 | } |
||
109 | } |
||
110 | } |
||
111 | |||
112 | foreach ( $tags as $name => $count ) { |
||
113 | if ( $count < $this->params['min'] ) { |
||
114 | unset( $tags[$name] ); |
||
115 | } |
||
116 | } |
||
117 | return $tags; |
||
118 | } |
||
119 | |||
120 | /** |
||
121 | * Determine ranks |
||
122 | * |
||
123 | * @since 1.7 |
||
124 | * |
||
125 | * @param array $tags |
||
126 | * |
||
127 | * @return array |
||
128 | */ |
||
129 | protected function getValueRank( array $tags ) { |
||
142 | |||
143 | /** |
||
144 | * Format the output representation |
||
145 | * |
||
146 | * @since 1.8 |
||
147 | * |
||
148 | * @param array $tags |
||
149 | * |
||
150 | * @return string |
||
151 | */ |
||
152 | protected function getFormatOutput( array $tags ) { |
||
181 | |||
182 | /** |
||
183 | * Create a template output |
||
184 | * |
||
185 | * @since 1.8 |
||
186 | * |
||
187 | * @param string $name |
||
188 | * @param integer $rank |
||
189 | * @param integer $rownum |
||
190 | * |
||
191 | * @return string |
||
192 | */ |
||
193 | protected function addTemplateOutput( $name, $rank, &$rownum ) { |
||
201 | |||
202 | /** |
||
203 | * @see SMWResultPrinter::getParamDefinitions |
||
204 | * |
||
205 | * @since 1.8 |
||
206 | * |
||
207 | * @param $definitions array of IParamDefinition |
||
208 | * |
||
209 | * @return array of IParamDefinition|array |
||
210 | */ |
||
211 | public function getParamDefinitions( array $definitions ) { |
||
265 | } |
||
266 |