libpairtwo/src/Player.php

100 lines
2.0 KiB
PHP
Raw Normal View History

2019-02-01 15:53:39 +01:00
<?php
/**
* Created by PhpStorm.
* User: jeroen
* Date: 1/02/19
* Time: 11:26
*/
2019-03-20 17:33:09 +01:00
namespace JeroenED\Libpairtwo;
2019-02-01 15:53:39 +01:00
use JeroenED\Libpairtwo\Models\Player as PlayerModel;
2019-05-01 16:04:37 +02:00
/**
* Class Player
* @package JeroenED\Libpairtwo
*/
2019-02-11 17:37:30 +01:00
class Player extends PlayerModel
2019-02-01 15:53:39 +01:00
{
2019-04-20 16:55:39 +02:00
/**
* Adds a pairing to the tournament
*
* @param Pairing $pairing
*/
public function addPairing(Pairing $pairing)
{
$newArray = $this->GetPairings();
$newArray[] = $pairing;
$this->setPairings($newArray);
}
2019-05-01 16:04:37 +02:00
/**
* 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;
}
2019-05-29 18:09:19 +02:00
/**
* @param string $type
* @return int
*/
public function getElo(string $type): int
{
return $this->getElos()[$type];
}
/**
* @param string $type
* @param int $value
* @return Player
*/
public function setElo(string $type, int $value): Player
{
$currentElos = $this->getElos();
$currentElos[$type] = $value;
$this->setElos($currentElos);
return $this;
}
/**
* @param string $type
* @return string
*/
public function getId(string $type): string
{
return $this->getElos()[$type];
}
/**
* @param string $type
* @param string $value
* @return Player
*/
public function setId(string $type, string $value): Player
{
$currentIds = $this->getIds();
$currentIds[$type] = $value;
$this->setIds($currentIds);
return $this;
}
2019-02-11 17:37:30 +01:00
}