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

quickcel’s picture

Assigned: crookednumber » quickcel
quickcel’s picture

Status: Active » Fixed
crookednumber’s picture

Status: Fixed » Closed (fixed)