diff --git a/class/AASkillsCalculator.php b/class/AASkillsCalculator.php index 891032c..0b3442f 100644 --- a/class/AASkillsCalculator.php +++ b/class/AASkillsCalculator.php @@ -7,12 +7,15 @@ class AASkillsCalculator { - private $_xml; // Contenu xml + private $_xml; // XML content - function AASkillsCalculator ($xml="xml/aa_skillsLists.xml") { - // Chargement du XML - $this->_xml = new DomDocument(); - $this->_xml->load($xml); + public function AASkillsCalculator ($xml="xml/aa_skillsLists.xml") { + // Load XML + if (file_exists($xml)) { + $this->_xml = simplexml_load_file($xml); + } else { + exit('Error while loading XML file.'); + } } /* @@ -42,10 +45,9 @@ class AASkillsCalculator { Return one tree's HTML */ private function createTree() { - $tree = $this->_xml->getElementsByTagName('ecole'); - $html = $this->getSpec($tree); + $html = $this->getSpec(); $html .= '
'; - $html .= $this->getSkills($tree); + $html .= $this->getSkills(); return $html; } @@ -53,12 +55,11 @@ class AASkillsCalculator { /* Return the skills's HTML from one tree - @tree : Tree's XML node (ecole) */ - private function getSkills($node) { + private function getSkills() { $html =''; - foreach ($node as $branch) { - $html .= '
'; + foreach ($this->_xml->ecole as $branch) { + $html .= '
'; $html .= $this->getActive($branch); $html .= $this->getPassive($branch); $html .= '
'; @@ -69,14 +70,13 @@ class AASkillsCalculator { /* Return the list of the skill trees - @node : Tree's XML node (ecole) */ - private function getSpec($node) { + private function getSpec() { $html = '
'; $html .= ''; $html .= '
'; @@ -86,42 +86,34 @@ class AASkillsCalculator { /* Return the active skills from one tree - @node : Active's XML node (ecole > active) + @node : Tree's XML node (ecole) */ private function getActive($node) { - $active = $node->getElementsByTagName('active'); - foreach ($active as $a) { - $skill = $a->getElementsByTagName('skill'); - $html = '
'; - foreach ($skill as $s) { - $html .= '
  • - '; - $html .= '
    '.$this->getSkillDetail($s).'
    '; - $html .= '
  • '; - } - $html .= '
    '; + $html = '
    '; + foreach ($node->active->skill as $s) { + $html .= '
  • + '; + $html .= '
    '.$this->getSkillDetail($s).'
    '; + $html .= '
  • '; } + $html .= '
    '; return $html; } /* Return the active skills from one tree - @node : Passive's XML node (ecole > passive) + @node : Tree's XML node (ecole) */ private function getPassive($node) { - $active = $node->getElementsByTagName('passive'); - foreach ($active as $a) { - $skill = $a->getElementsByTagName('skill'); - $html ='
    '; - foreach ($skill as $s) { - $html .= '
  • - '; - $html .= '
    '.$this->getSkillDetail($s).'
    '; - $html .= '
  • '; - } - $html .= '
    '; + $html ='
    '; + foreach ($node->passive->skill as $s) { + $html .= '
  • + '; + $html .= '
    '.$this->getSkillDetail($s).'
    '; + $html .= '
  • '; } + $html .= '
    '; return $html; } @@ -131,15 +123,11 @@ class AASkillsCalculator { @node : Skill's XML node (ecole > passive/active > skill) */ private function getSkillDetail($node) { - $html = '

    '.$node->getAttribute('name').'

    '; - $stat = $node->getElementsByTagName('stat'); - $desc = $node->getElementsByTagName('description'); - foreach ($desc as $d) { - $html .= '

    '.utf8_decode($this->renderTags($d->nodeValue)).'

    '; - } + $html = '

    '.$node['name'].'

    '; + $html .= '

    '.utf8_decode($this->renderTags($node->description)).'

    '; $html .= '
    '; - foreach ($stat as $s) { - $html .= '

    '.ucfirst(utf8_decode($s->getAttribute('name'))).': '.utf8_decode($s->nodeValue).'

    '; + foreach ($node->stat as $s) { + $html .= '

    '.ucfirst(utf8_decode($s['name'])).': '.utf8_decode($s).'

    '; } $html .= '
    ';