[cf98bc]: Guild.class.php Maximize Restore History

Download this file

Guild.class.php    105 lines (91 with data), 3.5 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
<?php
class Guild {
private $name;
private $region;
private $realm;
private $guildData;
private $fields = 'members,achievements';
private $cache;
function __construct($region, $realm, $name) {
$this->region = strtolower($region);
$this->realm = $realm;
$this->name = $name;
$jsonConnect = new jsonConnect();
$this->guildData = $jsonConnect->getGuild($name, $realm, $region, $this->fields);
}
/**
* Extract all guild data
* @return A large array with all raw information
*/
public function getData() {
return $this->guildData;
}
/**
* Get a list of the completed achievements by the guild
* @param String $sort Define what the list should be sorted by: timestamp|id|name
* @param String $sortFlag Can be asc|desc
*/
public function getAchievements($sort=FALSE,$sortFlag='asc'){
$wowhead = new WowHead();
$achievements['achievementsCompleted'] = $this->guildData['achievements']['achievementsCompleted'];
$achievements['achievementsCompletedTimestamp'] = $this->guildData['achievements']['achievementsCompletedTimestamp'];
for ($i = 0; $i < count($achievements['achievementsCompleted']); $i++){
// Build the new array to return
$achievement[$i]['id']=$achievements['achievementsCompleted'][$i];
$achievement[$i]['timestamp']=$achievements['achievementsCompletedTimestamp'][$i];
$achievement[$i]['url'] = $GLOBALS['wowarmory']['urls']['achievement']."=".$achievements['achievementsCompleted'][$i];
// Get name of achievement
$achievement[$i]['name'] = $wowhead->getData($achievement[$i]['url'], 'name');
$achievement[$i]['url'] .= "&who=".$this->name."&when=".$achievement[$i]['timestamp'];
}
if ($sort){
return $this->sortAchievements($achievement, $sort, $sortFlag);
}
return $achievement;
}
/**
* Retrieve all members of the guild with some basic information - Achievement points are currently broken from battle net, so use getCharacter() if you need achievement points
* @param $sort String Define what the list should be sorted by: name|class|race|gender|level|rank
* @param $sortFlag String Can be asc|desc
*/
public function getMembers($sort=FALSE,$sortFlag='asc'){
if ($sort){
$members = $this->guildData['members'];
return $this->sort($members, $sort, $sortFlag);
}
return $this->guildData['members'];
}
private function sort($array,$sortkey,$sortFlag){
$arraysize = count($array);
foreach(array_keys($array) as $key){
if ($sortkey == 'rank'){
$temp_array[$key] = $array[$key][$sortkey];
}else{
$temp_array[$key] = $array[$key]['character'][$sortkey];
}
}
natsort($temp_array);
if ($sortFlag == 'desc'){
$temp_array = array_reverse($temp_array,TRUE);
}
foreach(array_keys($temp_array) as $key){
$return_array[] = $array[$key];
}
return $return_array;
}
private function sortAchievements($array,$sortkey,$sortFlag){
$arraysize = count($array);
foreach(array_keys($array) as $key){
$temp_array[$key] = $array[$key][$sortkey];
}
natsort($temp_array);
if ($sortFlag == 'desc'){
$temp_array = array_reverse($temp_array,TRUE);
}
foreach(array_keys($temp_array) as $key){
$return_array[] = $array[$key];
}
return $return_array;
}
}
?>