2019-02-06 17:23:37 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2019-06-19 21:54:19 +02:00
|
|
|
* Class Round
|
|
|
|
*
|
|
|
|
* Class for a round of the tournament
|
|
|
|
*
|
|
|
|
* @author Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
* @category Main
|
|
|
|
* @package Libpairtwo
|
|
|
|
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
|
2019-02-06 17:23:37 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
namespace JeroenED\Libpairtwo;
|
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
use DateTime;
|
2019-05-13 20:03:25 +02:00
|
|
|
use JeroenED\Libpairtwo\Enums\Result;
|
2019-02-06 17:23:37 +01:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Class Round
|
|
|
|
*
|
|
|
|
* Class for a round of the tournament
|
|
|
|
*
|
|
|
|
* @author Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
* @category Main
|
|
|
|
* @package Libpairtwo
|
|
|
|
* @copyright Copyright (c) 2018-2019 Jeroen De Meerleer <schaak@jeroened.be>
|
|
|
|
*/
|
|
|
|
class Round
|
2019-02-06 17:23:37 +01:00
|
|
|
{
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Date of the round
|
|
|
|
*
|
|
|
|
* @var DateTime
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
private $Date;
|
2019-06-19 21:54:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of all games
|
|
|
|
*
|
|
|
|
* @var Game[]
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
private $Games = [];
|
2019-06-19 21:54:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Number of the round
|
|
|
|
*
|
|
|
|
* @var int
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
private $RoundNo;
|
2019-06-19 21:54:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Array of all pairings for this round
|
|
|
|
*
|
|
|
|
* @var Pairing[]
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
private $Pairings = [];
|
2019-06-19 21:54:19 +02:00
|
|
|
|
2019-03-20 17:33:09 +01:00
|
|
|
/**
|
|
|
|
* Adds a game to the round
|
|
|
|
*
|
|
|
|
* @param Game $game
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
2019-03-20 17:33:09 +01:00
|
|
|
*/
|
2019-06-19 21:54:19 +02:00
|
|
|
public function addGame(Game $game): Round
|
2019-02-11 22:41:44 +01:00
|
|
|
{
|
|
|
|
$newarray = $this->getGames();
|
|
|
|
$newarray[] = $game;
|
|
|
|
$this->setGames($newarray);
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
2019-02-11 22:41:44 +01:00
|
|
|
}
|
2019-05-01 15:50:44 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Adds a pairing to the round
|
|
|
|
*
|
|
|
|
* @param Pairing $pairing
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
2019-05-01 15:50:44 +02:00
|
|
|
*/
|
2019-06-19 21:54:19 +02:00
|
|
|
public function addPairing(Pairing $pairing): Round
|
2019-05-01 15:50:44 +02:00
|
|
|
{
|
|
|
|
$newarray = $this->getPairings();
|
|
|
|
$newarray[] = $pairing;
|
|
|
|
$this->setPairings($newarray);
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
2019-05-01 15:50:44 +02:00
|
|
|
}
|
2019-05-13 20:03:25 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of pairings where the player is bye
|
|
|
|
*
|
|
|
|
* @return Pairing[]
|
|
|
|
*/
|
|
|
|
public function getBye(): array
|
|
|
|
{
|
|
|
|
$allPairings = $this->getPairings();
|
|
|
|
$byePairings = [];
|
|
|
|
foreach ($allPairings as $pairing) {
|
2019-09-28 21:49:33 +02:00
|
|
|
if ($pairing->getResult() == Result::WonBye) {
|
2019-05-13 20:03:25 +02:00
|
|
|
$byePairings[] = $pairing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $byePairings;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns an array of pairings where the player is absent
|
|
|
|
*
|
|
|
|
* @return Pairing[]
|
|
|
|
*/
|
|
|
|
public function getAbsent(): array
|
|
|
|
{
|
|
|
|
$allPairings = $this->getPairings();
|
|
|
|
$absentPairings = [];
|
|
|
|
foreach ($allPairings as $pairing) {
|
2019-09-28 21:49:33 +02:00
|
|
|
if ($pairing->getResult() == Result::Absent) {
|
2019-05-13 20:03:25 +02:00
|
|
|
$absentPairings[] = $pairing;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return $absentPairings;
|
|
|
|
}
|
2019-06-19 21:54:19 +02:00
|
|
|
|
2019-09-28 21:49:33 +02:00
|
|
|
/**
|
|
|
|
* Retuns an array with the games of this round sorted by board
|
|
|
|
*
|
|
|
|
* @return Game[]
|
|
|
|
*/
|
|
|
|
public function getGamesByBoard(): array
|
|
|
|
{
|
|
|
|
$allGames = $this->getGames();
|
|
|
|
usort($allGames, array($this, 'sortByBoard'));
|
|
|
|
return $allGames;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sort by board
|
|
|
|
*
|
|
|
|
* @param Game $a
|
|
|
|
* @param Game $b
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
private function sortByBoard(Game $a, Game $b): int
|
|
|
|
{
|
|
|
|
if (($a->getBoard() == $b->getBoard()) || ($a->getBoard() === false) || ($b->getBoard() === false)) {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return ($a->getBoard() > $b->getBoard()) ? +1 : -1;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Returns the date of the round
|
|
|
|
*
|
|
|
|
* @return DateTime
|
|
|
|
*/
|
|
|
|
public function getDate(): DateTime
|
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
return $this->Date;
|
2019-06-19 21:54:19 +02:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Sets the date of the round
|
|
|
|
*
|
2019-09-28 21:49:33 +02:00
|
|
|
* @param DateTime $Date
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
public function setDate(DateTime $Date): Round
|
2019-06-19 21:54:19 +02:00
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
$this->Date = $Date;
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Returns an array of all games for the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
|
|
|
* @return Game[]
|
|
|
|
*/
|
|
|
|
public function getGames(): array
|
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
return $this->Games;
|
2019-06-19 21:54:19 +02:00
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Sets an array of all games for the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
2019-09-28 21:49:33 +02:00
|
|
|
* @param Game[] $Games
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
public function setGames(array $Games): Round
|
2019-06-19 21:54:19 +02:00
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
$this->Games = $Games;
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Returns the round number of the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
|
|
|
* @return int
|
|
|
|
*/
|
|
|
|
public function getRoundNo(): int
|
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
return $this->RoundNo;
|
2019-06-19 21:54:19 +02:00
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Sets the round number of the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
2019-09-28 21:49:33 +02:00
|
|
|
* @param int $RoundNo
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
public function setRoundNo(int $RoundNo): Round
|
2019-06-19 21:54:19 +02:00
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
$this->RoundNo = $RoundNo;
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Returns an array of all pairings for the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
|
|
|
* @return Pairing[]
|
|
|
|
*/
|
|
|
|
public function getPairings(): array
|
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
return $this->Pairings;
|
2019-06-19 21:54:19 +02:00
|
|
|
}
|
2019-09-28 21:49:33 +02:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
2019-06-20 15:32:26 +02:00
|
|
|
* Sets an array of all pairings for the round
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
2019-09-28 21:49:33 +02:00
|
|
|
* @param Pairing[] $Pairings
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Round
|
|
|
|
*/
|
2019-09-28 21:49:33 +02:00
|
|
|
public function setPairings(array $Pairings): Round
|
2019-06-19 21:54:19 +02:00
|
|
|
{
|
2019-09-28 21:49:33 +02:00
|
|
|
$this->Pairings = $Pairings;
|
2019-06-19 21:54:19 +02:00
|
|
|
return $this;
|
|
|
|
}
|
2019-02-11 17:37:30 +01:00
|
|
|
}
|