Skip to content

Creating bracket

Daniel Dolejška edited this page Jan 29, 2018 · 4 revisions
  1. Based on participant count
  2. Based on match list
    1. without filling
    2. with immediate filling
  3. Based on Node tree

Creating bracked based on participant count

use BracketGenerator\Bracket;
$bracket = Bracket::create($count, $settings);

Static function Bracket::create will create bracket layout based on participant count.

Creating bracked based on match list

without filling

use BracketGenerator\Bracket;
$bracket = Bracket::createFromList($match_list, $l, $r, $settings);
  • $match_list is array of either arrays or objects containing required data.
  • $l is $match_list item's property referencing to required match for the first participant (left subtree).
  • $r is $match_list item's property referencing to required match for the second participant (right subtree).
  • $settings is array of library settings. More about settings...

Example values:

$match_list = [
    30 => [
        'p1' => 'Player 1', // name of the first participant
        's1' => 0,          // first participant's score
        'l'  => 29,         // reference to match 29
        'p2' => 'Player 2',
        's2' => 0,
        'r'  => 34,
    ],
    29 => [
        'p1' => 'Player 1',
        's1' => 1,
        'l'  => null,
        'p2' => 'Player 4',
        's2' => 0,
        'r'  => null,
    ],
    34 => [
        'p1' => 'Player 2',
        's1' => 1,
        'l'  => null,
        'p2' => 'Player 3',
        's2' => 0,
        'r'  => null,
    ],
];

$l = 'l';
$r = 'r';

This bracket will be generated by the library:

Empty bracket from example

After filling, this is what you will end up with:

Filled bracket from example

with immediate filling

Brackets created from match list can also be immediatelly filled - instead of using createFromList you can use createFromListAndFill:

use BracketGenerator\Bracket;
$bracket = Bracket::createFromListAndFill($match_list, $n1, $s1, $l, $n2, $s2 $r, $settings);
  • $match_list is array of either arrays or objects containing required data.
  • $n1 is $match_list item's property containing first participant's name
  • $s1 is $match_list item's property containing first participant's score
  • $l is $match_list item's property referencing to required match for the first participant (left subtree).
  • $n2 is $match_list item's property containing second participant's name
  • $s2 is $match_list item's property containing second participant's score
  • $r is $match_list item's property referencing to required match for the second participant (right subtree).
  • $settings is array of library settings. More about settings...

Example values:

Other example values can be taken from example above.

$n1 = 'p1';
$s1 = 's1';
$n2 = 'p2';
$s2 = 's2';

Creating bracked based on Node tree

TBA

Clone this wiki locally