Index: trunk/extensions/MetricsReporting/ApiAnalyticsBase.php |
— | — | @@ -133,22 +133,33 @@ |
134 | 134 | $this->profileDBOut(); |
135 | 135 | |
136 | 136 | $result = $this->getResult(); |
137 | | - $data = array(); |
138 | 137 | |
139 | 138 | $fields = array_map( array( $this, 'getColumnName' ), $query['fields'] ); |
140 | 139 | |
| 140 | + $things = array(); |
| 141 | + // Build result set |
141 | 142 | foreach( $res as $row ) { |
142 | 143 | // Dump all data to output |
143 | 144 | $item = array(); |
144 | | - foreach( $fields as $field ) { |
| 145 | + foreach( array_diff( $fields, array( 'region_code', 'region_name' ) ) as $field ) { |
145 | 146 | $item[$field] = $row->$field; |
146 | 147 | } |
147 | | - $data[ $row->{$this->getColumnName( 'comscore.region_code' )} ][] = $item; |
148 | | - $result->setIndexedTagName( $data[ $row->{$this->getColumnName( 'comscore.region_code' )} ], 'region' ); |
| 148 | + |
| 149 | + if( !isset( $things[$row->region_code] ) ) { |
| 150 | + $things[$row->region_code] = array( 'region_code' => $row->region_code, 'region_name' => $row->region_name ); |
| 151 | + } |
| 152 | + |
| 153 | + $things[$row->region_code]['data'][] = $item; |
| 154 | + $result->setIndexedTagName( $things[$row->region_code]['data'], 'd' ); |
149 | 155 | } |
150 | 156 | |
151 | | - $result->setIndexedTagName( $data, 'data' ); |
152 | | - $result->addValue( 'metric', $this->getModuleName(), $data ); |
| 157 | + // Add data to the output |
| 158 | + foreach( $things as $thing ) { |
| 159 | + $result->addValue( array( $this->getModuleName() ), null, $thing ); |
| 160 | + } |
| 161 | + $result->setIndexedTagName_internal( array( $this->getModuleName() ), 'region' ); |
| 162 | + |
| 163 | + |
153 | 164 | } |
154 | 165 | |
155 | 166 | // TODO: Deal with foo AS bar, and return bar for nicer aliasing of stuff |