Error - Random Loans Less Than Max Number
quickcel - March 31, 2009 - 16:24
| Project: | Kiva |
| Version: | 6.x-1.x-dev |
| Component: | Code |
| Category: | bug report |
| Priority: | normal |
| Assigned: | quickcel |
| Status: | closed |
Jump to:
Description
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.

#1
#2
#3