mirror of
https://github.com/JeroenED/libpairtwo.git
synced 2024-12-01 18:51:32 +01:00
Merge branch 'task/get-player-by-name' into develop
This commit is contained in:
parent
f56455f4e5
commit
16afc410da
@ -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