Class \Scrivo\Role

Class that represents a system role class.

Access to pages and assets is restricted through roles. Users can be registered to one or more roles as well as objects (pages and assets). Do one or more roles of the object and the user match an access level higher than the default for the user is granted.

When access is granted, a distiction is made in editor roles and public roles. A user with User::STATUS_EDITOR can only be registered to one or more Role::EDITOR_ROLE-s, a user with status User::STATUS_MEMBER only to one or more User::PUBLIC_ROLE-s.

For role matching see \Scrivo\AccessController.

TODO currently object ids 1 and 2 are used for system roles, this is not in line with the policy for object ids.

Defined in: Role.php.


Constructor summary

Attr. Name / Description
public

Role($context)

Create an empty role object.

Constant summary

Name Description
EDITOR_ROLE Constant to denote an editor role.
PUBLIC_ROLE Constant to denote a public role.

Properties

Attr. Type Name Description
\..\String $description A descriptive name for this role.
read-only int $id The role id (DB key).
\..\String $title The role title.
int $type The role type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE

Member summary

Attr. Type Name Description
private \..\Context $context A Scrivo context.
private \..\String $description A descriptive name for this role.
protected int $id The role id (DB key).
private \..\String $title The role title.
private int $type The role type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE

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 static

delete($context, $id)

Delete existing role data from the database.

public static \..\Role

fetch($context, $id)

Fetch a role object from the database using its object id.

public

insert()

Insert new role object data into the database.

public static \..\Role[]

select($context, $type)

Select roles from the database.

private

setDescription($description)

Set the descriptive name for this role.

protected

setFields($context, $rd)

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

private

setTitle($title)

Set the role title.

private

setType($type)

Set the role's type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE.

public

update()

Update existing role object data in the database.

private static

validateDelete($context, $id)

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

private

validateInsert()

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

private

validateUpdate()

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

 


Constructor

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

Create an empty role object.

Parameters:

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

A Scrivo context.


Constants

EDITOR_ROLE

Constant to denote an editor role.

Value: 2

PUBLIC_ROLE

Constant to denote a public role.

Value: 3


Members


				
private \Scrivo\Context $context

A Scrivo context.

Inital value: null


				
private \Scrivo\String $description

A descriptive name for this role.

Inital value: null


				
protected int $id

The role id (DB key).

Inital value: 0


				
private \Scrivo\String $title

The role title.

Inital value: null


				
private int $type

The role type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE

Inital value: self::PUBLIC_ROLE


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 static delete(\Scrivo\Context $context, int $id)

Delete existing role data from the database.

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

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

The object id of the role to select.

Throws:

Exception Type Description
\Scrivo\ApplicationException If the data is not accessible or if it is not possible to delete the role data.
public static \Scrivo\Role fetch(\Scrivo\Context $context, int $id)

Fetch a role object from the database using its object id.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

The object id of the role to select.

Returns:

\Scrivo\Role Fetch a role object from the database using its object id.

public insert()

Insert new role object data into the database.

First it is checked if the data of this role 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 \Scrivo\Role[id] select(\Scrivo\Context $context, int $type)

Select roles from the database.

Depending on the given arguments the public or editor roles can be retrieved.

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $type

A role type: \Scrivo\Role::PUBLIC_ROLE or \Scrivo\Role::EDITOR_ROLE for which to retrieve the roles.

Returns:

\Scrivo\Role[id] Select roles from the database.

private setDescription(\Scrivo\String $description)

Set the descriptive name for this role.

Parameters:

Type Name Def. Description
\Scrivo\String $description

A descriptive name for this role.

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

Convenience method to set the fields of a role 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 setTitle(\Scrivo\String $title)

Set the role title.

Parameters:

Type Name Def. Description
\Scrivo\String $title

The role's title.

private setType(int $type)

Set the role's type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE.

Parameters:

Type Name Def. Description
int $type

The role's type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE.

public update()

Update existing role object data in the database.

First it is checked if the data of this role object can be updated in the database, then the data is 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.
private static validateDelete(\Scrivo\Context $context, int $id)

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

Parameters:

Type Name Def. Description
\Scrivo\Context $context

A Scrivo context.

int $id

The object id of the role to select.

Throws:

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

Check if this role 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 role 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