Skip to content

Commit

Permalink
Retrieve all nth youth team for secondary and hti teams
Browse files Browse the repository at this point in the history
  • Loading branch information
jetwitaussi committed Mar 14, 2019
1 parent df58490 commit 41cca7a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 7 deletions.
2 changes: 1 addition & 1 deletion PHT/Config/Team.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ class Team
public $number = 1;

/**
* Set to id to get user's team, combine with primary or secondary
* Set to get user's team, combine with primary, secondary or international
* @var integer
*/
public $userId = null;
Expand Down
37 changes: 31 additions & 6 deletions PHT/PHT.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,12 @@ public function getYouthTeam(Config\Team $team = null)
throw new Exception\InvalidArgumentException('Parameter $team should be instanceof \PHT\Config\Team');
}

if ($team->primary !== null) {
if ($team->primary === true) {
return $this->getPrimaryYouthTeam($team->userId);
} elseif ($team->secondary !== null) {
return $this->getSecondaryYouthTeam($team->userId);
} elseif ($team->secondary === true) {
return $this->getSecondaryYouthTeam($team->userId, $team->number);
} elseif ($team->international === true) {
return $this->getInternationalYouthTeam($team->userId, $team->number);
} else {
return $this->findYouthTeam($team->id, $team->userId);
}
Expand Down Expand Up @@ -205,16 +207,39 @@ protected function getSpecificSeniorTeam($type, $userId = null, $nth = 1)
*/
protected function getPrimaryYouthTeam($userId = null)
{
return $this->findYouthTeam($this->getPrimarySeniorTeam($userId)->getYouthTeamId());
$team = $this->getPrimarySeniorTeam($userId);
if ($team instanceof Xml\Team\Senior) {
return $this->findYouthTeam($team->getYouthTeamId());
}
return null;
}

/**
* @param integer $userId
* @param integer $nth
* @return \PHT\Xml\Team\Youth
*/
protected function getSecondaryYouthTeam($userId = null, $nth = 1)
{
$team = $this->getSecondarySeniorTeam($userId, $nth);
if ($team instanceof Xml\Team\Senior) {
return $this->findYouthTeam($team->getYouthTeamId());
}
return null;
}

/**
* @param integer $userId
* @param integer $nth
* @return \PHT\Xml\Team\Youth
*/
protected function getSecondaryYouthTeam($userId = null)
protected function getInternationalYouthTeam($userId = null, $nth = 1)
{
return $this->findYouthTeam($this->getSecondarySeniorTeam($userId)->getYouthTeamId());
$team = $this->getInternationalSeniorTeam($userId, $nth);
if ($team instanceof Xml\Team\Senior) {
return $this->findYouthTeam($team->getYouthTeamId());
}
return null;
}

/**
Expand Down

0 comments on commit 41cca7a

Please sign in to comment.