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.
Attr. | Name / Description |
---|---|
public |
User($context) Create an empty user object. |
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. |
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.* |
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. |
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 |
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 |
Update the password of this user. |
|
private |
validateDelete($context, $id) Check if deletion of user object data does not violate any business rules. |
|
private |
Check if this user object can be inserted into the database. |
|
private |
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.
View source: User.php line 177.
Constants
- ANONYMOUS_USER_ID
-
Reserved user id for the anonymous user.
Value: 3
View source: User.php line 104.
- PRIMARY_ADMIN_ID
-
Reserved user id for primary admin user.
Value: 4
View source: User.php line 99.
- STATUS_ADMIN
-
Status value indicating an admin user.
Value: 1
View source: User.php line 84.
- STATUS_EDITOR
-
Status value indicating an editor.
Value: 2
View source: User.php line 89.
- STATUS_MEMBER
-
Status value indicating a member.
Value: 3
View source: User.php line 94.
Members
- private \Scrivo\Context $context
-
A Scrivo context.
Inital value: null
View source: User.php line 170.
- private object $customData
-
A facility for 'free' storage.
Inital value: null
View source: User.php line 164.
- private \Scrivo\String $emailAddress
-
The user's email address.
Inital value: null
View source: User.php line 152.
- private \Scrivo\String $familyName
-
The user's family name.
Inital value: null
View source: User.php line 146.
- private \Scrivo\String $familyNamePrefix
-
A prefix for the user's family name.
Inital value: null
View source: User.php line 140.
- private \Scrivo\String $givenName
-
The user's given name.
Inital value: null
View source: User.php line 134.
- private int $id
-
The user's user id (DB key)
Inital value: 0
View source: User.php line 110.
- private \Scrivo\String $password
-
The user's password (encrypted).
Inital value: null
View source: User.php line 128.
- private array[] $roles
-
An array of role-ids representing the roles for the user.
Inital value: null
View source: User.php line 158.
- private int $status
-
The user status, one out of the constants self::STATUS_*
Inital value: self::STATUS_MEMBER
View source: User.php line 116.
- private \Scrivo\String $userCode
-
A more descriptive identification for the user than the user id.
Inital value: null
View source: User.php line 122.
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: User.php line 201.
- 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: User.php line 224.
- 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.
View source: User.php line 679.
- 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.
View source: User.php line 583.
- 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. View source: User.php line 385.
- 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. View source: User.php line 640.
- private string encrypt(\Scrivo\String $password)
-
Encrypt a password.
Parameters:
Type Name Def. Description \Scrivo\String $password Returns:
string Encrypt a password.
View source: User.php line 418.
- 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). View source: User.php line 697.
- private \Scrivo\UserRole[roleId] getRoles()
-
Get the user-roles for this user.
Returns:
\Scrivo\UserRole[roleId] Get the user-roles for this user.
View source: User.php line 292.
- 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. View source: User.php line 445.
- 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.
View source: User.php line 277.
- 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.
View source: User.php line 771.
- private setContext(\Scrivo\Context $context)
-
Set the user's context.
Parameters:
Type Name Def. Description \Scrivo\Context $context A Scrivo context.
View source: User.php line 373.
- private setEmailAddress(\Scrivo\String $emailAddress)
-
Set the user's email address
Parameters:
Type Name Def. Description \Scrivo\String $emailAddress The user's email address
View source: User.php line 364.
- private setFamilyName(\Scrivo\String $familyName)
-
Set the user's family name.
Parameters:
Type Name Def. Description \Scrivo\String $familyName The user's family name.
View source: User.php line 355.
- 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.
View source: User.php line 346.
- 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.
View source: User.php line 246.
- private setGivenName(\Scrivo\String $givenName)
-
Set the user's given name.
Parameters:
Type Name Def. Description \Scrivo\String $givenName The user's given name.
View source: User.php line 337.
- 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).
View source: User.php line 328.
- 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_*
View source: User.php line 305.
- 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.
View source: User.php line 319.
- 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. View source: User.php line 508.
- 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. View source: User.php line 555.
- 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. View source: User.php line 619.
- 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. View source: User.php line 430.
- 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. View source: User.php line 491.
Documentation generated by phpDocumentor 2.0.0a12 and ScrivoDocumentor on August 29, 2013