Index: trunk/extensions/SemanticMediaWiki/includes/SMW_DV_List.php |
— | — | @@ -118,48 +118,20 @@ |
119 | 119 | return $this->makeOutputText(4); |
120 | 120 | } |
121 | 121 | |
122 | | - private function makeOutputText($type = 0, $linker = NULL) { |
123 | | - if (!$this->isValid()) { |
124 | | - return ( ($type == 0)||($type == 1) )? '' : $this->getErrorText(); |
125 | | - } |
126 | | - $result = ''; |
127 | | - for ($i = 0; $i < count($this->getTypeValues()); $i++) { |
128 | | - if ($i == 1) { |
129 | | - $result .= ($type == 4)?'; ':' ('; |
130 | | - } elseif ($i > 1) { |
131 | | - $result .= ($type == 4)?'; ':", "; |
132 | | - } |
133 | | - $property = SMWPropertyValue::makeProperty('_' . ($i+1)); |
134 | | - $dv = reset($this->m_data->getPropertyValues($property)); |
135 | | - $result .= ($dv !== false)? $this->makeValueOutputText($type, $dv, $linker): '?'; |
136 | | - } |
137 | | - if ( ($i>1) && ($type != 4) ) $result .= ')'; |
138 | | - return $result; |
139 | | - } |
140 | | - |
141 | | - private function makeValueOutputText($type, $datavalue, $linker) { |
142 | | - switch ($type) { |
143 | | - case 0: return $datavalue->getShortWikiText($linker); |
144 | | - case 1: return $datavalue->getShortHTMLText($linker); |
145 | | - case 2: return $datavalue->getShortWikiText($linker); |
146 | | - case 3: return $datavalue->getShortHTMLText($linker); |
147 | | - case 4: return $datavalue->getWikiValue(); |
148 | | - } |
149 | | - } |
150 | | - |
151 | 122 | /// @todo Allowed values for multi-valued properties are not supported yet. |
152 | 123 | protected function checkAllowedValues() {} |
153 | 124 | |
154 | 125 | /** |
155 | 126 | * Make sure that the content is reset in this case. |
156 | 127 | * @todo This is not a full reset yet (the case that property is changed after a value |
157 | | - * was set does not occur in the normal flow of things, hence thishas low priority). |
| 128 | + * was set does not occur in the normal flow of things, hence this has low priority). |
158 | 129 | */ |
159 | 130 | public function setProperty(SMWPropertyValue $property) { |
160 | 131 | parent::setProperty($property); |
161 | 132 | $this->m_typevalues = NULL; |
162 | 133 | } |
163 | 134 | |
| 135 | + ///@todo Update (implementation below still from SMWNAryValue) |
164 | 136 | public function getExportData() { |
165 | 137 | if (!$this->isValid()) return NULL; |
166 | 138 | |
— | — | @@ -185,9 +157,60 @@ |
186 | 158 | return $result; |
187 | 159 | } |
188 | 160 | |
189 | | -////// Custom functions for n-ary attributes |
| 161 | +////// Additional API for value lists |
190 | 162 | |
191 | 163 | /** |
| 164 | + * Create a list (array with numeric keys) containing the datavalue objects |
| 165 | + * that this SMWListValue object holds. Values that are not present are set |
| 166 | + * to NULL, but the array still contains keys for each index from 0 through |
| 167 | + * 4. Note that the first index in the array is 0, not 1, and that the |
| 168 | + * declared length of the list is not taken into account: the size of the |
| 169 | + * result array is always 5. |
| 170 | + */ |
| 171 | + public function getDVs() { |
| 172 | + if (!$this->isValid()) return array(0=>NULL,1=>NULL,2=>NULL,3=>NULL,4=>NULL); |
| 173 | + $result = array(); |
| 174 | + for ($i=1; $i<6; $i++) { |
| 175 | + $property = SMWPropertyValue::makeProperty("_$i"); |
| 176 | + $dv = reset($this->m_data->getPropertyValues($property)); |
| 177 | + $result[$i-1] = ($dv instanceof SMWDataValue)?$dv:NULL; |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | +////// Internal helper functions |
| 182 | + |
| 183 | + private function makeOutputText($type = 0, $linker = NULL) { |
| 184 | + if (!$this->isValid()) { |
| 185 | + return ( ($type == 0)||($type == 1) )? '' : $this->getErrorText(); |
| 186 | + } |
| 187 | + $result = ''; |
| 188 | + for ($i = 0; $i < count($this->getTypeValues()); $i++) { |
| 189 | + if ($i == 1) { |
| 190 | + $result .= ($type == 4)?'; ':' ('; |
| 191 | + } elseif ($i > 1) { |
| 192 | + $result .= ($type == 4)?'; ':", "; |
| 193 | + } |
| 194 | + $property = SMWPropertyValue::makeProperty('_' . ($i+1)); |
| 195 | + $dv = reset($this->m_data->getPropertyValues($property)); |
| 196 | + $result .= ($dv !== false)? $this->makeValueOutputText($type, $dv, $linker): '?'; |
| 197 | + } |
| 198 | + if ( ($i>1) && ($type != 4) ) $result .= ')'; |
| 199 | + return $result; |
| 200 | + } |
| 201 | + |
| 202 | + private function makeValueOutputText($type, $datavalue, $linker) { |
| 203 | + switch ($type) { |
| 204 | + case 0: return $datavalue->getShortWikiText($linker); |
| 205 | + case 1: return $datavalue->getShortHTMLText($linker); |
| 206 | + case 2: return $datavalue->getShortWikiText($linker); |
| 207 | + case 3: return $datavalue->getShortHTMLText($linker); |
| 208 | + case 4: return $datavalue->getWikiValue(); |
| 209 | + } |
| 210 | + } |
| 211 | + |
| 212 | +////// Custom functions for old n-aries; may become obsolete. |
| 213 | + |
| 214 | + /** |
192 | 215 | * Change to query syntax mode. |
193 | 216 | */ |
194 | 217 | public function acceptQuerySyntax() { |