public function GetTopTeams($format, $bg_id, $limit = 3, $offset = 0, $count = false)
 {
     if (!isset(WoWConfig::$BattleGroups[$bg_id])) {
         WoW_Log::WriteError('%s : battleGroupd #%d was not found!', __METHOD__, $bg_id);
         return false;
     }
     $realms = WoWConfig::$BattleGroups[$bg_id]['realms'];
     if (!$realms) {
         WoW_Log::WriteError('%s : no realms found for battleGroup #%d, using first available bg instead.', __METHOD__, $bg_id);
         $realms = WoWConfig::$BattleGroups[1]['realms'];
         if (!$realms) {
             WoW_Log::WriteError('%s : default BG has no realms, unable to continue.', __METHOD__);
             return false;
         }
     }
     $top_teams_data = array();
     $counter = 0;
     foreach ($realms as $realmId) {
         DB::ConnectToDB(DB_CHARACTERS, $realmId);
         if (!DB::Characters()->TestLink()) {
             continue;
         }
         if (WoW::GetServerType($realmId) == SERVER_MANGOS) {
             if ($count) {
                 $counter += DB::Characters()->selectCell("\n                    SELECT COUNT(*)\n                    FROM `arena_team` AS `a`\n                    LEFT JOIN `arena_team_stats` AS `b` ON `b`.`arenateamid` = `a`.`arenateamid`\n                    WHERE `a`.`type` = %d\n                    AND `b`.`rank` > 0 AND `b`.`rank` < 4", $format);
                 continue;
             }
             $teams = DB::Characters()->select("SELECT\n                `a`.`arenateamid` AS `id`,\n                `a`.`rank`,\n                `a`.`rating`,\n                '%d' AS `realmId`,\n                `b`.`type`\n                FROM `arena_team_stats` AS `a`\n                LEFT JOIN `arena_team` AS `b` ON `b`.`arenateamid` = `a`.`arenateamid`\n                WHERE `a`.`rank` > 0 AND `a`.`rank` < 4 AND `b`.`type` = %d ORDER BY `rank`, `rating` LIMIT %d, %d", $realmId, $format, $offset, $limit);
         } else {
             $teams = DB::Characters()->select("SELECT `arenaTeamId` AS `id`, `rank`, `rating`, '%d' AS `realmId`, `type` FROM `arena_team` WHERE `rank` > 0 AND `rank` < 4 AND `type` = %d ORDER BY `rank`, `rating` LIMIT %d, %d", $realmId, $format, $offset, $limit);
         }
         if (!$teams) {
             continue;
         }
         $top_teams_data[] = array('realmId' => $realmId, 'teamsId' => $teams);
     }
     if ($count) {
         return $counter;
     }
     // Find top 3 teams
     $top_teams = array();
     foreach ($top_teams_data as &$teams) {
         foreach ($teams['teamsId'] as &$team) {
             if (!isset($top_teams[$team['rank']])) {
                 $top_teams[$team['rank']] = $team;
             }
             if ($top_teams[$team['rank']]['rating'] < $team['rating']) {
                 $top_teams[$team['rank']] = $team;
             }
         }
     }
     // Create objects
     $top_teams_objects = array();
     foreach ($top_teams as &$team) {
         $top_teams_objects[] = new WoW_ArenaTeam($team['realmId'], '', $team['id']);
     }
     unset($top_teams, $top_teams_data, $team, $teams);
     return $top_teams_objects;
 }
Example #2
0
 private function LoadTeam()
 {
     switch (WoW::GetServerType($this->m_realmId)) {
         case SERVER_MANGOS:
             $this->LoadMaNGOS();
             break;
         case SERVER_TRINITY:
             $this->LoadTrinity();
             break;
         default:
             WoW_Log::WriteError('%s : unknown realm type: %d (realm ID: %d)', __METHOD__, WoW::GetServerType($this->m_realmId), $this->m_realmId);
             return false;
     }
     $this->m_teamURL = sprintf('%s/wow/%s/arena/%s/%s/', WoW::GetWoWPath(), WoW_Locale::GetLocale(), $this->GetTeamRealmName(), $this->GetTeamName());
     return true;
 }
Example #3
0
 public function GetTopTeams($format, $bg_id)
 {
     if (!isset(WoWConfig::$BattleGroups[$bg_id])) {
         WoW_Log::WriteError('%s : battleGroupd #%d was not found!', __METHOD__, $bg_id);
         return false;
     }
     $realms = WoWConfig::$BattleGroups[$bg_id]['realms'];
     if (!$realms) {
         WoW_Log::WriteError('%s : no realms found for battleGroup #%d, using first available bg instead.', __METHOD__, $bg_id);
         $realms = WoWConfig::$BattleGroups[1]['realms'];
         if (!$realms) {
             WoW_Log::WriteError('%s : default BG has no realms, unable to continue.', __METHOD__);
             return false;
         }
     }
     $top_teams_data = array();
     foreach ($realms as $realmId) {
         DB::ConnectToDB(DB_CHARACTERS, $realmId);
         if (!DB::Characters()->TestLink()) {
             continue;
         }
         $teams = DB::Characters()->select("SELECT `%s`, `rank`, `rating` FROM `arena_team` ORDER BY `rank` LIMIT 3", WoW::GetServerType($realmId) == SERVER_MANGOS ? 'arenateamid' : 'arenaTeamId');
         if (!$teams) {
             continue;
         }
         $top_teams_data[] = array('realmId' => $realmId, 'teamsId' => $teams);
     }
     // Find top 3 teams
     foreach ($top_teams_data as &$teams) {
         foreach ($teams['teamsId'] as &$team) {
             if (!isset($top_teams[$team['rank']])) {
                 $top_teams[$team['rank']] = $team;
             }
             if ($top_teams[$team['rank']]['rating'] < $team['rating']) {
                 $top_teams[$team['rank']] = $team;
             }
         }
     }
     print_r($top_teams);
 }