improved path methods

This commit is contained in:
Steffen Schröder 2014-05-09 13:00:13 +02:00
parent 1e93aafd63
commit bd2a00ef46

View File

@ -153,50 +153,45 @@ class Player {
* @return string * @return string
*/ */
public function getProvince() { public function getProvince() {
$pathParts = explode('|', $this->path); return $this->getPathPart(3);
if (isset($pathParts[3])) {
return $pathParts[3];
}
return $this->getCountry();
} }
/** /**
* Get country * Get Country
* *
* @return string * @return string
*/ */
public function getCountry() { public function getCountry() {
$pathParts = explode('|', $this->path); return $this->getPathPart(2);
if (isset($pathParts[2])) {
return $pathParts[2];
}
if (isset($pathParts[1])) {
return $pathParts[1];
}
if (isset($pathParts[0])) {
return $pathParts[0];
}
return $this->path;
} }
/** /**
* Get continent * Get Continent
* *
* @return string * @return string
*/ */
public function getContinent() { public function getContinent() {
$pathParts = explode('|', $this->path); return $this->getPathPart(1);
if (isset($pathParts[1])) { }
return $pathParts[1];
/**
* Get the specified Part of the Path
*
* @param int $partNumber
* @return string
*/
public function getPathPart($partNumber) {
$pathParts = explode('|', $this->path);
for ($partIndex = $partNumber; $partIndex >= 0; $partIndex--) {
if (isset($pathParts[$partIndex])) {
return $pathParts[$partIndex];
} }
if (isset($pathParts[0])) {
return $pathParts[0];
} }
return $this->path; return $this->path;
} }
/** /**
* Updates the Flags of the Player * Update the Flags of the Player
* *
* @param $flags * @param $flags
*/ */
@ -214,7 +209,7 @@ class Player {
} }
/** /**
* Updates the Spectator Status of the player * Update the Spectator Status of the player
* *
* @param $spectatorStatus * @param $spectatorStatus
*/ */