View Single Post
Old 01-11-2010, 06:04 PM   #133 (permalink)
Tanyril
The Visitor
 
Join Date: Jan 2010
Posts: 2
Thanks: 1
Tanyril is on a distinguished road
Default

Quote:
Originally Posted by maeltar View Post
Well, I've been lurking in the background watching this thread with interest as there are lots of elements I have been wanting to do being discussed here, and have slowly, with my nose in books and lots of head scratching got a working Roster :D (even if you are not impressed, I'm pleased)

Code:
<?php


function return_class($classid) {
    switch ($classid) {
        case 1:
            $class = "Warrior";
            break;
        case 2:
            $class = "Paladin";
            break;
        case 3:
            $class = "Hunter";
            break;
        case 4:
            $class = "Rogue";
            break;
        case 5:
            $class = "Priest";
            break;
        case 6:
            $class = "Death Knight";
            break;
        case 7:
            $class = "Shaman";
            break;
        case 8:
            $class = "Mage";
            break;
        case 9:
            $class = "Warlock";
            break;
        case 11:
            $class = "Druid";
            break;
    }
    return $class;
}  


function return_rank($rankid) {        // Adjust the names here for the guild rank names.  0 is always the Guild owner
    switch ($rankid) {
        case 0:
            $class = "Guild Manager";
            break;
        case 1:
            $class = "Guild Manager";
            break;
        case 2:
            $class = "Bank Access";
            break;
        case 3:
            $class = "Advisor";
            break;
        case 4:
            $class = "Raider";
            break;
        case 5:
            $class = "Member";
            break;
        case 6:
            $class = "Recruit";
            break;
        case 7:
            $class = "Alt";
            break;
    }
    return $class;
}  



function return_race($raceid, $sex) {
    switch ($raceid) {
        case 1:
            if ($sex == "0") {$race = "Human Male";}
            if ($sex == "1") {$race = "Human Female";}
            break;
        case 2:
            if ($sex == "0") {$race = "Orc Male";}
            if ($sex == "1") {$race = "Orc Female";}
            break;
        case 3:
            if ($sex == "0") {$race = "Dwarf Male";}
            if ($sex == "1") {$race = "Dwarf Female";}
            break;
        case 4:
            if ($sex == "0") {$race = "Night Elf Male";}
            if ($sex == "1") {$race = "Night Elf Female";}
            break;
        case 5:
            if ($sex == "0") {$race = "Undead Male";}
            if ($sex == "1") {$race = "Undead Female";}
            break;
        case 6:
            if ($sex == "0") {$race = "Tauren Male";}
            if ($sex == "1") {$race = "Tauren Female";}
            break;
        case 7:
            if ($sex == "0") {$race = "Gnome Male";}
            if ($sex == "1") {$race = "Gnome Female";}
            break;
        case 8:
            if ($sex == "0") {$race = "Troll Male";}
            if ($sex == "1") {$race = "Troll Female";}
            break;
        case 10:
            if ($sex == "0") {$race = "Blood Elf Male";}
            if ($sex == "1") {$race = "Blood Elf Female";}
            break;
        case 11:
            if ($sex == "0") {$race = "Draenei Male";}
            if ($sex == "1") {$race = "Draenei Female";}
            break;
    }
    return $race;
}  





class armory {

 const BROWSER="Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.2) Gecko/20070319 Firefox/2.0.0.3";

 public $query;
 public $server;
 public $guild;
 public $guildie;
 public $page;

public function __construct ( $query, $server, $guild, $guildie, $page ) {
	$this->query = $query;
	$this->server = $server;
	$this->guild = $guild;
	$this->guildie = $guildie;
	$this->page = $page;
 } // end of __construct()

public function pull_xml() {


	// change the first part of the $url to the armory link that you need
	if( $this->query === 'roster' ){
		$url = 'http://eu.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
		
	  }elseif( $this->query === 'character' ){
		$url = 'http://eu.wowarmory.com/character-sheet.xml?r=' . urlencode($this->server) . '&n=' . $this->guildie;
		
		}  

	$ch = curl_init();
	curl_setopt ($ch, CURLOPT_URL, $url);
	curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
	curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, 15);
	curl_setopt ($ch, CURLOPT_USERAGENT,  self::BROWSER);
	
	$url_string = curl_exec($ch);
	curl_close($ch);
	return simplexml_load_string($url_string);
	
   
 } // end of pull_xml()

} // end class  

$xml_obj = simplexml_load_string($xml);


$armory = new armory('roster', 'Khadgar', 'Aeturnus Recuso', NULL, NULL);
$xml = $armory->pull_xml();

?>

<HTML>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<table border=1 align=center width=50%>
<tr>
	<th>Name</th><th>Class</th><th>Race</th><th>Level</th><th>Achievement Points</th>
</tr>

<?

foreach ($xml->guildInfo->guild->members->character as $char) {
    $toonclass = return_class($char['classId']);
    $toonrace = return_race($char['raceId'], $char['genderId']);

    echo '<td>' . $char['name'] . '</td> ';
    echo '<td>' . $toonclass . '</td> ';
    echo '<td>' . $toonrace . '</td> ';
    echo '<td>' . $char['level'] . '</td> ';
    echo '<td>' . $char['achPoints'] . '</td></tr>';
			// foreach ($xml->characterInfo->characterTab->professions as $prof);
			// {
                	// echo $prof['name'];
			// }

}

echo '</table>'

?>
The following bit of code for me is a handy one, but I cann't figure out how to get it working...

Code:
foreach ($xml->characterInfo->characterTab->professions as $prof);
			{
                	echo $prof['name'];
			}
With my limited understanding, the loop it runs in is looking at Guild info, and for the "profs" part to work I need to be in the char info ?

Code:
	// change the first part of the $url to the armory link that you need
	if( $this->query === 'roster' ){
		$url = 'http://eu.wowarmory.com/guild-info.xml?r=' . urlencode($this->server) . '&n=' . urlencode($this->guild) . '&p=' . $this->page;
		
	  }elseif( $this->query === 'character' ){
		$url = 'http://eu.wowarmory.com/character-sheet.xml?r=' . urlencode($this->server) . '&n=' . $this->guildie;
Now, not sure if am reading it wrong, (I must be) I need to set a var "$this->query" to "character" which would be $char['name'] withing the foreach loop so that I could pull the proffession info from the armoury....


Or, maybe I should just give up and go sit in a corner

Sooo, anyone any ideas ?


TIA
Profession Name:
$xml->characterInfo->characterTab->professions->skill[0][name]

Profession level:
$xml->characterInfo->characterTab->professions->skill[0][value]

Profession max level:
$xml->characterInfo->characterTab->professions->skill[0][max]

IE:

echo $xml->characterInfo->characterTab->professions->skill[0][name].':'. $xml->characterInfo->characterTab->professions->skill[0][value].'/'. $xml->characterInfo->characterTab->professions->skill[0][max];

would end up being something like:
Leatherworking: 439/450

I shortened mine with a variable though to $charinfo->professions->skill[0][name] etc.

Btw- skill[0] would be the first profession they picked up. skill[1] would be their second.
Tanyril is offline  
Reply With Quote