class user_loader

User loader class

This handles loading users from the database and storing in them in a temporary cache so we do not have to query the same user multiple times in different services.

Properties

protected driver_interface $db
protected string $phpbb_root_path
protected string $php_ext
protected string $users_table
protected array $users

Users loaded from the DB

Methods

__construct(driver_interface $db, string $phpbb_root_path, string $php_ext, string $users_table)

User loader constructor

load_users(array $user_ids, array $ignore_types = array())

Load user helper

int
load_user_by_username(string $username)

Load a user by username

array|bool
get_user(int $user_id, bool $query = false)

Get a user row from our users cache

string
get_username(int $user_id, string $mode, string $guest_username = false, string $custom_profile_url = false, bool $query = false)

Get username

string
get_avatar(int $user_id, bool $query = false, bool $lazy = false)

Get avatar

array
get_rank(int $user_id, bool $query = false)

Get rank

Details

at line 53
__construct(driver_interface $db, string $phpbb_root_path, string $php_ext, string $users_table)

User loader constructor

Parameters

driver_interface $db

A database connection

string $phpbb_root_path

Path to the phpbb includes directory.

string $php_ext

php file extension

string $users_table

The name of the database table (phpbb_users)

at line 69
load_users(array $user_ids, array $ignore_types = array())

Load user helper

Parameters

array $user_ids
array $ignore_types

user types to ignore

at line 104
int load_user_by_username(string $username)

Load a user by username

Stores the full data in the user cache so they do not need to be loaded again Returns the user id so you may use get_user() from the returned value

Parameters

string $username

Raw username to load (will be cleaned)

Return Value

int

User ID for the username

at line 133
array|bool get_user(int $user_id, bool $query = false)

Get a user row from our users cache

Parameters

int $user_id

User ID of the user you want to retrieve

bool $query

Should we query the database if this user has not yet been loaded? Typically this should be left as false and you should make sure you load users ahead of time with load_users()

Return Value

array|bool

Row from the database of the user or Anonymous if the user wasn't loaded/does not exist or bool False if the anonymous user was not loaded

at line 167
string get_username(int $user_id, string $mode, string $guest_username = false, string $custom_profile_url = false, bool $query = false)

Get username

Parameters

int $user_id

User ID of the user you want to retrieve the username for

string $mode

The mode to load (same as get_username_string). One of the following: profile (for getting an url to the profile) username (for obtaining the username) colour (for obtaining the user colour) full (for obtaining a html string representing a coloured link to the users profile) no_profile (the same as full but forcing no profile link)

string $guest_username

Optional parameter to specify the guest username. It will be used in favor of the GUEST language variable then.

string $custom_profile_url

Optional parameter to specify a profile url. The user id get appended to this url as &u={user_id}

bool $query

Should we query the database if this user has not yet been loaded? Typically this should be left as false and you should make sure you load users ahead of time with load_users()

Return Value

string

at line 187
string get_avatar(int $user_id, bool $query = false, bool $lazy = false)

Get avatar

Parameters

int $user_id

User ID of the user you want to retrieve the avatar for

bool $query

Should we query the database if this user has not yet been loaded? Typically this should be left as false and you should make sure you load users ahead of time with load_users()

bool $lazy

If true, will be lazy loaded (requires JS)

Return Value

string

at line 213
array get_rank(int $user_id, bool $query = false)

Get rank

Parameters

int $user_id

User ID of the user you want to retrieve the rank for

bool $query

Should we query the database if this user has not yet been loaded? Typically this should be left as false and you should make sure you load users ahead of time with load_users()

Return Value

array

Array with keys 'rank_title', 'rank_img', and 'rank_img_src'