2019-02-06 17:23:37 +01:00
|
|
|
<?php
|
|
|
|
/**
|
2019-06-19 21:54:19 +02:00
|
|
|
* Class Games
|
|
|
|
*
|
|
|
|
* Class for a game 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-03-20 12:46:46 +01:00
|
|
|
use JeroenED\Libpairtwo\Enums\Gameresult;
|
2019-06-19 21:54:19 +02:00
|
|
|
use JeroenED\Libpairtwo\Models\Round;
|
|
|
|
use JeroenED\Libpairtwo\Pairing;
|
2019-02-06 17:23:37 +01:00
|
|
|
|
2019-06-19 21:54:19 +02:00
|
|
|
/**
|
|
|
|
* Class Games
|
|
|
|
*
|
|
|
|
* Class for a game 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 Game
|
2019-02-06 17:23:37 +01:00
|
|
|
{
|
2019-06-20 15:32:26 +02:00
|
|
|
/** @var Pairing | null */
|
2019-06-19 21:54:19 +02:00
|
|
|
private $white;
|
|
|
|
|
2019-06-20 15:32:26 +02:00
|
|
|
/** @var Pairing | null */
|
2019-06-19 21:54:19 +02:00
|
|
|
private $black;
|
|
|
|
|
2019-06-20 15:32:26 +02:00
|
|
|
/** @var GameResult | null */
|
2019-06-19 21:54:19 +02:00
|
|
|
private $result;
|
|
|
|
|
2019-03-20 12:46:46 +01:00
|
|
|
/**
|
|
|
|
* This function gets the result from the game
|
2019-06-19 21:54:19 +02:00
|
|
|
*
|
|
|
|
* @return Gameresult
|
2019-03-20 12:46:46 +01:00
|
|
|
*/
|
|
|
|
public function getResult(): Gameresult
|
|
|
|
{
|
|
|
|
if (!is_null(parent::getResult())) {
|
|
|
|
return parent::getResult();
|
|
|
|
}
|
|
|
|
|
|
|
|
$whiteResult = $this->getWhite()->getResult();
|
|
|
|
$blackResult = $this->getBlack()->getResult();
|
|
|
|
|
|
|
|
$whitesplit = explode(" ", $whiteResult);
|
|
|
|
$blacksplit = explode(" ", $blackResult);
|
|
|
|
|
|
|
|
$special='';
|
|
|
|
if (isset($whitesplit[1]) && $whitesplit[1] != 'Bye') {
|
|
|
|
$special = ' ' . $whitesplit[1];
|
|
|
|
}
|
|
|
|
if (isset($blacksplit[1]) && $blacksplit[1] != 'Bye') {
|
|
|
|
$special = ' ' . $blacksplit[1];
|
|
|
|
}
|
2019-05-28 10:18:58 +02:00
|
|
|
if ($whitesplit[0] == '*') {
|
|
|
|
$whitesplit[0] = '';
|
|
|
|
}
|
|
|
|
if ($blacksplit[0] == '*') {
|
|
|
|
$blacksplit[0] = '';
|
|
|
|
}
|
2019-03-20 17:33:09 +01:00
|
|
|
$result = new Gameresult($whitesplit[0] . '-' . $blacksplit[0] . $special);
|
|
|
|
$this->setResult($result);
|
2019-03-20 12:46:46 +01:00
|
|
|
|
2019-03-20 17:33:09 +01:00
|
|
|
return $result;
|
2019-03-20 12:46:46 +01:00
|
|
|
}
|
2019-06-19 21:54:19 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets pairing for white player
|
|
|
|
*
|
2019-06-20 15:32:26 +02:00
|
|
|
* @return Pairing | null
|
2019-06-19 21:54:19 +02:00
|
|
|
*/
|
|
|
|
public function getWhite(): ?Pairing
|
|
|
|
{
|
|
|
|
return $this->white;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets pairing for white player
|
|
|
|
*
|
2019-06-20 15:32:26 +02:00
|
|
|
* @param Pairing | null $white
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Game
|
|
|
|
*/
|
|
|
|
public function setWhite(?Pairing $white): Game
|
|
|
|
{
|
|
|
|
$this->white = $white;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Gets pairing for black player
|
|
|
|
*
|
2019-06-20 15:32:26 +02:00
|
|
|
* @return Pairing | null
|
2019-06-19 21:54:19 +02:00
|
|
|
*/
|
|
|
|
public function getBlack(): ?Pairing
|
|
|
|
{
|
|
|
|
return $this->black;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets pairing for black player
|
|
|
|
*
|
2019-06-20 15:32:26 +02:00
|
|
|
* @param Pairing | null $black
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Game
|
|
|
|
*/
|
|
|
|
public function setBlack(?Pairing $black): Game
|
|
|
|
{
|
|
|
|
$this->black = $black;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Sets result for game
|
|
|
|
*
|
2019-06-20 15:32:26 +02:00
|
|
|
* @param Gameresult | null $result
|
2019-06-19 21:54:19 +02:00
|
|
|
* @return Game
|
|
|
|
*/
|
|
|
|
public function setResult(?Gameresult $result): Game
|
|
|
|
{
|
|
|
|
$this->result = $result;
|
|
|
|
return $this;
|
|
|
|
}
|
2019-02-11 17:37:30 +01:00
|
|
|
}
|