mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-22 12:21:22 +01:00
Merge branch 'task/get-player-by-name' into develop
This commit is contained in:
commit
dba9a876b7
@ -10,6 +10,10 @@ namespace JeroenED\Libpairtwo;
|
||||
|
||||
use JeroenED\Libpairtwo\Models\Player as PlayerModel;
|
||||
|
||||
/**
|
||||
* Class Player
|
||||
* @package JeroenED\Libpairtwo
|
||||
*/
|
||||
class Player extends PlayerModel
|
||||
{
|
||||
|
||||
@ -24,4 +28,28 @@ class Player extends PlayerModel
|
||||
$newArray[] = $pairing;
|
||||
$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;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user