Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_Filtered_Filter.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRF_Filtered_Filter class |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Stephan Gambke |
8 | 8 | * @file |
9 | 9 | * @ingroup SemanticResultFormats |
— | — | @@ -14,45 +14,45 @@ |
15 | 15 | * @ingroup SemanticResultFormats |
16 | 16 | */ |
17 | 17 | abstract class SRF_Filtered_Filter { |
18 | | - |
| 18 | + |
19 | 19 | private $mResults = null; |
20 | 20 | private $mPrintRequest = null; |
21 | 21 | private $mQueryPrinter = null; |
22 | | - |
| 22 | + |
23 | 23 | public function __construct( &$results, SMWPrintRequest $printRequest, SRFFiltered &$queryPrinter ) { |
24 | 24 | $this->mResults = $results; |
25 | 25 | $this->mPrintRequest = $printRequest; |
26 | 26 | $this->mQueryPrinter = $queryPrinter; |
27 | 27 | } |
28 | 28 | |
29 | | - public function &getQueryResults() {return $this->mResults;} |
30 | | - public function &getPrintRequest() {return $this->mPrintRequest;} |
31 | | - public function &getQueryPrinter() {return $this->mQueryPrinter;} |
32 | | - |
33 | | - |
| 29 | + public function &getQueryResults() { return $this->mResults; } |
| 30 | + public function &getPrintRequest() { return $this->mPrintRequest; } |
| 31 | + public function &getQueryPrinter() { return $this->mQueryPrinter; } |
| 32 | + |
| 33 | + |
34 | 34 | public function getActualParameters() { |
35 | | - |
| 35 | + |
36 | 36 | return $this->mPrintRequest->getParameters(); |
37 | | - |
| 37 | + |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | /** |
41 | 41 | * Returns the name (string) or names (array of strings) of the resource |
42 | 42 | * modules to load. |
43 | | - * |
| 43 | + * |
44 | 44 | * @return string|array |
45 | 45 | */ |
46 | 46 | public function getResourceModules() { |
47 | 47 | return null; |
48 | 48 | } |
49 | | - |
| 49 | + |
50 | 50 | /** |
51 | 51 | * Returns the HTML text that is to be included for this filter. |
52 | | - * |
| 52 | + * |
53 | 53 | * This text will appear on the page in a div that has the filter's id set |
54 | 54 | * as class. |
55 | | - * |
56 | | - * @return string |
| 55 | + * |
| 56 | + * @return string |
57 | 57 | */ |
58 | 58 | public function getResultText() { |
59 | 59 | return ''; |
— | — | @@ -60,7 +60,7 @@ |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Returns an array of config data for this filter to be stored in the JS |
64 | | - * @return null |
| 64 | + * @return null |
65 | 65 | */ |
66 | 66 | public function getJsData() { |
67 | 67 | return null; |
Index: trunk/extensions/SemanticResultFormats/Filtered/filters/SRF_FF_Value.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRF_FF_Value class |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Stephan Gambke |
8 | 8 | * @file |
9 | 9 | * @ingroup SemanticResultFormats |
— | — | @@ -13,18 +13,18 @@ |
14 | 14 | * |
15 | 15 | * Available parameters for this filter: |
16 | 16 | * value filter switches: switches to be shown for this filter; currently only 'and or' supported |
17 | | - * |
| 17 | + * |
18 | 18 | * @ingroup SemanticResultFormats |
19 | 19 | */ |
20 | 20 | class SRF_FF_Value extends SRF_Filtered_Filter { |
21 | | - |
| 21 | + |
22 | 22 | /** |
23 | 23 | * Returns the HTML text that is to be included for this view. |
24 | | - * |
| 24 | + * |
25 | 25 | * This text will appear on the page in a div that has the view's id set as |
26 | 26 | * class. |
27 | | - * |
28 | | - * @return string |
| 27 | + * |
| 28 | + * @return string |
29 | 29 | */ |
30 | 30 | public function getResultText() { |
31 | 31 | return ''; |
— | — | @@ -33,28 +33,28 @@ |
34 | 34 | /** |
35 | 35 | * Returns the name (string) or names (array of strings) of the resource |
36 | 36 | * modules to load. |
37 | | - * |
| 37 | + * |
38 | 38 | * @return string|array |
39 | 39 | */ |
40 | 40 | public function getResourceModules() { |
41 | 41 | return 'ext.srf.filtered.value-filter'; |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | /** |
45 | 45 | * Returns an array of config data for this filter to be stored in the JS |
46 | | - * @return null |
| 46 | + * @return null |
47 | 47 | */ |
48 | 48 | public function getJsData() { |
49 | 49 | $params = $this->getActualParameters(); |
50 | 50 | |
51 | 51 | if ( array_key_exists( 'value filter switches', $params ) ) { |
52 | | - $switches = explode(',', $params['value filter switches'] ); |
53 | | - $switches = array_map('trim', $switches ); |
54 | | - |
| 52 | + $switches = explode( ',', $params['value filter switches'] ); |
| 53 | + $switches = array_map( 'trim', $switches ); |
| 54 | + |
55 | 55 | return array( 'switches' => $switches ); |
56 | 56 | } |
57 | | - |
| 57 | + |
58 | 58 | return null; |
59 | 59 | } |
60 | | - |
| 60 | + |
61 | 61 | } |
Index: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered_Item.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRF_Filtered_Item class |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Stephan Gambke |
8 | 8 | * @file |
9 | 9 | * @ingroup SemanticResultFormats |
— | — | @@ -14,60 +14,60 @@ |
15 | 15 | * @ingroup SemanticResultFormats |
16 | 16 | */ |
17 | 17 | class SRF_Filtered_Item { |
18 | | - |
| 18 | + |
19 | 19 | private $mResultArray; |
20 | 20 | private $mItemData = array(); |
21 | 21 | private $mQueryPrinter; |
22 | | - |
23 | | - public function __construct($resultArray, SRFFiltered &$queryPrinter) { |
| 22 | + |
| 23 | + public function __construct( $resultArray, SRFFiltered &$queryPrinter ) { |
24 | 24 | $this->mResultArray = $resultArray; |
25 | 25 | $this->mQueryPrinter = $queryPrinter; |
26 | 26 | } |
27 | | - |
28 | | - public function setDataForView ( $viewId, &$data ){ |
| 27 | + |
| 28 | + public function setDataForView ( $viewId, &$data ) { |
29 | 29 | $this->mItemData[$viewId] = $data; |
30 | 30 | } |
31 | | - |
32 | | - public function unsetDataForView ( $viewId ){ |
33 | | - unset($this->mItemData[$viewId]); |
| 31 | + |
| 32 | + public function unsetDataForView ( $viewId ) { |
| 33 | + unset( $this->mItemData[$viewId] ); |
34 | 34 | } |
35 | | - |
36 | | - public function getDataForView ( $viewId ){ |
| 35 | + |
| 36 | + public function getDataForView ( $viewId ) { |
37 | 37 | return $this->mItemData[$viewId]; |
38 | 38 | } |
39 | | - |
| 39 | + |
40 | 40 | public function getValue() { |
41 | 41 | return $this->mResultArray; |
42 | 42 | } |
43 | | - |
| 43 | + |
44 | 44 | public function getArrayRepresentation() { |
45 | | - |
| 45 | + |
46 | 46 | $printouts = array(); |
47 | | - |
| 47 | + |
48 | 48 | foreach ( $this->mResultArray as $i => $field ) { |
49 | | - |
| 49 | + |
50 | 50 | $printRequest = $field->getPrintRequest(); |
51 | 51 | |
52 | 52 | $label = $printRequest->getLabel(); |
53 | 53 | $type = $printRequest->getTypeID(); |
54 | 54 | $params = $printRequest->getParameters(); |
55 | | - |
| 55 | + |
56 | 56 | $values = array(); |
57 | | - |
| 57 | + |
58 | 58 | $field->reset(); |
59 | 59 | while ( ( $value = $field->getNextText( SMW_OUTPUT_WIKI, null ) ) !== false ) { |
60 | 60 | $values[] = $value; |
61 | 61 | } |
62 | | - |
63 | | - $printouts[ md5($printRequest->getHash()) ] = array( |
| 62 | + |
| 63 | + $printouts[ md5( $printRequest->getHash() ) ] = array( |
64 | 64 | 'label' => $label, |
65 | 65 | 'type' => $type, |
66 | 66 | 'params' => $params, |
67 | 67 | 'values' => $values, |
68 | 68 | ); |
69 | 69 | } |
70 | | - |
71 | | - |
| 70 | + |
| 71 | + |
72 | 72 | return array( |
73 | 73 | 'printouts' => $printouts, |
74 | 74 | 'data' => $this->mItemData, |
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_FV_List.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRF_FV_List class |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Stephan Gambke |
8 | 8 | * @file |
9 | 9 | * @ingroup SemanticResultFormats |
— | — | @@ -17,44 +17,44 @@ |
18 | 18 | * list view introtemplate: a template prepended to the list |
19 | 19 | * list view outrotemplate: a template appended to the list |
20 | 20 | * list view named args: use named args for templates |
21 | | - * |
| 21 | + * |
22 | 22 | * @ingroup SemanticResultFormats |
23 | 23 | */ |
24 | 24 | class SRF_FV_List extends SRF_Filtered_View { |
25 | | - |
| 25 | + |
26 | 26 | private $mFormat, $mTemplate, $mIntroTemplate, $mOutroTemplate, $mNamedArgs, $mShowHeaders; |
27 | | - |
| 27 | + |
28 | 28 | /** |
29 | 29 | * Transfers the parameters applicable to this view into internal variables. |
30 | 30 | */ |
31 | 31 | protected function handleParameters() { |
32 | | - |
| 32 | + |
33 | 33 | $params = $this->getActualParameters(); |
34 | | - |
| 34 | + |
35 | 35 | $this->mFormat = $params['list view type']; |
36 | 36 | $this->mTemplate = $params['list view template']; |
37 | 37 | $this->mIntroTemplate = $params['list view introtemplate']; |
38 | 38 | $this->mOutroTemplate = $params['list view outrotemplate']; |
39 | 39 | $this->mNamedArgs = $params['list view named args']; |
40 | | - |
| 40 | + |
41 | 41 | if ( $params['headers'] == 'hide' ) { |
42 | 42 | $this->mShowHeaders = SMW_HEADERS_HIDE; |
43 | 43 | } elseif ( $params['headers'] == 'plain' ) { |
44 | 44 | $this->mShowHeaders = SMW_HEADERS_PLAIN; |
45 | 45 | } else { |
46 | 46 | $this->mShowHeaders = SMW_HEADERS_SHOW; |
47 | | - } |
| 47 | + } |
48 | 48 | } |
49 | 49 | |
50 | 50 | /** |
51 | 51 | * Returns the wiki text that is to be included for this view. |
52 | | - * |
53 | | - * @return string |
| 52 | + * |
| 53 | + * @return string |
54 | 54 | */ |
55 | 55 | public function getResultText() { |
56 | | - |
| 56 | + |
57 | 57 | $this->handleParameters(); |
58 | | - |
| 58 | + |
59 | 59 | // Determine mark-up strings used around list items: |
60 | 60 | if ( ( $this->mFormat == 'ul' ) || ( $this->mFormat == 'ol' ) ) { |
61 | 61 | $header = "<" . $this->mFormat . ">\n"; |
— | — | @@ -69,13 +69,13 @@ |
70 | 70 | $rowend = "</div>\n"; |
71 | 71 | $listsep = ', '; |
72 | 72 | } |
73 | | - |
| 73 | + |
74 | 74 | // Initialise more values |
75 | 75 | $result = ''; |
76 | 76 | |
77 | 77 | if ( $header !== '' ) { |
78 | 78 | $result .= $header; |
79 | | - } |
| 79 | + } |
80 | 80 | |
81 | 81 | if ( $this->mIntroTemplate !== '' ) { |
82 | 82 | $result .= "{{" . $this->mIntroTemplate . "}}"; |
— | — | @@ -83,32 +83,32 @@ |
84 | 84 | |
85 | 85 | // Now print each row |
86 | 86 | $rownum = -1; |
87 | | - |
88 | | - foreach ($this->getQueryResults() as $id => $value) { |
| 87 | + |
| 88 | + foreach ( $this->getQueryResults() as $id => $value ) { |
89 | 89 | $row = $value->getValue(); |
90 | | - |
| 90 | + |
91 | 91 | $this->printRow( $row, $rownum, $rowstart . $id . "' id='$id' >", $rowend, $result, $listsep ); |
92 | 92 | } |
93 | | - |
| 93 | + |
94 | 94 | if ( $this->mOutroTemplate !== '' ) { |
95 | 95 | $result .= "{{" . $this->mOutroTemplate . "}}"; |
96 | 96 | } |
97 | | - |
| 97 | + |
98 | 98 | // Print footer |
99 | 99 | if ( $footer !== '' ) { |
100 | 100 | $result .= $footer; |
101 | 101 | } |
102 | | - |
| 102 | + |
103 | 103 | return $result; |
104 | 104 | } |
105 | | - |
| 105 | + |
106 | 106 | /** |
107 | 107 | * Prints one row of a list view. |
108 | 108 | */ |
109 | 109 | protected function printRow( $row, &$rownum, $rowstart, $rowend, &$result, $listsep ) { |
110 | 110 | |
111 | 111 | $rownum++; |
112 | | - |
| 112 | + |
113 | 113 | $result .= $rowstart; |
114 | 114 | |
115 | 115 | if ( $this->mTemplate !== '' ) { // build template code |
— | — | @@ -116,28 +116,28 @@ |
117 | 117 | |
118 | 118 | // $wikitext = ( $this->mUserParam ) ? "|userparam=$this->mUserParam" : ''; |
119 | 119 | $wikitext = ''; |
120 | | - |
| 120 | + |
121 | 121 | foreach ( $row as $i => $field ) { |
122 | 122 | $wikitext .= '|' . ( $this->mNamedArgs ? '?' . $field->getPrintRequest()->getLabel() : $i + 1 ) . '='; |
123 | 123 | $first_value = true; |
124 | | - |
| 124 | + |
125 | 125 | $field->reset(); |
126 | 126 | while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $i == 0 ) ) ) !== false ) { |
127 | 127 | if ( $first_value ) $first_value = false; else $wikitext .= ', '; |
128 | 128 | $wikitext .= $text; |
129 | 129 | } |
130 | 130 | } |
131 | | - |
| 131 | + |
132 | 132 | $wikitext .= "|#=$rownum"; |
133 | 133 | $result .= '{{' . $this->mTemplate . $wikitext . '}}'; |
134 | 134 | |
135 | 135 | } else { // build simple list |
136 | 136 | $first_col = true; |
137 | 137 | $found_values = false; // has anything but the first column been printed? |
138 | | - |
| 138 | + |
139 | 139 | foreach ( $row as $field ) { |
140 | 140 | $first_value = true; |
141 | | - |
| 141 | + |
142 | 142 | while ( ( $text = $field->getNextText( SMW_OUTPUT_WIKI, $this->getQueryPrinter()->getLinker( $first_col ) ) ) !== false ) { |
143 | 143 | if ( !$first_col && !$found_values ) { // first values after first column |
144 | 144 | $result .= ' ('; |
— | — | @@ -146,64 +146,64 @@ |
147 | 147 | // any value after '(' or non-first values on first column |
148 | 148 | $result .= "$listsep "; |
149 | 149 | } |
150 | | - |
| 150 | + |
151 | 151 | if ( $first_value ) { // first value in any column, print header |
152 | 152 | $first_value = false; |
153 | | - |
| 153 | + |
154 | 154 | if ( ( $this->mShowHeaders != SMW_HEADERS_HIDE ) && ( $field->getPrintRequest()->getLabel() !== '' ) ) { |
155 | | - $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker(true, true) ) ) . ' '; |
| 155 | + $result .= $field->getPrintRequest()->getText( SMW_OUTPUT_WIKI, ( $this->mShowHeaders == SMW_HEADERS_PLAIN ? null:$this->getQueryPrinter()->getLinker( true, true ) ) ) . ' '; |
156 | 156 | } |
157 | 157 | } |
158 | | - |
| 158 | + |
159 | 159 | $result .= $text; // actual output value |
160 | 160 | } |
161 | | - |
| 161 | + |
162 | 162 | $first_col = false; |
163 | 163 | } |
164 | | - |
| 164 | + |
165 | 165 | if ( $found_values ) $result .= ')'; |
166 | 166 | } |
167 | | - |
| 167 | + |
168 | 168 | $result .= $rowend; |
169 | 169 | } |
170 | | - |
| 170 | + |
171 | 171 | /** |
172 | 172 | * A function to describe the allowed parameters of a query for this view. |
173 | | - * |
| 173 | + * |
174 | 174 | * @return array of Parameter |
175 | 175 | */ |
176 | 176 | public static function getParameters() { |
177 | 177 | $params = parent::getParameters(); |
178 | | - |
| 178 | + |
179 | 179 | $params['list view type'] = new Parameter( 'list type' ); |
180 | 180 | $params['list view type']->setMessage( 'srf-paramdesc-filtered-list-type' ); |
181 | | - $params['list view type']->setDefault( 'list' ); |
182 | | - |
| 181 | + $params['list view type']->setDefault( 'list' ); |
| 182 | + |
183 | 183 | $params['list view template'] = new Parameter( 'list template' ); |
184 | 184 | $params['list view template']->setMessage( 'srf-paramdesc-filtered-list-template' ); |
185 | | - $params['list view template']->setDefault( '' ); |
186 | | - |
| 185 | + $params['list view template']->setDefault( '' ); |
| 186 | + |
187 | 187 | $params['list view named args'] = new Parameter( 'list named args', Parameter::TYPE_BOOLEAN, false ); |
188 | 188 | $params['list view named args']->setMessage( 'srf-paramdesc-filtered-list-named-args' ); |
189 | | - |
| 189 | + |
190 | 190 | $params['list view introtemplate'] = new Parameter( 'list introtemplate' ); |
191 | | - $params['list view introtemplate']->setMessage( 'srf-paramdesc-filtered-list-introtemplate' ); |
| 191 | + $params['list view introtemplate']->setMessage( 'srf-paramdesc-filtered-list-introtemplate' ); |
192 | 192 | $params['list view introtemplate']->setDefault( '' ); |
193 | | - |
| 193 | + |
194 | 194 | $params['list view outrotemplate'] = new Parameter( 'list outrotemplate' ); |
195 | | - $params['list view outrotemplate']->setMessage( 'srf-paramdesc-filtered-list-outrotemplate' ); |
| 195 | + $params['list view outrotemplate']->setMessage( 'srf-paramdesc-filtered-list-outrotemplate' ); |
196 | 196 | $params['list view outrotemplate']->setDefault( '' ); |
197 | | - |
| 197 | + |
198 | 198 | return $params; |
199 | 199 | } |
200 | 200 | |
201 | 201 | /** |
202 | 202 | * Returns the name of the resource module to load for this view. |
203 | | - * |
| 203 | + * |
204 | 204 | * @return string|array |
205 | 205 | */ |
206 | 206 | public function getResourceModules() { |
207 | 207 | return 'ext.srf.filtered.list-view'; |
208 | 208 | } |
209 | | - |
| 209 | + |
210 | 210 | } |
Index: trunk/extensions/SemanticResultFormats/Filtered/views/SRF_Filtered_View.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRF_Filtered_View class |
6 | | - * |
| 6 | + * |
7 | 7 | * @author Stephan Gambke |
8 | 8 | * @file |
9 | 9 | * @ingroup SemanticResultFormats |
— | — | @@ -14,15 +14,15 @@ |
15 | 15 | * @ingroup SemanticResultFormats |
16 | 16 | */ |
17 | 17 | abstract class SRF_Filtered_View { |
18 | | - |
| 18 | + |
19 | 19 | private $mId; |
20 | 20 | private $mResults; |
21 | 21 | private $mParameters; |
22 | 22 | private $mQueryPrinter; |
23 | | - |
| 23 | + |
24 | 24 | /** |
25 | 25 | * Constructor for the view. |
26 | | - * |
| 26 | + * |
27 | 27 | * @param $id the view id |
28 | 28 | * @param $results array of SRF_Filtered_Item containing the query results |
29 | 29 | * @param type $params array of parameter values given as key-value-pairs |
— | — | @@ -33,25 +33,25 @@ |
34 | 34 | $this->mParameters = $params; |
35 | 35 | $this->mQueryPrinter = $queryPrinter; |
36 | 36 | } |
37 | | - |
38 | | - public function getId() {return $this->mId;} |
39 | | - public function &getQueryResults() {return $this->mResults;} |
40 | | - public function &getActualParameters() {return $this->mParameters;} |
41 | | - public function &getQueryPrinter() {return $this->mQueryPrinter;} |
42 | | - |
| 37 | + |
| 38 | + public function getId() { return $this->mId; } |
| 39 | + public function &getQueryResults() { return $this->mResults; } |
| 40 | + public function &getActualParameters() { return $this->mParameters; } |
| 41 | + public function &getQueryPrinter() { return $this->mQueryPrinter; } |
| 42 | + |
43 | 43 | /** |
44 | 44 | * Returns the name (string) or names (array of strings) of the resource |
45 | 45 | * modules to load. |
46 | | - * |
| 46 | + * |
47 | 47 | * @return string|array |
48 | 48 | */ |
49 | 49 | public function getResourceModules() { |
50 | 50 | return null; |
51 | 51 | } |
52 | | - |
| 52 | + |
53 | 53 | /** |
54 | 54 | * A function to describe the allowed parameters of a query for this view. |
55 | | - * |
| 55 | + * |
56 | 56 | * @return array of Parameter |
57 | 57 | */ |
58 | 58 | public static function getParameters() { |
— | — | @@ -60,11 +60,11 @@ |
61 | 61 | |
62 | 62 | /** |
63 | 63 | * Returns the HTML text that is to be included for this view. |
64 | | - * |
| 64 | + * |
65 | 65 | * This text will appear on the page in a div that has the view's id set as |
66 | 66 | * class. |
67 | | - * |
68 | | - * @return string |
| 67 | + * |
| 68 | + * @return string |
69 | 69 | */ |
70 | 70 | public function getResultText() { |
71 | 71 | return ''; |
Index: trunk/extensions/SemanticResultFormats/Filtered/SRF_Filtered.php |
— | — | @@ -2,11 +2,11 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * File holding the SRFFiltered class. |
6 | | - * |
| 6 | + * |
7 | 7 | * @file |
8 | 8 | * @ingroup SemanticResultFormats |
9 | 9 | * @author Stephan Gambke |
10 | | - * |
| 10 | + * |
11 | 11 | */ |
12 | 12 | |
13 | 13 | $formatDir = dirname( __FILE__ ) . '/'; |
— | — | @@ -23,56 +23,56 @@ |
24 | 24 | /** |
25 | 25 | * Result printer that displays results in switchable views and offers |
26 | 26 | * client-side (JavaScript based) filtering. |
27 | | - * |
| 27 | + * |
28 | 28 | * This result printer is ultimately planned to replace exhibit. Currently only |
29 | 29 | * a list view is available. It is not yet possible to switch between views. |
30 | 30 | * There is also only the 'value' filter available yet. |
31 | | - * |
| 31 | + * |
32 | 32 | * Syntax of the #ask call: |
33 | 33 | * (This is only a syntax example. For currently available features see the |
34 | 34 | * documentation of the various classes.) |
35 | | - * |
| 35 | + * |
36 | 36 | * {{#ask:[[SomeCondition]] |
37 | 37 | * |? SomePrintout |+filter=value, someFutureFilter |+value filter switches=and or, disable, all, none |+someFutureFilter filter option=someOptionValue |
38 | 38 | * |? SomeOtherPrintout |+filter=value, someOtherFutureFilter |+someOtherFutureFilter filter option=someOptionValue |
39 | | - * |
| 39 | + * |
40 | 40 | * |format=filtered |
41 | 41 | * |views=list, someFutureView, someOtherFutureView |
42 | | - * |
| 42 | + * |
43 | 43 | * |list view type=list |
44 | 44 | * |list view template=ListItem |
45 | | - * |
| 45 | + * |
46 | 46 | * |someFutureView view option=someOptionValue |
47 | | - * |
| 47 | + * |
48 | 48 | * |someOtherFutureView view option=someOptionValue |
49 | | - * |
| 49 | + * |
50 | 50 | * }} |
51 | | - * |
| 51 | + * |
52 | 52 | * All format specific parameters are optional, although leaving the 'views' |
53 | 53 | * parameter empty probably does not make much sense. |
54 | | - * |
| 54 | + * |
55 | 55 | */ |
56 | 56 | class SRFFiltered extends SMWResultPrinter { |
57 | | - |
| 57 | + |
58 | 58 | /** |
59 | 59 | * The available view types |
60 | | - * @var array of Strings |
| 60 | + * @var array of Strings |
61 | 61 | */ |
62 | 62 | private $mViewTypes = array( |
63 | 63 | 'list' => 'SRF_FV_List', |
64 | 64 | ); |
65 | | - |
| 65 | + |
66 | 66 | /** |
67 | 67 | * The available filter types |
68 | | - * @var array of Strings |
| 68 | + * @var array of Strings |
69 | 69 | */ |
70 | 70 | private $mFilterTypes = array( |
71 | 71 | 'value' => 'SRF_FF_Value', |
72 | 72 | ); |
73 | | - |
| 73 | + |
74 | 74 | private $mViews; |
75 | 75 | private $mParams; |
76 | | - |
| 76 | + |
77 | 77 | public function hasTemplates ( $hasTemplates = null ) { |
78 | 78 | $ret = $this->hasTemplates; |
79 | 79 | if ( is_bool( $hasTemplates ) ) { |
— | — | @@ -84,7 +84,7 @@ |
85 | 85 | protected function handleParameters( array $params, $outputmode ) { |
86 | 86 | parent::handleParameters( $params, $outputmode ); |
87 | 87 | |
88 | | - //// Set in SMWResultPrinter: |
| 88 | + // // Set in SMWResultPrinter: |
89 | 89 | // $this->mIntro = $params['intro']; |
90 | 90 | // $this->mOutro = $params['outro']; |
91 | 91 | // $this->mSearchlabel = $params['searchlabel'] === false ? null : $params['searchlabel']; |
— | — | @@ -94,42 +94,42 @@ |
95 | 95 | // $this->mShowHeaders = SMW_HEADERS_HIDE | SMW_HEADERS_PLAIN | SMW_HEADERS_SHOW; |
96 | 96 | |
97 | 97 | $this->mSearchlabel = null; |
98 | | - |
| 98 | + |
99 | 99 | $this->mParams = $params; |
100 | 100 | $this->mViews = array_map( 'trim', explode( ',', $params['views'] ) ); |
101 | | - |
| 101 | + |
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
105 | 105 | * Return serialised results in specified format. |
106 | 106 | */ |
107 | 107 | protected function getResultText( SMWQueryResult $res, $outputmode ) { |
108 | | - |
| 108 | + |
109 | 109 | // collect the query results in an array |
110 | 110 | $result = array(); |
111 | 111 | while ( $row = $res->getNext() ) { |
112 | 112 | $result[uniqid()] = new SRF_Filtered_Item( $row, $this ); |
113 | 113 | } |
114 | | - |
| 114 | + |
115 | 115 | $resourceModules = array(); |
116 | | - |
| 116 | + |
117 | 117 | // prepare filter data for inclusion in HTML and JS |
118 | 118 | $filterHtml = ''; |
119 | 119 | $filterHandlers = array(); |
120 | 120 | $filterData = array(); |
121 | | - |
| 121 | + |
122 | 122 | foreach ( $res->getPrintRequests() as $printRequest ) { |
123 | 123 | $filter = $printRequest->getParameter( 'filter' ); |
124 | 124 | if ( $filter ) { |
125 | 125 | |
126 | 126 | $filtersForPrintout = explode( ',', $filter ); |
127 | | - $filtersForPrintout = array_map('trim', $filtersForPrintout); |
128 | | - |
| 127 | + $filtersForPrintout = array_map( 'trim', $filtersForPrintout ); |
| 128 | + |
129 | 129 | foreach ( $filtersForPrintout as $filterName ) { |
130 | 130 | if ( array_key_exists( $filterName, $this->mFilterTypes ) ) { |
131 | | - |
132 | | - $filter = new $this->mFilterTypes[$filterName]( $result, $printRequest, $this); |
133 | | - |
| 131 | + |
| 132 | + $filter = new $this->mFilterTypes[$filterName]( $result, $printRequest, $this ); |
| 133 | + |
134 | 134 | $resourceModules = $filter->getResourceModules(); |
135 | 135 | |
136 | 136 | if ( is_array( $resourceModules ) ) { |
— | — | @@ -137,18 +137,18 @@ |
138 | 138 | } elseif ( is_string( $resourceModules ) ) { |
139 | 139 | SMWOutputs::requireResource( $resourceModules ); |
140 | 140 | } |
141 | | - |
| 141 | + |
142 | 142 | $printRequestHash = md5( $printRequest->getHash() ); |
143 | | - $filterHtml .= Html::rawElement( 'div', array('class' => "filtered-$filterName $printRequestHash"), $filter->getResultText() ); |
144 | | - |
| 143 | + $filterHtml .= Html::rawElement( 'div', array( 'class' => "filtered-$filterName $printRequestHash" ), $filter->getResultText() ); |
| 144 | + |
145 | 145 | $filterHandlers[$filterName] = null; |
146 | 146 | $filterData[$filterName][$printRequestHash] = $filter->getJsData(); |
147 | | - |
| 147 | + |
148 | 148 | } |
149 | 149 | } |
150 | 150 | } |
151 | 151 | } |
152 | | - |
| 152 | + |
153 | 153 | // wrap filters in a div |
154 | 154 | $filterHtml = Html::rawElement( 'div', array( 'class' => 'filtered-filters' ), $filterHtml ); |
155 | 155 | |
— | — | @@ -156,33 +156,33 @@ |
157 | 157 | $viewHtml = ''; |
158 | 158 | $viewHandlers = array(); |
159 | 159 | $viewElements = array(); |
160 | | - |
| 160 | + |
161 | 161 | foreach ( $this->mViews as $viewName ) { |
162 | 162 | if ( array_key_exists( $viewName, $this->mViewTypes ) ) { |
163 | | - |
| 163 | + |
164 | 164 | // generate unique id |
165 | 165 | $viewid = uniqid(); |
166 | 166 | |
167 | 167 | $view = new $this->mViewTypes[$viewName]( $viewid, $result, $this->mParams, $this ); |
168 | | - |
| 168 | + |
169 | 169 | $resourceModules = $view->getResourceModules(); |
170 | | - |
| 170 | + |
171 | 171 | if ( is_array( $resourceModules ) ) { |
172 | 172 | array_walk( $resourceModules, 'SMWOutputs::requireResource' ); |
173 | 173 | } elseif ( is_string( $resourceModules ) ) { |
174 | 174 | SMWOutputs::requireResource( $resourceModules ); |
175 | 175 | } |
176 | | - |
177 | | - $viewHtml .= Html::rawElement( 'div', array('class' => "filtered-$viewName $viewid"), $view->getResultText() ); |
178 | | - |
| 176 | + |
| 177 | + $viewHtml .= Html::rawElement( 'div', array( 'class' => "filtered-$viewName $viewid" ), $view->getResultText() ); |
| 178 | + |
179 | 179 | $viewHandlers[$viewName] = null; |
180 | 180 | $viewElements[$viewName][] = $viewid; |
181 | 181 | } |
182 | 182 | } |
183 | | - |
| 183 | + |
184 | 184 | // wrap views in a div |
185 | 185 | $viewHtml = Html::rawElement( 'div', array( 'class' => 'filtered-views' ), $viewHtml ); |
186 | | - |
| 186 | + |
187 | 187 | // Define the srf_filtered_values array |
188 | 188 | SMWOutputs::requireScript( 'srf_filtered_values', Html::inlineScript( |
189 | 189 | 'srf_filtered_values = {};' |
— | — | @@ -199,23 +199,23 @@ |
200 | 200 | Html::inlineScript( |
201 | 201 | 'srf_filtered_values["' . $id . '"] = { "values":' . json_encode( $resultAsArray ) . |
202 | 202 | ', "data": {' . |
203 | | - ' "viewhandlers" : ' . json_encode( $viewHandlers ) . |
204 | | - ', "viewelements" : ' . json_encode( $viewElements ) . |
205 | | - ', "filterhandlers" : ' . json_encode( $filterHandlers ) . |
206 | | - ', "filterdata" : ' . json_encode( $filterData ) . |
| 203 | + ' "viewhandlers" : ' . json_encode( $viewHandlers ) . |
| 204 | + ', "viewelements" : ' . json_encode( $viewElements ) . |
| 205 | + ', "filterhandlers" : ' . json_encode( $filterHandlers ) . |
| 206 | + ', "filterdata" : ' . json_encode( $filterData ) . |
207 | 207 | '}};' |
208 | 208 | ) |
209 | 209 | ); |
210 | | - |
211 | | - SMWOutputs::requireResource('ext.srf.filtered'); |
212 | 210 | |
| 211 | + SMWOutputs::requireResource( 'ext.srf.filtered' ); |
| 212 | + |
213 | 213 | // wrap all in a div |
214 | 214 | $html = Html::rawElement( 'div', array( 'class' => 'filtered ' . $id ), $filterHtml . $viewHtml ); |
215 | | - |
| 215 | + |
216 | 216 | return $html; |
217 | 217 | } |
218 | 218 | |
219 | | - |
| 219 | + |
220 | 220 | public function getParameters() { |
221 | 221 | $params = array_merge( parent::getParameters(), |
222 | 222 | parent::textDisplayParameters() ); |
— | — | @@ -225,14 +225,14 @@ |
226 | 226 | $params['views']->setDefault( '' ); |
227 | 227 | |
228 | 228 | foreach ( $this->mViewTypes as $viewType ) { |
229 | | - $params = array_merge($params, call_user_func( array( $viewType, 'getParameters') ) ); |
| 229 | + $params = array_merge( $params, call_user_func( array( $viewType, 'getParameters' ) ) ); |
230 | 230 | } |
231 | | - |
| 231 | + |
232 | 232 | return $params; |
233 | 233 | } |
234 | 234 | |
235 | 235 | public function getLinker( $firstcol = false, $force = false ) { |
236 | 236 | return ( $force ) ? $this->mLinker : parent::getLinker( $firstcol ); |
237 | 237 | } |
238 | | - |
| 238 | + |
239 | 239 | } |