z_userModel
extends z_model
in package
User Model
This model handles database stuff with the focus on user managment. An instance of this class can be acquired with z_framework::getModel("z_user")
Table of Contents
- add() : int
- Creates an user account
- addRoleToUserByRoleId() : mixed
- Add a role to a user
- changeRoleStateByUserIdAndRoleId() : mixed
- Change the state of a role granted to a user, Can be used to add or remove roles
- createRole() : int
- Creates a role
- createVerifyToken() : mixed
- Creates an email verify token and puts it into the database
- deactivateRole() : mixed
- Deactivates a role
- getCount() : int
- Gets the number of registered users
- getPermissionsByUserId() : array<string|int, string>
- Gets all permissions a specific user has
- getRoleIdByRoleName() : int
- Gets the id of a role by it's name
- getRoles() : array<string|int, array<string|int, mixed>>
- Gets all the roles a user has
- getUserByEmail() : bool|array<string|int, mixed>|null
- Returns a user row of the database, selected by the users email address
- getUserById() : bool|array<string|int, mixed>|null
- Returns a user row of the database, selected by the users id
- getUserList() : array<string|int, array<string|int, mixed>>
- Returns all user data from the database
- updateAccountSettings() : mixed
- Updates the clients settings
- verifyUser() : bool
- Verifies an users mail address
Methods
add()
Creates an user account
public
add(string $email[, string $passwordString = null ][, mixed $verified = null ]) : int
Parameters
- $email : string
-
Email of the user
- $passwordString : string = null
-
The raw users password. Not hashed! It will be hashed in this function
- $verified : mixed = null
Return values
int —The id of the new created user
addRoleToUserByRoleId()
Add a role to a user
public
addRoleToUserByRoleId(int $userId, int $roleId) : mixed
Parameters
- $userId : int
-
The id of the user itended to recieve the role
- $roleId : int
-
The id of the role to be added
Return values
mixed —changeRoleStateByUserIdAndRoleId()
Change the state of a role granted to a user, Can be used to add or remove roles
public
changeRoleStateByUserIdAndRoleId(int $userId, int $roleId[, mixed $shouldHaveRole = true ]) : mixed
Parameters
- $userId : int
-
The id of the user
- $roleId : int
-
The id of the role
- $shouldHaveRole : mixed = true
Return values
mixed —createRole()
Creates a role
public
createRole() : int
Return values
int —The id of the new created role
createVerifyToken()
Creates an email verify token and puts it into the database
public
createVerifyToken(mixed $userId) : mixed
Parameters
- $userId : mixed
Return values
mixed —deactivateRole()
Deactivates a role
public
deactivateRole(int $roleId) : mixed
After a role is deactivated the users with it will loose the role specific permissions as long as they don't have another role with these.
Parameters
- $roleId : int
-
The id of the role to deactivate
Return values
mixed —getCount()
Gets the number of registered users
public
getCount() : int
Return values
int —The number of registered users
getPermissionsByUserId()
Gets all permissions a specific user has
public
getPermissionsByUserId(int $userId) : array<string|int, string>
Parameters
- $userId : int
-
Id of the target user
Return values
array<string|int, string> —Array filled with permissions
getRoleIdByRoleName()
Gets the id of a role by it's name
public
getRoleIdByRoleName(string $name) : int
Parameters
- $name : string
-
The name of the role
Return values
int —The id of the role
getRoles()
Gets all the roles a user has
public
getRoles(int $userId) : array<string|int, array<string|int, mixed>>
Parameters
- $userId : int
-
The id of the target user
Return values
array<string|int, array<string|int, mixed>> —The datasets of the user_role table
getUserByEmail()
Returns a user row of the database, selected by the users email address
public
getUserByEmail(string $email) : bool|array<string|int, mixed>|null
Parameters
- $email : string
-
Email of the user from who we want the data about
Return values
bool|array<string|int, mixed>|null —The dataset
getUserById()
Returns a user row of the database, selected by the users id
public
getUserById(int $userid) : bool|array<string|int, mixed>|null
Parameters
- $userid : int
-
ID of the user we want the data about
Return values
bool|array<string|int, mixed>|null —The dataset
getUserList()
Returns all user data from the database
public
getUserList() : array<string|int, array<string|int, mixed>>
Return values
array<string|int, array<string|int, mixed>> —The table as a two dimensional array
updateAccountSettings()
Updates the clients settings
public
updateAccountSettings(int $id, string $email, int $language) : mixed
Parameters
- $id : int
-
Id of the target user
- $email : string
-
The new email
- $language : int
-
The new language id
Return values
mixed —verifyUser()
Verifies an users mail address
public
verifyUser(mixed $token) : bool
Parameters
- $token : mixed
Return values
bool —True if the user was successfully verified or already was verified