Reading out pairings

This commit is contained in:
Jeroen De Meerleer 2019-02-11 16:43:36 +01:00
parent 682cf386b6
commit b6c72e9021
Signed by: JeroenED
GPG Key ID: 28CCCB8F62BFADD6
7 changed files with 222 additions and 13 deletions

20
src/Enums/Color.php Normal file
View File

@ -0,0 +1,20 @@
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 11/02/19
* Time: 14:51
*/
namespace JeroenED\LibPairtwo\Enums;
use MyCLabs\Enum\Enum;
class Color extends Enum
{
const black = 255; // Implementing two's-complement for these values only is not worth the trick
const black3 = 253; // Especially if you can just do unsigned
const white = 1;
const white3 = 3;
const none = 0;
}

26
src/Enums/Result.php Normal file
View File

@ -0,0 +1,26 @@
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 11/02/19
* Time: 16:03
*/
namespace JeroenED\Libpairtwo\Enums;
use MyCLabs\Enum\Enum;
class Result extends Enum
{
const none = 0;
const lost = 1;
const draw = 6;
const won = 11;
const absent = 2;
const wonforfait = 12;
const adjourn = 3;
const drawadjourned = 8;
const wonadjourned = 13;
const bye = 4;
const wonbye = 14;
}

105
src/Models/Pairing.php Normal file
View File

@ -0,0 +1,105 @@
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 11/02/19
* Time: 14:48
*/
namespace JeroenED\Libpairtwo\Models;
use JeroenED\LibPairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Result;
use JeroenED\LibPairtwo\Player;
use phpDocumentor\Reflection\Types\Integer;
class Pairing
{
private $Player;
private $Opponent;
private $Color;
private $Result;
private $Round;
/**
* @return Player
*/
public function getPlayer(): Player
{
return $this->Player;
}
/**
* @param Player $Player
*/
public function setPlayer(Player $Player): void
{
$this->Player = $Player;
}
/**
* @return mixed
*/
public function getOpponent(): Player
{
return $this->Opponent;
}
/**
* @param mixed $Opponent
*/
public function setOpponent(Player $Opponent): void
{
$this->Opponent = $Opponent;
}
/**
* @return Color
*/
public function getColor(): Color
{
return $this->Color;
}
/**
* @param Color $Color
*/
public function setColor(Color $Color): void
{
$this->Color = $Color;
}
/**
* @return Result
*/
public function getResult(): Result
{
return $this->Result;
}
/**
* @param Result $Result
*/
public function setResult(Result $Result): void
{
$this->Result = $Result;
}
/**
* @return int
*/
public function getRound(): int
{
return $this->Round;
}
/**
* @param int $Round
*/
public function setRound(int $Round): void
{
$this->Round = $Round;
}
}

View File

@ -55,6 +55,7 @@ class Tournament
private $Federation; private $Federation;
private $Players; private $Players;
private $Year; private $Year;
private $Pairings;
/** /**
* @return string * @return string
@ -376,4 +377,22 @@ class Tournament
$this->Year = $Year; $this->Year = $Year;
} }
/**
* @return Pairing[]
*/
public function getPairings()
{
return $this->Pairings;
}
/**
* @param Pairing[] $Pairings
*/
public function setPairings($Pairings): void
{
$this->Pairings = $Pairings;
}
} }

16
src/Pairing.php Normal file
View File

@ -0,0 +1,16 @@
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 11/02/19
* Time: 15:56
*/
namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Pairing as PairingModel;
class Pairing extends PairingModel
{
}

View File

@ -28,6 +28,8 @@ namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Enums\Title; use JeroenED\Libpairtwo\Enums\Title;
use JeroenED\Libpairtwo\Enums\Sex; use JeroenED\Libpairtwo\Enums\Sex;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Result;
use JeroenED\Libpairtwo\Models\Sws as SwsModel; use JeroenED\Libpairtwo\Models\Sws as SwsModel;
use JeroenED\Libpairtwo\Enums\TournamentSystem; use JeroenED\Libpairtwo\Enums\TournamentSystem;
@ -470,23 +472,33 @@ class Sws extends SwsModel
} }
if ($sws->getBinaryData("CurrentRound") > 0) { if ($sws->getBinaryData("CurrentRound") > 0) {
// echo "go" . PHP_EOL; for ($i = 0; $i < $sws->getBinaryData("NewPlayer"); $i++) {
for ($i = 0; $i < $sws->getBinaryData("CreatedRounds"); $i++) { for ($x = 0; $x < $sws->getBinaryData("CreatedRounds"); $x++) {
$game = new Game(); $pairing = new Pairing();
$length = 4; $pairing->setPlayer($sws->getTournament()->getPlayerById($i));
//echo $offset . "Opponent: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL;
$offset += $length;
$length = 1; $length = 4;
//echo $offset . "Color: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL; $opponent = self::ReadData('Int', substr($swscontents, $offset, $length));
$offset += $length; if ($opponent != 4294967295) {
$pairing->setOpponent($sws->getTournament()->getPlayerById($opponent));
}
$offset += $length;
$length = 1; $length = 1;
//echo $offset . "Result: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL; $pairing->setColor(new Color(self::ReadData('Int', substr($swscontents, $offset, $length))));
$offset += $length; $offset += $length;
$length = 1;
$pairing->setResult(new Result(self::ReadData('Int', substr($swscontents, $offset, $length))));
$offset += $length;
$pairing->setRound($x);
$offset += 2;
$sws->getTournament()->addPairing($pairing);
}
} }
} }
return $sws; return $sws;
@ -518,6 +530,7 @@ class Sws extends SwsModel
} }
$hex = implode($hex); $hex = implode($hex);
$hex = ($hex == "") ? "00" : $hex;
if ($type == 'Hex') { if ($type == 'Hex') {
return $hex; return $hex;
} elseif ($type == 'Int') { } elseif ($type == 'Int') {

View File

@ -53,6 +53,16 @@ class Tournament extends TournamentModel
$this->setRounds($newArray); $this->setRounds($newArray);
} }
/**
* @param Pairing $pairing
*/
public function addPairing(Pairing $pairing)
{
$newArray = $this->GetPairings();
$newArray[] = $pairing;
$this->setPairings($newArray);
}
/** /**
* @return array * @return array
*/ */