Class \Scrivo\User

The Scrivo User class represents the user entity in Scrivo.

Access rights to objects like pages and assets are determined using these user principals.

An user is identified by it's object id, but also by it's user code. Convention (but not mandatory) is to use email addresses for user codes. Both the user id and user code can be used to retrieve a user.

The User class defines some descriptive members for the user's name and and email address. For additional user data to store along with a user you can use the multipurose 'customData' field.

Peudo users

The situation that you'll need to autenticate to different user database arises frequently. Since the existence of Scrivo users is a requirement for dertermining access to pages and assest it is suggested to use psuedo users. After autenticating to an other database the user should adopt a predefined (or progamatically defined) Scrivo user to access Scrivo resources. This is already the case for annymous access to Scrivo resources, in that case the user will adopt the Scrivo anymous user identity.

TODO currently object ids 1 and 2 are used for reserved user ids, this is not in line with the policy for object ids. In the code the are patched to the values 3 and 4.

Defined in: User.php.


Constructor summary

Attr. Name / Description
public

User($context)

Create an empty user object.

Constant summary

Name Description
ANONYMOUS_USER_ID Reserved user id for the anonymous user.
PRIMARY_ADMIN_ID Reserved user id for primary admin user.
STATUS_ADMIN Status value indicating an admin user.
STATUS_EDITOR Status value indicating an editor.
STATUS_MEMBER Status value indicating a member.

Properties

Attr. Type Name Description
read-only object $customData A facility for 'free' storage.
\..\String $emailAddress The user's email address.
\..\String $familyName The user's family name.
\..\String $familyNamePrefix A prefix for the user's family name.
\..\String $givenName The user's given name.
read-only int $id The user's user id (DB key)
\..\String $password The user's password (encrypted).
read-only array[] $roles An array of role-ids representing the roles for the user.
int $status The user's status, one out of the constants self::STATUS_*
\..\String $userCode A more descriptive identification for the user than the user id.*

Member summary

Attr. Type Name Description
private \..\Context $context A Scrivo context.
private object $customData A facility for 'free' storage.
private \..\String $emailAddress The user's email address.
private \..\String $familyName The user's family name.
private \..\String $familyNamePrefix A prefix for the user's family name.
private \..\String $givenName The user's given name.
private int $id The user's user id (DB key)
private \..\String $password The user's password (encrypted).
private array[] $roles An array of role-ids representing the roles for the user.
private int $status The user status, one out of the constants self::STATUS_*
private \..\String $userCode A more descriptive identification for the user than the user id.

Method summary

Attr. Type Name / Description
public mixed

__get($name)

Implementation of the readable properties using the PHP magic method __get().

public

__set($name, $value)

Implementation of the writable properties using the PHP magic method __set().

public

assignRoles($roles)

Assign user roles to this user.

public boolean

checkPassword($toTest)

Check if a given password matches with the one of this user.

private

checkUserCode()

Check if the current user code is valid.

public static

delete($context, $id)

Delete existing user data from the database.

private string

encrypt($password)

Encrypt a password.

public static \..\User

fetch($context, $id)

Fetch a user object from the database using the object id or user code.

private \..\UserRole[]

getRoles()

Get the user-roles for this user.

public

insert()

Insert new user object data into the database.

public static int

patchId($id)

Utility to patch legacy ids 1 and 2.

public static \..\User[]

select($context, $roleId)

Select users from the database.

private

setContext($context)

Set the user's context.

private

setEmailAddress($emailAddress)

Set the user's email address

private

setFamilyName($familyName)

Set the user's family name.

private

setFamilyNamePrefix($familyNamePrefix)

Set a prefix for the user's family name.

private

setFields($context, $rd)

Convenience method to set the fields of a user object from an array (result set row).

private

setGivenName($givenName)

Set the user's given name.

private

setPassword($password)

Set the user's password (not encrypted).

private

setStatus($status)

Set the user status, one out of the constants User::STATUS_*

private

setUserCode($userCode)

Set the user code.

public

update()

Update existing user object data in the database.

public

updatePassword()

Update the password of this user.

private

validateDelete($context, $id)

Check if deletion of user object data does not violate any business rules.

private

validateInsert()

Check if this user object can be inserted into the database.

private

validateUpdate()

Check if this user object can be updated in the database.

 


Constructor

public User(\Scrivo\Context $context=null)

Create an empty user object.

Parameters:

Type Name Def. Description
\Scrivo\Context $context null

A Scrivo context.


Constants

ANONYMOUS_USER_ID

Reserved user id for the anonymous user.

Value: 3

PRIMARY_ADMIN_ID

Reserved user id for primary admin user.

Value: 4

STATUS_ADMIN

Status value indicating an admin user.

Value: 1

STATUS_EDITOR

Status value indicating an editor.

Value: 2

STATUS_MEMBER

Status value indicating a member.

Value: 3


Members


				
private \Scrivo\Context $context

A Scrivo context.

Inital value: null


				
private object $customData

A facility for 'free' storage.

Inital value: null


				
private \Scrivo\String $emailAddress

The user's email address.

Inital value: null


				
private \Scrivo\String $familyName

The user's family name.

Inital value: null


				
private \Scrivo\String $familyNamePrefix

A prefix for the user's family name.

Inital value: null


				
private \Scrivo\String $givenName

The user's given name.

Inital value: null


				
private int $id

The user's user id (DB key)

Inital value: 0


				
private \Scrivo\String $password

