Welcome to dbFreaks.com!
FAQFAQ      ProfileProfile    Private MessagesPrivate Messages   Log inLog in

Design question: User objects and a Role object

 
   Database Help (Home) -> PHP RSS
Next:  combining different databases into 1 large with s..  
Author Message
Anthony Smith

External


Since: Jan 11, 2008
Posts: 9



(Msg. 1) Posted: Thu Oct 09, 2008 9:31 am
Post subject: Design question: User objects and a Role object
Archived from groups: comp>lang>php (more info?)

I have a user object that is set when a user logs in. There are also
permissions that I get about the user from a web service. Currently I
take the results from those web services and store them as XML in the
user object so I can parse it when I need to look at them. I wanted to
turn the xml permissions into ROle objects, but does that mean that my
User class needs to make reference to the Role class?

User class example

class User{

protected $firstName;
protected $lastName;
protected $employeeNumber;
protected $orgCode;
protected $roles; //Could this be an object of my class Role?
protected $scope;
protected $type;
protected $primaryAssignmentsXML = null;
protected $securityRolesXML = null;

.... getters ad setters



getRole(roleName){
//get the securityRolesXML and then parse it setting the Role
Object

$role = new Role();
$role->setName();
$role->setFunction();


return $role;
}


Is this how I should be going about this?

 >> Stay informed about: Design question: User objects and a Role object 
Back to top
Login to vote
R. Rajesh Jeba Anb1

External


Since: Jun 15, 2004
Posts: 49



(Msg. 2) Posted: Thu Oct 09, 2008 10:30 am
Post subject: Re: Design question: User objects and a Role object [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

On Oct 9, 9:31 pm, Anthony Smith <mrsmi....TakeThisOut@hotmail.com> wrote:
> I have a user object that is set when a user logs in. There are also
> permissions that I get about the user from a web service. Currently I
> take the results from those web services and store them as XML in the
> user object so I can parse it when I need to look at them. I wanted to
> turn the xml permissions into ROle objects, but does that mean that my
> User class needs to make reference to the Role class?
>
> User class example
>
> class User{
>
> protected $firstName;
> protected $lastName;
> protected $employeeNumber;
> protected $orgCode;
> protected $roles; //Could this be an object of my class Role?
> protected $scope;
> protected $type;
> protected $primaryAssignmentsXML = null;
> protected $securityRolesXML = null;
>
> .... getters ad setters
>
> getRole(roleName){
> //get the securityRolesXML and then parse it setting the Role
> Object
>
> $role = new Role();
> $role->setName();
> $role->setFunction();
>
> return $role;
> }
>
> Is this how I should be going about this?

Theoretically looks ok. But, practically you'll end up deeper
object chains which might need caching to improve performance.

--
<?php echo 'Just another PHP saint'; ?>
Email: rrjanbiah-at-Y!com Blog: http://rajeshanbiah.blogspot.com/

 >> Stay informed about: Design question: User objects and a Role object 
Back to top
Login to vote
Jerry Stuckle

External


Since: Aug 11, 2004
Posts: 3463



(Msg. 3) Posted: Thu Oct 09, 2008 1:31 pm
Post subject: Re: Design question: User objects and a Role object [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Anthony Smith wrote:
> I have a user object that is set when a user logs in. There are also
> permissions that I get about the user from a web service. Currently I
> take the results from those web services and store them as XML in the
> user object so I can parse it when I need to look at them. I wanted to
> turn the xml permissions into ROle objects, but does that mean that my
> User class needs to make reference to the Role class?
>

Yes, the user will have zero or more roles, so it has to be able to
access the role class.

> User class example
>
> class User{
>
> protected $firstName;
> protected $lastName;
> protected $employeeNumber;
> protected $orgCode;
> protected $roles; //Could this be an object of my class Role?
> protected $scope;
> protected $type;
> protected $primaryAssignmentsXML = null;
> protected $securityRolesXML = null;
>
> .... getters ad setters
>
>
>
> getRole(roleName){
> //get the securityRolesXML and then parse it setting the Role
> Object
>
> $role = new Role();
> $role->setName();
> $role->setFunction();
>
>
> return $role;
> }
>
>
> Is this how I should be going about this?
>

Yes, it $roles could be an object of type Role. But also bear in mind a
user may have several roles - i.e. authorized user, power user, admin,
etc., each with its own permissions. You'll want to plan for this, also.

Of course, if you have a straight hierarchy (each higher role includes
all of the permissions of all the roles below it), then you could get by
with only one role. But that can be hard to change if you should have
to someday create a role which doesn't match that hierarchy.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex.TakeThisOut@attglobal.net
==================
 >> Stay informed about: Design question: User objects and a Role object 
Back to top
Login to vote
Display posts from previous:   
   Database Help (Home) -> PHP All times are: Pacific Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum



[ Contact us | Terms of Service/Privacy Policy ]