mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-11-22 06:26:57 +01:00
Added function to get Players by Name
This commit is contained in:
parent
25a9a6d2fe
commit
e1388056ca
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user