class Player extends AvatarModel implements NamedModel, DuplexUrlInterface

A league player

Constants

DEVELOPER

These are built-in roles that cannot be deleted via the web interface so we will be storing these values as constant variables. Hopefully, a user won't be silly enough to delete them manually from the database.

ADMIN

COP

REFEREE

S_ADMIN

PLAYER

PLAYER_NO_PM

TABLE

The name of the database table used for queries

AVATAR_LOCATION

The location where avatars will be stored

EDIT_PERMISSION

SOFT_DELETE_PERMISSION

HARD_DELETE_PERMISSION

Methods

bool
addRole(Role|int $role_id)

Add a player a new role

string
getAdminNotes()

Get the notes admins have left about a player

int
getBZID()

Get the player's BZID

getCountry()

Get the country a player belongs to

string
getEmailAddress()

Get the e-mail address of the player

bool
isVerified()

Returns whether the player has verified their e-mail address

string
getConfirmCode()

Returns the confirmation code for the player's e-mail address verification

string
getReceives()

Returns what kind of events the player should be e-mailed about

bool
canReceive(string $type)

Finds out whether the specified player wants and can receive an e-mail message

bool
isCorrectConfirmCode(string $code)

Find out whether the specified confirmation code is correct

string
getDescription()

Get the player's sanitized description

getJoinedDate()

Get the joined date of the player

string[][]
getKnownIPs()

Get all of the known IPs used by the player

getLastLogin()

Get the last login for a player

getLastMatch()

Get the last match

string[]
getPastCallsigns()

Get all of the callsigns a player has used to log in to the website

getTeam()

Get the player's team

string
getTimezone()

Get the player's timezone PHP identifier (example: "Europe/Paris")

Role[]
getRoles()

Get the roles of the player

bool
hasPermission(string|null $permission)

Check if a player has a specific permission

bool
hasBeenActive()

Check whether or not a player been in a match or has logged on in the specified amount of time to be considered active

bool
isOutdated()

Check whether the callsign of the player is outdated

bool
isDisabled()

Check if a player's account has been disabled

bool
isTestUser()

Check if everyone can log in as this user on a test environment

bool
isTeamless()

Check if a player is teamless

markAsBanned()

Mark a player's account as banned

markAsUnbanned()

Mark a player's account as unbanned

bool
isBanned()

Find out if a player is banned

Ban|null
getBan()

Get the ban of the player

bool
removeRole(int $role_id)

Remove a player from a role

setEmailAddress(string $email)

Set the player's email address and reset their verification status

setVerified(bool $verified)

Set whether the player has verified their e-mail address

generateNewConfirmCode()

Generate a new random confirmation token for e-mail address verification

setReceives(string $receives)

Set what kind of events the player should be e-mailed about

setOutdated(bool $outdated)

Set whether the callsign of the player is outdated

setDescription(string $description)

Set the player's description

setTimezone(string $timezone)

Set the player's timezone

setTeam(int $team)

Set the player's team

setLastMatch(int $match)

Set the match the player last participated in

setStatus(string $status)

Set the player's status

setAdminNotes(string $admin_notes)

Set the player's admin notes

setCountry(int $country)

Set the player's country

updateLastLogin()

Updates this player's last login

string
getUsername()

Get the player's username

string
getEscapedUsername()

Get the player's username, safe for use in your HTML

setName(string $username)

Alias for Player::setUsername()

void
markMessagesAsRead()

Mark all the unread messages of a player as read

setRoles(Role[] $roles)

Set the roles of a user

static Player
getFromBZID(int $bzid)

Given a player's BZID, get a player object

static Player
getFromUsername(string $username)

Get a single player by their username

static Player[]
getPlayers()

Get all the players in the database that have an active status

int
countUnreadNotifications()

Show the number of notifications the user hasn't read yet

int
getMatchCount()

Count the number of matches a player has participated in

float
getMatchWinRatio()

Get the (victory/total matches) ratio of the player

float
getMatchAverageCaps()

Get the (total caps made by team/total matches) ratio of the player

float
getMatchActivity()

Get the match activity in matches per day for a player

int
countUnreadMessages()

Show the number of messages the user hasn't read yet

static Player[]
getTeamMembers(int $teamID)

Get all of the members belonging to a team

static string[]
getActiveStatuses()

Get the possible statuses representing an active model (visible to everyone)

static string
getEagerColumns()

Get the MySQL columns that will be loaded as soon as the model is created

static 
getLazyColumns()

{@inheritdoc}

static QueryBuilder
getQueryBuilder()

Get a query builder for players

static Player
newPlayer(int $bzid, string $username, int $team = null, string $status = 'active', int $role_id = self::PLAYER, string $avatar = '', string $description = '', int $country = 1, string $timezone = null, string|TimeDate $joined = 'now', string|TimeDate $last_login = 'now')

Enter a new player to the database

static bool
playerBZIDExists(int $bzid)

Determine if a player exists in the database

setUsername(string $username)

Change a player's callsign and add it to the database if it does not exist as a past callsign

static Closure
getAlphabeticalSort()

