Tournament Generator

Group extends HierarchyBase
in package
implements WithGeneratorSetters, WithSkipSetters, WithTeams, WithGames Uses WithTeams, WithGames

Tournament group

Group is a collection of teams that play against each other. It defaults to Round-robin group where one team plays against every other team in a group. Group can also be setup in such a way that teams play only one game against one other team (randomly selected). Teams from groups can be progressed (moved) to other groups.

Tags
author

Tomáš Vojík vojik@wboy.cz

since
0.1

Interfaces, Classes and Traits

WithGeneratorSetters
Interface for objects that can generate games
WithSkipSetters
Interface that allows for setting skipping of not-playable games
WithTeams
Functions for objects that contain teams
WithGames
Interface for objects that contain games

Table of Contents

$container  : HierarchyContainer
$drawPoints  : int
$games  : GameContainer
$generator  : Generator
$id  : string|int
$lostPoints  : int
$name  : string
$order  : int
$ordering  : string
$progressed  : array<string|int, mixed>
$progressions  : array<string|int, mixed>
$progressPoints  : int
$secondPoints  : int
$teams  : TeamContainer
$thirdPoints  : int
$winPoints  : int
__construct()  : mixed
Group constructor.
__toString()  : string
addGame()  : $this
Add games to this group
addGameContainer()  : WithGames
Add a child container for games
addProgressed()  : $this
Add teams to the `progressed` list
addProgression()  : $this
Add a progression to this group
addTeam()  : $this
Add one or more teams into the object.
addTeamContainer()  : WithTeams
Add a child container for games
allowSkip()  : $this
Allows round skipping
disallowSkip()  : $this
Set round skipping
export()  : ExporterInterface
Prepares a general hierarchy exporter for this hierarchy class
filterTeams()  : array<string|int, mixed>
Filter teams using the specified filters
game()  : Game
Create a new game and add it to the group
genGames()  : array<string|int, mixed>
Generate all games
getContainer()  : HierarchyContainer
Get the hierarchy container
getDrawPoints()  : int
Get points for draw
getGameContainer()  : GameContainer
Get the container for games
getGames()  : array<string|int, Game>
Get all tournament games
getId()  : string|int
Gets the unique identifier of the object
getInGame()  : int
Get how many teams play in one game
getLostPoints()  : int
Get points for losing
getMaxSize()  : int
Get the maximum group size
getName()  : string
Gets the name of the object
getOrder()  : int
Get group order
getOrdering()  : string
Get parameter to order the teams by
getProgressions()  : array<string|int, Progression>
Get all progressions
getProgressPoints()  : int
Get points for progression
getSecondPoints()  : int
Get points for being second
getSkip()  : bool
Getter for round skipping
getTeamContainer()  : TeamContainer
Get the container for games
getTeams()  : array<string|int, Team>
Get all teams in the object
getThirdPoints()  : int
Get points for being third
getType()  : string
Get group type
getWinPoints()  : int
Get points for winning
insertIntoContainer()  : $this
Insert into hierarchical container
isPlayed()  : bool
Check if all games in this group has been played
isProgressed()  : bool
Check if a given team is progressed from this group
orderGames()  : array<string|int, Game>
Order generated games to minimize teams playing multiple games after one other.
progress()  : $this
Progress all teams using already setup progression
progression()  : Progression
Creates a new progression from this group
resetGames()  : $this
Reset all game results as if they were not played
setDrawPoints()  : $this
Set points for draw
setGameAutoincrementId()  : WithGames
Sets a new autoincrement value (start) for the generated games
setId()  : self
Sets the unique identifier of the object
setInGame()  : $this
Set how many teams play in one game
setLostPoints()  : $this
Set points for losing
setMaxSize()  : $this
Set maximum group size
setName()  : self
Sets the name of the object
setOrder()  : $this
Set group order
setOrdering()  : $this
Set parameter to order the teams by
setProgressPoints()  : Group
Set points for progression
setResults()  : Game|null
Set the game's results
setSecondPoints()  : $this
Set points for being second
setSkip()  : $this
Set round skipping
setThirdPoints()  : $this
Set points for being third
setType()  : $this
Set group type
setWinPoints()  : $this
Set points for winning
simulate()  : array<string|int, Team>
Simulate all games in this group as they would be played for real
sortTeams()  : array<string|int, Team>
Sort the teams by their score/points
splitTeams()  : $this
Split teams into its Groups
team()  : Team
Create a new team and add it into the object

Properties

$drawPoints

protected int $drawPoints = 1

$id

protected string|int $id

$lostPoints

protected int $lostPoints = 0

$name

protected string $name = ''

$order

protected int $order = 0

$ordering

protected string $ordering = TournamentGeneratorConstants::POINTS

$progressed

protected array<string|int, mixed> $progressed = []

$progressions

protected array<string|int, mixed> $progressions = []

$progressPoints

protected int $progressPoints = 50
Tags
details

