Class \Scrivo\UserRole
Class that represents a user-role relation.
The User-Role relationship is a 0 to n relation of Scrivo users and Scrivo roles. This relation can carry an additional entity: the publisher status. This status is only relevant for editor roles and determines if an editor is allowed to publish data in an staging environment.
Note that both static methods are also exposed through the User::getRoles() and User::assignRoles($roles) methods. This class should not be considered part of the public API but as private to the User class.
Extends
\Scrivo\Role .
Defined in:
UserRole.php.
Attr. | Name / Description |
---|---|
public |
UserRole($context) Create an empty role object. |
Name | Description |
---|---|
EDITOR_ROLE | Constant to denote an editor role. |
PUBLIC_ROLE | Constant to denote a public role. |
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 | boolean | $isPublisher | The publisher status. |
private | \..\String | $title | The role title. |
private | int | $type | The role type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE |
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 | \..\UserRole[] |
select($context, $user) Select the user-roles for a given user. |
public static |
set($context, $user, $roles) Set the user roles for a given user. |
|
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). |
|
public |
setIsPublisher($status) Set the publisher status for this user-role relation. |
|
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 |
Check if this role object can be inserted into the database. |
|
private |
Check if this role object can be updated in the database. |
Constructor
- public UserRole(\Scrivo\Context $context=null)
-
Create an empty role object.
Inherited from \Scrivo\Role
Parameters:
Type Name Def. Description \Scrivo\Context $context null A Scrivo context.
View source: Role.php line 109.
Constants
- EDITOR_ROLE
-
Constant to denote an editor role.
Inherited from \Scrivo\Role
Value: 2
View source: Role.php line 72.
- PUBLIC_ROLE
-
Constant to denote a public role.
Inherited from \Scrivo\Role
Value: 3
View source: Role.php line 67.
Members
- private \Scrivo\Context $context
-
A Scrivo context.
Inherited from \Scrivo\Role
Inital value: null
View source: Role.php line 102.
- private \Scrivo\String $description
-
A descriptive name for this role.
Inherited from \Scrivo\Role
Inital value: null
View source: Role.php line 96.
- protected int $id
-
The role id (DB key).
Inherited from \Scrivo\Role
Inital value: 0
View source: Role.php line 78.
- private boolean $isPublisher
-
The publisher status.
View source: UserRole.php line 56.
- private \Scrivo\String $title
-
The role title.
Inherited from \Scrivo\Role
Inital value: null
View source: Role.php line 90.
- private int $type
-
The role type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE
Inherited from \Scrivo\Role
Inital value: self::PUBLIC_ROLE
View source: Role.php line 84.
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().
View source: UserRole.php line 66.
- 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.
View source: UserRole.php line 80.
- 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.
Inherited from \Scrivo\Role
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. View source: Role.php line 321.
- public static \Scrivo\Role fetch(\Scrivo\Context $context, int $id)
-
Fetch a role object from the database using its object id.
Inherited from \Scrivo\Role
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.
View source: Role.php line 356.
- 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.
Inherited from \Scrivo\Role
Throws:
Exception Type Description \Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data. View source: Role.php line 226.
- public static \Scrivo\UserRole[roleId] select(\Scrivo\Context $context, \Scrivo\User $user)
-
Select the user-roles for a given user.
Depending on the given arguments the public or editor roles can be retrieved.
Parameters:
Type Name Def. Description \Scrivo\Context $context A connection to a Scrivo database.
\Scrivo\User $user A user to create the user-roles for.
Returns:
\Scrivo\UserRole[roleId] Select the user-roles for a given user.
View source: UserRole.php line 110.
- public static set(\Scrivo\Context $context, \Scrivo\User $user, array $roles)
-
Set the user roles for a given user.
The user roles to set is either an array of UserRole or stdClass objects. stdClass need to contain the members id 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\Context $context A connection to a Scrivo database.
\Scrivo\User $user A user to set the user-roles for.
array $roles A new set of user-roles for the given user.
View source: UserRole.php line 160.
- private setDescription(\Scrivo\String $description)
-
Set the descriptive name for this role.
Inherited from \Scrivo\Role
Parameters:
Type Name Def. Description \Scrivo\String $description A descriptive name for this role.
View source: Role.php line 202.
- protected setFields(\Scrivo\Context $context, array $rd)
-
Convenience method to set the fields of a role object from an array (result set row).
Inherited from \Scrivo\Role
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.
View source: Role.php line 162.
- public setIsPublisher(boolean $status)
-
Set the publisher status for this user-role relation.
Parameters:
Type Name Def. Description boolean $status The publisher status.
View source: UserRole.php line 93.
- private setTitle(\Scrivo\String $title)
-
Set the role title.
Inherited from \Scrivo\Role
Parameters:
Type Name Def. Description \Scrivo\String $title The role's title.
View source: Role.php line 193.
- private setType(int $type)
-
Set the role's type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE.
Inherited from \Scrivo\Role
Parameters:
Type Name Def. Description int $type The role's type, \Scrivo\Role::EDITOR_ROLE or \Scrivo\Role::PUBLIC_ROLE.
View source: Role.php line 179.
- 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.
Inherited from \Scrivo\Role
Throws:
Exception Type Description \Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data. View source: Role.php line 270.
- private static validateDelete(\Scrivo\Context $context, int $id)
-
Check if deletion of role object data does not violate any business rules.
Inherited from \Scrivo\Role
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. View source: Role.php line 304.
- private validateInsert()
-
Check if this role object can be inserted into the database.
Inherited from \Scrivo\Role
Throws:
Exception Type Description \Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data. View source: Role.php line 212.
- private validateUpdate()
-
Check if this role object can be updated in the database.
Inherited from \Scrivo\Role
Throws:
Exception Type Description \Scrivo\ApplicationException If the data is not accessible or one or more of the fields contain invalid data. View source: Role.php line 257.
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013