Merge branch 'task/get-player-by-name' into develop

This commit is contained in:
Jeroen De Meerleer 2019-05-01 16:04:42 +02:00
parent f56455f4e5
commit 16afc410da

View File

@ -10,6 +10,10 @@ namespace JeroenED\Libpairtwo;
use JeroenED\Libpairtwo\Models\Player as PlayerModel; use JeroenED\Libpairtwo\Models\Player as PlayerModel;
/**
* Class Player
* @package JeroenED\Libpairtwo
*/
class Player extends PlayerModel class Player extends PlayerModel
{ {
@ -24,4 +28,28 @@ class Player extends PlayerModel
$newArray[] = $pairing; $newArray[] = $pairing;
$this->setPairings($newArray); $this->setPairings($newArray);
} }
/**
* 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;
}
} }