# \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

File
  models/UsersModel.inc
Package
  Default
Class hierarchy
  \nre\core\Model
  \nre\models\DatabaseModel
  \hhu\z\Model
  \hhu\z\models\UsersModel

## Tags

author | Oliver Hanraths oliver.hanraths@uni-duesseldorf.de

## Properties

### $db

    $db : \nre\models\DatabaseDriver

Database connection

#### Type

\nre\models\DatabaseDriver

#

Inherited from
  \nre\models\DatabaseModel

## Tags

static |

## Methods

### __construct()

    __construct()

Construct a new UsersModel.

TODO Catch exception

#

## Tags

None found

### load()

    load(string  $modelName)

Load the class of a Model.

#### Parameters

string | $modelName | Name of the Model to load

#### Throws

\nre\core\ModelNotFoundException
\nre\core\ModelNotValidException

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### factory()

    factory(string  $modelName)

Instantiate a Model (Factory Pattern).

#### Parameters

string | $modelName | Name of the Model to instantiate

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### 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

#

## Tags

None found

### 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

\hhu\z\models\ParamsNotValidException

#### Returns

array —

Users

#

## Tags

None found

### getUsersWithRole()

    getUsersWithRole(string  $userrole) : array

Get users with the given user role.

#### Parameters

string | $userrole | User role

#### Returns

array —

List of users

#

## Tags

None found

### getUserById()

    getUserById(integer  $userId) : array

Get a user and its data by its ID.

#### Parameters

integer | $userId | ID of an user

#### Throws

\hhu\z\models\IdNotFoundException

#### Returns

array —

Userdata

#

## Tags

None found

### getUserByUrl()

    getUserByUrl(string  $userUrl) : array

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

#### Parameters

string | $userUrl | URL-Username of an user

#### Throws

\hhu\z\models\IdNotFoundException

#### Returns

array —

Userdata

#

## Tags

None found

### 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

\hhu\z\models\DatamodelException

#

## Tags

None found

### 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

#

## Tags

None found

### 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

#

## Tags

None found

### createUser()

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

Create a new user.

#### Parameters

string | $username | Username of the user to create
| $prename |
| $surname |
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

#

## Tags

None found

### editUser()

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

Edit a user.

#### Parameters

integer | $userId | ID of the user to delete
string | $username | New name of user
| $prename |
| $surname |
string | $email | Changed e‑mail-address of user
string | $password | Changed plaintext password of user
| $mailing |

#### Throws

\hhu\z\models\DatamodelException

#

## Tags

None found

### deleteUser()

    deleteUser(integer  $userId)

Delete a user.

#### Parameters

integer | $userId | ID of the user to delete

#

## Tags

None found

### hash()

    hash(string  $password) : string

Hash a password.

#### Parameters

string | $password | Plaintext password

#### Returns

string —

Hashed password

#

## Tags

None found

### loadDriver()

    loadDriver(string  $driverName)

Load the database driver.

#### Parameters

string | $driverName | Name of the database driver

#### Throws

\nre\models\DriverNotFoundException
\nre\models\DriverNotValidException

#

Inherited from
  \nre\models\DatabaseModel

## Tags

None found

### 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\models\DatamodelException

#

Inherited from
  \nre\models\DatabaseModel

## Tags

None found

### 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

#

static

Inherited from
  \nre\core\Model

## Tags

None found

### loadModels()

    loadModels()

Load the Models of this Model.

#### Throws

\nre\core\DatamodelException
\nre\core\DriverNotFoundException
\nre\core\DriverNotValidException
\nre\core\ModelNotValidException
\nre\core\ModelNotFoundException

#

Inherited from
  \nre\core\Model

## Tags

None found

### 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

#

## Tags

None found

### UsersModel.inc