/** * Loads all characters from DB * * @access public * @static WoW_Account::LoadCharacters() * @category Account Manager Class * @return bool **/ private static function LoadCharacters() { self::$characters_loaded = false; self::$myGamesList = DB::WoW()->select("SELECT `account_id` FROM `DBPREFIX_users_accounts` WHERE `id` = %d", self::GetUserID()); $account_ids = array(); $accounts_count = count(self::$myGamesList); for ($i = 0; $i < $accounts_count; ++$i) { $account_ids[] = self::$myGamesList[$i]['account_id']; } if (is_array($account_ids) && $accounts_count > 0) { $total_chars_count = DB::Realm()->selectCell("SELECT SUM(`numchars`) FROM `realmcharacters` WHERE `acctid` IN (%s)", implode(', ', $account_ids)); sprintf("SELECT SUM(`numchars`) FROM `realmcharacters` WHERE `acctid` IN (%s)", implode(', ', $account_ids)); self::$characters_data = DB::WoW()->select("SELECT * FROM `DBPREFIX_user_characters` WHERE `account` IN (%s) ORDER BY `index`", implode(', ', $account_ids)); } else { $total_chars_count = 0; } if (!self::$characters_data || count(self::$characters_data) != $total_chars_count) { self::LoadCharactersFromWorld(); } else { self::$characters_loaded = true; for ($i = 0; $i < $total_chars_count; ++$i) { // Rebuild *_text fields self::$characters_data[$i]['class_text'] = WoW_Locale::GetString('character_class_' . self::$characters_data[$i]['class'], self::$characters_data[$i]['gender']); self::$characters_data[$i]['race_text'] = WoW_Locale::GetString('character_race_' . self::$characters_data[$i]['race'], self::$characters_data[$i]['gender']); self::$characters_data[$i]['faction_text'] = WoW_Utils::GetFactionId(self::$characters_data[$i]['race']) == FACTION_ALLIANCE ? 'alliance' : 'horde'; // Rebuild character url self::$characters_data[$i]['url'] = sprintf('%s/wow/%s/character/%s/%s/', WoW::GetWoWPath(), WoW_Locale::GetLocale(), self::$characters_data[$i]['realmName'], self::$characters_data[$i]['name']); // Realm status $status = WoW::GetRealmStatus(self::$characters_data[$i]['realmId']); self::$characters_data[$i]['realmStatus'] = isset($status[0], $status[0]['status']) ? $status[0]['status'] : 'down'; if (self::$characters_data[$i]['isActive']) { self::$active_character = self::$characters_data[$i]; } } return true; } if (!self::$characters_data) { return false; } $active_set = false; $index = 0; DB::WoW()->query("DELETE FROM `DBPREFIX_user_characters` WHERE `account` IN (%s)", $account_ids); foreach (self::$characters_data as $char) { DB::WoW()->query("INSERT INTO `DBPREFIX_user_characters` VALUES (%d, %d, %d, %d, '%s', %d, '%s', '%s', %d, '%s', '%s', %d, %d, %d, '%s', %d, %d, '%s', %d, '%s', '%s', '%s')", self::GetUserID(), $char['account'], $index, $char['guid'], $char['name'], $char['class'], $char['class_text'], $char['class_key'], $char['race'], $char['race_text'], $char['race_key'], $char['gender'], $char['level'], $char['realmId'], $char['realmName'], $active_set ? 0 : 1, $char['faction'], $char['faction_text'], $char['guildId'], $char['guildName'], $char['guildUrl'], $char['url']); if (!$active_set) { self::$active_character = $char; $active_set = true; } ++$index; } self::$characters_loaded = true; return true; }