Compare commits

...

10 Commits

8 changed files with 68 additions and 10 deletions

View File

@ -2,11 +2,12 @@
Copyright 2018- (c) Jeroen De Meerleer <schaak@jeroened.be>
This library reads and writes sws-files that are saved using PairTwo developed by the Belgian Chess Federation (KBSB-FRBE).
This library reads sws-files that are saved using PairTwo developed by the Belgian Chess Federation (KBSB-FRBE).
## Special thanks
* Daniel Halleux (Webmaster KBSB - Developer PairTwo)
* Daniel Halleux (Webmaster KBSB)
* Bernard Malfliet (Original developer Pairtwo)
## Licence

View File

@ -69,8 +69,4 @@ class Game
{
$this->result = $result;
}
}

View File

@ -70,7 +70,7 @@ class Player
private $Absent;
/** @var Pairing[] */
private $Pairings;
private $Pairings = [];
/**
* @return string
@ -379,6 +379,4 @@ class Player
{
$this->Pairings = $Pairings;
}
}

View File

@ -9,6 +9,8 @@
namespace JeroenED\Libpairtwo\Models;
use DateTime;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round
{
@ -21,6 +23,9 @@ class Round
/** @var int */
private $roundNo;
/** @var Pairing[] */
private $pairings = [];
/**
* @return DateTime
*
@ -70,4 +75,20 @@ class Round
$this->roundNo = $roundNo;
}
/**
* @return Pairing[]
*/
public function getPairings(): array
{
return $this->pairings;
}
/**
* @param Pairing[] $pairings
*/
public function setPairings(array $pairings): void
{
$this->pairings = $pairings;
}
}

View File

@ -10,6 +10,10 @@ namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Player as PlayerModel;
/**
* Class Player
* @package JeroenED\Libpairtwo
*/
class Player extends PlayerModel
{
@ -24,4 +28,28 @@ class Player extends PlayerModel
$newArray[] = $pairing;
$this->setPairings($newArray);
}
/**
* Returns an array of Player objects where name matches $search
*
* @param string $search
* @param Tournament $tournament
* @return Player[]
*/
public static function getPlayersByName(string $search, Tournament $tournament): array
{
/** @var Player[] */
$players = $tournament->getPlayers();
/** @var Player[] */
$return = [];
foreach ($players as $player) {
if (fnmatch($search, $player->getName())) {
$return[] = $player;
}
}
return $return;
}
}

View File

@ -9,6 +9,8 @@
namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Round as RoundModel;
use JeroenED\Libpairtwo\Game;
use JeroenED\Libpairtwo\Pairing;
class Round extends RoundModel
{
@ -22,6 +24,17 @@ class Round extends RoundModel
$newarray = $this->getGames();
$newarray[] = $game;
$this->setGames($newarray);
}
/**
* Adds a pairing to the round
*
* @param Pairing $pairing
*/
public function addPairing(Pairing $pairing)
{
$newarray = $this->getPairings();
$newarray[] = $pairing;
$this->setPairings($newarray);
}
}

View File

@ -100,6 +100,8 @@ class Tournament extends TournamentModel
$pairing->getPlayer()->addPairing($pairing);
$round = $pairing->getRound();
$color = $pairing->getColor();
$this->getRoundByNo($round)->addPairing($pairing);
$opponent = null;
foreach ($cache as $key=>$cached) {
if (!is_null($cached)) {

View File

@ -68,4 +68,3 @@ echo "Color Pairing 3: " . $sws->getTournament()->getPairings()[3]->getColor()->
echo "Player Pairing 1: " . $sws->getTournament()->getPairings()[0]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 2: " . $sws->getTournament()->getPairings()[1]->getPlayer()->getName() . PHP_EOL;
echo "Player Pairing 3: " . $sws->getTournament()->getPairings()[2]->getPlayer()->getName() . PHP_EOL;