Alphabetical order function for use in usort (case-insensitive)

void
wipe()

Permanently delete the object from the database

bool
canSee(PermissionModel $model, bool $showDeleted = false)

Find whether the player can delete a model

bool
canDelete(PermissionModel $model, bool $hard = false)

Find whether the player can delete a model

bool
canCreate(string $modelName)

Find whether the player can create a model

bool
canEdit(PermissionModel $model)

Find whether the player can edit a model

Details

at line line 203
bool addRole(Role|int $role_id)

Add a player a new role

Parameters

Role|int $role_id The role ID to add a player to

Return Value

bool Whether the operation was successful or not

at line line 228
string getAdminNotes()

Get the notes admins have left about a player

Return Value

string The notes

at line line 239
int getBZID()

Get the player's BZID

Return Value

int The BZID

at line line 249
Country getCountry()

Get the country a player belongs to

Return Value

Country The country belongs to

at line line 259
string getEmailAddress()

Get the e-mail address of the player

Return Value

string The address

at line line 271
bool isVerified()

Returns whether the player has verified their e-mail address

Return Value

bool true for verified players

at line line 283
string getConfirmCode()

Returns the confirmation code for the player's e-mail address verification

Return Value

string The player's confirmation code

at line line 295
string getReceives()

Returns what kind of events the player should be e-mailed about

Return Value

string The type of notifications

at line line 309
bool canReceive(string $type)

Finds out whether the specified player wants and can receive an e-mail message

Parameters

string $type

Return Value

bool true if the player should be sent an e-mail

at line line 333
bool isCorrectConfirmCode(string $code)

Find out whether the specified confirmation code is correct

This method protects against timing attacks

Parameters

string $code The confirmation code to check

Return Value

bool true for a correct e-mail verification code

at line line 348
string getDescription()

Get the player's sanitized description

Return Value

string The description

at line line 359
TimeDate getJoinedDate()

Get the joined date of the player

Return Value

TimeDate The joined date of the player

at line line 371
string[][] getKnownIPs()

Get all of the known IPs used by the player

Return Value

string[][] An array containing IPs and hosts

at line line 380
TimeDate getLastLogin()

Get the last login for a player

Return Value

TimeDate The date of the last login

at line line 391
Match getLastMatch()

Get the last match

Return Value

Match

at line line 402
string[] getPastCallsigns()

Get all of the callsigns a player has used to log in to the website

Return Value

string[] An array containing all of the past callsigns recorded for a player

at line line 411
Team getTeam()

Get the player's team

Return Value

Team The object representing the team

at line line 420
string getTimezone()

Get the player's timezone PHP identifier (example: "Europe/Paris")

Return Value

string The timezone

at line line 431
Role[] getRoles()

Get the roles of the player

Return Value

Role[]

at line line 458
bool hasPermission(string|null $permission)

Check if a player has a specific permission

Parameters

string|null $permission The permission to check for

Return Value

bool Whether or not the player has the permission

at line line 475
bool hasBeenActive()

Check whether or not a player been in a match or has logged on in the specified amount of time to be considered active

Return Value

bool True if the player has been active

at line line 500
bool isOutdated()

Check whether the callsign of the player is outdated

Returns true if this player has probably changed their callsign, making the current username stored in the database obsolete

Return Value

bool Whether or not the player is disabled

at line line 512
bool isDisabled()

Check if a player's account has been disabled

Return Value

bool Whether or not the player is disabled

at line line 522
bool isTestUser()

Check if everyone can log in as this user on a test environment

Return Value

bool

at line line 532
bool isTeamless()

Check if a player is teamless

Return Value

bool True if the player is teamless

at line line 540
markAsBanned()

Mark a player's account as banned

at line line 552
markAsUnbanned()

Mark a player's account as unbanned

at line line 566
bool isBanned()

Find out if a player is banned

Return Value

bool

at line line 579
Ban|null getBan()

Get the ban of the player

This method performs a load of all the lazy parameters of the Player

Return Value

Ban|null The current ban of the player, or null if the player is is not banned

at line line 593
bool removeRole(int $role_id)

Remove a player from a role

Parameters

int $role_id The role ID to add or remove

Return Value

bool Whether the operation was successful or not

at line line 605
setEmailAddress(string $email)

Set the player's email address and reset their verification status

Parameters

string $email The address

at line line 626
Player setVerified(bool $verified)

Set whether the player has verified their e-mail address

Parameters

bool $verified Whether the player is verified or not

Return Value

Player

at line line 642
Player generateNewConfirmCode()

Generate a new random confirmation token for e-mail address verification

Return Value

Player

at line line 669
Player setReceives(string $receives)

Set what kind of events the player should be e-mailed about

Parameters

string $receives The type of notification

Return Value

Player

at line line 682
Player setOutdated(bool $outdated)

Set whether the callsign of the player is outdated

Parameters

bool $outdated Whether the callsign is outdated

Return Value

Player

at line line 693
setDescription(string $description)

Set the player's description

Parameters

string $description The description

at line line 702
setTimezone(string $timezone)

Set the player's timezone

Parameters

