Introduction
Group is the main class for storing and generating games.
Creating a new group class
Basic construction
include_once 'vendor/autoload.php';
$round = new TournamentGenerator\Round('Round name');
$group = new TournamentGenerator\Group('Group name');
$round->addGroup($group);
From a group class
Recomended
This automatically assigns the group to the group.
include_once 'vendor/autoload.php';
$round = new TournamentGenerator\Round('Round name');
$group = $round->group('Group name');
Properties
Scope | Name | Type | Default | Description |
---|---|---|---|---|
protected | $name |
string |
'' |
Name of the group |
protected | $id |
string|int |
null |
Id of the group |
private | $generator |
Utilis\Generator |
null |
Generator class to generate all games |
private | $games |
array |
[] |
List of group games |
private | $teams |
array |
[] |
List of teams |
private | $progressed |
array |
[] |
List of all progressed teams |
private | $ordering |
Constants::POINTS|SCORE |
Constants::POINTS |
What to order teams by |
private | $progressions |
array |
[] |
List of all progressions to progress teams by |
private | $winPoints |
3 |
int |
Points acquired from winning |
private | $drawPoints |
1 |
int |
Points acquired from drawing |
private | $lostPoints |
0 |
int |
Points acquired from losing |
private | $secondPoints |
2 |
int |
Points acquired from being second (at least 3 teams in one game) |
private | $thirdPoints |
1 |
int |
Points acquired from being third (at least 4 teams in one game) |
private | $progressPoints |
50 |
int |
Points acquired from progressing |
private | $order |
0 |
int |
Index to order groups by |
Methods
Method list
Scope | Name | Return | Description |
---|---|---|---|
public | __construct |
$this |
Construct method |
public | __toString |
string |
Returns the name of the group |
public | setName |
$this |
Sets name of the group. |
public | getName |
string |
Gets name of the group. |
public | setId |
$this |
Sets id of the group. |
public | getId |
string|int |
Gets id of the group. |
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 | addTeam |
$this |
Adds created Team to Group. |
public | team |
new TournamentGenerator\Team |
Creates and adds new Team to Group. |
public | getTeams |
array |
Gets an array of all Teams from Group. |
public | sortTeams |
array |
Sorts all Teams from Group and returns them. |
public | setWinPoints |
$this |
Sets points acquired from winning. |
public | getWinPoints |
int |
Gets points acquired from winning. |
public | setDrawPoints |
$this |
Sets points acquired from drawing. |
public | getDrawPoints |
int |
Gets points acquired from drawing. |
public | setLostPoints |
$this |
Sets points acquired from losing. |
public | getLostPoints |
int |
Gets points acquired from losing. |
public | setSecondPoints |
$this |
Sets points acquired from being second (at least 3 teams in one game). |
public | getSecondPoints |
int |
Gets points acquired from being second (at least 3 teams in one game). |
public | setThirdPoints |
$this |
Sets points acquired from being third (at least 4 teams in one game). |
public | getThirdPoints |
int |
Gets points acquired from being third (at least 4 teams in one game). |
public | setProgressPoints |
$this |
Sets points acquired from progressing. |
public | getProgressPoints |
int |
Gets points acquired from progressing. |
public | setMaxSize |
$this |
Sets maximum amount of teams in group for generating (Only for ROUND_SPLIT). |
public | getMaxSize |
int |
Gets maximum amount of teams in group for generating (Only for ROUND_SPLIT). |
public | setType |
$this |
Sets type of the group for generating |
public | getType |
string |
Gets type of the group for generating |
public | setOrder |
$this |
Sets index to order the groups by |
public | getOrder |
string |
Gets index to order the groups by |
public | setOrdering |
$this |
Sets ordering of the teams in a group |
public | getOrdering |
string |
Gets ordering of the teams in a group |
public | setInGame |
$this |
Sets the number of teams in one game (2-4) |
public | getInGame |
int |
Gets the number of teams in one game (2-4) |
public | addProgression |
$this |
Adds created Progression to group |
public | progression |
Progression |
Creates and adds a new Progression to group |
public | progress |
$this |
Progresses all teams according to all created Progressions |
public | addProgressed |
$this |
Adds Teams to progressed list. |
public | isProgressed |
bool |
Check if Team have been progressed from this group |
public | genGames |
array |
Generates all the Games of the Group. |
public | addGame |
$this |
Adds created Game to group |
public | game |
Game |
Creates and adds a new Game to group |
public | getGames |
array |
Gets an array of all Games from Group. |
public | orderGames |
array |
Orders all Games so the Teams doesn't play that many Games after one other |
public | simulate |
$this |
Simulate all Games from this Group just like it was really played. |
public | resetGames |
$this |
Resets the results of all Games in Group. |
public | isPlayed |
bool |
Returns true if all Games have been played. |
Group __construct(string $name, string|int $id = null)
Creates a new Group class
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
'' |
Name of the group |
$id |
string|int |
'' |
Name of the group |
Return value
new TournamentGenerator\Group();
Code
public function __construct(string $name = '', $id = null) {
$this->setName($name);
$this->generator = new Utilis\Generator($this);
$this->setId(isset($id) ? $id : uniqid());
}
public string __toString()
Returns group name
Return value
string $this->name;
Code
public function __toString() {
return $this->name;
}
public Group setName(string $name)
Sets the name of the group.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$name |
string |
Name of the group |
Return value
TournamentGenerator\Group $this
Code
public function setName(string $name) {
$this->name = $name;
return $this;
}
public string getName()
Gets the name of the group.
Return value
string $this->name;
Code
public function getName() {
return $this->name;
}
public Group setId(string|int $id)
Sets the name of the group.
Parameters
Id | Type | Default | Description |
---|---|---|---|
$id |
string|int |
Id of the group |
Return value
TournamentGenerator\Group $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;
}
public string|int getId()
Gets the name of the group.
Return value
string|int $this->id;
Code
public function getId() {
return $this->id;
}
public Group allowSkip()
Allow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Group $this
Code
public function allowSkip(){
$this->allowSkip = true;
return $this;
}
public Group disallowSkip()
Disallow skipping of unplayed games while progressing.
Return value
TournamentGenerator\Group $this
Code
public function disallowSkip(){
$this->allowSkip = false;
return $this;
}
public Group 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\Group $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 Group addTeam(TournamentGenerator\Team ...$teams)
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;
}
public Team team(string $name)
Creates and adds new Team to Group.
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;
}
public array getTeams(bool $ordered = false, $ordering = POINTS)
Gets an array of all Teams from Group.
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;
if ($ordered) return $this->sortTeams($ordering, $filters);
// APPLY FILTERS
$filter = new Filter([$this], $filters);
$filter->filter($teams);
return $teams;
}
public array sortTeams($ordering = POINTS)
Sorts all Teams from Group 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 = []) {
if (!isset($ordering)) $ordering = $this->ordering;
$this->teams = Utilis\Sorter\Teams::sortGroup($this->teams, $this, $ordering);
return $this->getTeams(false, null, $filters);
}
public Group setWinPoints(int $points)
Sets points acquired from winning.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setWinPoints(int $points) {
$this->winPoints = $points;
return $this;
}
public int getWinPoints()
Gets points acquired from winning.
Return value
int $this->winPoints
Code
public function getWinPoints() {
return $this->winPoints;
}
public Group setDrawPoints(int $points)
Sets points acquired from drawing.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setDrawPoints(int $points) {
$this->drawPoints = $points;
return $this;
}
public int getDrawPoints()
Gets points acquired from drawing.
Return value
int $this->drawPoints
Code
public function getDrawPoints() {
return $this->drawPoints;
}
public Group setLostPoints(int $points)
Sets points acquired from losing.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setLostPoints(int $points) {
$this->lostPoints = $points;
return $this;
}
public int getLostPoints()
Gets points acquired from losing.
Return value
int $this->lostPoints
Code
public function getLostPoints() {
return $this->lostPoints;
}
public Group setSecondPoints(int $points)
Sets points acquired from being second (at least 3 teams in one game).
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setSecondPoints(int $points) {
$this->secondPoints = $points;
return $this;
}
public int getSecondPoints()
Gets points acquired from being second (at least 3 teams in one game).
Return value
int $this->secondPoints
Code
public function getSecondPoints() {
return $this->secondPoints;
}
public Group setThirdPoints(int $points)
Sets points acquired from being third (at least 4 teams in one game).
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setThirdPoints(int $points) {
$this->thirdPoints = $points;
return $this;
}
public int getThirdPoints()
Gets points acquired from being third (at least 4 teams in one game).
Return value
int $this->thirdPoints
Code
public function getThirdPoints() {
return $this->thirdPoints;
}
public Group setProgressPoints(int $points)
Sets points acquired from progressing.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$points |
int |
Get all points |
Return value
TournamentGenerator\Group $this
Code
public function setProgressPoints(int $points) {
$this->progressPoints = $points;
return $this;
}
public int getProgressPoints()
Gets points acquired from progressing.
Return value
int $this->progressPoints
Code
public function getProgressPoints() {
return $this->progressPoints;
}
public Group setMaxSize(int $size)
Sets maximum amount of teams in group for generating (Only for ROUND_SPLIT).
Parameters
Name | Type | Default | Description |
---|---|---|---|
$size |
int |
Max size of the group |
Return value
TournamentGenerator\Group $this
Code
public function setMaxSize(int $size) {
$this->generator->setMaxSize($size);
return $this;
}
public int getMaxSize()
Gets maximum amount of teams in group for generating (Only for ROUND_SPLIT).
Return value
int $this->generator->maxSize
Code
public function getMaxSize() {
return $this->generator->getMaxSize();
}
public Group setType(string $type)
Sets type of the group for generating
Parameters
Name | Type | Default | Description |
---|---|---|---|
$type |
string |
Type of the group |
Return value
TournamentGenerator\Group $this
Code
public function setType(string $type) {
$this->generator->setType($type);
return $this;
}
public string getType()
Gets type of the group for generating
Return value
int $this->generator->type
Code
public function getType() {
return $this->generator->getType();
}
public Group setOrder(int $order)
Sets index to order the groups by
Parameters
Name | Type | Default | Description |
---|---|---|---|
$order |
int |
Group index |
Return value
TournamentGenerator\Group $this
Code
public function setOrder(int $order) {
$this->order = $order;
return $this;
}
public string getOrder()
Gets index to order the groups by
Return value
int $this->order
Code
public function getOrder() {
return $this->order;
}
public Group setOrdering(string $ordering)
Sets ordering of the teams in a group
Parameters
Name | Type | Default | Description |
---|---|---|---|
$ordering |
string |
Constants::POINTS |
Ordering |
Return value
TournamentGenerator\Group $this
Code
public function setOrdering(int $ordering) {
if (!in_array($ordering, \TournamentGenerator\Constants::OrderingTypes)) throw new \Exception('Unknown group ordering: '.$ordering);
$this->ordering = $ordering;
return $this;
}
public string getOrdering()
Gets ordering of the teams in a group
Return value
string $this->ordering
Code
public function getOrdering() {
return $this->ordering;
}
public Group setInGame(int $inGame)
Sets the number of teams in one game
Parameters
Name | Type | Default | Description |
---|---|---|---|
$inGame |
int |
Number of teams in one game |
Return value
TournamentGenerator\Group $this
Code
public function setInGame(int $inGame) {
$this->generator->setInGame($inGame);
return $this;
}
public int getInGame()
Gets the number of teams in one game
Return value
int $this->generator->inGame;
Code
public function getInGame() {
return $this->generator->getInGame();
}
public Group addProgression(Progression $progression)
Adds a Progression to a Group.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$progression |
Progression |
An instantiated Progression to add |
Return value
$this
Code
public function addProgression(bool $blank = false){
$this->progressions[] = $progression;
return $this;
}
public Group progression(Group $to, int $start = 0, int $len = null)
Creates and adds new Progression to a Group.
See: Using progressions example
Parameters
Name | Type | Default | Description |
---|---|---|---|
$to |
Group |
An instantiated Group to progress the teams into | |
$start |
int |
0 |
Offset to start picking teams (if negative, the start of the progressed portion is at that offset from the end of the teams array) |
$len |
int |
null |
How many teams to progress from the offset |
Return value
$this
Code
public function progression(Group $to, int $start = 0, int $len = null) {
$p = new Progression($this, $to, $start, $len);
$this->progressions[] = $p;
return $p;
}
public Group progress(bool $blank = false)
Progresses all the Teams.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$blank |
bool |
false |
Whether to progress teams as blank |
Return value
$this
Code
public function progress(bool $blank = false){
foreach ($this->progressions as $progression) {
$progression->progress($blank);
}
return $this;
}
public Group addProgressed(...$teams)
Marks Teams as progressed.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$teams |
array|Team |
A list of teams which have already been progressed |
Return value
$this
Code
public function addProgressed(bool $blank = false){
$this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($teams, function($a){return $a instanceof Team;})));
foreach (array_filter($teams, function($a){return is_array($a);}) as $team) {
$this->progressed = array_merge($this->progressed, array_map(function ($a) {return $a->getId();}, array_filter($team, function($a) {
return ($a instanceof Team);
})));
}
return $this;
}
public bool isProgressed(Team $team)
Checks if Team have already been progressed.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$team |
Team |
Teams to check |
Return value
bool
Code
public function isProgressed(Team $team) {
return in_array($team->getId(), $this->progressed);
}
public array genGames()
Generates all Games from Group.
Return value
array of TournamentGenerator\Game
Code
public function genGames() {
$this->generator->genGames();
return $this->games;
}
public Game game(array $teams = [])
Creates and adds a new Game to Group.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$teams |
array |
[] |
List of Teams playing the game |
Return value
new TournamentGenerator\Game
Code
public function game(array $teams = []) {
$g = new Game($teams, $this);
$this->games[] = $g;
return $g;
}
public Group addGame(...$games)
Parameters
Name | Type | Default | Description |
---|---|---|---|
$games |
array|Game |
Games to add |
Return value
$this
Code
public function addGame(...$games){
$this->games = array_merge($this->games, array_filter($games, function($a){ return ($a instanceof Game); }));
foreach (array_filter($games, function($a){return is_array($a);}) as $key => $game) {
$this->games = array_merge($this->games, array_filter($game, function($a){ return ($a instanceof Game); }));
}
return $this;
}
public array getGames()
Gets an array of all Games from Group.
Return value
array of TournamentGenerator\Game
Code
public function getGames() {
return $this->games;
}
public array orderGames()
Orders all Games so the Teams doesn't play that many Games after one other.
Return value
array of TournamentGenerator\Game
Code
public function orderGames() {
if (count($this->games) <= 4) return $this->games;
$this->games = $this->generator->orderGames();
return $this->games;
}
public array simulate(array $filters = [], bool $reset = true)
Simulate all Games from this Group just like it was really played.
Parameters
Name | Type | Default | Description |
---|---|---|---|
$filters |
array |
[] |
Array of TeamFilters to filter the teams |
$reset |
bool |
false |
If true only return the generated games and not store them |
Return value
array of TournamentGenerator\Game
Code
public function simulate(array $filters = [], bool $reset = true) {
return Utilis\Simulator::simulateGroup($this, $filters, $reset);
}
public Group resetGames()
Resets the results of all Games in Group.
Return value
$this
Code
public function resetGames() {
foreach ($this->getGames() as $game) {
$game->resetResults();
}
return $this;
}
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->games as $game) {
if (!$game->isPlayed()) return false;
}
return true;
}