\hhu\z\modelsUsersModel

Model of the UsersAgent to list users and get their data.

Summary

Methods
Properties
Constants
__construct()
load()
factory()
getUsersCount()
getUsers()
getUsersWithRole()
getUserById()
getUserByUrl()
login()
usernameExists()
emailExists()
createUser()
editUser()
deleteUser()
hash()
No public properties found
No constants found
No protected methods found
$db
N/A
loadDriver()
connect()
getClassName()
loadModels()
verify()
No private properties found
N/A

Properties

$db

$db : \nre\models\DatabaseDriver

Database connection

Type

\nre\models\DatabaseDriver

Methods

__construct()

__construct() 

Construct a new UsersModel.

TODO Catch exception

load()

load(string  $modelName) 

Load the class of a Model.

Parameters

string $modelName

Name of the Model to load

Throws

\nre\exceptions\ModelNotFoundException
\nre\exceptions\ModelNotValidException

factory()

factory(string  $modelName) 

Instantiate a Model (Factory Pattern).

Parameters

string $modelName

Name of the Model to instantiate

getUsersCount()

getUsersCount(string  $username = null) : integer

Get count of registered users.

Parameters

string $username

Only get users with the given username (optional)

Returns

integer —

Count of users

getUsers()

getUsers(string  $sort, string  $username = null, integer  $limit = null, integer  $offset) : array

Get registered users.

Parameters

string $sort

Field to sort by

string $username

Only get users with the given username (optional)

integer $limit

Limit amount of Characters (optional)

integer $offset

Offset (optional)

Throws

\nre\exceptions\ParamsNotValidException

Returns

array —

Users

getUsersWithRole()

getUsersWithRole(string  $userrole) : array

Get users with the given user role.

Parameters

string $userrole

User role

Returns

array —

List of users

getUserById()

getUserById(integer  $userId) : array

Get a user and its data by its ID.

Parameters

integer $userId

ID of an user

Throws

\nre\exceptions\IdNotFoundException

Returns

array —

Userdata

getUserByUrl()

getUserByUrl(string  $userUrl) : array

Get a user and its data by its URL-username.

Parameters

string $userUrl

URL-Username of an user

Throws

\nre\exceptions\IdNotFoundException

Returns

array —

Userdata

login()

login(string  $username, string  $password) 

Log a user in if its credentials are valid.

Parameters

string $username

The name of the user to log in

string $password

Plaintext password of the user to log in

Throws

\nre\exceptions\DatamodelException

usernameExists()

usernameExists(string  $username, integer  $userId = null) : boolean

Check if an username already exists.

Parameters

string $username

Username to check

integer $userId

Do not check this ID (for editing)

Returns

boolean —

Whether username exists or not

emailExists()

emailExists(string  $email, integer  $userId = null) : boolean

Check if an e‑mail address already exists.

Parameters

string $email

E‑mail address to check

integer $userId

Do not check this ID (for editing)

Returns

boolean —

Whether e‑mail address exists or not

createUser()

createUser(string  $username, string  $prename, string  $surname, string  $email, string  $password) : integer

Create a new user.

Parameters

string $username

Username of the user to create

string $prename

Prename of the user to create

string $surname

Surname of the user to create

string $email

E‑Mail-Address of the user to create

string $password

Password of the user to create

Returns

integer —

ID of the newly created user

editUser()

editUser(integer  $userId, string  $username, string  $prename, string  $surname, string  $email, string  $password, boolean  $mailing) 

Edit a user.

Parameters

integer $userId

ID of the user to delete

string $username

New name of user

string $prename

Prename of the user to create

string $surname

Surname of the user to create

string $email

Changed e‑mail-address of user

string $password

Changed plaintext password of user

boolean $mailing

Whether to activate mailing or not

Throws

\nre\exceptions\DatamodelException

deleteUser()

deleteUser(integer  $userId) 

Delete a user.

Parameters

integer $userId

ID of the user to delete

hash()

hash(string  $password) : string

Hash a password.

Parameters

string $password

Plaintext password

Returns

string —

Hashed password

loadDriver()

loadDriver(string  $driverName) 

Load the database driver.

Parameters

string $driverName

Name of the database driver

Throws

\nre\exceptions\DriverNotFoundException
\nre\exceptions\DriverNotValidException

connect()

connect(string  $driverName, array  $config) 

Establish a connection to the database.

Parameters

string $driverName

Name of the database driver

array $config

Connection settings

Throws

\nre\exceptions\DatamodelException

getClassName()

getClassName(string  $modelName) : string

Determine the classname for the given Model name.

Parameters

string $modelName

Model name to get classname of

Returns

string —

Classname fore the Model name

loadModels()

loadModels() 

Load the Models of this Model.

Throws

\nre\exceptions\DatamodelException
\nre\exceptions\DriverNotFoundException
\nre\exceptions\DriverNotValidException
\nre\exceptions\ModelNotValidException
\nre\exceptions\ModelNotFoundException

verify()

verify(string  $password, string  $hash) : boolean

Verify a password.

Parameters

string $password

Plaintext password to verify

string $hash

Hashed password to match with

Returns

boolean —

Verified