Perso
extends Entity
in package
Perso class
This class maps the persos table.
The class also provides methods to move or locate a perso, to gets and sets perso's flags and notes (tables persos_flags and persos_notes), to gets user's perso or check if a perso is online, to handle on select and logout events.
Table of Contents
Properties
- $avatar : string
- $flags : mixed
- $hashtable_id : mixed
- $hashtable_name : mixed
- $id : mixed
- $lastError : string
- $location : mixed
- $location_global : mixed
- $location_local : mixed
- $name : mixed
- $nickname : mixed
- $race : mixed
- $sex : mixed
- $user_id : mixed
- $db : DatabaseEngine
Methods
- __construct() : mixed
- Initializes a new instance
- count_notes() : int
- Counts the amount of notes the perso have saved
- create_perso_from_form() : bool
- Creates a new perso, from a parameter form
- delete_flag() : mixed
- Deletes the specified flag
- flag_exists() : bool
- Determines if the specified flag exists
- get() : Perso
- Initializes a new Perso instance if needed or get already available one.
- get_first_perso() : mixed
- Gets the first perso a user have (typically to be used when get_persos_count returns 1 to autoselect)
- get_flag() : mixed
- Gets the specified flag value
- get_note() : string
- Gets the specified note
- get_persos() : array<string|int, mixed>
- Gets an array with all the perso of the specified user
- get_persos_count() : int
- Counts the perso a user have
- getDatabase() : DatabaseEngine
- is_available_id() : mixed
- is_available_nickname() : mixed
- Checks if the nickname is available
- is_online() : bool
- Determines whether the perso is online
- load_from_database() : bool
- Loads the object Perso (ie fill the properties) from the database
- load_from_form() : mixed
- Loads the object Perso (ie fill the properties) from the $_POST array
- move_to() : void
- Moves the perso to a new location
- notify_inviter() : mixed
- Notifies the person having invited this perso
- on_create() : mixed
- This event method is called when the perso is created
- on_logout() : mixed
- This event method is called when the user logs off its account or perso
- on_select() : mixed
- This event method is called when the user selects a new perso
- request_flag() : mixed
- Ensures the current perso have the specified flag or exits.
- save_field() : void
- Updates the specified field in the database record
- save_to_database() : void
- Saves to database
- set_flag() : mixed
- Sets the specified flag
- set_note() : mixed
- Sets the specified note
- setDatabase() : void
- where() : string
- Gets perso location
- generate_id() : mixed
- Generates a unique ID for the current object
Properties
$avatar
public
string
$avatar
= ""
$flags
public
mixed
$flags
$hashtable_id
public
static mixed
$hashtable_id
= []
$hashtable_name
public
static mixed
$hashtable_name
= []
$id
public
mixed
$id
$lastError
public
string
$lastError
= ""
$location
public
mixed
$location
$location_global
public
mixed
$location_global
$location_local
public
mixed
$location_local
$name
public
mixed
$name
$nickname
public
mixed
$nickname
$race
public
mixed
$race
$sex
public
mixed
$sex
$user_id
public
mixed
$user_id
$db
private
DatabaseEngine
$db
Methods
__construct()
Initializes a new instance
public
__construct(DatabaseEngine $db[, mixed $data = null ]) : mixed
Parameters
- $db : DatabaseEngine
- $data : mixed = null
count_notes()
Counts the amount of notes the perso have saved
public
count_notes() : int
Return values
int —the amount of notes assigned to the perso
create_perso_from_form()
Creates a new perso, from a parameter form
public
static create_perso_from_form(DatabaseEngine $db, User $user, Perso &$perso, array<string|int, mixed> &$errors) : bool
Parameters
- $db : DatabaseEngine
- $user : User
-
The user to attach the perso to
- $perso : Perso
-
A reference to the created perso (don't initialize it, give it a null value)
- $errors : array<string|int, mixed>
-
A reference to the arrays containing errors (should be an empty array, or the method will always return false)
Return values
bool —true if the perso has ben created ; otherwise, false
delete_flag()
Deletes the specified flag
public
delete_flag(string $key) : mixed
Parameters
- $key : string
-
flag key
flag_exists()
Determines if the specified flag exists
public
flag_exists(string $key) : bool
Parameters
- $key : string
-
the flag key to check
Return values
bool —true if the specified flag exists ; otherwise, false.
get()
Initializes a new Perso instance if needed or get already available one.
public
static get(DatabaseEngine $db[, mixed $data = null ]) : Perso
Parameters
- $db : DatabaseEngine
- $data : mixed = null
Tags
Return values
Persoget_first_perso()
Gets the first perso a user have (typically to be used when get_persos_count returns 1 to autoselect)
public
static get_first_perso(DatabaseEngine $db, int $user_id) : mixed
Parameters
- $db : DatabaseEngine
- $user_id : int
Tags
get_flag()
Gets the specified flag value
public
get_flag(string $key[, mixed $defaultValue = null ]) : mixed
Parameters
- $key : string
-
flag key
- $defaultValue : mixed = null
-
default value if the flag doesn't exist
Return values
mixed —the flag value (string) or null if not existing
get_note()
Gets the specified note
public
get_note(string $code) : string
Parameters
- $code : string
-
the note code
Return values
string —the note content
get_persos()
Gets an array with all the perso of the specified user
public
static get_persos(DatabaseEngine $db, User $user) : array<string|int, mixed>
Parameters
- $db : DatabaseEngine
- $user : User
Return values
array<string|int, mixed>get_persos_count()
Counts the perso a user have
public
static get_persos_count(mixed $user_id) : int
Parameters
- $user_id : mixed
Return values
int —the user's perso count
getDatabase()
public
getDatabase() : DatabaseEngine
Return values
DatabaseEngineis_available_id()
public
static is_available_id(mixed $id) : mixed
Parameters
- $id : mixed
is_available_nickname()
Checks if the nickname is available
public
static is_available_nickname(string $nickname) : mixed
Parameters
- $nickname : string
-
the nickname to check
is_online()
Determines whether the perso is online
public
is_online() : bool
Return values
bool —true if the perso is online ; otherwise, false.
load_from_database()
Loads the object Perso (ie fill the properties) from the database
public
load_from_database() : bool
Return values
boolload_from_form()
Loads the object Perso (ie fill the properties) from the $_POST array
public
load_from_form() : mixed
move_to()
Moves the perso to a new location
public
move_to([string|null $global = null ][, string|null $local = null ]) : void
Parameters
- $global : string|null = null
-
the global target location
- $local : string|null = null
-
the local target location
notify_inviter()
Notifies the person having invited this perso
public
notify_inviter() : mixed
on_create()
This event method is called when the perso is created
public
on_create() : mixed
on_logout()
This event method is called when the user logs off its account or perso
public
on_logout() : mixed
on_select()
This event method is called when the user selects a new perso
public
on_select() : mixed
request_flag()
Ensures the current perso have the specified flag or exits.
public
request_flag(string $flag[, int $threshold = 0 ]) : mixed
Parameters
- $flag : string
-
the flag to assert
- $threshold : int = 0
-
value the flags must strictly be greater than (optional, the default value is 0)
Example:
$perso->set_flag('quux.foo', 1); //The perso wants to read quux, which we allow with the flag quux.foo $perso->request_flag('quux.foo'); //will be okay
//The perso wants also to write quux, which we all allow if quux.foo = 2 //The threshold will so be 1, as 2 > 1 $perso->request_flag('quux.foo', 1); //Will exits, with a "You don't have quux.foo permission" message
save_field()
Updates the specified field in the database record
public
save_field(string $field) : void
Parameters
- $field : string
save_to_database()
Saves to database
public
save_to_database() : void
set_flag()
Sets the specified flag
public
set_flag(string $key[, string $value = 1 ]) : mixed
Parameters
- $key : string
-
flag key
- $value : string = 1
-
flag value (optional, default value: 1)
set_note()
Sets the specified note
public
set_note(string $code, string $text) : mixed
Parameters
- $code : string
-
the note code
- $text : string
-
the note content
setDatabase()
public
setDatabase(DatabaseEngine $db) : void
Parameters
- $db : DatabaseEngine
where()
Gets perso location
public
where() : string
Return values
string —The location names
generate_id()
Generates a unique ID for the current object
private
generate_id() : mixed