4 d. Converting your code to the generalized format
Jeroen De Meerleer edited this page 2019-09-27 19:39:25 +02:00

Before the 1.0 release the project was in the phase of transforming from pairtwo-only to a generalized view for multiple programs. This makes it relatively easy to add other filetypes. However, this process requires rewriting and renaming some functions. This document is dedicated to these adjustments.

Sws::readSws renamed to ReaderInterface::read Master

When you want to read a file, all you need to do is to create an instance of the ReaderInterface and call its read function. This procedure will be the same for any filetype in the library.

I have created a easy class to get to the right class for your file. This IOFactory class currently only has 1 type which is for Pairtwo (starting from version 6). But there will be added other filetypes as well.

Old code

require_once 'vendor/autoload.php';
$sws = Sws::readSws('<filename>');

New code

require_once 'vendor/autoload.php';
$reader = IOFactory::createReader('Pairtwo-6');
$sws = $reader->read('<filename>');

Getting a ranking Master

With the generalization, work has been put in fixing the tiebreaks. This also includes that the Tournament::GetRanking() method has changed. Most important is that it does not have a parameter for american sort anymore.

When you try to get a ranking and want to display a certain tiebreak, all you need to do is to call the Player::GetTiebreaks() function. This will return an array of applied tiebreaks. Every tiebreak which was set as tiebreak to the tournament gets calculated. This means that if a tiebreak was not needed anymore of the calculation of the ranking, it still gets calculated.

Changed getters and setters Master

Getters

Property Old code New Code (getter) Current Status
Player::Absent Player::getAbsent() Player::getBinaryData('Absent') Final
Player::Club Player::getClub() Player::getId('Club') Final
Player::ExtraPts Player::getExtraPts() Player::getBinaryData('XtraPts') Final
Player::FideElo Player::getFideElo() Player::getElo('Fide') Final
Player::FideId Player::getFideId() Player::getId('Fide') Final
Player::KbsbElo Player::getKbsbElo() Player::getElo('Nation') Final
Player::KbsbId Player::getKbsbId() Player::getId('Nation') Final
Player::NumberOfTies Player::getNumberofTies() Player::getBinaryData('NumberOfTies') Final
Player::Points Player::getPoints() Player::getBinaryData('Points')* Final
Player::Rank Player::getRank() Player::getBinaryData('Rank') Final
Player::ScoreAmerican Player::getScoreAmerican() Player::getBinaryData('ScoreAmerican') Final
Player::ScoreBucholtz Player::getScoreBucholtz() Player::getBinaryData('ScoreBuchholz') Final
Sws::Players($i)_ColorDiff Sws::getBinaryData('Players($i)_ColorDiff') Player::getBinaryData('ColorDiff') Final
Sws::Players($i)_ColorPref Sws::getBinaryData('Players($i)_ColorPref') Player::getBinaryData('ColorPref') Final
Sws::Players($i)_Float Sws::getBinaryData('Players($i)_Float') Player::getBinaryData('Float') Final
Sws::Players($i)_FloatBefore Sws::getBinaryData('Players($i)_FloatBefore') Player::getBinaryData('FloatBefore') Final
Sws::Players($i)_FloatPrev Sws::getBinaryData('Players($i)_FloatPrev') Player::getBinaryData('FloatPrev') Final
Sws::Players($i)_HelpValue Sws::getBinaryData('Players($i)_HelpValue') Player::getBinaryData('HelpValue') Final
Sws::Players($i)_Paired Sws::getBinaryData('Players($i)_Paired') Player::getBinaryData('Paired') Final
Sws::Players($i)_NameLength Sws::getBinaryData('Players($i)_NameLength') Player::getBinaryData('NameLength') Final
Sws::Players($i)_Namepos Sws::getBinaryData('Players($i)_Namepos') Player::getBinaryData('NamePos') Final
Sws::Players($i)_TieMatch Sws::getBinaryData('Players($i)_TieMatch') Player::getBinaryData('Tiematch') Final

*: Old method still exists, but has a different implementation that should return the same value

Setters

Property Old code New Code (setter) Current Status
Player::Absent Player::setAbsent($value) Player::setBinaryData('Absent', $value) Final
Player::Club Player::setClub($value) Player::setId('Club', $value) Final
Player::ExtraPts Player::setExtraPts($value) Player::setBinaryData('XtraPts', $value) Final
Player::FideElo Player::setFideElo($value) Player::setElo('Fide', $value) Final
Player::FideId Player::setFideId($value) Player::setId('Fide', $value) Final
Player::KbsbElo Player::setKbsbElo($value) Player::setElo('Nation', $value) Final
Player::KbsbId Player::setKbsbId($value) Player::setId('Nation', $value) Final
Player::NumberOfTies Player::setNumberofTies($value) Player::setBinaryData('NumberOfTies', $value) Final
Player::Points Player::setPoints($value) Player::setBinaryData('Points', $value) Final
Player::Rank Player::setRank($value) Player::setBinaryData('Rank', $value) Final
Player::ScoreAmerican Player::setScoreAmerican($value) Player::setBinaryData('ScoreAmerican', $value) Final
Player::ScoreBucholtz Player::setScoreBucholtz($value) Player::setBinaryData('ScoreBuchholz', $value) Final
Sws::Players($i)_ColorDiff Sws::setBinaryData('Players($i, $value)_ColorDiff', $value) Player::setBinaryData('ColorDiff', $value) Final
Sws::Players($i)_ColorPref Sws::setBinaryData('Players($i, $value)_ColorPref', $value) Player::setBinaryData('ColorPref', $value) Final
Sws::Players($i)_Float Sws::setBinaryData('Players($i, $value)_Float', $value) Player::setBinaryData('Float', $value) Final
Sws::Players($i)_FloatBefore Sws::setBinaryData('Players($i, $value)_FloatBefore', $value) Player::setBinaryData('FloatBefore', $value) Final
Sws::Players($i)_FloatPrev Sws::setBinaryData('Players($i, $value)_FloatPrev', $value) Player::setBinaryData('FloatPrev', $value) Final
Sws::Players($i)_HelpValue Sws::setBinaryData('Players($i, $value)_HelpValue', $value) Player::setBinaryData('HelpValue', $value) Final
Sws::Players($i)_Paired Sws::setBinaryData('Players($i, $value)_Paired', $value) Player::setBinaryData('Paired', $value) Final
Sws::Players($i)_NameLength Sws::setBinaryData('Players($i, $value)_NameLength', $value) Player::setBinaryData('NameLength', $value) Final
Sws::Players($i)_Namepos Sws::setBinaryData('Players($i, $value)_Namepos', $value) Player::setBinaryData('NamePos', $value) Final
Sws::Players($i)_TieMatch Sws::setBinaryData('Players($i, $value)_TieMatch', $value) Player::setBinaryData('Tiematch', $value) Final