4 a.2 Showing the pairings of a specific round
Jeroen De Meerleer edited this page 2019-09-27 19:37:35 +02:00

To get pairings of a specific round you can use the Round::getPairings() method.

First, import your sws-file using the ReaderInterface::read() method. Using the Tournament::getRoundByNo() method you can get a specific round. Tournament::getRoundByNo() takes 1 integer parameter that defines the round no. The very first round has number 0.

TODO: change first round no to 1

When you have the round object you can the Round::GetPairings() method to get the pairings for the round. This method returns an Array of Pairing objects making it easy to iterate over itusing foreach.

Example

<?php
require_once('vendor/autoload.php');
use JeroenED\Libpairtwo\IOFactory;
use JeroenED\Libpairtwo\Enums\Result;

$reader = IOFactory::createReader('Swar-4');
$reader->read('mycompetition.sws');
$tournament = $reader->getTournament();
$pairings = $tournament->getRoundByNo($_GET['round'])->getPairings();

foreach($pairings as $pairing) {
    $player = $pairing->getPlayer()->getName();
    if (!is_null($pairing->getOpponent())) {
        $opponent = $pairing->getOpponent()->getName();
        $color = $pairing->getColor()->getKey();
        echo $player . ' ' . $pairing->getResult()->getKey() . ' against ' . $opponent . ' using ' . $color . PHP_EOL;
    } elseif ($pairing->getResult() == Result::wonbye) {
        echo $player . ' is bye' . PHP_EOL;
    } elseif ($pairing->getResult() == Result::absent) {
        echo $player . ' is absent' . PHP_EOL;
    }
}