class UserCollectionModel (View source)

The user collection model.

Properties

private $users The collection of existing user objects.
private $userType The class name of the user type.
private $userTypeSerialized The replacement for the user type class in a serialized string.

Methods

__construct()

The constructor.

bool
createUser(string $username, string $password1, string $password2, string $email, Messenger $Messenger)

Add user account.

bool
delete(array $users, Messenger $Messenger)

Delete one ore more user accounts.

bool
editCurrentUserInfo(string $username, string $email, Messenger $Messenger)

Edit info of the currently logged in user.

string
generatePHP()

Generate the PHP code for the accounts file. Basically the code returns the unserialized serialized array with all users.

array
getCollection()

Return the user collection array.

User|null
getUser(string $nameOrEmail)

Return a user by name or email address.

bool
save(Messenger $Messenger)

Save the accounts array as PHP to AM_FILE_ACCOUNTS.

bool
sendInvitation(string $username, string $email, Messenger $Messenger)

Send invitation email.

string
convertLegacyAccountsFile(array $contents)

Convert legacy accounts file content.

int|null
getUserId(string $nameOrEmail)

Return a user id by name or email address.

string
invalidEmailError()

The invalid email error message.

string
invalidUsernameError()

The invalid username error message.

array
load()

Get the accounts array by including the accounts PHP file.

bool
validEmail(string $email = '')

Verify if a given email address is valid.

bool
validUsername(string $username)

Verify if a given username is valid.

Details

__construct()

The constructor.

bool createUser(string $username, string $password1, string $password2, string $email, Messenger $Messenger)

Add user account.

Parameters

string $username
string $password1
string $password2
string $email
Messenger $Messenger

Return Value

bool true on success

bool delete(array $users, Messenger $Messenger)

Delete one ore more user accounts.

Parameters

array $users
Messenger $Messenger

Return Value

bool true on success

bool editCurrentUserInfo(string $username, string $email, Messenger $Messenger)

Edit info of the currently logged in user.

Parameters

string $username
string $email
Messenger $Messenger

Return Value

bool true on success

string generatePHP()

Generate the PHP code for the accounts file. Basically the code returns the unserialized serialized array with all users.

That way, the accounts array can be stored as PHP. The accounts file has to be a PHP file for security reasons. When trying to access the file directly via the browser, it gets executed instead of revealing any user names.

Return Value

string the PHP code

array getCollection()

Return the user collection array.

Return Value

array the user collection array

User|null getUser(string $nameOrEmail)

Return a user by name or email address.

Parameters

string $nameOrEmail

Return Value

User|null the requested user account

bool save(Messenger $Messenger)

Save the accounts array as PHP to AM_FILE_ACCOUNTS.

Parameters

Messenger $Messenger

Return Value

bool true on success

bool sendInvitation(string $username, string $email, Messenger $Messenger)

Send invitation email.

Parameters

string $username
string $email
Messenger $Messenger

Return Value

bool true on success

private string convertLegacyAccountsFile(array $contents)

Convert legacy accounts file content.

Parameters

array $contents

Return Value

string the serialized accounts

private int|null getUserId(string $nameOrEmail)

Return a user id by name or email address.

Parameters

string $nameOrEmail

Return Value

int|null the requested user id

private string invalidEmailError()

The invalid email error message.

Return Value

string the error message

private string invalidUsernameError()

The invalid username error message.

Return Value

string the error message

private array load()

Get the accounts array by including the accounts PHP file.

Return Value

array The registered accounts

See also

User

private bool validEmail(string $email = '')

Verify if a given email address is valid.

Parameters

string $email

Return Value

bool true in case the username is valid

private bool validUsername(string $username)

Verify if a given username is valid.

Parameters

string $username

Return Value

bool true in case the username is valid