Index: trunk/extensions/SemanticMediaWiki/includes/queryprinters/SMW_QP_JSONlink.php |
— | — | @@ -70,37 +70,33 @@ |
71 | 71 | |
72 | 72 | if ( $pr->getMode() != SMWPrintRequest::PRINT_THIS ) { |
73 | 73 | $values = array(); |
74 | | - $finalvalues = ''; |
| 74 | + $jsonObject = array(); |
75 | 75 | |
76 | 76 | while ( ( $dataValue = $field->getNextDataValue() ) !== false ) { |
77 | | - $finalvalues = ''; |
78 | 77 | switch ( $dataValue->getTypeID() ) { |
79 | 78 | case '_geo': |
| 79 | + $jsonObject[] = $dataValue->getDataItem()->getCoordinateSet(); |
80 | 80 | $values[] = FormatJson::encode( $dataValue->getDataItem()->getCoordinateSet() ); |
81 | 81 | break; |
82 | 82 | case '_num': |
83 | | - $values[] = $dataValue->getDataItem()->getNumber(); |
| 83 | + $jsonObject[] = $dataValue->getDataItem()->getNumber(); |
84 | 84 | break; |
85 | 85 | case '_dat': |
86 | | - $values[] = |
87 | | - '"' . $dataValue->getYear() . '-' . |
| 86 | + $jsonObject[] = |
| 87 | + $dataValue->getYear() . '-' . |
88 | 88 | str_pad( $dataValue->getMonth(), 2, '0', STR_PAD_LEFT ) . '-' . |
89 | 89 | str_pad( $dataValue->getDay(), 2, '0', STR_PAD_LEFT ) . ' ' . |
90 | | - $dataValue->getTimeString() . '"'; |
| 90 | + $dataValue->getTimeString(); |
91 | 91 | break; |
92 | 92 | default: |
93 | | - $values[] = '"' . $dataValue->getShortText( $outputmode, null ) . '"'; |
| 93 | + $jsonObject[] = $dataValue->getShortText( $outputmode, null ); |
94 | 94 | } |
95 | | - |
96 | | - if ( sizeof( $values ) > 1 ) { |
97 | | - $finalvalues = '[' . implode( ',', $values ) . ']'; |
98 | | - } else { |
99 | | - $finalvalues = $values[0]; |
100 | | - } |
101 | 95 | } |
102 | 96 | |
103 | | - if ( $finalvalues != '' ) { |
104 | | - $valuestack[] = '"' . str_replace( ' ', '_', strtolower( $pr->getLabel() ) ) . '": ' . $finalvalues . ''; |
| 97 | + if ( !is_array( $jsonObject ) || count( $jsonObject ) > 0 ) { |
| 98 | + $valuestack[] = |
| 99 | + '"' . str_replace( ' ', '_', strtolower( $pr->getLabel() ) ) |
| 100 | + . '": ' . FormatJson::encode( $jsonObject ) . ''; |
105 | 101 | } |
106 | 102 | } |
107 | 103 | } |