Introduction
Tournament class is a main class, you will be working with most of the time. It's used to generate brackets, create new games and store all information about the tournament.
Creating a new tournament class
include_once 'vendor/autoload.php';
$tournament = new TournamentGenerator\Tournament('Tournament name');
Setting up a basic tournament
See Examples
Properties
Scope | Name | Type | Default | Description |
---|---|---|---|---|
public | $name |
string |
'' |
Name of the tournament |
private | $categories |
array |
[] |
List of tournament categories |
private | $rounds |
array |
[] |
List of tournament rounds |
private | $teams |
array |
[] |
List of teams |
private | $expectedPlay |
int |
0 |
Time to play one game in minutes |
private | $expectedGameWait |
int |
0 |
Pause between 2 games in minutes |
private | $expectedRoundWait |
int |
0 |
Pause between 2 rounds in minutes |
private | $allowSkip |
bool |
false |
If true , generator will skip unplayed games without throwing exception |
Methods
Method list
Scope | Name | Return | Description |
---|---|---|---|
public | __construct |
$this |
Construct method |
public | __toString |
string |
Returns the name of the tournament |
public | setPlay |
$this |
Sets time to play one game in minutes. |
public | getPlay |
int |
Gets time to play one game in minutes. |
public | setGameWait |
$this |
Sets time to wait between games in minutes. |
public | getGameWait |
int |
Gets time to wait between games in minutes. |
public | setRoundWait |
$this |
Sets time to wait between rounds in minutes. |
public | getRoundWait |
int |
Gets time to wait between rounds in minutes. |
public | setCategoryWait |
$this |
Sets time to wait between category in minutes. |
public | getCategoryWait |
int |
Gets time to wait between category in minutes. |
public | getTournamentTime |
int |
Gets time to play the whole tournament in minutes. |
public | allowSkip |
$this |
Allow skipping of unplayed games while progressing. |
public | disallowSkip |
$this |
Disllow skipping of unplayed games while progressing. |
public | setSkip |
$this |
Sets whether to skip unplayed games while progressing or not. |
public | getSkip |
bool |
Gets whether to skip unplayed games while progressing or not. |
public | addCategory |
$this |
Adds created Category to Tournament. |
public | category |
TournamentGenerator\Category |
Creates and adds new Category to Tournament. |
public | getCategories |
array |
Gets an array of all Categories from Tournament. |
public | addRound |
$this |
Adds created Round to Tournament. |
public | round |
TournamentGenerator\Round |
Creates and adds new Round to Tournament. |
public | getRounds |
array |
Gets an array of all Rounds from Tournament. |
public | addTeam |
$this |
Adds created Team to Tournament. |
public | team |
new TournamentGenerator\Team |
Creates and adds new Team to Tournament. |
public | getTeams |
array |
Gets an array of all Teams from Tournament. |
public | sortTeams |
array |
Sorts all Teams from Tournament and returns them. |
public | getGames |
array |
Gets an array of all Games from Tournament. |
public | splitTeams |
$this |
Splits all Teams from Tournament to given Rounds (or all Rounds from a Tournament). |
public | genGamesSimulate |
array /int |
Generate and simulate all Games from Tournament without real teams (just to export) and returns array of all Games or caculated tournament time. |
public | genGamesSimulateReal |
array /int |
Generate and simulate all Games from Tournament with real teams (just as it was played for real) and returns array of all Games or caculated tournament time. |
TournamentGenerator\Tournament __construct(string $name)
Creates a new Tournament class
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
'' |
Name of the tournament |
Return value
new TournamentGenerator\Tournament();
Code
function __construct(string $name = ''){
$this->name = $name;
}
public string __toString()
Returns tournament name
Return value
string $this->name;
Code
public function __toString() {
return $this->name;
}
public TournamentGenerator\Tournament setPlay(int $play)
Sets time to play one game in minutes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$play |
int |
Time of one game in minutes |
Return value
TournamentGenerator\Tournament $this
Code
public function setPlay(int $play) {
$this->expectedPlay = $play;
return $this;
}
public int getPlay()
Gets time to play one game in minutes.
Return value
int $this->expectedPlay;
Code
public function getPlay() {
return $this->expectedPlay;
}
public TournamentGenerator\Tournament setGameWait(int $wait)
Sets time to wait between games in minutes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$wait |
int |
Pause between two games in minutes |
Return value
TournamentGenerator\Tournament $this
Code
public function setGameWait(int $wait) {
$this->expectedGameWait = $wait;
return $this;
}
public int getGameWait()
Sets time to play one game in minutes.
Return value
int $this->expectedGameWait;
Code
public function getGameWait() {
return $this->expectedGameWait;
}
public TournamentGenerator\Tournament setRoundWait(int $wait)
Sets time to wait between rounds in minutes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$wait |
int |
Pause between rounds in minutes |
Return value
TournamentGenerator\Tournament $this
Code
public function setRoundWait(int $wait) {
$this->expectedRoundWait = $wait;
return $this;
}
public int getRoundWait()
Gets time between rounds in minutes.
Return value
int $this->expectedRoundWait
Code
public function getRoundWait() {
return $this->expectedRoundWait;
}
public TournamentGenerator\Tournament setCategoryWait(int $wait)
Sets time to wait between categories in minutes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$wait |
int |
Pause between categories in minutes |
Return value
TournamentGenerator\Tournament $this
Code
public function setCategoryWait(int $wait) {
$this->expectedCategoryWait = $wait;
return $this;
}
public int getCategoryWait()
Gets time between categories in minutes.
Return value
int $this->expectedCategoryWait
Code
public function getCategoryWait() {
return $this->expectedCategoryWait;
}
public int getTournamentTime()
Gets expected time to play the whole tournament.
Return value
int
Code
public function getTournamentTime(){
$games = count($this->getGames());
return $games*$this->expectedPlay+$games*$this->expectedGameWait+count($this->getRounds())*$this->expectedRoundWait+count($this->getCategories())*$this->expectedCategoryWait;
}
public TournamentGenerator\Tournament allowSkip()
Allow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Tournament $this
Code
public function allowSkip(){
$this->allowSkip = true;
return $this;
}
public TournamentGenerator\Tournament disallowSkip()
Disallow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Tournament $this
Code
public function disallowSkip(){
$this->allowSkip = false;
return $this;
}
public TournamentGenerator\Tournament setSkip(bool $skip)
Sets whether an unplayed games should be skipped while progressing or not.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$skip |
bool |
Skip or not |
Return value
TournamentGenerator\Tournament $this
Code
public function setSkip(bool $skip) {
$this->allowSkip = $skip;
return $this;
}
public bool getSkip()
Gets whether an unplayed games should be skipped while progressing or not.
Return value
bool $this->allowSkip
Code
public function getSkip(bool $skip) {
return $this->allowSkip;
}
public bool addCategory(TournamentGenerator\Category ...$categories)
Adds created Categories to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$categories |
TournamentGenerator\Category |
[] |
One or more instances of Category class |
Return value
TournamentGenerator\Tournament $this
Code
public function addCategory(Category ...$categories){
foreach ($categories as $category) {
if ($category instanceof Category) $this->categories[] = $category;
else throw new \Exception('Trying to add category which is not an instance of the Category class.');
}
return $this;
}
public bool category(string $name)
Creates and adds new Category to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
'' |
Name of the new Category. |
Return value
new TournamentGenerator\Category
Code
public function category(string $name = '') {
$c = new Category($name);
$this->categories[] = $c->setSkip($this->allowSkip);
return $c;
}
public bool getCategories()
Gets an array of all Categories from Tournament.
Return value
array of TournamentGenerator\Category
Code
public function getCategories() {
return $this->categories;
}
public bool addRound(TournamentGenerator\Round ...$rounds)
Adds created Round to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$rounds |
TournamentGenerator\Round |
[] |
One or more instances of Round class. |
Return value
$this
Code
public function addRound(Round ...$rounds) {
foreach ($rounds as $round) {
if ($round instanceof Round) $this->rounds[] = $round;
else throw new \Exception('Trying to add round which is not an instance of the Round class.');
}
return $this;
}
public bool round(string $name)
Creates and adds new Round to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
'' |
Name of the new Round. |
Return value
new TournamentGenerator\Round
Code
public function round(string $name = '') {
$r = new Round($name);
$this->rounds[] = $r->setSkip($this->allowSkip);
return $r;
}
public bool getRounds()
Gets an array of all Rounds from Tournament.
Return value
array of TournamentGenerator\Round
Code
public function getRounds() {
if (count($this->categories) > 0) {
$rounds = [];
foreach ($this->categories as $category) {
$rounds = array_merge($rounds, $category->getRounds());
}
return $rounds;
}
return $this->rounds;
}
public bool addTeam(TournamentGenerator\Team ...$teams)
Adds created Team to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$teams |
TournamentGenerator\Team |
[] |
One or more instances of Team class. |
Return value
$this
Code
public function addTeam(Team ...$teams) {
foreach ($teams as $team) {
if ($team instanceof Team) {
$this->teams[] = $team;
continue;
}
elseif (gettype($team) === 'array') {
$teams = array_merge($teams, array_filter($team, function($a) {
return ($a instanceof Team);
}));
continue;
}
throw new \Exception('Trying to add team which is not an instance of Team class');
}
return $this;
}
public bool team(string $name)
Creates and adds new Team to Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
'' |
Name of the new Team. |
Return value
new TournamentGenerator\Team
Code
public function team(string $name = '') {
$t = new Team($name);
$this->teams[] = $t;
return $t;
}
public bool getTeams(bool $ordered = false, $ordering = POINTS)
Gets an array of all Teams from Tournament.
If passed true
as the first argument, teams will be ordered.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$ordered |
bool |
false |
If teams should be ordered. |
$ordering |
POINTS / SCORE |
POITS |
What to order the teams by. |
Return value
array of TournamentGenerator\Team
Code
public function getTeams(bool $ordered = false, $ordering = \POINTS) {
if (count($this->teams) === 0) {
$teams = [];
foreach ($this->categories as $category) {
$teams = array_merge($teams, $category->getTeams());
}
foreach ($this->rounds as $round) {
$teams = array_merge($teams, $round->getTeams());
}
$this->teams = $teams;
}
if ($ordered) $this->sortTeams($ordering);
return $this->teams;
}
public bool sortTeams($ordering = POINTS)
Sorts all Teams from Tournament and returns them.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$ordering |
POINTS / SCORE |
POITS |
What to order the teams by. |
Return value
array of TournamentGenerator\Team
Code
public function sortTeams($ordering = \POINTS) {
$teams = [];
for ($i = count($this->rounds)-1; $i >= 0; $i--) {
$rTeams = array_filter($this->rounds[$i]->getTeams(true, $ordering), function($a) use ($teams) { return !in_array($a, $teams); });
$teams = array_merge($teams, $rTeams);
}
$this->teams = $teams;
return $this->teams;
}
public bool getGames()
Gets an array of all Games from Tournament.
Return value
array of TournamentGenerator\Game
Code
public function getGames() {
$games = [];
foreach ($this->getRounds() as $round) {
$games = array_merge($games, $round->getGames());
}
return $games;
}
public bool splitTeams(TournamentGenerator\Round ...$wheres)
Split all Teams from Tournament into given Rounds. If no argument is given, method will split into all available Rounds in Tournament.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$wheres |
TournamentGenerator\Round |
[] |
One or more instances of Round class to split the teams into. |
Return value
$this
Code
public function splitTeams(Round ...$wheres) {
if (count($wheres) === 0) $wheres = $this->getRounds();
foreach ($wheres as $key => $value) {
if (gettype($value) === 'array') {
unset($wheres[$key]);
$wheres = array_merge($wheres, $value);
continue;
}
}
$teams = $this->getTeams();
shuffle($teams);
while (count($teams) > 0) {
foreach ($wheres as $where) {
if (count($teams) > 0) $where->addTeam(array_shift($teams));
}
}
foreach ($wheres as $where) {
$where->splitTeams();
}
return $this;
}
public bool genGamesSimulate(bool $returnTime)
Generate and simulate all Games from Tournament without real teams (just to export) and returns array of all Games or caculated tournament time. It uses BlankTeam class for progressing.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$returnTime |
bool |
false |
If true, returns calculated tournament time in minutes. |
Return value
If $returnTime
parameter empty or false
array of TournamentGenerator\Games
If $returnTime
parameter true
int $this->getTournamentTime()
Code
public function genGamesSimulate(bool $returnTime = false) {
$games = Utilis\Simulator::simulateTournament($this);
if ($returnTime) return $this->getTournamentTime();
return $games;
}
public bool genGamesSimulateReal(bool $returnTime)
Generate and simulate all Games from Tournament with real teams (just as it was played for real) and returns array of all Games or caculated tournament time.
Could be used for testing and demonstration purposes.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$returnTime |
bool |
false |
If true, returns calculated tournament time in minutes. |
Return value
If $returnTime
parameter empty or false
array of TournamentGenerator\Games
If $returnTime
parameter true
int $this->getTournamentTime()
Code
public function genGamesSimulateReal(bool $returnTime = false) {
$games = Utilis\Simulator::simulateTournamentReal($this);
if ($returnTime) return $this->getTournamentTime();
return $games;
}