3 a.3 Showing the pairings of a specific player
Jeroen De Meerleer edited this page 2019-09-27 19:37:50 +02:00

You can show the pairings of a specific player by using the Player::getPairings() method. To get the specific player you can use the static function Player::getPlayersByName().

Example

<?php

require_once('vendor/autoload.php');

use JeroenED\Libpairtwo\IOFactory;
use JeroenED\Libpairtwo\Player;
use JeroenED\Libpairtwo\Enums\Result;

$filereader = IOFactory::createReader('Swar-4');
$filereader->read('Tata-Steel-2018.sws');
$magnusses = Player::getPlayersByName("Magnus Carlsen", $filereader->getTournament());
$magnus = $magnusses[0];

foreach ($magnus->getPairings() 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;
    }
}