DownloadIntroduction
Round stores all groups that should play roughly at the same time.
Creating a new round class
Basic construction
include_once 'vendor/autoload.php';
$tournament = new TournamentGenerator\Tournament('Tournament name');
$round = new TournamentGenerator\Round('Round name');
$tournament->addRound($round);
From a round class
Recomended
This automatically assigns the round to the round.
include_once 'vendor/autoload.php';
$tournament = new TournamentGenerator\Tournament('Tournament name');
$round = $tournament->round('Round name');
Tournament class can be also replaced by a Category
include_once 'vendor/autoload.php';
$tournament = new TournamentGenerator\Tournament('Tournament name');
$category = $tournament->category('Category name');
$round = $category->round('Round name');
Properties
| Scope | Name | Type | Default | Description |
| :---: | :--: | :--: | :-----: | :---------: |
| protected | $name | string | '' | Name of the round |
| protected | $id | string|int | null | Id of the round |
| private | $groups | array | [] | List of round groups |
| private | $games | array | [] | List of round games |
| private | $teams | array | [] | List of teams |
| 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 round |
| public | setName | $this | Sets name of the round. |
| public | getName | string | Gets name of the round. |
| public | setId | $this | Sets id of the round. |
| public | getId | string|int | Gets id of the round. |
| 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 | addGroup | $this | Adds created Group to Round. |
| public | group | TournamentGenerator\Round | Creates and adds new Group to Round. |
| public | getGroups | array | Gets an array of all Groups from Round. |
| public | getGroupsIds | array | Gets an array of all Group ids from Round. |
| public | orderGroups | array | Sorts all Groups from Round. |
| public | addTeam | $this | Adds created Team to Round. |
| public | team | new TournamentGenerator\Team | Creates and adds new Team to Round. |
| public | getTeams | array | Gets an array of all Teams from Round. |
| public | sortTeams | array | Sorts all Teams from Round and returns them. |
| public | genGames | array | Generates all the Games of the Round. |
| public | getGames | array | Gets an array of all Games from Round. |
| public | isPlayed | bool | Returns true if all Games have been played. |
| public | splitTeams | $this | Splits all Teams from Round to given Groups (or all Groups from a Round). |
| public | progress | $this | Progresses all the Teams. |
| public | simulate | $this | Simulate all Games from this Round just like it was really played. |
| public | resetGames | $this | Resets the results of all Games in Round. |
<a name="construct" id="construct"></a>
Round \_\_construct(string $name, string|int $id = null)
Creates a new Round class
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $name | string | '' | Name of the round |
| $id | string|int | '' | Name of the round |
Return value
new TournamentGenerator\Round();
Code
public function __construct(string $name = '', $id = null) {
$this->setName($name);
$this->setId(isset($id) ? $id : uniqid());
}
<a name="toString" id="toString"></a>
public string \_\_toString()
Returns round name
Return value
string $this->name;
Code
public function __toString() {
return $this->name;
}
<a name="setName" id="setName"></a>
public Round setName(string $name)
Sets the name of the round.
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $name | string | | Name of the round |
Return value
TournamentGenerator\Round $this
Code
public function setName(string $name) {
$this->name = $name;
return $this;
}
<a name="getName" id="getName"></a>
public string getName()
Gets the name of the round.
Return value
string $this->name;
Code
public function getName() {
return $this->name;
}
<a name="setName" id="setId"></a>
public Round setId(string|int $id)
Sets the name of the round.
Parameters
| Id | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $id | string|int | | Id of the round |
Return value
TournamentGenerator\Round $this
Code
public function setId($id) {
if (!is_string($id) && !is_int($id)) {
$this->id = uniqid();
throw new \Exception('Unsupported id type ('.gettype($id).') - expected type of string or int');
}
$this->id = $id;
}
<a name="getId" id="getId"></a>
public string|int getId()
Gets the name of the round.
Return value
string|int $this->id;
Code
public function getId() {
return $this->id;
}
<a name="allowSkip" id="allowSkip"></a>
public Round allowSkip()
Allow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Round $this
Code
public function allowSkip(){
$this->allowSkip = true;
return $this;
}
<a name="disallowSkip" id="disallowSkip"></a>
public Round disallowSkip()
Disallow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Round $this
Code
public function disallowSkip(){
$this->allowSkip = false;
return $this;
}
<a name="setSkip" id="setSkip"></a>
public Round 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\Round $this
Code
public function setSkip(bool $skip) {
$this->allowSkip = $skip;
return $this;
}
<a name="getSkip" id="getSkip"></a>
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;
}
<a name="addGroup" id="addGroup"></a>
public Round addGroup(TournamentGenerator\\Group ...$groups)
Adds created Group to Round.
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $groups | TournamentGenerator\Group | [] | One or more instances of Group class. |
Return value
$this
Code
public function addGroup(Group ...$groups){
foreach ($groups as $group) {
$this->groups[] = $group;
}
return $this;
}
<a name="group" id="group"></a>
public Group group(string $name)
Creates and adds new Group to Round.
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $name | string | '' | Name of the new Group. |
| $id | string|int | null | Id of the new Group. |
Return value
new TournamentGenerator\Group
Code
public function group(string $name, $id = null) {
$g = new Group($name, $id);
$this->groups[] = $g->setSkip($this->allowSkip);
return $g;
}
<a name="getGroups" id="getGroups"></a>
public array getGroups()
Gets an array of all Groups from Round.
Return value
array of TournamentGenerator\Group
Code
public function getGroups(){
$this->orderGroups();
return $this->groups;
}
<a name="getGroupsIds" id="getGroupsIds"></a>
public array getGroupsIds()
Gets an array of all Group ids from Round.
Return value
array of TournamentGenerator\Group::$id
Code
public function getGroupsIds() {
$this->orderGroups();
return array_map(function($a) { return $a->getId(); }, $this->groups);
}
<a name="orderGroups" id="orderGroups"></a>
public array orderGroups()
Sorts all Groups from Round.
Return value
array of TournamentGenerator\Group
Code
public function orderGroups() {
usort($this->groups, function($a, $b){
return $a->getOrder() - $b->getOrder();
});
return $this->groups;
}
<a name="addTeam" id="addTeam"></a>
public Round addTeam(TournamentGenerator\\Team ...$teams)
Adds created Team to Round.
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) {
$this->teams[] = $team;
}
return $this;
}
<a name="team" id="team"></a>
public Team team(string $name)
Creates and adds new Team to Round.
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $name | string | '' | Name of the new Team. |
| $id | string|int | null | Id of the new Team. |
Return value
new TournamentGenerator\Team
Code
public function team(string $name = '', $id = null) {
$t = new Team($name, $id);
$this->teams[] = $t;
return $t;
}
<a name="getTeams" id="getTeams"></a>
public array getTeams(bool $ordered = false, $ordering = POINTS)
Gets an array of all Teams from Round.
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 | \TournamentGenerator\Constants::POINTS | \TournamentGenerator\Constants::SCORE | \TournamentGenerator\Constants::POINTS | What to order the teams by. |
| $filters | array | [] | Filters to filter the teams. |
Return value
array of TournamentGenerator\Team
Code
public function getTeams(bool $ordered = false, $ordering = \TournamentGenerator\Constants::POINTS, array $filters = []) {
$teams = $this->teams;
foreach ($this->rounds as $round) {
$teams = \array_merge($teams, $round->getTeams());
}
$teams = \array_unique($teams);
$this->teams = $teams;
if ($ordered) $teams = $this->sortTeams($ordering);
// APPLY FILTERS
$filter = new Filter($this->getGroups(), $filters);
$filter->filter($teams);
return $teams;
}
<a name="sortTeams" id="sortTeams"></a>
public array sortTeams($ordering = POINTS)
Sorts all Teams from Round and returns them.
Parameters
| Name | Type | Default | Description |
| :--: | :--: | :-----: | :---------: |
| $ordering | \TournamentGenerator\Constants::POINTS | \TournamentGenerator\Constants::SCORE | \TournamentGenerator\Constants::POINTS | What to order the teams by. |
| $filters | array | [] | Filters to filter the teams. |
Return value
array of TournamentGenerator\Team
Code
public function sortTeams($ordering = \TournamentGenerator\Constants::POINTS, array $filters = []) {
$teams = Utilis\Sorter\Teams::sortRound($this->teams, $this, $ordering);
// APPLY FILTERS
$filter = new Filter($this->getGroups(), $filters);
$filter->filter($teams);
return $teams;
}
<a name="genGames" id="genGames"></a>
public array genGames()
Generates all Games from Round.
Return value
array of TournamentGenerator\Game
Code
public function genGames(){
foreach ($this->groups as $group) {
$group->genGames();
$this->games = array_merge($this->games, $group->orderGames());
}
return $this->games;
}
<a name="getGames" id="getGames"></a>
public array getGames()
Gets an array of all Games from Round.
Return value
array of TournamentGenerator\Game
Code
public function getGames() {
return $this->games;
}
<a name="isPlayed" id="isPlayed"></a>
public bool isPlayed()
Returns true if all Games have been played.
Return value
bool
Code
public function isPlayed(){
if (count($this->games) === 0) return false;
foreach ($this->groups as $group) {
if (!$group->isPlayed()) return false;
}
return true;
}
<a name="splitTeams" id="splitTeams"></a>
public bool splitTeams(TournamentGenerator\\Round ...$wheres)
Split all Teams from Round into given Rounds. If no argument is given, method will split into all available Rounds in Round.
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(Group ...$groups) {
if (count($groups) === 0) $groups = $this->getGroups();
$teams = $this->getTeams();
shuffle($teams);
while (count($teams) > 0) {
foreach ($groups as $group) {
if (count($teams) > 0) $group->addTeam(array_shift($teams));
}
}
return $this;
}
<a name="progress" id="progress"></a>
public Round progress(bool $returnTime)
Progresses all the Teams.
Return value
$this
Code
public function progress(bool $blank = false){
foreach ($this->groups as $group) {
$group->progress($blank);
}
return $this;
}
<a name="simulate" id="simulate"></a>
public Round simulate(bool $returnTime)
Simulate all Games from this Round just like it was really played.
Return value
$this
Code
public function simulate() {
Utilis\Simulator::simulateRound($this);
return $this;
}
<a name="resetGames" id="resetGames"></a>
public Round resetGames(bool $returnTime)
Resets the results of all Games in Round.
Return value
$this
Code
public function resetGames() {
foreach ($this->groups as $group) {
$group->resetGames();
}
return $this;
}
|