/** * Function will calculate the top publisher results * from the performance table * @return Array of Top Earners */ public static function topEarners($users, $dateQuery = [], $count = 10) { $pubClicks = []; $result = []; foreach ($users as $u) { $perf = \Performance::calculate($u, $dateQuery); $clicks = $perf['clicks']; if ($clicks === 0) { continue; } if (!array_key_exists($clicks, $pubClicks)) { $pubClicks[$clicks] = []; } $pubClicks[$clicks][] = AM::toObject(['name' => $u->name, 'clicks' => $clicks]); } if (count($pubClicks) === 0) { return $result; } krsort($pubClicks); array_splice($pubClicks, $count); $i = 0; foreach ($pubClicks as $key => $value) { foreach ($value as $u) { $result[] = $u; $i++; if ($i >= $count) { break 2; } } } return $result; }