string $timezone The timezone

at line line 711
setTeam(int $team)

Set the player's team

Parameters

int $team The team's ID

at line line 721
setLastMatch(int $match)

Set the match the player last participated in

Parameters

int $match The match's ID

at line line 730
setStatus(string $status)

Set the player's status

Parameters

string $status The new status

at line line 740
Player setAdminNotes(string $admin_notes)

Set the player's admin notes

Parameters

string $admin_notes The new admin notes

Return Value

Player

at line line 750
Player setCountry(int $country)

Set the player's country

Parameters

int $country The ID of the new country

Return Value

Player

at line line 758
updateLastLogin()

Updates this player's last login

at line line 767
string getUsername()

Get the player's username

Return Value

string The username

at line line 776
string getEscapedUsername()

Get the player's username, safe for use in your HTML

Return Value

string The username

at line line 787
AliasModel setName(string $username)

Alias for Player::setUsername()

Parameters

string $username The new username

Return Value

AliasModel

at line line 797
void markMessagesAsRead()

Mark all the unread messages of a player as read

Return Value

void

at line line 812
Player setRoles(Role[] $roles)

Set the roles of a user

Parameters

Role[] $roles The new roles of the user

Return Value

Player

at line line 869
static Player getFromBZID(int $bzid)

Given a player's BZID, get a player object

Parameters

int $bzid The player's BZID

Return Value

Player

at line line 880
static Player getFromUsername(string $username)

Get a single player by their username

Parameters

string $username The username to look for

Return Value

Player

at line line 891
static Player[] getPlayers()

Get all the players in the database that have an active status

Return Value

Player[] An array of player BZIDs

at line line 902
int countUnreadNotifications()

Show the number of notifications the user hasn't read yet

Return Value

int

at line line 911
int getMatchCount()

Count the number of matches a player has participated in

Return Value

int

at line line 927
float getMatchWinRatio()

Get the (victory/total matches) ratio of the player

Return Value

float

at line line 947
float getMatchAverageCaps()

Get the (total caps made by team/total matches) ratio of the player

Return Value

float

at line line 977
float getMatchActivity()

Get the match activity in matches per day for a player

Return Value

float

at line line 998
int countUnreadMessages()

Show the number of messages the user hasn't read yet

Return Value

int

at line line 1010
static Player[] getTeamMembers(int $teamID)

Get all of the members belonging to a team

Parameters

int $teamID The ID of the team to fetch the members of

Return Value

Player[] An array of Player objects of the team members

at line line 1020
static string[] getActiveStatuses()

Get the possible statuses representing an active model (visible to everyone)

Return Value

string[]

at line line 1028
static string getEagerColumns()

Get the MySQL columns that will be loaded as soon as the model is created

Return Value

string The columns in a format readable by MySQL

at line line 1036
static getLazyColumns()

{@inheritdoc}

at line line 1045
static QueryBuilder getQueryBuilder()

Get a query builder for players

Return Value

QueryBuilder

at line line 1073
static Player newPlayer(int $bzid, string $username, int $team = null, string $status = 'active', int $role_id = self::PLAYER, string $avatar = '', string $description = '', int $country = 1, string $timezone = null, string|TimeDate $joined = 'now', string|TimeDate $last_login = 'now')

Enter a new player to the database

Parameters

int $bzid The player's bzid
string $username The player's username
int $team The player's team
string $status The player's status
int $role_id The player's role when they are first created
string $avatar The player's profile avatar
string $description The player's profile description
int $country The player's country
string $timezone The player's timezone
string|TimeDate $joined The date the player joined
string|TimeDate $last_login The timestamp of the player's last login

Return Value

Player An object representing the player that was just entered

at line line 1105
static bool playerBZIDExists(int $bzid)

Determine if a player exists in the database

Parameters

int $bzid The player's bzid

Return Value

bool Whether the player exists in the database

at line line 1117
Player setUsername(string $username)

Change a player's callsign and add it to the database if it does not exist as a past callsign

Parameters

string $username The new username of the player

Return Value

Player

at line line 1153
static Closure getAlphabeticalSort()

Alphabetical order function for use in usort (case-insensitive)

Return Value

Closure The sort function

at line line 1164
void wipe()

Permanently delete the object from the database

Return Value

void

at line line 1178
bool canSee(PermissionModel $model, bool $showDeleted = false)

Find whether the player can delete a model

Parameters

PermissionModel $model The model that will be seen
bool $showDeleted Whether to show deleted models to admins

Return Value

bool

at line line 1191
bool canDelete(PermissionModel $model, bool $hard = false)

Find whether the player can delete a model

Parameters

PermissionModel $model The model that will be deleted
bool $hard Whether to check for hard-delete perms, as opposed to soft-delete ones

Return Value

bool

at line line 1206
bool canCreate(string $modelName)

Find whether the player can create a model

Parameters

string $modelName The PHP class identifier of the model type

Return Value

bool

at line line 1217
bool canEdit(PermissionModel $model)

Find whether the player can edit a model

Parameters

PermissionModel $model The model which will be edited

Return Value

bool