Hi there everyone,
I'm utilizing some fantastic code provided by another person for retrieving character data from a game's data servers. One of the things I'm trying to do is to get the characters' reputation standing with the guild. The array provided to me gets the standing with every faction in the game. Here's the code:
$character = $armory->getCharacter('Govannin');
$reputations = $character->getReputation(TRUE,'name','asc');
foreach($reputations as $reputation) {
$rep_name = $reputation['name'];
$standing = $reputation['standingName'];
echo($standing." with ".$rep_name.".<br />");
}
Which produces:
Exalted with Frenzyheart Tribe.
Honored with Gadgetzan.
Neutral with Gelkis Clan Centaur.
Exalted with Gilneas.
Exalted with Gnomeregan.
Exalted with Guardians of Hyjal.
Exalted with Guild.
Exalted with Honor Hold.
Friendly with Hydraxian Waterlords.
Exalted with Ironforge.
Exalted with Keepers of Time.
Exalted with Kirin Tor.
Exalted with Knights of the Ebon Blade.
Exalted with Kurenai.
Exalted with Lower City.
Neutral with Magram Clan Centaur.
Only with a bunch more....
I only need the standing with Guild. I know that I can do an if inside the foreach loop to see if the rep_name equals guild for each result inside the array, but I'm wondering if there's a more efficient way of getting the reputation for just that one entry.
I'm wondering if maybe I can even alter his function to only pull the data for Guild(I think the added benefit of this would be the much lower transfer of data between servers, and thus less time to run):
/**
* Get character reputations
* @param Boolean $sort Use to enable sorting
* @param String $sortfield Define the field you want to sort by - Values are: id | name | standing
* @param String $order Define the order of the sorting - Values are: desc | asc
* @return Returns an array with all the reputations
*/
public function getReputation($sort=FALSE,$sortfield='standing',$order='desc'){
$reputations = $this->characterData['reputation'];
foreach ($reputations as $key => $reputation){
$reputation['standing'] == 0 ? $reputations[$key]['standingName'] = 'Hated':FALSE;
$reputation['standing'] == 1 ? $reputations[$key]['standingName'] = 'At war':FALSE;
$reputation['standing'] == 2 ? $reputations[$key]['standingName'] = 'Unfriendly':FALSE;
$reputation['standing'] == 3 ? $reputations[$key]['standingName'] = 'Neutral':FALSE;
$reputation['standing'] == 4 ? $reputations[$key]['standingName'] = 'Friendly':FALSE;
$reputation['standing'] == 5 ? $reputations[$key]['standingName'] = 'Honored':FALSE;
$reputation['standing'] == 6 ? $reputations[$key]['standingName'] = 'Revered':FALSE;
$reputation['standing'] == 7 ? $reputations[$key]['standingName'] = 'Exalted':FALSE;
}
if ($sort){
$reputations = $this->sortReputation($reputations, $sortfield, $order);
}
return $reputations;
}
Any thoughts you might have on the matter would be greatly appreciated!