2019-02-01 15:53:39 +01:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* Created by PhpStorm.
|
|
|
|
* User: jeroen
|
|
|
|
* Date: 1/02/19
|
|
|
|
* Time: 11:18
|
|
|
|
*/
|
|
|
|
|
|
|
|
namespace JeroenED\Libpairtwo;
|
|
|
|
|
|
|
|
use JeroenED\Libpairtwo\Models\Tournament as TournamentModel;
|
2019-02-06 20:10:52 +01:00
|
|
|
use phpDocumentor\Reflection\Types\Boolean;
|
2019-02-01 15:53:39 +01:00
|
|
|
|
|
|
|
class Tournament extends TournamentModel
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* @param Integer $id
|
|
|
|
* @return Player
|
|
|
|
*/
|
|
|
|
public function getPlayerById($id)
|
|
|
|
{
|
|
|
|
return $this->GetPlayers()[$id];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Player $Player
|
|
|
|
*/
|
|
|
|
public function addPlayer(Player $Player)
|
|
|
|
{
|
|
|
|
$newArray = $this->GetPlayers();
|
|
|
|
$newArray[] = $Player;
|
|
|
|
$this->setPlayers($newArray);
|
|
|
|
}
|
2019-02-01 17:02:33 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $id
|
|
|
|
* @param Player $player
|
|
|
|
*/
|
|
|
|
public function updatePlayer($id, Player $player)
|
|
|
|
{
|
|
|
|
$newArray = $this->GetPlayers();
|
|
|
|
$newArray[$id] = $player;
|
|
|
|
$this->setPlayers($newArray);
|
|
|
|
}
|
2019-02-06 17:23:37 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param Round $round
|
|
|
|
*/
|
|
|
|
public function addRound(Round $round)
|
|
|
|
{
|
|
|
|
$newArray = $this->GetRounds();
|
|
|
|
$newArray[] = $round;
|
|
|
|
$this->setRounds($newArray);
|
|
|
|
}
|
|
|
|
|
2019-02-06 17:24:10 +01:00
|
|
|
/**
|
|
|
|
* @return array
|
|
|
|
*/
|
2019-02-06 20:10:52 +01:00
|
|
|
public function getRanking(bool $sort)
|
2019-02-06 17:24:10 +01:00
|
|
|
{
|
|
|
|
$players = $this->getPlayers();
|
|
|
|
|
2019-02-06 20:10:52 +01:00
|
|
|
$sort ? usort($players, array($this, "SortNormal")) : usort($players, array($this, "SortAmerican"));
|
2019-02-06 17:24:10 +01:00
|
|
|
|
2019-02-06 18:22:25 +01:00
|
|
|
return $players;
|
|
|
|
}
|
|
|
|
|
2019-02-06 20:10:52 +01:00
|
|
|
/**
|
|
|
|
* @param $a
|
|
|
|
* @param $b
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
private function sortNormal($a, $b)
|
2019-02-06 18:22:25 +01:00
|
|
|
{
|
|
|
|
return $b->getPoints() - $a->getPoints();
|
2019-02-06 17:24:10 +01:00
|
|
|
}
|
2019-02-06 20:10:52 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $a
|
|
|
|
* @param $b
|
|
|
|
* @return mixed
|
|
|
|
*/
|
|
|
|
private function sortAmerican($a, $b)
|
|
|
|
{
|
|
|
|
return $b->getScoreAmerican() - $a->getScoreAmerican();
|
|
|
|
}
|
2019-02-01 15:53:39 +01:00
|
|
|
}
|