The user's password (encrypted).

Inital value: null


				
private array[] $roles

An array of role-ids representing the roles for the user.

Inital value: null


				
private int $status

The user status, one out of the constants self::STATUS_*

Inital value: self::STATUS_MEMBER


				
private \Scrivo\String $userCode

A more descriptive identification for the user than the user id.

Inital value: null


Methods

public mixed __get(string $name)

Implementation of the readable properties using the PHP magic method __get().

Parameters:

Type Name Def. Description
string $name

The name of the property to get.

Returns:

mixed Implementation of the readable properties using the PHP magic method __get().

public __set(string $name, mixed $value)

Implementation of the writable properties using the PHP magic method __set().

Parameters:

Type Name Def. Description
string $name

The name of the property to set.

mixed $value

The value of the property to set.

public assignRoles(\Scrivo\UserRole[] $roles)

Assign user roles to this user.

The user roles to set is either an array of UserRole or stdObject objects. stdObject need to contain the members roleId and isPublisher.

Note: this sets all the roles for the user at once. So not giving the the roles effectivily clears the roles for the given user.

Parameters:

Type Name Def. Description
\Scrivo\UserRole[] $roles

A new set of user-roles for the given user.

public boolean checkPassword(\Scrivo\String $toTest)

Check if a given password matches with the one of this user.

Parameters:

Type Name Def. Description
\Scrivo\String $toTest

Password to test.

Returns:

boolean Check if a given password matches with the one of this user.

private checkUserCode()

Check if the current user code is valid.

The user code must be unique in the current database instance and at least three characters in length.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the user code does not comply.
public static delete(\Scrivo\Context $context, int $id)

Delete existing user data from the database.

First it is is checked if it's possible to delete user data, then the user data including its dependecies is deleted from the database.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

a valid object id.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or if it is not possible to delete the user data.
private string encrypt(\Scrivo\String $password)

Encrypt a password.

Parameters:

Type Name Def. Description
\Scrivo\String $password

Returns:

string Encrypt a password.

public static \Scrivo\User fetch(\Scrivo\Context $context, int $id)

Fetch a user object from the database using the object id or user code.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

a valid object id or user code.

Returns:

\Scrivo\User Fetch a user object from the database using the object id or user code.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the given user code was not found (when selecting by user code).
private \Scrivo\UserRole[roleId] getRoles()

Get the user-roles for this user.

Returns:

\Scrivo\UserRole[roleId] Get the user-roles for this user.

public insert()

Insert new user object data into the database.

First it is checked if the data of this user object can be inserted into the database, then the data is inserted into the database. If no id was set a new object id is generated.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data.
public static int patchId(int $id)

Utility to patch legacy ids 1 and 2.

Parameters:

Type Name Def. Description
int $id

The id to patch.

Returns:

int Utility to patch legacy ids 1 and 2.

public static \Scrivo\User[id] select(\Scrivo\Context $context, int $roleId=null)

Select users from the database.

Depending on the given arguments all users or all users for a given role can be retrieved.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $roleId null

Optional role id for which to retrieve the users.

Returns:

\Scrivo\User[id] Select users from the database.

private setContext(\Scrivo\Context $context)

Set the user's context.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

private setEmailAddress(\Scrivo\String $emailAddress)

Set the user's email address

Parameters:

Type Name Def. Description
\Scrivo\String $emailAddress

The user's email address

private setFamilyName(\Scrivo\String $familyName)

Set the user's family name.

Parameters:

Type Name Def. Description
\Scrivo\String $familyName

The user's family name.

private setFamilyNamePrefix(\Scrivo\String $familyNamePrefix)

Set a prefix for the user's family name.

Parameters:

Type Name Def. Description
\Scrivo\String $familyNamePrefix

A prefix for the user's family name.

private setFields(\Scrivo\Context $context, array $rd)

Convenience method to set the fields of a user object from an array (result set row).

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

array $rd

An array containing the field data using the database field names as keys.

private setGivenName(\Scrivo\String $givenName)

Set the user's given name.

Parameters:

Type Name Def. Description
\Scrivo\String $givenName

The user's given name.

private setPassword(\Scrivo\String $password)

Set the user's password (not encrypted).

Parameters:

Type Name Def. Description
\Scrivo\String $password

The user's password (not encrypted).

private setStatus(int $status)

Set the user status, one out of the constants User::STATUS_*

Parameters:

Type Name Def. Description
int $status

The user status, one out of the constants User::STATUS_*

private setUserCode(\Scrivo\String $userCode)

Set the user code.

Parameters:

Type Name Def. Description
\Scrivo\String $userCode

A more descriptive identification for the user than the user id.

public update()

Update existing user object data in the database.

First it is checked if the data of this user object can be updated in the database, then the data is updated in the database.

The user's password cannot be updated with this method. Use User::updatePassword() in order to do that.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data.
public updatePassword()

Update the password of this user.

The password property should be set to its new value. When saving a encrypted value will be stored into the database. When this user object is loaded again its password property will contain the encrypted value for the new password.

Throws:

Exception Type Description
\Scrivo\ApplicationException If one or more of the fields contain invalid data.
private validateDelete(\Scrivo\Context $context, int $id)

Check if deletion of user object data does not violate any business rules.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

a valid object id.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or if it is not possible to delete the user data.
private validateInsert()

Check if this user object can be inserted into the database.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data.
private validateUpdate()

Check if this user object can be updated in the database.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data.

Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013