This can be useful when getting the total team order in a tournament. Ex: If you consider teams that progressed to the next round to be higher on the scoreboard even if they got less points in total than some other teams that did not progressed.

$secondPoints

protected int $secondPoints = 2

$thirdPoints

protected int $thirdPoints = 1

$winPoints

protected int $winPoints = 3

Methods

__construct()

Group constructor.

public __construct(string $name[, string|int|null $id = null ]) : mixed
Parameters
$name : string

Group name

$id : string|int|null = null

Group id - if omitted -> it is generated automatically as unique string

Return values
mixed

__toString()

public __toString() : string
Return values
string

Name of the object

addGame()

Add games to this group

public addGame(array<string|int, Game...$games) : $this
Parameters
$games : array<string|int, Game>
Tags
post

The games' id is set to the current auto-incremented value

throws
Exception
Return values
$this

addProgressed()

Add teams to the `progressed` list

public addProgressed(array<string|int, Team...$teams) : $this
Parameters
$teams : array<string|int, Team>
Return values
$this

addProgression()

Add a progression to this group

public addProgression(Progression $progression) : $this
Parameters
$progression : Progression
Return values
$this

addTeam()

Add one or more teams into the object.

public addTeam(Team ...$teams) : $this
Parameters
$teams : Team

Team objects

Tags
throws
Exception
Return values
$this

allowSkip()

Allows round skipping

public allowSkip() : $this
Return values
$this

disallowSkip()

Set round skipping

public disallowSkip() : $this
Return values
$this

filterTeams()

Filter teams using the specified filters

public filterTeams(array<string|int, mixed> &$teams, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters) : array<string|int, mixed>
Parameters
$teams : array<string|int, mixed>

Teams to filter through

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>>

Filters to use

Tags
throws
Exception
Return values
array<string|int, mixed>

game()

Create a new game and add it to the group

public game([array<string|int, Team$teams = [] ]) : Game
Parameters
$teams : array<string|int, Team> = []

Teams that are playing

Tags
post

The game's id is set to the current auto-incremented value

throws
Exception
Return values
Game

genGames()

Generate all games

public genGames() : array<string|int, mixed>
Tags
throws
Exception
Return values
array<string|int, mixed>

getDrawPoints()

Get points for draw

public getDrawPoints() : int
Return values
int

getGames()

Get all tournament games

public getGames() : array<string|int, Game>
Return values
array<string|int, Game>

getId()

Gets the unique identifier of the object

public getId() : string|int
Return values
string|int

Unique identifier of the object

getInGame()

Get how many teams play in one game

public getInGame() : int
Return values
int

getLostPoints()

Get points for losing

public getLostPoints() : int
Return values
int

getMaxSize()

Get the maximum group size

public getMaxSize() : int

Does not disallow adding teams to this round! This can be used to split teams in a group into "subgroups" if you need to limit the maximum number of games.

Return values
int

getName()

Gets the name of the object

public getName() : string
Return values
string

Name of the object

getOrder()

Get group order

public getOrder() : int
Return values
int

getOrdering()

Get parameter to order the teams by

public getOrdering() : string
Return values
string

getProgressions()

Get all progressions

public getProgressions() : array<string|int, Progression>
Return values
array<string|int, Progression>

getProgressPoints()

Get points for progression

public getProgressPoints() : int
Return values
int

getSecondPoints()

Get points for being second

public getSecondPoints() : int
Return values
int

getSkip()

Getter for round skipping

public getSkip() : bool
Return values
bool

getTeams()

Get all teams in the object

public getTeams([bool $ordered = false ][, string|null $ordering = Constants::POINTS ][, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters = [] ]) : array<string|int, Team>
Parameters
$ordered : bool = false

If true - order the teams by their score/points

$ordering : string|null = Constants::POINTS

What to order the teams by - Constants::POINTS, Constants::SCORE

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> = []

Filters to filter the returned teams (ex. if you only want to get the first 3 teams)

Tags
throws
Exception
Return values
array<string|int, Team>

getThirdPoints()

Get points for being third

public getThirdPoints() : int
Return values
int

getWinPoints()

Get points for winning

public getWinPoints() : int
Return values
int

insertIntoContainer()

Insert into hierarchical container

public insertIntoContainer(Base $object) : $this
Parameters
$object : Base
Tags
post

Object is added to hierarchy

post

If the object has teams -> add other team container to hierarchy

post

If the object has games -> add other game container to hierarchy

throws
Exception
Return values
$this

isPlayed()

Check if all games in this group has been played

public isPlayed() : bool
Return values
bool

isProgressed()

Check if a given team is progressed from this group

public isProgressed(Team $team) : bool
Parameters
$team : Team
Return values
bool

orderGames()

Order generated games to minimize teams playing multiple games after one other.

public orderGames() : array<string|int, Game>
Tags
post

The game ids are reset according to their new order

throws
Exception
Return values
array<string|int, Game>

