Index: trunk/extensions/Contest/includes/ContestDBObject.php |
— | — | @@ -187,10 +187,11 @@ |
188 | 188 | * @since 0.1 |
189 | 189 | * |
190 | 190 | * @param null|array $props |
| 191 | + * @param boolean $incNullId |
191 | 192 | * |
192 | 193 | * @return array |
193 | 194 | */ |
194 | | - public function toArray( $fields = null ) { |
| 195 | + public function toArray( $fields = null, $incNullId = false ) { |
195 | 196 | $data = array(); |
196 | 197 | $setFields = array(); |
197 | 198 | |
— | — | @@ -205,7 +206,9 @@ |
206 | 207 | } |
207 | 208 | |
208 | 209 | foreach ( $setFields as $field ) { |
209 | | - $data[$field] = $this->getField( $field ); |
| 210 | + if ( $incNullId || $field != 'id' || $this->hasIdField() ) { |
| 211 | + $data[$field] = $this->getField( $field ); |
| 212 | + } |
210 | 213 | } |
211 | 214 | |
212 | 215 | return $data; |
Index: trunk/extensions/Contest/api/ApiContestQuery.php |
— | — | @@ -2,7 +2,7 @@ |
3 | 3 | |
4 | 4 | /** |
5 | 5 | * Base class for API query modules that return results using a |
6 | | - * ContestDBClass deriving class. |
| 6 | + * ContestDBObject deriving class. |
7 | 7 | * |
8 | 8 | * @since 0.1 |
9 | 9 | * |
— | — | @@ -17,7 +17,7 @@ |
18 | 18 | |
19 | 19 | /** |
20 | 20 | * Returns the class specific info. |
21 | | - * * class: name of the ContestDBClass deriving class (ie Contest) |
| 21 | + * * class: name of the ContestDBObject deriving class (ie Contest) |
22 | 22 | * * item: item name (ie contest) |
23 | 23 | * * set: item set name (ie contests) |
24 | 24 | * |
— | — | @@ -28,7 +28,7 @@ |
29 | 29 | protected abstract function getClassInfo(); |
30 | 30 | |
31 | 31 | /** |
32 | | - * Returns an instance of the ContestDBClass deriving class. |
| 32 | + * Returns an instance of the ContestDBObject deriving class. |
33 | 33 | * Once PHP 5.3 becomes an accaptable requirement, we |
34 | 34 | * can get rid of this silly hack and simply return the class |
35 | 35 | * name (since all methods we need ought to be static in PHP >= 5.3). |
— | — | @@ -129,7 +129,7 @@ |
130 | 130 | * @param array $params |
131 | 131 | * @param array $results |
132 | 132 | */ |
133 | | - protected function addResults( array $params, array /* of ContestDBClass */ $results ) { |
| 133 | + protected function addResults( array $params, array /* of ContestDBObject */ $results ) { |
134 | 134 | $serializedResults = array(); |
135 | 135 | $count = 0; |
136 | 136 | |
— | — | @@ -141,20 +141,35 @@ |
142 | 142 | break; |
143 | 143 | } |
144 | 144 | |
145 | | - $serializedResults[] = $result->toArray(); |
| 145 | + $serializedResults[] = $result->toArray( $params['props'] ); |
146 | 146 | } |
147 | | - |
148 | | - $this->addIndexedTagNames( $serializedResults ); |
149 | | - $this->addSerializedResults( $serializedResults ); |
| 147 | + |
| 148 | + $this->setIndexedTagNames( $serializedResults ); |
| 149 | + $this->addSerializedResults( $serializedResults ); |
150 | 150 | } |
151 | 151 | |
152 | | - protected function addIndexedTagNames( array $serializedResults ) { |
| 152 | + /** |
| 153 | + * Set the tag names for formats such as XML. |
| 154 | + * |
| 155 | + * @since 0.1 |
| 156 | + * |
| 157 | + * @param array $serializedResults |
| 158 | + */ |
| 159 | + protected function setIndexedTagNames( array &$serializedResults ) { |
153 | 160 | $classInfo = $this->getClassInfo(); |
154 | 161 | $this->getResult()->setIndexedTagName( $serializedResults, $classInfo['item'] ); |
155 | 162 | } |
156 | 163 | |
| 164 | + /** |
| 165 | + * Add the serialized results to the result object. |
| 166 | + * |
| 167 | + * @since 0.1 |
| 168 | + * |
| 169 | + * @param array $serializedResults |
| 170 | + */ |
157 | 171 | protected function addSerializedResults( array $serializedResults ) { |
158 | 172 | $classInfo = $this->getClassInfo(); |
| 173 | + |
159 | 174 | $this->getResult()->addValue( |
160 | 175 | null, |
161 | 176 | $classInfo['set'], |