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 $Players;
private $Year;
private $Pairings;
/**
* @return string
@ -376,4 +377,22 @@ class Tournament
$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\Sex;
use JeroenED\Libpairtwo\Enums\Color;
use JeroenED\Libpairtwo\Enums\Result;
use JeroenED\Libpairtwo\Models\Sws as SwsModel;
use JeroenED\Libpairtwo\Enums\TournamentSystem;
@ -470,23 +472,33 @@ class Sws extends SwsModel
}
if ($sws->getBinaryData("CurrentRound") > 0) {
// echo "go" . PHP_EOL;
for ($i = 0; $i < $sws->getBinaryData("CreatedRounds"); $i++) {
$game = new Game();
for ($i = 0; $i < $sws->getBinaryData("NewPlayer"); $i++) {
for ($x = 0; $x < $sws->getBinaryData("CreatedRounds"); $x++) {
$pairing = new Pairing();
$pairing->setPlayer($sws->getTournament()->getPlayerById($i));
$length = 4;
//echo $offset . "Opponent: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL;
$offset += $length;
$length = 1;
//echo $offset . "Color: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL;
$offset += $length;
$length = 1;
//echo $offset . "Result: " . self::ReadData('String', substr($swscontents, $offset, $length)) . PHP_EOL;
$offset += $length;
$opponent = self::ReadData('Int', substr($swscontents, $offset, $length));
if ($opponent != 4294967295) {
$pairing->setOpponent($sws->getTournament()->getPlayerById($opponent));
}
$offset += $length;
$length = 1;
$pairing->setColor(new Color(self::ReadData('Int', substr($swscontents, $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;
@ -518,6 +530,7 @@ class Sws extends SwsModel
}
$hex = implode($hex);
$hex = ($hex == "") ? "00" : $hex;
if ($type == 'Hex') {
return $hex;
} elseif ($type == 'Int') {

View File

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