Index: trunk/extensions/ArticleFeedback/SpecialArticleFeedback.php |
— | — | @@ -277,7 +277,8 @@ |
278 | 278 | * |
279 | 279 | * Divides the number of ratings in half to determine the range of |
280 | 280 | * articles to consider 'highest'. In the event of an odd number |
281 | | - * of articles, round up, giving preference to the 'highs' so |
| 281 | + * of articles, (determined by checking for modulus of # of ratings / 2), |
| 282 | + * round up, giving preference to the 'highs' so |
282 | 283 | * everyone feels warm and fuzzy about having more 'highs', as |
283 | 284 | * it were... |
284 | 285 | * |
— | — | @@ -285,20 +286,32 @@ |
286 | 287 | * @return array Containing the... highest rated article data |
287 | 288 | */ |
288 | 289 | protected function getDailyHighs( $highs_lows ) { |
289 | | - $num_ratings = round( count( $highs_lows ) / 2 ); |
290 | | - return array_slice( $highs_lows, -$num_ratings, $num_ratings ); |
| 290 | + $num_ratings = count( $highs_lows ); |
| 291 | + if ( $num_ratings % 2 ) { |
| 292 | + $num_highs = round( $num_ratings / 2 ); |
| 293 | + } else { |
| 294 | + $num_highs = $num_ratings / 2; |
| 295 | + } |
| 296 | + return array_slice( $highs_lows, -$num_highs, $num_highs ); |
291 | 297 | } |
292 | 298 | |
293 | 299 | /** |
294 | 300 | * Determine the 'lowest' rated articles |
295 | | - * |
296 | | - * @see $this->getDailyHighs() |
| 301 | + * |
| 302 | + * @see getDailyHighs() However, if we are dealing with an odd number of |
| 303 | + * ratings, round up and then subtract 1 since we are giving preference |
| 304 | + * to the 'highs' when dealing with an odd number of ratings. |
297 | 305 | * @param array Pre-orderd from lowest to highest |
298 | 306 | * @return array Containing the... lowest rated article data |
299 | 307 | */ |
300 | 308 | protected function getDailyLows( $highs_lows ) { |
301 | | - $num_ratings = round( count( $highs_lows ) / 2, 0, PHP_ROUND_HALF_DOWN); |
302 | | - return array_slice( $highs_lows, 0, $num_ratings ); |
| 309 | + $num_ratings = count( $highs_lows ); |
| 310 | + if ( $num_ratings % 2 ) { |
| 311 | + $num_lows = round( $num_ratings / 2 ) - 1; |
| 312 | + } else { |
| 313 | + $num_lows = $num_ratings / 2; |
| 314 | + } |
| 315 | + return array_slice( $highs_lows, 0, $num_lows ); |
303 | 316 | } |
304 | 317 | |
305 | 318 | /** |