progress()

Progress all teams using already setup progression

public progress([bool $blank = false ]) : $this
Parameters
$blank : bool = false

If true - create dummy teams instead of progressing the real objects

Tags
pre

All progressions are setup

post

All teams have been moved into their next groups

throws
Exception
Return values
$this

resetGames()

Reset all game results as if they were not played

public resetGames() : $this
Tags
post

All games in this group are marked as "not played"

post

All scores in this group are deleted

throws
Exception
Return values
$this

setDrawPoints()

Set points for draw

public setDrawPoints(int $points) : $this
Parameters
$points : int
Return values
$this

setGameAutoincrementId()

Sets a new autoincrement value (start) for the generated games

public setGameAutoincrementId(int $id) : WithGames
Parameters
$id : int

Id - probably from the database

Tags
warning

Do this on the top-level hierarchy element (Tournament class) or else, it might be reset later

post

Propagates the value to all child hierarchy objects

see
GameContainer::setAutoIncrement()
since
0.5
Return values
WithGames

setId()

Sets the unique identifier of the object

public setId(string|int $id) : self
Parameters
$id : string|int

Unique identifier of the object

Tags
throws
InvalidArgumentException

if the provided argument is not of type 'string' or 'int'

Return values
self

setInGame()

Set how many teams play in one game

public setInGame(int $inGame) : $this
Parameters
$inGame : int

2 / 3 / 4

Tags
throws
Exception
Return values
$this

setLostPoints()

Set points for losing

public setLostPoints(int $points) : $this
Parameters
$points : int
Return values
$this

setMaxSize()

Set maximum group size

public setMaxSize(int $size) : $this

Does not disallow adding teams to this round! This can be used to split teams in a group into "subgroups" if you need to limit the maximum number of games.

Parameters
$size : int
Tags
throws
Exception
Return values
$this

setName()

Sets the name of the object

public setName(string $name) : self
Parameters
$name : string

Name of the object

Return values
self

setOrder()

Set group order

public setOrder(int $order) : $this
Parameters
$order : int
Return values
$this

setOrdering()

Set parameter to order the teams by

public setOrdering([string $ordering = Constants::POINTS ]) : $this
Parameters
$ordering : string = Constants::POINTS
Tags
throws
Exception
see
Constants::OrderingTypes
Return values
$this

setProgressPoints()

Set points for progression

public setProgressPoints(int $points) : Group
Parameters
$points : int
Return values
Group

setResults()

Set the game's results

public setResults(array<string|int, int> $results) : Game|null

Results is an array of [teamId => teamScore] key-value pairs. This method will look for a game with given teams and try to set the first not played.

Parameters
$results : array<string|int, int>

array of [teamId => teamScore] key-value pairs

Tags
throws
Exception
Return values
Game|null

setSecondPoints()

Set points for being second

public setSecondPoints(int $points) : $this
Parameters
$points : int
Return values
$this

setSkip()

Set round skipping

public setSkip(bool $skip) : $this
Parameters
$skip : bool
Return values
$this

setThirdPoints()

Set points for being third

public setThirdPoints(int $points) : $this
Parameters
$points : int
Return values
$this

setType()

Set group type

public setType([string $type = Constants::ROUND_ROBIN ]) : $this
Parameters
$type : string = Constants::ROUND_ROBIN
Tags
throws
Exception
see
Constants::GroupTypes
Return values
$this

setWinPoints()

Set points for winning

public setWinPoints(int $points) : $this
Parameters
$points : int
Return values
$this

simulate()

Simulate all games in this group as they would be played for real

public simulate([array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters = [] ][, bool $reset = true ]) : array<string|int, Team>
Parameters
$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> = []

Filters to teams returned from the group

$reset : bool = true

If true - the scores will be reset after simulation

Tags
throws
Exception
Return values
array<string|int, Team>

sortTeams()

Sort the teams by their score/points

public sortTeams([string|null $ordering = Constants::POINTS ][, array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> $filters = [] ]) : array<string|int, Team>
Parameters
$ordering : string|null = Constants::POINTS

What to order the teams by - Constants::POINTS, Constants::SCORE

$filters : array<string|int, TeamFilter>|array<string|int, array<string|int, TeamFilter>> = []

Filters to filter the returned teams (ex. if you only want to get the first 3 teams)

Tags
throws
Exception
Return values
array<string|int, Team>

splitTeams()

Split teams into its Groups

public splitTeams(Round ...$wheres) : $this
Parameters
$wheres : Round
Tags
throws
Exception
noinspection

CallableParameterUseCaseInTypeContextInspection

Return values
$this

team()

Create a new team and add it into the object

public team([string $name = '' ][, string|int|null $id = null ]) : Team
Parameters
$name : string = ''

Name of the new team

$id : string|int|null = null

Id of the new team - if omitted -> it is generated automatically as unique string

Tags
throws
Exception
Return values
Team

Newly created team

Search results