2. Follow Along With Code
Example
1. Download a copy of the example code at
www.prodigyview.com/source.
2. Install the system in an environment you feel comfortable
testing in.
3. Proceed to examples/user/UserRoles.php
3. Overview
Objective
Learn to create, update, delete, user roles. Also learn how
to assign users to a role
Requirements
Install version of ProdigyView with a database
connection
Understanding of basic user management
Estimated Time
10 Minutes
www.prodigyview.com
4. What are roles?
A user’s ability to access an area can either be restricted by a
user’s access levels or a user’s roles. Roles are more complex
than access levels in that a user can have multiple roles that
they belong too. In this tutorial we will be covering:
1. Creating A Role
2. Assigning a Role to A User
3. Updating a Role
4. Searching for a Role
5. Removing A role
Limiting access by a role is discussed in the security tutorial on
roles and access level.
5. Creating A Role
Roles are created with only a few simple arguments, the
only required arguments being the name of the role. The
arguments are passed as an array into
PVUsers::addUserRole
1. Arguments for defining the role 2. Pass arguments to create
role and return the roles id
www.prodigyview.com
6. Adding/Removing A Role
From User
User roles do not any good if they are just sitting there. So
lets assign them to a user using the function
addUserToRole().
1. The id of the user to add to the role
2. The name of the role
7. Updating A Role Part 1
Whoops we made a boo-boo and spelt something wrong
and need to update the role. First we need to start out by
getting the role from the database. The role can either be
retrieved by the name or the id.
1. Retrieve the roles data by 2. Retrieve the roles data by the name of the
the role id role
3. The roles information returned in an array
8. Updating A Role Part 2
Now that we have the role, and most importantly the role
id, lets update the role. Change the fields you want to in
the array and pass it to updateUserRole function.
Update complete.
1. Change information the role
2. Pass array to update method
9. Finding User Roles
Now we want to search for user roles. In the slide on
creating a user role we set a role_type.Lets search on
that field. What will be returned is an array of roles that we
can iterate through. Like any other list, PV Standard
Search Arguments are used.
1. Search the user roles based on type
2. Returns an array of arrays of
user role information
3. Iterate through the roles to retrieve information of each
role that matches the arguments passed
10. Deleting A Role
Deleting a role is relatively simple task. Simply pass the
role ID to deleteUserRole and the role will no longer
exist.
www.prodigyview.com
11. The Not So Obvious
1. Retrieving the role information by the role name
seems nice but if you have two roles with the same
name, this will be a problem because it will only pick
one of them.
2. To get the roles assigned to a user, use the
PVUsers::getAssignedUserRole()
www.prodigyview.com
12. Challenge!
We know how to create a user role and how to add a role
to a user.
Create the roles ‘Administrator’ and ‘Super Administrator’
3x times. When adding the roles, give a different
role_type too each(site_1, site_2, site_3). Add the user
ONLY to the roles that have the role_type being site_2.
www.prodigyview.com
13. API Reference
For a better understanding of the users, visit the api by
clicking on the link below.
PVUsers
More Tutorials
For more tutorials, please visit:
http://www.prodigyview.com/tutorials
www.prodigyview.com