Page 1 of 1

Set widget:type based on ROLE

PostPosted: Thu Apr 19, 2012 10:16 am
by wisni1rr
Is it possible to set a widget:type based on the role? For Example, The My Profile link will allow you to modify your profile. However I do not want my users to be able to modify their assigned ROLE. I would like the field to appear static for most or the ROLEs. My ADMIN and MANAGER ROLEs should be able to edit the ROLE field.

Thanks for taking the time to read my post!

Re: Set widget:type based on ROLE

PostPosted: Fri Apr 27, 2012 2:59 am
by Jean
Hello Steve,

I have too this kind of problem, how to access to parameters from the fields.ini and change them according to user id or role ?
Here for wisni1rr, it is about the widget type or for me the savepath for a file field.
Steve, how can we do ?

Thank you

Jean

Re: Set widget:type based on ROLE

PostPosted: Sat Apr 28, 2012 10:03 pm
by shannah
This has to be done programatically. Use the init() method of the table delegate class to change the field configuration. This method is called only once per request when the table is initially loaded.

e.g.
Code: Select all
function init(Dataface_Table $table){
    if ( userIsRole1() ){
        $myfield =& $table->getField('myfield');
        $myfield['widget']['type'] = 'select';
    }
}



etc...

-Steve

Re: Set widget:type based on ROLE

PostPosted: Tue May 01, 2012 9:42 am
by wisni1rr
I'm confused on this line:

Code: Select all
if ( userIsRole1() ){


In my case, the role I need to check is DATAINPUT. How would I use the call?

Re: Set widget:type based on ROLE

PostPosted: Wed May 02, 2012 12:28 am
by Jean
Hello,
Have a look on this topic http://xataface.com/forum/viewtopic.php?f=4&t=6734 to see hw to implement the authentication class in your table Delegate Class.
In fact it is a function you create in your table Delegate Class :

Code: Select all
function userIsRole1(){
     $user = $this->getUser();
$role=$user->val('role');
if ($role=='DATAINPUT'){
return TRUE;
}
}


Cheers
Jean