/** * @param $include_bank * @return float */ public function getTotalCoinExisting($include_bank) { $userSQL = new \GroupBot\Database\User($this->db); $users = $userSQL->getAllUsers($include_bank); $total_coin = 0.0; foreach ($users as $i) { $total_coin += $i->getBalance(true); } return $total_coin; }
/** * @param $chat_id * @return LeaderboardItem[] */ public function getVoteLeaderboard($chat_id) { $DbUser = new \GroupBot\Database\User($this->db); if (isset($chat_id)) { $users = $DbUser->getAllUsersInChat($chat_id); } else { $users = $DbUser->getAllUsers(true); } $votes = $this->SQL->get_all_votes(); $tallies = array(); if ($votes) { foreach ($votes as $vote) { if ($this->in_array_field($vote->voter->user_id, 'user_id', $users)) { if (isset($tallies[$vote->voted_for->user_id])) { $tallies[$vote->voted_for->user_id] += $vote->vote; } else { $tallies[$vote->voted_for->user_id] = $vote->vote; } } } } $leaderboard = array(); foreach ($users as $user) { $tally = array_key_exists($user->user_id, $tallies) ? $tallies[$user->user_id] : 0; $leaderboard[] = new LeaderboardItem($user, $tally); } usort($leaderboard, function ($a, $b) { if ($a->vote_total == $b->vote_total) { return 0; } return $a->vote_total > $b->vote_total ? -1 : 1; }); return $leaderboard; }