Closed (fixed)
Project:
Kiva
Version:
6.x-1.x-dev
Component:
Code
Priority:
Normal
Category:
Bug report
Assigned:
Reporter:
Created:
31 Mar 2009 at 16:24 UTC
Updated:
14 Apr 2009 at 01:50 UTC
I found a bug when the number of random loans is less than the max number of loans set to display. I tried creating a patch with CVS, but am having difficulties at the moment so I'll just paste the code up here for you:
Change:
if (variable_get('kiva_loans_rand', 0)) {
$filter = array_rand($json->loans, $max);To:
$num_loans = count($json->loans);
if (variable_get('kiva_loans_rand', 0) && $num_loans > 1) {
// in case there are fewer loans than the max
$limit = ($max < $num_loans) ? $max : $num_loans;
$filter = array_rand($json->loans, $limit);As you can see I just basically took the code you had in a different section and put it here to make sure the max number doesn't exceed the number of loans, and also to make sure anything random has at least two loans listed.
Comments
Comment #1
quickcel commentedComment #2
quickcel commentedComment #3
crookednumber commented