Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Moving order of teams to TeamTable, as well as small tables
- Loading branch information
1 parent
c3329c5
commit 069c944
Showing
3 changed files
with
90 additions
and
40 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
<?php | ||
require_once('Team.php'); | ||
|
||
class TeamTable { | ||
|
||
private $teamSymbols = []; | ||
private $teams = []; | ||
|
||
public function __construct(array $teamSymbols = [], array $teams = []) { | ||
$this->teamSymbols = $teamSymbols; | ||
$this->teams = $teams; | ||
} | ||
|
||
public function addTeam(Team $team) { | ||
$this->teamSymbols[] = $team->symbol; | ||
$this->teams[] = $team; | ||
} | ||
|
||
public function getTeamSymbols() { | ||
return $this->teamSymbols; | ||
} | ||
|
||
public function getTeams() { | ||
return $this->teams; | ||
} | ||
|
||
public function getTeamBySymbol(string $symbol): Team { | ||
for($i = 0; $i < count($this->teamSymbols); ++$i) { | ||
if($this->teamSymbols[$i] == $symbol) { | ||
return $this->teams[$i]; | ||
} | ||
} | ||
|
||
return null; | ||
} | ||
|
||
public function swapOrder($i, $j) { | ||
list($this->teamSymbols[$i], $this->teamSymbols[$j]) = [$this->teamSymbols[$j], $this->teamSymbols[$i]]; | ||
list($this->teams[$i], $this->teams[$j]) = [$this->teams[$j], $this->teams[$i]]; | ||
} | ||
|
||
public function reorderBySymbols(array $symbols) { | ||
$this->teamSymbols = $symbols; | ||
$newTeams = []; | ||
|
||
foreach($symbols as $symbol) { | ||
$newTeams[] = $this->getTeamBySymbol($symbol); | ||
} | ||
|
||
$this->teams[] = $newTeams; | ||
} | ||
} |
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