Skip to content

Commit

Permalink
[369] Display all available achievements in Feats of Strength categor…
Browse files Browse the repository at this point in the history
…y (comparison), use unique cache ID for comparison cases. phpDoc documentations for missed classes were updated.
  • Loading branch information
Shadez committed Aug 22, 2010
1 parent a0925d5 commit c9555fb
Show file tree
Hide file tree
Showing 7 changed files with 669 additions and 113 deletions.
38 changes: 25 additions & 13 deletions character-achievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 366
* @revision 369
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -78,10 +78,20 @@
// Get page cache
if($characters->GetGUID() > 0 && $isCharacter && $armory->armoryconfig['useCache'] == true && !isset($_GET['skipCache'])) {
if($achievement_category > 0) {
$cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $characters->GetName(), $armory->currentRealmInfo['name']);
if(is_array($comparisonData)) {
$cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $utils->GenerateCacheIdForComparisons($comparisonData));
}
else {
$cache_id = $utils->GenerateCacheId('character-achievements-c'.$achievement_category, $characters->GetName(), $armory->currentRealmInfo['name']);
}
}
else {
$cache_id = $utils->GenerateCacheId('character-achievements', $characters->GetName(), $armory->currentRealmInfo['name']);
if(is_array($comparisonData)) {
$cache_id = $utils->GenerateCacheId('character-achievements', $utils->GenerateCacheIdForComparisons($comparisonData));
}
else {
$cache_id = $utils->GenerateCacheId('character-achievements', $characters->GetName(), $armory->currentRealmInfo['name']);
}
}
if($cache_data = $utils->GetCache($cache_id)) {
echo $cache_data;
Expand All @@ -106,18 +116,20 @@
$pages_count = count($pages);
$achievements_page = $achievements->LoadAchievementPage($achievement_category, ($characters->GetFaction() == 1) ? 0 : 1);
$i = 0;
if($achievement_category == 81) {
// Generate all available achievements
$owner_fos = $achievements->BuildFoSListForComparison($pages);
$pages = $owner_fos;
$achievements_page = $owner_fos[0];
}
if(isset($achievements_page['completed'])) {
foreach($achievements_page['completed'] as $achievement) {
if($achievement['display'] == 0) {
if(isset($achievement['display']) && $achievement['display'] == 0) {
continue;
}
if($utils->IsWriteRaw()) {
if(is_array($pages)) {
$xml->XMLWriter()->writeRaw('<achievement');
foreach($achievement['data'] as $a_data_key => $a_data_value) {
$xml->XMLWriter()->writeRaw(' ' . $a_data_key . '="' . $a_data_value . '"');
}
$xml->XMLWriter()->writeRaw('>'); //achievement
$xml->XMLWriter()->writeRaw('<achievement desc="' . $achievement['data']['desc'] . '" icon="' . $achievement['data']['icon'] . '" title="' . $achievement['data']['title'] . '">');
for($aCount = 0; $aCount < $pages_count; $aCount++) {
$tmp = $pages[$aCount];
$xml->XMLWriter()->writeRaw('<c');
Expand Down Expand Up @@ -160,13 +172,13 @@
else {
if(is_array($pages)) {
$xml->XMLWriter()->startElement('achievement');
foreach($achievement['data'] as $a_data_key => $a_data_value) {
$xml->XMLWriter()->writeAttribute($a_data_key, $a_data_value);
}
$xml->XMLWriter()->writeAttribute('desc', $achievement['data']['desc']);
$xml->XMLWriter()->writeAttribute('icon', $achievement['data']['icon']);
$xml->XMLWriter()->writeAttribute('title', $achievement['data']['title']);
for($aCount = 0; $aCount < $pages_count; $aCount++) {
$tmp = $pages[$aCount];
$xml->XMLWriter()->startElement('c');
if(isset($tmp['completed'][$achievement['data']['id']])) {
if(isset($tmp['completed'][$achievement['data']['id']]['data']['dateCompleted']) && $tmp['completed'][$achievement['data']['id']]['data']['dateCompleted'] != null) {
$xml->XMLWriter()->writeAttribute('dateCompleted', $tmp['completed'][$achievement['data']['id']]['data']['dateCompleted']);
}
$xml->XMLWriter()->endElement(); //c
Expand Down
76 changes: 69 additions & 7 deletions includes/classes/class.achievements.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
/**
* @package World of Warcraft Armory
* @version Release Candidate 1
* @revision 367
* @revision 369
* @copyright (c) 2009-2010 Shadez
* @license http://opensource.org/licenses/gpl-license.php GNU Public License
*
Expand Down Expand Up @@ -110,6 +110,12 @@ public function GetAchievementPoints() {
return $this->pts;
}

/**
* Returns completed achievements count
* @category Achievements class
* @access public
* @return int
**/
public function GetAchievementsCount() {
return $this->m_count;
}
Expand Down Expand Up @@ -153,6 +159,13 @@ public function CountCharacterAchievements() {
return $this->m_count;
}

/**
* Returns summary data for completed achievements in selected category.
* @category Achievements class
* @access public
* @param int $category
* @return array
**/
public function GetSummaryAchievementData($category) {
if(!$this->guid) {
$this->Log()->writeError('%s : player guid not defined', __METHOD__);
Expand Down Expand Up @@ -272,7 +285,7 @@ public function GetLastAchievements() {
}

/**
* Returns achievement date. If $guid not provided, function will use $this->guid.
* Returns achievement date.
* @category Achievements class
* @access public
* @param int $achId = 0
Expand Down Expand Up @@ -427,7 +440,7 @@ public function LoadAchievementPage($page_id, $faction) {
return false;
}
$return_data = array();
$i=0;
$i = 0;
$hide_id = array();
foreach($achievements_data as $achievement) {
$this->achId = $achievement['id'];
Expand Down Expand Up @@ -495,7 +508,13 @@ public function LoadAchievementPage($page_id, $faction) {
return $return_data;
}

public function BuildAchievementCriteriaTable() {
/**
* Builds criterias table for current (this->achId) achievement
* @category Achievements class
* @access private
* @return array
**/
private function BuildAchievementCriteriaTable() {
if($this->GetLocale() == 'es_es' || $this->GetLocale() == 'es_mx') {
$locale = 'en_gb';
}
Expand All @@ -517,7 +536,7 @@ public function BuildAchievementCriteriaTable() {
if($criteria['completionFlag']&ACHIEVEMENT_CRITERIA_FLAG_HIDE_CRITERIA) {
continue;
}
$m_data = $this->GetCriteriaData($criteria['id']);
$m_data = self::GetCriteriaData($criteria['id']);
if(!isset($m_data['counter']) || !$m_data['counter']) {
$m_data['counter'] = 0;
}
Expand All @@ -544,14 +563,29 @@ public function BuildAchievementCriteriaTable() {
return $achievement_criteria;
}

public function GetCriteriaData($criteria_id) {
/**
* Returns criteria ($criteria_id) data
* @category Achievements class
* @access private
* @param int $criteria_id
* @return array
**/
private function GetCriteriaData($criteria_id) {
if(!$this->guid) {
$this->Log()->writeError('%s : player guid not defined', __METHOD__);
return false;
}
return $this->db->selectRow("SELECT * FROM `character_achievement_progress` WHERE `guid`=%d AND `criteria`=%d", $this->guid, $criteria_id);
}

/**
* Generates statistics page
* @category Achievements class
* @access public
* @param int $page_id
* @param int $faction
* @return array
**/
public function LoadStatisticsPage($page_id, $faction) {
if(!$this->guid) {
$this->Log()->writeError('%s : player guid not defined', __METHOD__);
Expand All @@ -577,7 +611,13 @@ public function LoadStatisticsPage($page_id, $faction) {
return $return_data;
}

public function GetCriteriaValue() {
/**
* Returns criteria value for current achievement (this->achId)
* @category Achievements class
* @access private
* @return int
**/
private function GetCriteriaValue() {
if(!$this->guid || !$this->achId) {
$this->Log()->writeError('%s : player guid or achievement id not defined', __METHOD__);
return false;
Expand All @@ -601,5 +641,27 @@ public function GetCriteriaValue() {
}
return $tmp_criteria_value;
}

/**
* Generates Feats of Strength list for achievements comparison.
* @category Achievements class
* @access public
* @param array $pages
* @return array
**/
public function BuildFoSListForComparison($pages) {
if(!is_array($pages)) {
return false;
}
foreach($pages as $char) {
foreach($char['completed'] as $achList) {
if(!isset($pages[0]['completed'][$achList['data']['id']])) {
$pages[0]['completed'][$achList['data']['id']] = $achList;
$pages[0]['completed'][$achList['data']['id']]['data']['dateCompleted'] = null;
}
}
}
return $pages;
}
}
?>
Loading

0 comments on commit c9555fb

Please sign in to comment.