Index: trunk/extensions/SemanticMediaWiki/includes/datavalues/SMW_DV_Record.php |
— | — | @@ -27,6 +27,7 @@ |
28 | 28 | if ( $value == '' ) { |
29 | 29 | smwfLoadExtensionMessages( 'SemanticMediaWiki' ); |
30 | 30 | $this->addError( wfMsg( 'smw_novalues' ) ); |
| 31 | + |
31 | 32 | if ( $queryMode ) { |
32 | 33 | return new SMWThingDescription(); |
33 | 34 | } else { |
— | — | @@ -44,8 +45,11 @@ |
45 | 46 | $valueIndex = 0; // index in value array |
46 | 47 | $propertyIndex = 0; // index in property list |
47 | 48 | $empty = true; |
| 49 | + |
48 | 50 | foreach ( $this->getPropertyDataItems() as $diProperty ) { |
49 | | - if ( !array_key_exists( $valueIndex, $values ) ) break; // stop if there are no values left |
| 51 | + if ( !array_key_exists( $valueIndex, $values ) ) { |
| 52 | + break; // stop if there are no values left |
| 53 | + } |
50 | 54 | |
51 | 55 | if ( $queryMode ) { // special handling for supporting query parsing |
52 | 56 | $comparator = SMW_CMP_EQ; |
— | — | @@ -57,12 +61,14 @@ |
58 | 62 | $valueIndex++; |
59 | 63 | } else { |
60 | 64 | $dataValue = SMWDataValueFactory::newPropertyObjectValue( $diProperty, $values[$valueIndex] ); |
| 65 | + |
61 | 66 | if ( $dataValue->isValid() ) { // valid DV: keep |
62 | 67 | if ( $queryMode ) { |
63 | 68 | $subdescriptions[] = new SMWSomeProperty( $diProperty, new SMWValueDescription( $dataValue->getDataItem(), $comparator ) ); |
64 | 69 | } else { |
65 | 70 | $semanticData->addPropertyObjectValue( $diProperty, $dataValue->getDataItem() ); |
66 | 71 | } |
| 72 | + |
67 | 73 | $valueIndex++; |
68 | 74 | $empty = false; |
69 | 75 | } elseif ( ( count( $values ) - $valueIndex ) == ( count( $this->m_diProperties ) - $propertyIndex ) ) { |
— | — | @@ -70,6 +76,7 @@ |
71 | 77 | if ( !$queryMode ) { |
72 | 78 | $semanticData->addPropertyObjectValue( $diProperty, $dataValue->getDataItem() ); |
73 | 79 | } |
| 80 | + |
74 | 81 | $this->addError( $dataValue->getErrors() ); |
75 | 82 | $valueIndex++; |
76 | 83 | } |
— | — | @@ -160,34 +167,43 @@ |
161 | 168 | * and minimize the below special code. |
162 | 169 | */ |
163 | 170 | public function getExportData() { |
164 | | - if ( !$this->isValid() ) return null; |
| 171 | + if ( !$this->isValid() ) { |
| 172 | + return null; |
| 173 | + } |
165 | 174 | |
166 | 175 | $result = new SMWExpData( new SMWExpResource( '', $this ) ); // bnode |
167 | 176 | $ed = new SMWExpData( SMWExporter::getSpecialNsResource( 'swivt', 'Container' ) ); |
168 | 177 | $result->addPropertyObjectValue( SMWExporter::getSpecialNsResource( 'rdf', 'type' ), $ed ); |
169 | 178 | $count = 0; |
| 179 | + |
| 180 | + // FIXME: obtain DVs or build them from DIs |
170 | 181 | foreach ( $this->getDVs() as $dataValue ) { |
171 | 182 | $count++; |
| 183 | + |
172 | 184 | if ( ( $dataValue === null ) || ( !$dataValue->isValid() ) ) { |
173 | 185 | continue; |
174 | 186 | } |
175 | | - if ( ( $dataValue->getTypeID() == '_wpg' ) || ( $dataValue->getTypeID() == '_uri' ) || ( $dataValue->getTypeID() == '_ema' ) ) { |
| 187 | + |
| 188 | + if ( in_array( $dataValue->getTypeID(), array( '_wpg', '_uri', '_ema' ) ) ) { |
176 | 189 | $result->addPropertyObjectValue( |
177 | | - SMWExporter::getSpecialNsResource( 'swivt', 'object' . $count ), |
178 | | - $dataValue->getExportData() ); |
| 190 | + SMWExporter::getSpecialNsResource( 'swivt', 'object' . $count ), |
| 191 | + $dataValue->getExportData() |
| 192 | + ); |
179 | 193 | } else { |
180 | 194 | $result->addPropertyObjectValue( |
181 | | - SMWExporter::getSpecialNsResource( 'swivt', 'value' . $count ), |
182 | | - $dataValue->getExportData() ); |
| 195 | + SMWExporter::getSpecialNsResource( 'swivt', 'value' . $count ), |
| 196 | + $dataValue->getExportData() |
| 197 | + ); |
183 | 198 | } |
184 | 199 | } |
| 200 | + |
185 | 201 | return $result; |
186 | 202 | } |
187 | 203 | |
188 | 204 | ////// Additional API for value lists |
189 | 205 | |
190 | 206 | /** |
191 | | - * @deprecated as of 1.0, use getDataItems instead |
| 207 | + * @deprecated as of 1.6, use getDataItems instead |
192 | 208 | * |
193 | 209 | * @return array of SMWDataItem |
194 | 210 | */ |
— | — | @@ -213,7 +229,10 @@ |
214 | 230 | * Return the array (list) of properties that the individual entries of |
215 | 231 | * this datatype consist of. |
216 | 232 | * |
| 233 | + * @since 1.6 |
| 234 | + * |
217 | 235 | * @todo I18N for error message. |
| 236 | + * |
218 | 237 | * @return array of SMWDIProperty |
219 | 238 | */ |
220 | 239 | public function getPropertyDataItems() { |
— | — | @@ -231,7 +250,10 @@ |
232 | 251 | * Return the array (list) of properties that the individual entries of |
233 | 252 | * this datatype consist of. |
234 | 253 | * |
| 254 | + * @since 1.6 |
| 255 | + * |
235 | 256 | * @param $diProperty mixed null or SMWDIProperty object for which to retrieve the types |
| 257 | + * |
236 | 258 | * @return array of SMWDIProperty |
237 | 259 | */ |
238 | 260 | public static function findPropertyDataItems( $diProperty ) { |
— | — | @@ -244,6 +266,7 @@ |
245 | 267 | } else { |
246 | 268 | $listDiProperty = new SMWDIProperty( '_LIST' ); |
247 | 269 | $dataitems = smwfGetStore()->getPropertyValues( $propertyDiWikiPage, $listDiProperty ); |
| 270 | + |
248 | 271 | if ( count( $dataitems ) == 1 ) { |
249 | 272 | $propertyListValue = new SMWPropertyListValue( '__pls' ); |
250 | 273 | $propertyListValue->setDataItem( reset( $dataitems ) ); |