2019-02-06 17:23:37 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: jeroen
|
|
|
|
* Date: 1/02/19
|
|
|
|
* Time: 17:17
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace JeroenED\Libpairtwo;
|
|
|
|
|
2019-03-20 12:46:46 +01:00
|
|
|
use JeroenED\Libpairtwo\Enums\Gameresult;
|
2019-02-06 17:23:37 +01:00
|
|
|
use JeroenED\Libpairtwo\Models\Game as GameModel;
|
|
|
|
|
|
|
|
class Game extends GameModel
|
|
|
|
{
|
2019-03-20 12:46:46 +01:00
|
|
|
/**
|
|
|
|
* This function gets the result from the game
|
|
|
|
*/
|
|
|
|
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];
|
|
|
|
}
|
|
|
|
$result = $whitesplit[0] . '-' . $blacksplit[0] . $special;
|
|
|
|
$this->setResult(new Gameresult($result));
|
|
|
|
|
|
|
|
return new Gameresult($result);
|
|
|
|
}
|
2019-02-11 17:37:30 +01:00
|
|
|
}
|