-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add leaguelevels file. Add league structure
- Loading branch information
1 parent
ef98722
commit 54063b3
Showing
5 changed files
with
262 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,142 @@ | ||
<?php | ||
/** | ||
* PHT | ||
* | ||
* @author Telesphore | ||
* @link https://github.com/jetwitaussi/PHT | ||
* @version 3.0 | ||
* @license "THE BEER-WARE LICENSE" (Revision 42): | ||
* Telesphore wrote this file. As long as you retain this notice you | ||
* can do whatever you want with this stuff. If we meet some day, and you think | ||
* this stuff is worth it, you can buy me a beer in return. | ||
*/ | ||
|
||
namespace PHT\Xml\World\League; | ||
|
||
use PHT\Xml; | ||
use PHT\Wrapper; | ||
|
||
class Level extends Xml\Base | ||
{ | ||
/** | ||
* @param \DOMDocument $xml | ||
*/ | ||
public function __construct($xml) | ||
{ | ||
$this->xmlText = $xml->saveXML(); | ||
$this->xml = $xml; | ||
} | ||
|
||
/** | ||
* Return group id | ||
* | ||
* @return integer | ||
*/ | ||
public function getNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('LeagueLevel')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of series in the league level | ||
* | ||
* @return integer | ||
*/ | ||
public function getSeniorLeagueNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfLeagueLevelUnits')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return array of league level unit id (senior league id) | ||
* | ||
* @return array | ||
*/ | ||
public function getSeniorLeagueIds() | ||
{ | ||
return explode(',', $this->getXml()->getElementsByTagName('LeagueLevelUnitIdList')->item(0)->nodeValue); | ||
} | ||
|
||
/** | ||
* Return the league level unit id (senior league id) from the number of the serie | ||
* | ||
* @param integer $number | ||
* @return integer | ||
*/ | ||
public function getSeniorLeagueId($number) | ||
{ | ||
$ids = $this->getSeniorLeagueIds(); | ||
return $ids[--$number]; | ||
} | ||
|
||
/** | ||
* Return senior league object from serie number | ||
* | ||
* @param integer $number | ||
* @return \PHT\Xml\World\League\Senior | ||
*/ | ||
public function getSeniorLeague($number) | ||
{ | ||
return Wrapper\World\League::senior($this->getSeniorLeagueId($number)); | ||
} | ||
|
||
/** | ||
* Return number of teams in the league level | ||
* | ||
* @return integer | ||
*/ | ||
public function getTeamsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfTeams')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of shared promotion slots | ||
* | ||
* @return integer | ||
*/ | ||
public function getSharedPromotionSlotsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfSharedPromotionSlotsPerSeries')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of direct promotion slots | ||
* | ||
* @return integer | ||
*/ | ||
public function getDirectPromotionSlotsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfDirectPromotionSlotsPerSeries')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of qualification promotion slots | ||
* | ||
* @return integer | ||
*/ | ||
public function getQualificationPromotionSlotsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfQualificationPromotionSlotsPerSeries')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of qualification demotion slots | ||
* | ||
* @return integer | ||
*/ | ||
public function getQualificationDemotionSlotsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfQualificationDemotionSlotsPerSeries')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of direct deomotion slots | ||
* | ||
* @return integer | ||
*/ | ||
public function getDirectDemotionSlotsNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfDirectDemotionSlotsPerSeries')->item(0)->nodeValue; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php | ||
/** | ||
* PHT | ||
* | ||
* @author Telesphore | ||
* @link https://github.com/jetwitaussi/PHT | ||
* @version 3.0 | ||
* @license "THE BEER-WARE LICENSE" (Revision 42): | ||
* Telesphore wrote this file. As long as you retain this notice you | ||
* can do whatever you want with this stuff. If we meet some day, and you think | ||
* this stuff is worth it, you can buy me a beer in return. | ||
*/ | ||
|
||
namespace PHT\Xml\World; | ||
|
||
use PHT\Xml; | ||
use PHT\Wrapper; | ||
use PHT\Utils; | ||
|
||
class LeagueStructure extends Xml\File | ||
{ | ||
/** | ||
* Return league id | ||
* | ||
* @return integer | ||
*/ | ||
public function getLeagueId() | ||
{ | ||
return $this->getXml()->getElementsByTagName('LeagueID')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return country object | ||
* | ||
* @return \PHT\Xml\World\Country | ||
*/ | ||
public function getCountry() | ||
{ | ||
return Wrapper\World::country($this->getLeagueId()); | ||
} | ||
|
||
/** | ||
* Return season number | ||
* | ||
* @return integer | ||
*/ | ||
public function getSeason() | ||
{ | ||
return $this->getXml()->getElementsByTagName('Season')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return number of levels in the league | ||
* | ||
* @return integer | ||
*/ | ||
public function getLevelNumber() | ||
{ | ||
return $this->getXml()->getElementsByTagName('NrOfLeagueLevels')->item(0)->nodeValue; | ||
} | ||
|
||
/** | ||
* Return league level object | ||
* | ||
* @param integer $number | ||
* @return \PHT\Xml\World\League\Level | ||
*/ | ||
public function getLevel($number) | ||
{ | ||
$number = round($number); | ||
if ($number >=1 && $number <= $this->getLevelNumber()) { | ||
$xpath = new \DOMXPath($this->getXml()); | ||
$nodeList = $xpath->query('//LeagueLevel[.="'.$number.'"]'); | ||
$level = new \DOMDocument('1.0', 'UTF-8'); | ||
$level->appendChild($level->importNode($nodeList->item(0)->parentNode, true)); | ||
return new League\Level($level); | ||
} | ||
return null; | ||
} | ||
|
||
/** | ||
* Return iterator of league level objects | ||
* | ||
* @return \PHT\Xml\World\League\Level[] | ||
*/ | ||
public function getLevels() | ||
{ | ||
$xpath = new \DOMXPath($this->getXml()); | ||
$nodeList = $xpath->query('//Staff'); | ||
/** @var \PHT\Xml\World\League\Level[] $data */ | ||
$data = new Utils\XmlIterator($nodeList, '\PHT\Xml\World\League\Level'); | ||
return $data; | ||
} | ||
} |