From ddf618a86b0373d9b5b6e990b4f631cf6d6ff7ce Mon Sep 17 00:00:00 2001 From: Shadez Date: Tue, 3 Aug 2010 23:15:21 +0900 Subject: [PATCH] [340] Store achievement class instance in Characters::$m_achievementMgr --- character-achievements.php | 6 +- character-arenateams.php | 6 +- character-calendar.php | 6 +- character-model-embed.php | 6 +- character-reputation.php | 6 +- character-sheet.php | 6 +- character-statistics.php | 6 +- character-talents.php | 6 +- guild-info.php | 5 +- includes/armory_loader.php | 4 +- includes/classes/class.achievements.php | 286 +++++++++++++----------- includes/classes/class.characters.php | 29 ++- includes/classes/class.dbhandler.php | 56 +++-- includes/classes/class.guilds.php | 7 +- includes/classes/class.utils.php | 34 ++- includes/defines.php | 10 +- includes/revision_nr.php | 2 +- 17 files changed, 287 insertions(+), 194 deletions(-) diff --git a/character-achievements.php b/character-achievements.php index f86a1a97e..1438e2c39 100644 --- a/character-achievements.php +++ b/character-achievements.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 299 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -56,7 +56,7 @@ $realmId = $utils->GetRealmIdByName($_GET['r']); $characters->BuildCharacter($name, $realmId); $isCharacter = $characters->CheckPlayer(); -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); if($_GET['r'] === false || !$armory->currentRealmInfo) { $isCharacter = false; } @@ -263,7 +263,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw('guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); $arenateams->guid = $characters->GetGUID(); $tabUrl = $characters->GetUrlString(); /** Header **/ @@ -83,7 +83,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $character_arenateams = $arenateams->GetCharacterArenaTeamInfo(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { diff --git a/character-calendar.php b/character-calendar.php index 1f86bed2e..7b03b71cc 100644 --- a/character-calendar.php +++ b/character-calendar.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 297 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -44,7 +44,7 @@ $realmId = $utils->GetRealmIdByName($_GET['r']); $characters->BuildCharacter($name, $realmId); $isCharacter = $characters->CheckPlayer(); -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); if($_GET['r'] === false || !$armory->currentRealmInfo) { $isCharacter = false; } @@ -81,7 +81,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw('GetRealmIdByName($_GET['r']); $characters->BuildCharacter($name, $realmId); $isCharacter = $characters->CheckPlayer(); -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); if($_GET['r'] === false || !$armory->currentRealmInfo) { $isCharacter = false; } @@ -81,7 +81,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw('GetRealmIdByName($_GET['r']); $characters->BuildCharacter($name, $realmId); $isCharacter = $characters->CheckPlayer(); -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); if($_GET['r'] === false || !$armory->currentRealmInfo) { $isCharacter = false; } @@ -81,7 +81,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw('LoadXSLT('character/sheet.xsl'); /** Basic info **/ -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); $arenateams->guid = $characters->GetGUID(); $tabUrl = $characters->GetUrlString(); /** Header **/ @@ -86,7 +86,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $character_arenateams = $arenateams->GetCharacterArenaTeamInfo(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { diff --git a/character-statistics.php b/character-statistics.php index fa94e93e9..44ffc3976 100644 --- a/character-statistics.php +++ b/character-statistics.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 297 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -53,7 +53,7 @@ $realmId = $utils->GetRealmIdByName($_GET['r']); $characters->BuildCharacter($name, $realmId); $isCharacter = $characters->CheckPlayer(); -$achievements->guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); if($_GET['r'] === false || !$armory->currentRealmInfo) { $isCharacter = false; } @@ -126,7 +126,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw('guid = $characters->GetGUID(); +$achievements = $characters->GetAchievementMgr(); $tabUrl = $characters->GetUrlString(); /** Header **/ $xml->XMLWriter()->startElement('page'); @@ -82,7 +82,7 @@ exit; } $character_title = $characters->GetChosenTitleInfo(); -$character_element = $characters->GetHeader($achievements); +$character_element = $characters->GetHeader(); $xml->XMLWriter()->startElement('characterInfo'); if($utils->IsWriteRaw()) { $xml->XMLWriter()->writeRaw(' urlencode($armory->currentRealmInfo['name']), 'url' => sprintf('r=%s&gn=%s', urlencode($armory->currentRealmInfo['name']), urlencode($guilds->guildName)) ); -// start $xml->XMLWriter()->startElement('guildInfo'); -// start $xml->XMLWriter()->startElement('guildHeader'); foreach($guild_header as $header_key => $header_value) { $xml->XMLWriter()->writeAttribute($header_key, $header_value); @@ -112,7 +110,6 @@ } $xml->XMLWriter()->endElement(); //emblem $xml->XMLWriter()->endElement(); //guildHeader -// start $xml->XMLWriter()->startElement('guild'); $xml->XMLWriter()->startElement('members'); $xml->XMLWriter()->writeAttribute('memberCount', $guilds->CountGuildMembers()); diff --git a/includes/armory_loader.php b/includes/armory_loader.php index dd92cba60..4f85e5fb3 100644 --- a/includes/armory_loader.php +++ b/includes/armory_loader.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 301 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -185,7 +185,7 @@ if(!@include('classes/class.achievements.php')) { die('Error: can not load achievements class!'); } - $achievements = new Achievements; + // Class instance will be created in Characters::GetAchievementMgr() } if(defined('load_items_class')) { if(!@include('classes/class.items.php')) { diff --git a/includes/classes/class.achievements.php b/includes/classes/class.achievements.php index d249c8568..9a63c3512 100644 --- a/includes/classes/class.achievements.php +++ b/includes/classes/class.achievements.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 321 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -30,72 +30,123 @@ /** * Character guid + * @category Achievements class + * @access public **/ public $guid; /** * Character achievement points + * @category Achievements class + * @access public **/ public $pts; /** * Achievement ID + * @category Achievements class + * @access public **/ public $achId; /** - * Calculate total character achievement points + * Characters database handler + * @category Achievements class + * @access private + **/ + private $db; + + /** + * Character achievements count * @category Achievements class - * @example Achievements::calculateAchievementPoints() - * @return int + * @access private **/ - public function CalculateAchievementPoints($guid = null) { - if($guid == null) { - $guid = $this->guid; + private $m_count; + + /** + * Creates Achievement class instance + * @category Achievements class + * @access public + * @param int $player_guid + * @param ArmoryDatabaseHandler $db + * @param bool $check = true + * @return bool + **/ + public function InitAchievements($player_guid, ArmoryDatabaseHandler $db, $check = true) { + // Clear values before recalculation + $this->guid = 0; + $this->db = null; + $this->achId = 0; + $this->m_count = 0; + $this->pts = 0; + if(!$db->TestLink()) { + $this->Log()->writeError('%s : wrong database handler!', __METHOD__); + unset($db, $player_guid); + return false; } - if(!$guid) { - $this->Log()->writeError('%s : player guid not defined', __METHOD__); + if($check == true && !$db->selectCell("SELECT 1 FROM `characters` WHERE `guid`=%d LIMIT 1", $player_guid)) { + $this->Log()->writeError('%s : player with guid %d not found in `characters` table!', __METHOD__, $player_guid); + unset($db, $player_guid); return false; } - $pts = $this->aDB->selectCell(" - SELECT SUM(`points`) - FROM `armory_achievement` - WHERE `id` IN - ( - SELECT `achievement` - FROM `%s`.`character_achievement` - WHERE `guid`=%d - ) - ", $this->connectionData['name_characters'], $guid); - $this->pts = $pts; + $this->guid = $player_guid; + $this->db = $db; + self::CalculateAchievementPoints(); + self::CountCharacterAchievements(); + return true; + } + + /** + * Returns achievement points for current character + * @category Achievements class + * @access public + * @return int + **/ + public function GetAchievementPoints() { return $this->pts; } + public function GetAchievementsCount() { + return $this->m_count; + } + /** - * Returns % (0-100) for achievement progress bar width. + * Calculate total character achievement points * @category Achievements class - * @example Achievements::getAchievementProgressBar(150) - * @todo Check ACH_MAX_COUNT_GAME - * @return int + * @access public + * @return int **/ - public function getAchievementProgressBar($sum) { - $percent = ACHIEVEMENTS_COUNT_SUMMARY / 100; - $progressPercent = $sum / $percent; - return $progressPercent; + public function CalculateAchievementPoints() { + if(!$this->guid) { + $this->Log()->writeError('%s : player guid not defined', __METHOD__); + return false; + } + $achievement_ids = $this->db->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d", $this->guid); + if(!$achievement_ids) { + $this->Log()->writeError('%s : unable to find any completed achievement for player %d', __METHOD__, $this->guid); + return false; + } + $ids = array(); + foreach($achievement_ids as $_tmp) { + $ids[] = $_tmp['achievement']; + } + $this->pts = $this->aDB->selectCell("SELECT SUM(`points`) FROM `armory_achievement` WHERE `id` IN (%s)", $ids); + return $this->pts; } /** * Returns number of character completed achievements. * @category Achievements class - * @example Achievements::countCharacterAchievements() - * @return int + * @access public + * @return int **/ public function CountCharacterAchievements() { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } - return $this->cDB->selectCell("SELECT COUNT(`achievement`) FROM `character_achievement` WHERE `guid`=%d", $this->guid); + $this->m_count = $this->db->selectCell("SELECT COUNT(`achievement`) FROM `character_achievement` WHERE `guid`=%d", $this->guid); + return $this->m_count; } public function GetSummaryAchievementData($category) { @@ -104,7 +155,7 @@ public function GetSummaryAchievementData($category) { return false; } $achievement_data = array('categoryId' => $category); - $categories = null; + $categories = 0; // 3.3.5a switch($category) { case 92: @@ -151,22 +202,23 @@ public function GetSummaryAchievementData($category) { $categories = '81'; break; default: // Summary - $categories = null; + $categories = 0; $achievement_data['total'] = ACHIEVEMENTS_COUNT_SUMMARY; $achievement_data['totalPoints'] = ACHIEVEMENT_POINTS_SUMMARY; break; } - if($categories != null) { - $achievement_ids = $this->aDB->select(" - SELECT `achievement` - FROM `%s`.`character_achievement` - WHERE `achievement` IN - ( - SELECT `id` - FROM `%s`.`armory_achievement` - WHERE `categoryId` IN (%s) - ) - AND `guid`=%d", $this->connectionData['name_characters'], $this->mysqlconfig['name_armory'], $categories, $this->guid); + if($categories != 0) { + $id_in_category = $this->aDB->select("SELECT `id` FROM `armory_achievement` WHERE `categoryId` IN (%s)", $categories); + if(!$id_in_category) { + $this->Log()->writeError('%s : unable to find any achievements in %s category', __METHOD__, $categories); + } + $a_ids = array(); + if(is_array($id_in_category)) { + foreach($id_in_category as $_tId) { + $a_ids[] = $_tId['id']; + } + } + $achievement_ids = $this->db->select("SELECT `achievement` FROM `character_achievement` WHERE `guid`=%d AND `achievement` IN (%s)", $this->guid, $a_ids); if(!$achievement_ids) { $achievement_data['earned'] = 0; $achievement_data['points'] = 0; @@ -186,8 +238,8 @@ public function GetSummaryAchievementData($category) { } } else { - $achievement_data['earned'] = self::CountCharacterAchievements(); - $achievement_data['points'] = self::CalculateAchievementPoints(); + $achievement_data['earned'] = self::GetAchievementsCount(); + $achievement_data['points'] = self::GetAchievementPoints(); } return $achievement_data; } @@ -195,15 +247,15 @@ public function GetSummaryAchievementData($category) { /** * Returns array with 5 latest completed achievements. Requires $this->guid! * @category Achievements class - * @example Achievements::GetLastAchievements() - * @return array + * @access public + * @return array **/ public function GetLastAchievements() { if(!$this->guid) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } - $achievements = $this->cDB->select("SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid`=%d ORDER BY `date` DESC LIMIT 5", $this->guid); + $achievements = $this->db->select("SELECT `achievement`, `date` FROM `character_achievement` WHERE `guid`=%d ORDER BY `date` DESC LIMIT 5", $this->guid); if(!$achievements) { $this->Log()->writeError('%s : unable to get data from character_achievement (player %d does not have achievements?)', __METHOD__, $this->guid); return false; @@ -218,70 +270,31 @@ public function GetLastAchievements() { /** * Returns achievement date. If $guid not provided, function will use $this->guid. * @category Achievements class - * @example Achievements::GetAchievementDate(17, false) - * @return string + * @access public + * @param int $achId = 0 + * @return string **/ - public function GetAchievementDate($guid = null, $achId = null) { - if($guid == null) { - $guid = $this->guid; - } - if($achId == null) { + public function GetAchievementDate($achId = 0) { + if($achId == 0) { $achId = $this->achId; } - $achievement_date = $this->cDB->selectCell("SELECT `date` FROM `character_achievement` WHERE `achievement`=%d AND `guid`=%d LIMIT 1", $achId, $guid); + if(!$this->guid || !$achId) { + $this->Log()->writeError('%s : not enough data for calculation (guid: %d, achId: %d).', __METHOD__, $this->guid, $achId); + return false; + } + $achievement_date = $this->db->selectCell("SELECT `date` FROM `character_achievement` WHERE `achievement`=%d AND `guid`=%d LIMIT 1", $achId, $this->guid); if(!$achievement_date) { - $this->Log()->writeError('%s : unable to find completion date for achievement %d, player %d', __METHOD__, $achId, $guid); + $this->Log()->writeError('%s : unable to find completion date for achievement %d, player %d', __METHOD__, $achId, $this->guid); return false; } return date('Y-m-d\TH:i:s+02:00', $achievement_date); } /** - * Returns progress bar width % (0-100) for selected category ($achType) - * @category Achievements class - * @example Achievements::CountAchievementPercent(15, 4) - * @return int - **/ - public function CountAchievementPercent($sum, $achType) { - switch($achType) { - case 1: - $maxAch = 54; - break; - case 2: - $maxAch = 49; - break; - case 3: - $maxAch = 70; - break; - case 4: - $maxAch = 166; - break; - case 5: - $maxAch = 454; - break; - case 6: - $maxAch = 75; - break; - case 7: - $maxAch = 45; - break; - case 8: - $maxAch = 141; - break; - case 9: - $maxAch = 126; - break; - } - $percent = $maxAch / 100; - $progressPercent = $sum / $percent; - return $progressPercent; - } - - /** - * Generates achievement categories menu (for character-achievements.php) + * Generates achievements categories tree * @category Achievements class - * @example Achievements::BuildCategoriesTree() - * @return string + * @access public + * @return string **/ public function BuildCategoriesTree() { $categoryIds = $this->aDB->select("SELECT `id`, `name_%s` AS `name` FROM `armory_achievement_category` WHERE `parentCategory`=-1 AND `id` <> 1", $this->_locale); @@ -307,6 +320,12 @@ public function BuildCategoriesTree() { return $root_tree; } + /** + * Generates statistics categories tree + * @category Achievements class + * @access public + * @return array + **/ public function BuildStatisticsCategoriesTree() { $categoryIds = $this->aDB->select("SELECT `id`, `name_%s` AS `name` FROM `armory_achievement_category` WHERE `parentCategory`=1", $this->_locale); $root_tree = array(); @@ -331,10 +350,11 @@ public function BuildStatisticsCategoriesTree() { * Returns basic achievement info (name, description, points). * $achievementData must be in array format: array('achievement' => ACHIEVEMENT_ID, 'date' => TIMESTAMP_DATE) * @category Achievements class - * @example Achievements::GetAchievementInfo(1263163814) - * @return string + * @access public + * @param array $achievementData + * @return string **/ - public function GetAchievementInfo(&$achievementData) { + public function GetAchievementInfo($achievementData) { if(!is_array($achievementData)) { $this->Log()->writeError('%s : achievementData must be an array!', __METHOD__); return false; @@ -352,39 +372,43 @@ public function GetAchievementInfo(&$achievementData) { } /** - * Returns formatted date + * Checks is achievement with $achId ID completed by current player * @category Achievements class - * @example Achievements::GetDateFormat(1263163814) - * @return string + * @access public + * @param int $achId + * @return bool **/ - public function GetDateFormat($timestamp) { - return date('d/m/Y', $timestamp); - } - public function IsAchievementCompleted($achId) { if(!$this->guid || !$achId) { - $this->Log()->writeError('%s : player guid or achievement id not provided', __METHOD__); + $this->Log()->writeError('%s : player guid or achievement id not provided (guid: %d, achId: %d)', __METHOD__, $this->guid, $achId); return false; } - if($achId == 0 || $achId == -1 || !$this->IsAchievementExists($achId)) { - $this->Log()->writeError('%s : achievement %u not exists', __METHOD__, $achId); + if($achId == 0 || $achId == -1 || !self::IsAchievementExists($achId)) { + $this->Log()->writeError('%s : achievement %d not exists', __METHOD__, $achId); return false; } - $date = $this->cDB->selectCell("SELECT `date` FROM `character_achievement` WHERE `guid`=%d AND `achievement`=%d", $this->guid, $achId); - if($date) { - return true; - } - return false; + return $this->db->selectCell("SELECT 1 FROM `character_achievement` WHERE `guid`=%d AND `achievement`=%d", $this->guid, $achId); } + /** + * Checks is achievement $achId exists in DB + * @category Achievements class + * @access public + * @param int $achId + * @return bool + **/ public function IsAchievementExists($achId) { - $data = $this->aDB->selectCell("SELECT 1 FROM `armory_achievement` WHERE `id`=%d LIMIT 1", $achId); - if($data) { - return true; - } - return false; + return $this->aDB->selectCell("SELECT 1 FROM `armory_achievement` WHERE `id`=%d LIMIT 1", $achId); } + /** + * Generates achievement page + * @category Achievements class + * @access public + * @param int $page_id + * @param int $faction + * @return array + **/ public function LoadAchievementPage($page_id, $faction) { if(!$this->guid) { $this->Log()->writeError('%s : player guid not provided', __METHOD__); @@ -474,7 +498,7 @@ public function BuildAchievementCriteriaTable() { $locale = $this->_locale; } if(!$this->guid || !$this->achId) { - $this->Log()->writeError('%s : player guid or achievement id not defiend', __METHOD__); + $this->Log()->writeError('%s : player guid or achievement id not defiend (guid: %s, achId: %d)', __METHOD__, $this->guid, $this->achId); return false; } $data = $this->aDB->select("SELECT * FROM `armory_achievement_criteria` WHERE `referredAchievement`=%d ORDER BY `showOrder`", $this->achId); @@ -520,11 +544,7 @@ public function GetCriteriaData($criteria_id) { $this->Log()->writeError('%s : player guid not defined', __METHOD__); return false; } - $criteria_data = $this->cDB->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id); - if($criteria_data) { - return $criteria_data; - } - return false; + return $this->db->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id); } public function LoadStatisticsPage($page_id, $faction) { @@ -564,7 +584,7 @@ public function GetCriteriaValue() { } $tmp_criteria_value = 0; foreach($criteria_ids as $criteria) { - $tmp_criteria_value = $this->cDB->selectCell("SELECT `counter` FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d LIMIT 1", $this->guid, $criteria['id']); + $tmp_criteria_value = $this->db->selectCell("SELECT `counter` FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d LIMIT 1", $this->guid, $criteria['id']); if(!$tmp_criteria_value) { continue; } @@ -573,7 +593,7 @@ public function GetCriteriaValue() { } } if(!$tmp_criteria_value) { - $this->Log()->writeError('%s : criteria value not found (id: %d)', __METHOD__, $this->achId); + $this->Log()->writeError('%s : criteria value for achievement %d not found', __METHOD__, $this->achId); return 0; } return $tmp_criteria_value; diff --git a/includes/classes/class.characters.php b/includes/classes/class.characters.php index b42f8f5a0..83aa1b0de 100644 --- a/includes/classes/class.characters.php +++ b/includes/classes/class.characters.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 337 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -225,6 +225,13 @@ **/ private $realmID = false; + /** + * Achievement MGR + * @category Characters class + * @access private + **/ + private $m_achievementMgr = null; + /** * Checks current player (loaded or not). * @category Characters class @@ -315,6 +322,7 @@ public function BuildCharacter($name, $realmId = 1, $full = true) { return false; } if($full == true) { + // Character data required for character-sheet page only. $player_stats_check = $this->db->selectCell("SELECT 1 FROM `armory_character_stats` WHERE `guid`=%d LIMIT 1", $player_data['guid']); if(!$player_stats_check) { $this->Log()->writeError('%s : player %d (%s) does not have any data in `armory_character_stats` table (SQL update to characters DB not applied?)', __METHOD__, $player_data['guid'], $player_data['name']); @@ -382,7 +390,7 @@ public function BuildCharacter($name, $realmId = 1, $full = true) { $this->raceText = $race_class['race']; // Get title info if($this->chosenTitle > 0) { - $this->__GetTitleInfo(); + $this->__HandleTitle(); } } $this->realmName = $realm_info['name']; @@ -420,7 +428,7 @@ private function __HandleEquipmentCacheData() { * @access private * @return bool **/ - private function __GetTitleInfo() { + private function __HandleTitle() { $title_data = $this->aDB->selectRow("SELECT `title_F_%s` AS `titleF`, `title_M_%s` AS `titleM`, `place` FROM `armory_titles` WHERE `id`=%d", $this->_locale, $this->_locale, $this->chosenTitle); if(!$title_data) { $this->Log()->writeError('%s: player %d (%s) have wrong chosenTitle id (%d) or there is no data for %s locale (locId: %d)', __METHOD__, $this->guid, $this->name, $this->chosenTitle, $this->_locale, $this->_loc); @@ -665,14 +673,21 @@ public function GetMoney() { return $this->money; } + public function GetAchievementMgr() { + if($this->m_achievementMgr === null) { + $this->m_achievementMgr = new Achievements; + $this->m_achievementMgr->InitAchievements($this->GetGUID(), $this->GetDB(), true); + } + return $this->m_achievementMgr; + } + /** * Generates character header (for XML output) * @category Characters class * @access public - * @param Achievements $achievements * @return array **/ - public function GetHeader(Achievements $achievements) { + public function GetHeader() { $header = array( 'battleGroup' => $this->armoryconfig['defaultBGName'], 'charUrl' => $this->GetUrlString(), @@ -688,7 +703,7 @@ public function GetHeader(Achievements $achievements) { 'lastModified' => null, 'level' => $this->level, 'name' => $this->name, - 'points' => $achievements->CalculateAchievementPoints(), + 'points' => $this->GetAchievementMgr()->GetAchievementPoints(), 'prefix' => $this->character_title['prefix'], 'race' => $this->raceText, 'raceId' => $this->race, @@ -2523,7 +2538,7 @@ public function GetCharacterFeed($full = false) { switch($event['type']) { case TYPE_ACHIEVEMENT_FEED: $send_data = array('achievement' => $event['data'], 'date' => $event_date); - $achievement_info = Achievements::GetAchievementInfo($send_data); + $achievement_info = $this->GetAchievementMgr()->GetAchievementInfo($send_data); if(!isset($achievement_info['title']) || !$achievement_info['title'] || empty($achievement_info['title'])) { continue; } diff --git a/includes/classes/class.dbhandler.php b/includes/classes/class.dbhandler.php index f6385aac6..1896109b6 100644 --- a/includes/classes/class.dbhandler.php +++ b/includes/classes/class.dbhandler.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 332 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -26,7 +26,7 @@ die('Direct access to this file not allowed!'); } -/* Database Query Types */ +/** Database Query Types **/ define('SINGLE_CELL', 0x01); define('SINGLE_ROW', 0x02); define('MULTIPLY_ROW', 0x03); @@ -36,6 +36,7 @@ Class ArmoryDatabaseHandler { private $dbLink = false; private $connectionLink = false; + private $databaseInfo = array(); /** Queries counter **/ private $queryCount = 0; @@ -44,12 +45,14 @@ /** * Connect to DB - * @param string host - * @param string user - * @param string password - * @param string dbName - * @param string charset - * @return bool + * @category Armory Database Handler + * @access public + * @param string host + * @param string user + * @param string password + * @param string dbName + * @param string charset + * @return bool **/ public function ArmoryDatabaseHandler($host, $user, $password, $dbName, $charset = false, $logHandler = null) { $this->connectionLink = @mysql_connect($host, $user, $password, true); @@ -61,12 +64,32 @@ public function ArmoryDatabaseHandler($host, $user, $password, $dbName, $charset $this->query("SET NAMES %s", $charset); } $this->logHandler = $logHandler; + $this->databaseInfo = array( + 'host' => $host, + 'user' => $user, + 'password' => $password, + 'name' => $dbName, + 'charset' => ($charset === false) ? 'UTF8' : $charset, + ); return true; } + /** + * Returns current database info + * @category Armory Database Handler + * @access public + * @param string $info + * @return mixed + **/ + public function GetDatabaseInfo($info) { + return (isset($this->databaseInfo[$info])) ? $this->databaseInfo[$info] : false; + } + /** * Tests conection link - * @return bool + * @category Armory Database Handler + * @access public + * @return bool **/ public function TestLink() { if($this->connectionLink == true) { @@ -77,14 +100,17 @@ public function TestLink() { /** * Execute SQL query - * @param string $safe_sql - * @param int $queryType - * @return mixed + * @category Armory Database Handler + * @access public + * @param string $safe_sql + * @param int $queryType + * @return mixed **/ private function _query($safe_sql, $queryType) { // Execute query and calculate execution time $make_array = array(); $query_start = microtime(true); + $this->queryCount++; $perfomed_query = @mysql_query($safe_sql, $this->connectionLink); if($perfomed_query === false) { if($this->logHandler != null && is_object($this->logHandler)) { @@ -190,8 +216,10 @@ public function selectObject($query) { /** * Converts array values to string format (for IN(%s) cases) - * @param array $source - * @return string + * @category Armory Database Handler + * @access public + * @param array $source + * @return string **/ private function ConvertArray($source) { if(!is_array($source)) { diff --git a/includes/classes/class.guilds.php b/includes/classes/class.guilds.php index 8b99464b6..9090b0680 100644 --- a/includes/classes/class.guilds.php +++ b/includes/classes/class.guilds.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 324 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -237,8 +237,11 @@ public function BuildGuildList() { WHERE `guild`.`guildid`=%d AND `characters`.`level`>=%d AND `guild_member`.`guid`=`characters`.`guid`", $this->guildId, $this->guildId, $this->guildId, $this->armoryconfig['minlevel']); $countMembers = count($memberListTmp); for($i=0;$i<$countMembers;$i++) { - $memberListTmp[$i]['achPoints'] = Achievements::calculateAchievementPoints($memberListTmp[$i]['guid']); + $pl = new Characters; + $pl->BuildCharacter($memberListTmp[$i]['name'], $this->currentRealmInfo['id'], false); + $memberListTmp[$i]['achPoints'] = $pl->GetAchievementMgr()->GetAchievementPoints(); $memberListTmp[$i]['url'] = sprintf('r=%s&cn=%s&gn=%s', urlencode($this->currentRealmInfo['name']), urlencode($memberListTmp[$i]['name']), urlencode($this->guildName)); + unset($pl); } return $memberListTmp; } diff --git a/includes/classes/class.utils.php b/includes/classes/class.utils.php index 83d80b427..1d66b99a0 100644 --- a/includes/classes/class.utils.php +++ b/includes/classes/class.utils.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 331 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -49,7 +49,7 @@ public function authUser() { return false; } elseif(strtoupper($info['sha_pass_hash']) != $this->createShaHash()) { - $this->Log()->writeError('%s : sha_pass_hash and generated SHA1 hash are diffirent (%s and %s), unable to auth user.', __METHOD__, $info['sha_pass_hash'], $this->createShaHash()); + $this->Log()->writeError('%s : sha_pass_hash and generated SHA1 hash are different (%s and %s), unable to auth user.', __METHOD__, strtoupper($info['sha_pass_hash']), $this->createShaHash()); return false; } else { @@ -1268,5 +1268,35 @@ public function GetRaceBitMaskByRaceId($raceId) { } return $mask; } + + /** + * Returns realm type for provided $realm_id. + * Warning: if detection fails, realm with provided ID will be deleted from allowed realms! + * @category Utils class + * @access public + * @param int $realm_id + * @return mixed + **/ + public function GetRealmType($realm_id) { + if(!isset($this->realmData[$realm_id]) || !isset($this->realmData[$realm_id]['name_world'])) { + $this->Log()->writeError('%s : unable to detect realm type: world database config not found', __METHOD__); + return false; + } + $realm_info = $this->realmData[$realm_id]; + $db = new ArmoryDatabaseHandler($realm_info['host_world'], $realm_info['user_world'], $realm_info['pass_world'], $realm_info['name_world'], $realm_info['charset_world'], $this->Log()); + if(!$db->TestLink()) { + $this->Log()->writeError('%s : unable to connect to MySQL database (%s:%s:%s:%s)', __METHOD__, $realm_info['host_world'], $realm_info['user_world'], $realm_info['pass_world'], $realm_info['name_world']); + return false; + } + if($tmp = $db->selectCell("SELECT 1 FROM `mangos_string` LIMIT 1")) { + return 'mangos'; + } + elseif($tmp = $db->selectCell("SELECT 1 FROM `trinity_string` LIMIT 1")) { + return 'trinity'; + } + $this->Log()->writeError('%s : unable to detect realm type, realm info with ID #%d was removed from allowed realms', __METHOD__, $realm_id); + unset($realm_id, $realm_info, $this->realmData[$realm_id], $db); + return false; + } } ?> \ No newline at end of file diff --git a/includes/defines.php b/includes/defines.php index b609a835b..e9f966889 100644 --- a/includes/defines.php +++ b/includes/defines.php @@ -3,7 +3,7 @@ /** * @package World of Warcraft Armory * @version Release Candidate 1 - * @revision 334 + * @revision 340 * @copyright (c) 2009-2010 Shadez * @license http://opensource.org/licenses/gpl-license.php GNU Public License * @@ -63,22 +63,22 @@ define('ACHIEVEMENTS_CATEGORY_EVENTS', 155); define('ACHIEVEMENTS_CATEGORY_FEATS', 81); -define('ACHIEVEMENTS_COUNT_SUMMARY', 1054); +define('ACHIEVEMENTS_COUNT_SUMMARY', 1058); define('ACHIEVEMENTS_COUNT_GENERAL', 54); define('ACHIEVEMENTS_COUNT_QUESTS', 49); define('ACHIEVEMENTS_COUNT_EXPLORATION', 70); define('ACHIEVEMENTS_COUNT_PVP', 166); -define('ACHIEVEMENTS_COUNT_DUNGEONS', 454); +define('ACHIEVEMENTS_COUNT_DUNGEONS', 458); define('ACHIEVEMENTS_COUNT_PROFESSIONS', 75); define('ACHIEVEMENTS_COUNT_REPUTATION', 45); define('ACHIEVEMENTS_COUNT_EVENTS', 141); -define('ACHIEVEMENT_POINTS_SUMMARY', 11635); +define('ACHIEVEMENT_POINTS_SUMMARY', 11675); define('ACHIEVEMENT_POINTS_GENERAL', 570); define('ACHIEVEMENT_POINTS_QUESTS', 530); define('ACHIEVEMENT_POINTS_EXPLORATION', 830); define('ACHIEVEMENT_POINTS_PVP', 1930); -define('ACHIEVEMENT_POINTS_DUNGEONS', 4915); +define('ACHIEVEMENT_POINTS_DUNGEONS', 4955); define('ACHIEVEMENT_POINTS_PROFESSIONS', 760); define('ACHIEVEMENT_POINTS_REPUTATION', 560); define('ACHIEVEMENT_POINTS_EVENTS', 1540); diff --git a/includes/revision_nr.php b/includes/revision_nr.php index b5f7b919b..7507a7099 100644 --- a/includes/revision_nr.php +++ b/includes/revision_nr.php @@ -1,5 +1,5 @@ \ No newline at end of file